Вы находитесь на странице: 1из 6

Cs116- REVISION Questions – Done By:Mr.

Mustafa Radaideh – Final Revisions

For each of the following questions choose (a) for true and (b) for false, and code your choice in the
answer sheet.

1. Each argument in a Call statement must have the same name as the corresponding parameter in the
corresponding Sub statement.

2. A Sub procedure can call another Sub procedure.

3. Both Sub and Function procedures are accessed through the Call statement.

4. When a general sub procedure is used, the number of arguments must equal the number of parameters.

5. Suppose you want to write a procedure that takes three numbers, num1, num2, and num3; and returns
their sum, product, and average. It is best to use a Function procedure for this task.

6. One disadvantage of using arrays is they cannot easily be passed to procedures.

7. Parallel arrays are two or more arrays that have corresponding elements.

8. The statement Dim state(50)has the same effect as the statement Dim state(1 To 50).

9. Consider the following Dim and assignment statements for myArray(). The assignment statement will
cause a "Subscript out of range" error.
Dim myArray(1 To 50) As Single
myArray(34) = 51

10. Consider the following sub procedure declaration.


Private Sub MyProcedure(var1 As Single, var2 As Single, var3 As Single)

Arguments passed to this sub procedure are passed by value rather than by reference.

For each of the following questions choose the best possible answer from choices (a) through (d), and
code your choice in the answer sheet.

11. What is wrong with the following Call statement and its corresponding Sub statement?

Call MyProcedure("The Jetsons", 1000, 209.53)


Private Sub MyProcedure(var1 As Single, var2 As Single, var3 As
Single)
(A) It is not valid to pass something like "The Jetsons."
(B) Constant values like 1000 cannot be passed, only variables.
(C) Var1 is not of the same data type as "The Jetsons."
(D) Nothing is wrong with them.
Cs116- REVISION Questions – Done By:Mr. Mustafa Radaideh – Final Revisions

12. What will be displayed when the command button is clicked?


Private Sub cmdButton_Click()
Dim x As String, y As String
x = "tin"
y = "can"
Call DOCS116(x, y)
picOutput.Print x; " "; y
End Sub
Sub DOICS116 (x As String, ByVal y As String)
Dim temp As String
temp = x
x = y
y = temp
End Sub
(A) tin can
(B) can tin
(C) tin tin
(D) can can

13. 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 procedure.

14. What will be the output of the following program when the command button is clicked?
Private Sub cmdButton_Click()
Dim var1 As Integer, var2 As Integer, var3 As Integer, num As
Integer
var1 = 2
var2 = 4
var3 = 6
Call Add(num)
picBox.Cls
picBox.Print num
End Sub
Private Sub Add(num As Integer)
Dim var1 As Integer, var2 As Integer, var3 As Integer
num = var1 + var2 + var3
End Sub
(A) 0
(B) 12
(C) 6
(D) None of the above
Cs116- REVISION Questions – Done By:Mr. Mustafa Radaideh – Final Revisions

15. What will be the output of the following program when the command button is clicked?
Private Sub cmdButton_Click()
Dim number As Single
picBox.Cls
number = 3
Call SquareAndDouble(number)
picBox.Print number
End Sub
Private Sub SquareAndDouble(myVar As Single)
myVar = myVar myVar
myVar = myVar + myVar
End Sub
(A) 3
(B) 18
(C) 36
(D) 0

16. Consider the following event procedure that calls a user-defined function named Cube, which
returns the cube of a number.
Private Sub cmdButton_Click()
Dim num As Single, result As Single
num = Val(InputBox("Enter a number to cube:"))
result = Cube(num)
picBox.Print "The cube of"; num; "is"; result
End Sub
Which of the following is a correct Function definition for Cube?
1. Private Function Cube(var As Single) As Single
Cube = var ^ 3
End Function

2. Private Function Cube(num As Single) As Single


Cube = num ^ 3
End Function
(A) 1 only
(B) 2 only
(C) Both 1 and 2
(D) Neither 1 nor 2
Cs116- REVISION Questions – Done By:Mr. Mustafa Radaideh – Final Revisions

17. What will be the output of the following program when the command button is clicked?
Private Sub cmdButton_Click()
Dim word As String, result As String
picBox.Cls
word = "Benjamin"
result = Rotate(word)
result = Rotate(result & word)
result = Rotate(result)
picBox.Print result
End Sub
Private Function Rotate(var As String) As String
Dim varlength As Integer
varlength = Len(var)
Rotate = Mid(var, 2, varlength - 1) & Left(var, 1)
End Function
(A) jaminBBenjaminen
(B) BenjaminBenjamin
(C) njaminBe
(D) No output.

18. The arguments appearing in a call statement must match the parameters in the appropriate Sub or
Function statement in all but one of the following ways. Which one?
(A) Number of arguments
(B) Names of arguments
(C) Data type of arguments
(D) Order of arguments

19. After the following Dim statement, how many subscripted variables called myvar(i) will be
available?
Dim myvar(3 To 8) As Single
(A) 5
(B) 6
(C) 7
(D) 8

20. Which of the following is NOT a valid Dim statement?


(A) Dim myArray(0 To 1) As String
(B) Dim bigarray(100) As Single
(C) Dim numbers(4 To 1) As Single
(D) Dim values(-3 To 3) As Integer
Cs116- REVISION Questions – Done By:Mr. Mustafa Radaideh – Final Revisions

21. What is the output of the following program when the command button is clicked?
Private Sub cmdButton_Click()
Dim i As Integer, nom(1 To 5) As String
Open "DATA.TXT" For Input As #1
For i = 1 To 5
Input #1, nom(i)
Next i
Close #1
picBox.Cls
For i = 5 To 1 Step -2
picBox.Print nom(i); " ";
Next i
End Sub
Contents of DATA.TXT: "Bach", "Borodin", "Brahms", "Beethoven", "Britain"
(A) Bach Brahms Britain
(B) Britain Beethoven Brahms Borodin Bach
(C) Bach Borodin Brahms Beethoven Britain
(D) Britain Brahms Bach

22. What is the output of the following program segment?


Dim numbers(1 To 4) As Single, h As Single, i As Integer, k As
Integer
h = 0
Open "DATA.TXT" For Input As #1
For i = 1 To 4
Input #1, numbers(i)
Next i
Close #1
For k = 1 to 4
h = h + numbers(k)
Next k
picBox.Cls
picBox.Print h
Contents of DATA.TXT: 2, 4, 2, 3
(A) 11
(B) 2
(C) 7
(D) 4
Cs116- REVISION Questions – Done By:Mr. Mustafa Radaideh – Final Revisions

23. What is the output of the following program segment?


Dim numbers(0 To 4) As Single, i As Integer, k As Integer
Open "DATA.TXT" For Input As #1
For i = 0 To 4
Input #1, numbers(i)
Next i
Close #1
For k = 1 To 3
numbers(k + 1) = numbers(k + 1) + numbers(k)
Next k
picBox.Cls
picBox.Print numbers(4)
Contents of DATA.TXT: 3, 6, 4, 8, 3
(A) 10
(B) 21
(C) 18
(D) 11

24. Given the Dim statement below, which set of statements will initialize all elements of myArray()
to 100?
Dim myArray(0 To 100) As Single
(A) myArray = 100
(B) For i = 0 To 100
(i) = 100
Next i
(C) For j = 0 to 100
myArray(j) = 100
Next j
(D) myArray() is already initialized to 100 by the ReDim statement.

25. Form_Load is which of the following?


(A) A command to load a new copy of the form.
(B) An event procedure that executes when the program runs the first time.
(C) A method of loading pictures or text onto the form.
(D) An event procedure that is automatically executed at the beginning of the program.

Вам также может понравиться