Makeup Quiz - Answers

CSE100, Autumn 2000
This quiz is 20 points total.

  1. What is the value of y after the following Visual Basic statements are executed?
    Dim y As Integer
    
    y = 10
    
    If y>5 Then
        y = 1
    Else
        y = 20
    End If
    
    If y>5 Then
      y = 100
    End If
    
    
    The value of y is 1.

  2. Suppose we have an integer array x, declared as follows.
    Dim x(0 To 10) As Integer
    
    Write Visual Basic statements to set each element in the array to 100. (Hint: note that the array bounds start at 0!)

    Dim i As Integer
    For i=0 to 10
      x(i) = 100
    Next i
    
    

  3. Consider the following Visual Basic statements. How many squids does this print?
    Dim i As Integer, j As Integer
    For i=1 to 100
      For j=1 to 20
        Print "squid"
      Next j
    Next i
    

    2000 squids!

  4. What is the output generated when the Form_Click event handler runs?
    Private Sub Form_Click()
      Dim x As Integer
      x = 10
      Call clam(x)
      Print x
    End Sub
    
    Private Sub clam(y As Integer)
      y = y*2
    End Sub
    
    The output is:
    20
    

  5. Suppose that you have a lot of CDs and a lot of friends. You also sometime loan CDs to friends. The information you want to keep track of for friends is the first and last name, phone, and e-mail; for CDs the artist, title, and cost; and for loans which CD you loaned, who borrowed it, and when.

    Here is a design for a database to keep track of this information. Is this a good design? If not, why not, and what should be done to improve it?

    There are three tables: Friends, CDs, and Loans.

    Friends has the following fields: FriendID (the key), FirstName, LastName, Phone, and Email.

    CDs has the following fields: Artist (the key), Title, and Cost.

    Loans has the following fields: LoanID (the key), FirstName, LastName, Artist, and Date. (FirstName and LastName is the first and last name of the friend who borrowed the CD, and Artist is the artist or group who recorded it. Date is when you loaned the CD.)

    There are two problems with the design. First, the tuples in the CDs table need to have a unique key -- you might have several CDs recorded by the same artist. So we add a field CDID to the CDs table. Second, the Loans table has redundant information, including FirstName and LastName (redundant with Friends). If we stop using Artist as the key in CDs, the Artist field is also redundant. Replace these fields with FriendID and CDID.