Quiz 4 - Answers

CSE100, Autumn 2000
This quiz is 20 points total.

  1. How many elements are there in the following array?
    Dim x(1 To 10, 1 To 20) As Integer
    
    There are 200 elements.

  2. Suppose we have an integer array x, declared as follows.
    Dim x(1 To 10, 1 To 20) As Integer
    
    Write Visual Basic statements to set each element in the array to 100.

    Dim i As Integer, j As Integer
    For i=1 to 10
       For j=1 to 20
          x(i,j) = 100
       Next j
    Next i
    
    

  3. What does it mean to say that a computer is "universal"?

    Universality: Any problem solvable by some computer can be solvable by any computer

  4. What is the output generated when the Form_Click event handler runs?
    Private Sub Form_Click()
      Call octopus(3,10)
    End Sub
    
    Private Sub octopus(a As Integer, b As Integer)
      Call jellyfish(a)
      Call jellyfish(b)
    End Sub
    
    Private Sub jellyfish(k As Integer)
      Print k+k
    End Sub
    
    The output is:
    6
    20
    

  5. Write a procedure "cube" that takes two parameters, which are both integers. It should set the second parameter to the cube of the first parameter. For example, if you evaluate the following:
    Call cube(2,x)
    
    x will be set to 8. If you evaluate cube with a different argument:
    Call cube(5,x)
    
    then x will be set to 125. Include the proper header for the procedure.

    Here's the procedure:

    Private Sub cube(a As Integer, c As Integer)
      c = a*a*a
    End Sub