Quiz 2 - Answers

CSE100, Autumn 2000
This quiz is 20 points total.

  1. How is the meaning of "=" in an assignment statement, such as x=x+1 in Visual Basic, different from the meaning of "=" in algebra?

    In Visual Basic, "=" is the assignment operator. It means that the expression on the right hand side is evaluated, and the result is stored in the variable on the left hand side. So in the statement x=x+1, the expression x+1 is evaluated (using the current value of x), and the result is stored back in x (thus changing the value of x).

    In algebra, "=" means that the two sides of the equation must be equal. There isn't any notion of changing the value of a variable as you go. So in algebra, x=x+1 is just an unsatisfiable equation.

  2. What is the value of x after the following Visual Basic statements are executed?
    Dim x As Integer
    x = 10
    x = 3+x*4
    x = x-1
    
    42

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

  4. What is the value of x after calling the procedure Squid?
    Dim x As Integer
    
    Private Sub squid ()
      x = 0
      Call clam
      Call clam
    End sub
    
    Private Sub clam
      x = x+3
    End sub
    
    6

  5. What was the timer control used for in Part 1 of Project 1?

    The timer control is used to call a procedure every second that updates the displayed time.