COSC 2409
Fall 2001
Exam 1 Answers
For each of the following questions choose (a) for true and (b) for false, and code your choice in the
answer sheet.
1.
True - Although a flowchart (as its name suggests) depicts data flow very well, it is not easily modified
once written.
2.
False - The following two statements are equivalent.
num1 = num2
num2 = num1
3.
False - The following If block is valid.
If a < b Or > c Then
picBox.Print a
End If
4.
True - The End If statement may be omitted if the If statement is written on a single line.
5.
True - One may use a Select Case block within an If block.
6.
False - Changing a control's Caption property also changes how you refer to the control in code.
7.
False - Given that x = 7, y = 2, and z = 4, the following If block will display "TRUE".
If (x > y) And (y > z) Then
picBox.Print "TRUE"
End If
8.
False - A hierarchy chart is the same thing as a flowchart.
9.
False - The following statements assign the lowercase letters to the string variable alphabet.
Dim alphabet As String
alphabet = abcdefghijklmnopqrstuvwxyz
For each of the following questions choose the best possible answer from choices (a) through (d), and
code your choice in the answer sheet.
10. Which of the following is the proper order of procedures used in the problem-solving process?
(A)
(B)
*(C)
(D)
Design, analysis, coding, testing
Analysis, testing, design, coding
Analysis, design, coding, testing
Analysis, design, testing, coding
11. The process of finding and correcting errors in a program is called
(A)
*(B)
(C)
(D)
pseudocoding.
debugging.
algorithms.
development cycles.
12.
Which is the correct assignment statement for the following equation?
y=
a+b
_______
b
---- – d
c
(A)
*(B)
(C)
(D)
13.
y = a + b / (b / c) - d
y = (a + b) / (b / c - d)
y = (a + b / b / c) - d
None of the above
A user action such as clicking a command button is called:
(A)
*(B)
(C)
(D)
An accident
An event
A procedure
A property
14. The Cls method removes text and graphics from a
*(A)
(B)
(C)
(D)
picture box.
text box.
label.
command button.
15. Assume that x, y, and temp are numeric variables. Which of the following lines of code swaps the
values of x and y?
(A)
x = y
y = x
(B)
x = temp
x = y
y = temp
*(C) temp = x
x = y
y = temp
(D)
x = y
temp = x
y = temp
16. The symbol for the string concatenation operator is
(A)
*(B)
(C)
(D)
17.
@
&
%
#
Visual Basic can require all variables to be declared by which of the following statements?
(A)
*(B)
(C)
(D)
Option Declare
Option Explicit
Dim All
None of the above
18. Suppose a file has been opened with reference number 2. Which of the following statements assigns a
value from the file to the variable person?
(A)
*(B)
(C)
(D)
person = Input #2
Input #2, person
person = InputBox(2)
Input #2 = person
19. Given the data in the string variable y shown below, which of the following statements will assign the
value ALL to the string variable x?
y = "WHEN ALL ELSE FAILS, READ THE DIRECTIONS"
*(A)
(B)
(C)
(D)
x
x
x
x
=
=
=
=
Mid(y, 6, 3)
Mid(6, y, "ALL")
Left(y, 3)
Middle(y, 6, 3)
20. 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, z As Single
x = 3
y = 3
If x > y Then
z = x + y
Else
z = y - x
End If
picBox.Print z
End Sub
(A)
(B)
*(C)
(D)
6
3
0
No output
21. What is the problem (if any) with the following Select Case block which is intended to determine the
price of a movie depending on the patron's age?
Private Sub cmdButton_Click()
age = Val(InputBox("Enter your age:"))
Select Case age
Case Is >= 65
'Senior citizen
price = 4.50
Case Is >= 5
'Regular price
price = 6.00
Case Is >= 0
'Child (no charge with parents)
price = 0
Case Else
picBox.Print "Entry error"
End Select
End Sub
(A) Everyone will get in free at the child rate.
(B) The output will always be "Entry error."
(C) The Case Is statements have bad syntax.
*(D) There is nothing wrong.
22. In analyzing the solution to a program, you conclude that you want to construct a loop so control
leaves the loop either when a < 12 or when b = 16. Using a Do loop, the test condition should be
(A) Do While (a > 12) Or (b <>16)
*(B) Do While (a >= 12) Or (b <> 16)
(C) Do While (a < 12) Or (b <> 16)
(D) Do While (a < 12) And (b = 16)
23. When the number of repetitions needed for a set of instructions is known before they are executed in a
program, the best repetition structure to use is a(n)
(A) Do While...Loop structure.
(B) Do...Loop Until structure.
*(C)For...Next loop.
(D) If block with a GoTo statement.
24. Which statement prompts the user for a name and then assigns the name to the string variable
strName?
*(A) strName = InputBox("What is your first name?", "First Name")
(B) strName = Msgbox "What is your first name?", "First Name"
(C) InputBox("What is your first name?", "First Name")= strName
(D) Msgbox "What is your first name?", "First Name" = strName
25. Which of the following program segments will sum all the numbers read in? Assume the data file has
been open for input as #1.
For k = 1 To 8
Input #1, s
s = s + k
Next k
(B) For k = 1 To 8
Input #1, a
s = s + 1
Next k
(C) For k = 1 To 8
Input #1, a
a = a + s
Next k
(D) For k = 1 To 8
Input #1, s
s = k + a
Next k
*(E) None of the above
(A)
26. Federal law requires hourly employees be paid “time-and-a-half” for work in excess of 40 hours per
week. For example, if a person’s hourly wage is $8 and he works 60 hours in a week, his gross pay
should be
(40 * 8) + (1.5 * 8 * (60 – 40)) = $560
Write a program that requests as input the number of hours a person works in a given week and his
hourly wage, and then displays his gross pay. Include a form caption of Pay Computation and format
the pay to currency.
Turn in a printout of your code, and your program on a diskette.
Private Sub cmdCalcOvertime_Click()
Dim hours As Single, pay As Single
Dim total As Single
'Compute gross pay, including "time-and-a-half"
'for overtime
picWages.Cls
hours = Val(txtHours.Text)
'Hours worked
pay = Val(txtHourlyPay.Text)
'Hourly pay
If hours <= 40 Then
total = pay * hours
Else
total = pay * 40 + 1.5 * pay * (hours - 40)
End If
picWages.Print "You get paid ";
FormatCurrency(total)
End Sub
© Copyright 2026 Paperzz