P.S: This is just a study guide. The questions may not appear exactly like this.
1. If a module is useful and well written, you may want to use it more than once within a program. This is known as _____. (Points : 3)
reusability
reliability
scalability
abstraction
2. A _____ is used to identify the relationships between modules within a program. (Points : 3)
relationship chart
flowchart
hierarchy chart
All of the above
3. What datatype is being passed to the function based on the following Visual Basic function declaration?
Public Function doSomething(input as Integer) As String (Points : 3)
Integer
String
Public
Input
4. What is the output of the following Visual Basic code if the numbers input are 20 and then 10?
Sub Main()
Dim n1, n2, temp As Integer
Console.Write(“Enter a number: “)
n1 = Console.ReadLine
Console.Write(“Enter a number: “)
n2 = Console.ReadLine
Console.WriteLine(n1 & “ and ” & n2)
temp = goofy(n1, n2)
Console.WriteLine(“The answer is ” & temp)
End Sub
Public Function goofy(x As Integer, y As Integer) As Integer
Dim ans As Integer
If x > y Then
ans = 2 * (x – y)
ElseIf (x < y) Then
ans = 2 * (x + y)
Else
ans = x + y
End If
Return ans
End Function
(Points : 4)
5. Write a Visual Basic function called Compare to compare two numbers and return a code that indicates their relationship: 0 if they are equal, 1 if the first number is larger, and -1 if the first number is smaller. Your main module should prompt the user for the two numbers and pass them to the function. The result is printed in your main module.
The output should look like this (note that it should work for any values that are input; these are just examples).
Enter a number: 10
Enter a number: 21
10 is smaller than 21 (Points : 7)