Quiz 3 - Answers

CSE100, Autumn 2000
This quiz is 20 points total.

  1. What is printed when the following Visual Basic statements are executed?
    Dim x As Integer
    x = 5
    Do While x > 0
      Print x
      x = x-1
    Loop
    
    5
    4
    3
    2
    1
    

  2. Write a Do While loop in Visual Basic that will print out the even numbers between 2 and 100 inclusive (i.e. 2, 4, 6, ... 98, 100).
    Dim i As Integer
    i = 2
    Do While i <= 100
      Print i
      i = i+2
    Loop
    

  3. What is the output generated when the Form_Click event handler runs?
    Private Sub Form_Click()
      Call squid(10,20)
      Call clam(0)
    End Sub
    
    Private Sub squid(i As Integer, j As Integer)
      Call clam(i)
      Call clam(j)
    End Sub
    
    Private Sub clam(k As Integer)
      Print k+3
    End Sub
    
    13
    23
    3
    

  4. Write a procedure "twice" that takes two parameters, which are both strings. It should set the second parameter to a new string, which is the first string repeated. For example, if you evaluate the following:
    Call twice("octopus ",x)
    
    x will be set to "octopus octopus ". Include the proper header for the procedure. (Hint: & is the string concatenation operator. You will want to use it in writing your procedure.)

    Private Sub twice(in As String, out As String)
      out = in & in
    End Sub
    
  5. In the DayFinder project (Project 1 Part 3), how many times does the program have to ask "Were you born between ..." to know the exact birthday? Circle the correct answer below. (Hint: let's say that after picking the sign, there are initially 31 possible days the player could be born. After one guess, there are 16 days. Then how many possible days are there after two guesses?) 5 is the correct answer.