Test 2
comp 125-609, Goldwasser
Tuesday, 16 November 1999

Name: _________________________

For each question, please Circle the one correct answer. If I can't tell which ONE is circled, it will unfortunately be marked wrong.
1. How many elements are in the array delcared by
Dim myArray(0 To 3, 1 To 3, 1 to 4) as Single
(A) 10
(B) 11
(C) 36
(D) 48

2. Assume that array num(1 to 2, 1 to 3) has been initialized as shown.
  |  1   2   3 
--+------------
1 |  5   3   1
2 |  2   6   4
What is the output of the following program segment?
For row = 1 to 2
  For col = 1 to 2
    If num(row,col) > num(row,col+1) then
      temp = num(row,col)
      num(row,col) = num(row,col+1)
      num(row,col+1) = temp)
    End If
  Next col
Next row
picBox.Cls
picBox.Print num(1,2)
(A) 1
(B) 2
(C) 3
(D) 5
















3. A programmer wants to have a global array of Integers which will be read from a datafile. Unfortunately she does not know how many integers to be read (and thus the necessary array size) at design time. Assuming that when reading the file, she learns that size is the number of integers, what is the correct sequence of commands for declaring the array?
(A) Use
  Dim MyArray() As Integer
at the top of the code, and then
  Dim MyArray(1 to size) As Integer
inside the procedure that reads the file.

(B) Use
  ReDim MyArray() As Integer
at the top of the code, and then
  ReDim MyArray(1 to size) As Integer
inside the procedure that reads the file.

(C) Use
  Dim MyArray() As Integer
at the top of the code, and then
  ReDim MyArray(1 to size) As Integer
inside the procedure that reads the file.

(D) Use
  ReDim MyArray() As Integer
at the top of the code, and then
  Dim MyArray(1 to size) As Integer
inside the procedure that reads the file.











4. Assume that we want a control array of 10 command buttons which appear on the screen with each one immediately BELOW the previous one. We will place the first control at design time and name it cmd(1). What line should appear in place of "[----------]" to make the following work?
Private Sub Form_Load()
  Dim X As Integer

  For X = 2 to 10 Do
    Load cmd(X)
    [----------]
    cmd(X).Visible = True
  Loop
End Sub
(A) cmd(X).Left = cmd(X-1).Left + cmd(X-1).Width
(B) cmd(X).Left = cmd(X-1).Right + cmd(X-1).Width
(C) cmd(X).Top = cmd(X-1).Top + cmd(X-1).Height
(D) cmd(X).Top = cmd(X-1).Bottom + cmd(X-1).Height

5. Which is the property that uniquely identifies a particular control in a control array?
(A) Control
(B) Index
(C) Load
(D) Tab

6. What will be the output of the following program when the command button is clicked? (be careful when answering)
Private Sub cmdbutton_Click()
  Dim word1 As String, word2 As String, word3 As String
  picBox.Cls
  word1 = "First"
  word2 = "Second"
  word3 = "Third"
  Call Myproc(word1,word2,word3)
End Sub

Private Sub Myproc(var3 As String, var2 As String, var1 As String)
  picbox.Print var1; var2; var3
End Sub
(A) FirstSecondThird
(B) SecondThirdFirst
(C) ThirdSecondFirst
(D) ThirdFirstSecond



7. What will be the output of the following program when the command button is clicked? (again, be careful in answering)
Private Sub cmdbutton_Click()
  Dim w as Long, x as Long, y as Long, z as Long
  w = 1
  x = 2
  y = 3
  z = 4
  Call Mix(w,x,y,z)
End Sub

Private Sub Mix(x as Long, y as Long, z as Long, w as Long)
  Call Scramble(w,x,y,z)
End Sub

Private Sub Scramble(y as Long, z as Long, w as Long, x as Long)
  PicBox.Print w
End Sub

(A) 1
(B) 2
(C) 3
(D) 4

8. Suppose the variable myName is declared in a Dim statement in two different Sub procedures. Which statement is true?
(A) The program will malfunction when it is executed
(B) When the value of myName is changed in one Sub procedure, it will also be changed in the other Sub procedure
(C) Visual Basic's smart editor will alert you that this is an error before the program is executed
(D) The two variables will be local to their respective Sub procedures

9. What will be the output of the following program when the command button is clicked?
Private Sub cmdbutton_Click()
  Dim x as Single, y as Single, result as Single
  x = 2
  y = 8
  Print Calculate(x,y,result)
End Sub

Private Function Calculate(byRef a as Integer, byRef b as Integer, _
                           byRef result as Integer) as Single
  result = a / b
  Calculate = a - b
End Sub

(A) -6
(B) 0.25
(C) 4
(D) 6

10. What will be displayed when the command button is clicked? (this question tests your knowledge of using ByRef and ByVal)
Private Sub cmdButton_Click()
  Dim x As String, y As String
  x = "tin"
  y = "can"
  Call Mystery(x, y)
  picOutput.Print x; " "; y
End Sub

Sub Mystery(ByRef x As String, ByVal y As String)
  Dim temp As String
  temp = x
  x = y
  y = temp
End Sub
(A) can can
(B) can tin
(C) tin can
(D) tin tin

11. What line should appear in place of "[----------]" in the following code, in order to produce the given picture when the command button is clicked?
Private Sub Command_Click()
  Picture1.Scale (0, 0)-(100, 100)
  [----------]
End Sub
(A) Picture1.Line (50, 50)-(0, 50)
(B) Picture1.Line (50, 50)-(50, 0)
(C) Picture1.Line (50, 50)-(100, 50)
(D) Picture1.Line (50, 50)-(50, 100)



12. What line should appear in place of "[----------]" in the following code, in order to produce the given picture when the command button is clicked?
Private Sub Command_Click()
  [----------]
  Picture1.Line (50,0)-(0, 50)
End Sub
(A) Picture1.Scale (0, 0)-(100, 100)
(B) Picture1.Scale (100, 0)-(0, 100)
(C) Picture1.Scale (0, 100)-(100, 0)
(D) Picture1.Scale (100, 100)-(0, 0)

13. What line should appear in place of "[----------]" in the following code, in order to produce the given picture when the command button is clicked?
Private Sub Command_Click()
  Picture1.Scale (0, 0)-(100, 100)
  [----------]
End Sub
(A) Picture1.Line (25, 25)-(75, 75)
(B) Picture1.Line (25, 25)-(75, 75), , B
(C) Picture1.Line (25, 25)-(75, 75), , F
(D) Picture1.Line (25, 25)-(75, 75), , BF

14. What line should appear in place of "[----------]" in the following code, in order to produce the given picture when the command button is clicked?
Private Sub Command_Click()
  Dim WHOLE As Single
  WHOLE = 8*atn(1)    ' WHOLE=2*PI
  Picture1.Scale (0, 0)-(100, 100)
  Picture1.Circle (50, 50), 20
  [----------]
End Sub
(A) Picture1.Circle (50,50), 25, , 0.00*WHOLE, 0.25*WHOLE
(B) Picture1.Circle (50,50), 25, , 0.25*WHOLE, 0.00*WHOLE
(C) Picture1.Circle (50,50), 25, , 0.25*WHOLE, 0.50*WHOLE
(D) Picture1.Circle (50,50), 25, , 0.50*WHOLE, 0.25*WHOLE

15. Which of the replacements for "[----------]" does NOT produce the given picture when the command button is clicked?
Private Sub Command_Click()
  Picture1.Scale (0, 0)-(100, 100)
  [----------]
End Sub
(A) Picture1.Line (25, 25)-(25, 75), , BF
(B) Picture1.Line (75, 25)-(25, 75), , BF
(C) Picture1.Line (25, 75)-(75, 25), , BF
(D) Picture1.Line (75, 75)-(25, 25), , BF

16. Which of the replacements for "[----------]" does NOT produce the given picture when the command button is clicked?
Private Sub Command_Click()
  Picture1.Scale (0, 0)-(100, 100)
  Picture1.CurrentX = 50
  Picture1.CurrentY = 25
  [----------]
End Sub
(A) Picture1.Line (50,25)-(75,50)
(B) Picture1.Line -(75,50)
(C) Picture1.Line Step(0,0)-(25,25)
(D) Picture1.Line (50,25)-Step(25,25)

17. Assume that insertion sort (as described in class) is used to sort the following initial array from smallest to largest:
    16,  3, 21, 22, 43,  2, 17, 25.
What is the content of the array after the first pass of the method?
(A)
2,  3, 21, 22, 43, 16, 17, 25
(B)
3, 16, 21, 22, 43,  2, 17, 25
(C)
3, 16, 21, 22,  2, 43, 17, 25
(D)
3, 16, 21, 22,  2, 17, 25, 43






18. Assume that selection sort (as described in class) is used to sort the following initial array from smallest to largest:
    16,  3, 21, 22, 43,  2, 17, 25.
What is the content of the array after the first pass of the method?
(A)
2,  3, 21, 22, 43, 16, 17, 25
(B)
3, 16, 21, 22, 43,  2, 17, 25
(C)
3, 16, 21, 22,  2, 43, 17, 25
(D)
3, 16, 21, 22,  2, 17, 25, 43

19. Assume that bubble sort (as described in class) is used to sort the following initial array from smallest to largest:
    16,  3, 21, 22, 43,  2, 17, 25.
What is the content of the array after the first pass of the method?
(A)
2,  3, 21, 22, 43, 16, 17, 25
(B)
3, 16, 21, 22, 43,  2, 17, 25
(C)
3, 16, 21, 22,  2, 43, 17, 25
(D)
3, 16, 21, 22,  2, 17, 25, 43











20. Assume that merge sort (as described in class) is used to sort the following initial array from smallest to largest:
    16,  3, 21, 22, 43,  2, 17, 25.
What is the content of the array after the first pass of the method?
(A)
2,  3, 21, 22, 43, 16, 17, 25
(B)
3, 16, 21, 22, 43,  2, 17, 25
(C)
3, 16, 21, 22,  2, 43, 17, 25
(D)
3, 16, 21, 22,  2, 17, 25, 43