Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 18

Final Exam

Name: _______________________________________________ Score: _________________

Write the letter of your chosen answer on the answer sheet.

1. A collection of lines of instruction is called a(n)


(A) program.
(B) algorithm.
(C) system.
(D) programmer.

2. Software refers to the people who work with computer hardware. (T/F)

3. Which of the following is the proper order of procedures used in the problem-solving
process?
(A) design, analysis, coding, testing
(B) analysis, testing, design, coding
(C) analysis, design, coding, testing
(D) analysis, design, testing, coding
(E) design, testing, analysis, coding

4. Although the documentation step is usually listed last in the problem-solving process, it
should actually begin when the problem is first defined and continue through the problem-
solving process. (T/F)

5. If you are writing a program that needs to repeat a series of calculations, what programming
structure should you use to repeat the calculations?
(A) sequence structure
(B) decision structure
(C) looping structure

1
(D) unconditional branching

6. A flowchart is an arrangement of geometric shapes connected by arrows. (T/F)

7. The purpose of a test or decision in a looping structure is to tell when the loop should end.
(T/F)

8. Press F5 to
(A) run a program.
(B) display the Properties window.
(C) display the Solution Explorer window.
(D) terminate a program.

9.In Visual Basic, tooltips assist by showing a small caption about the purpose of each icon
on the Toolbar. How do you make a tooltip appear?
(A) Right click the Toolbar icon, select purpose from the available options.
(B) Position the mouse pointer over the icon for a few seconds, the tooltip will appear.
(C) Hold your shift key, then click the appropriate Toolbar icon to display its purpose.
(D) Hold your Alt key, then click the appropriate Toolbar icon to display its purpose.

10. The Font dialog box allows you to select different Fonts, their style, their size,
and some other special effects. How do you bring up this Font dialog box?
(A) In the Properties window, click the ellipsis (…) on the right side of the settings box for
the Font property.
(B) Double-click the control, and select Font Property.
(C) Right-click the control, and select Font Property.
(D) None of the above.

11. What would be a good name for a text box to hold a person’s first name?
(A) txtFirstName
(B) FirstName

2
(C) txt First Name
(D) First Name

12. Which property is available for most controls that allows you to hide/unhide them
either manually by setting the property or by setting it during run time via code?
(A) Clear
(B) Refresh
(C) Visible
(D) View-Control

13. When working with text boxes, the sizing handles allow you to resize the object
by dragging to make it wider or narrower. (T/F)

14. When the user clicks a button, _________ is triggered.


(A) an event
(B) a method
(C) a setting
(D) a property

15. When will the following event procedure be executed?


Private Sub txtBox_TextChanged(...) Handles txtBox.TextChanged

(A) when text is added to the text box


(B) when text is deleted from the text box
(C) when text is modified inside the text box
(D) all of the above

16. Visual Basic responds to events using which of the following?


(A) a code procedure

3
(B) an event procedure
(C) a form procedure
(D) a property

17. What will be the contents of the variable x after the following statement is executed?
x = Math.Sqrt(((9 + 7) / (4 * 2)) + 2)

(A) 1
(B) 2
(C) 3
(D) 4
(E) None of the above

18. What will be displayed when the following lines are executed?
Dim x As Double = 3, y As Double = 1
Dim z As Double
z = x + (y * x)
x = y
z = x + z
lstBox.Items.Add(x + y + z)

(A) 4
(B) 9
(C) 10
(D) None of the above

4
19. The following statement is valid. (T/F)
y = y + 72

20. A numeric variable that has not been assigned a value has the value zero. (T/F)

21. The following two statements are equivalent, where numVar is a numeric variable. (T/F).
numVar = numVar + 1
numVar += 1

22. Which of the following statements will NOT display the number 5 in the text box?
(A) txtBox.Text = 5
(B) txtBox.Text = "5"
(C) txtBox.Text = CStr("5")
(D) txtBox.Text = CStr(5)

23. Which of the following expressions has as its value the value of strVar with its leading and
trailing spaces removed?
(A) strVar.Length
(B) strVar.ToUpper
(C) strVar.Ctrim
(D) strVar.Trim

24. Given the data assigned to 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) x = y.Substring(5)
(B) x = y.IndexOfStr("ALL")
(C) x = y.Substring(6, 3)

5
(D) x = y.Substring(5, 3)

25. What will be the output of the following lines?


Dim alphabet, soup As String
alphabet = "abcdefghijklmnopqrstuvwxyz"
soup = alphabet.ToUpper
txtBox.Text = alphabet.Substring(0, 5) & soup.Substring(0, 5)

(A) abcdeABCDE
(B) ABCDEABCDE
(C) eE
(D) EE

26. What will be the value of numVar when the following code is executed?
Dim strVar As String, numVar As Integer
strVar = "Now is the time for all good men"
numVar = strVar.IndexOf("the time for")

(A) "Now is all good men"


(B) "12"
(C) 7
(D) 8

27. What will be displayed when the following lines are executed?
Dim a, b, c As String
a = "THE WHOLE"

6
b = "PART"
c = a.Substring(CInt(Math.Sqrt(4)), b.Length)
txtBox.Text = CStr(c)

(A) THE WHOLE PART


(B) 6
(C) E WH
(D) HE W

28. The symbol for the string concatenation operator is


(A) @
(B) &
(C) %
(D) #

29. Option Explicit requires you to declare every variable before its use. (T/F)

30. Which format statement should be used when you want to output your results in tabular
format with the first column 10 characters wide, the second 5, and the third 10?
(A) Dim fmtStr as String = "{10}{5}{10}"
(B) Dim fmtStr as String = "{0}{1}{2}"
(C) Dim fmtStr as String = "{0, 10}{1, 5}{2, 10}"
(D) Dim fmtStr as String = "{0, 10; 1, 5; 2, 10}"

31. After the statement


Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")

has been executed, which of the following statements will close the file?

7
(A) "DATA.TXT".Close()
(B) Close "DATA.TXT"
(C) sr.Close()
(D) Close sr

32. Suppose you are 20 years old, num is an integer variable, and the statement
num = 1 + CInt(InputBox("How old are you?"))

is executed and responded to? What will be the output of


txtBox.Text = num & " years old"

(A) 1 + "How old are you?"


(B) Syntax error
(C) 20 years old
(D) 21 years old

33. What will be the output of the following statement?


txtBox.Text = FormatCurrency(1234.567)

(A) $1234.567
(B) 1,234.57
(C) $1234.57
(D) $1,234.57

34. Which statement is true?


(A) "Ford" < "Ford"
(B) “Chevy” > “Chevy”

8
(C) “GMC” <= “GMC”
(D) “Oldsmobile” < “Oldsmobile”

35. When is the expression “Not cond1” true?


(A) when cond1 is false.
(B) when cond1 is true.
(C) when cond1 is either true or false.
(D) none of the above.

36. Which value for x would make the following condition true: (x >= 5) And (x <= 6)
(A) x is equal to 7
(B) x is equal to 5
(C) x is equal to 5.001
(D) B and C

37. Assume that A, B, and C are conditions, with A being true, B being true, and C being false.
Give the truth value of each of the following conditions.
(a) A And (Not B)
(b) A And Not (B Or C)
(c) Not (A And B)

38. Consider the following program.


Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim x, y, z As Double
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
x = CDbl(sr.ReadLine)

9
y = CDbl(sr.ReadLine)
z = CDbl(sr.ReadLine)
If ((x > y) Or (x > z)) And (z >= 100) Then
txtBox.Text = "Hello, "
Else
txtBox.Text = "Good-bye, "
End If
sr.Close()
txtBox.Text &= "Larry."
End Sub

Which of the following sets of data in the three lines of the file DATA.TXT will produce the
output "Hello, Larry."?
(A) 2, 3, 101
(B) 3, 2, 100
(C) 2, 3, 100
(D) 3, 2,4

39. What will be the output of the following program when the button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim x, y, z As Double
x = 3
y = 3
If x > y Then
z = x + y
Else
z = y - x
End If
txtBox.Text = CStr(z)
End Sub

(A) 6
(B) 3
(C) 0
(D) No output

40. Constructs in which an If block is contained inside another If block are called:
(A) multi-If blocks
(B) nested If blocks
(C) sequential If blocks
(D) none of the above

41. The Else part of an If block may be omitted if no action is associated with it. (T/F)

42. Which Case clause will be true whenever the value of the selector in a Select Case block is
greater than or equal to 7?
(A) Case Is >7
(B) Case Is = 8
(C) Case Is >= 7
(D) Case Is <= 8

10
43. One may use an If block within a Select Case block. (T/F)

44. One may use a Select Case block within an If block. (T/F)

45. Every Select Case block can be replaced by If blocks. (T/F)

46. What will be the output of the following program when the button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim word As String
word = "progression"
Strange(word)
End Sub
Sub Strange(ByVal var As String)
txtBox.Text = var.Substring(CInt(Int(var.Length / 2)), 1)
End Sub

(A) progr
(B) r
(C) e
(D) progre

47. The ______________ of a Sub procedure are vehicles for passing numbers and strings to the
Sub procedure.
(A) Call statements
(B) arguments
(C) parameters
(D) variables declared inside

48. What will be the output of the following program when the button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim word As String
word = "hairbrush"
Decapitate ((word))
txtBox.Text = word
End Sub
Sub Decapitate(ByRef word As String)
'Chop the first letter off the word.
word = word.Substring(1)
End Sub

(A) airbrush
(B) hairbrush
(C) hairbrus
(D) h

49. When the button is clicked, the output of the following program will be 20. (T/F)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim num As Integer = 20
DoubleIt(num)

11
txtBox.Text = CStr(num)
End Sub
Sub DoubleIt(ByRef var As Integer)
var = var * 2
End Sub

50. Which of the following names would be best for the following Function (called NoName)?
Function NoName(ByVal number As Double) As Double
Return number ^ 3 + number ^ 3
End Function

(A) SquareAndCube
(B) CubeAndCube
(C) CubeAndSquare
(D) DoubleAndCube

51. Function procedures are different from Sub procedures because functions return a single
value. (T/F)

52. 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. (T/F)

53. What numbers will be displayed in the list box when the button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim num as Double = 10
Do While num > 1
lstBox.Items.Add(num)
num = num - 3
Loop
End Sub

(A) 10, 7, and 4


(B) 10, 7, 4, and 1
(C) 10, 7, 4, 1, and -2
(D) No output

54. What is wrong with the following Do While loop?


Dim index As Integer = 1
Do While index <> 10
lstBox.Items.Add("Hello")
index += 2
Loop

(A) It should have been written with a Do Until loop.


(B) It is an infinite loop.
(C) The test variable should not be changed within the loop itself.
(D) Nothing

55. When Visual Basic executes a Do While loop it first checks the truth value of the
_________.

12
(A) pass
(B) loop
(C) condition
(D) statement

56. The following two sets of code produce the same output. (T/F)
Dim num As Integer = 1 Dim num As Integer = 1
Do While num <=5 Do
lstBox.Items.Add("Hello") lstBox.Items.Add("Hello")
num += 1 num += 1
Loop Loop Until (num > 5)

57. What will be displayed by the following program when the button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim letter As String, s As String = ""
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
letter = sr.ReadLine
Do While letter <> "q"
s = letter & s
letter = sr.ReadLine
Loop
txtBox.Text = s
End Sub

The seven lines of the file DATA.TXT contain the following data: n, o, p, q, r, s, t.
(A) rst
(B) pon
(C) nop
(D) qpon

58. What will be the output of the following program when the button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim num as Double, sum As Double = 0
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
Do While sr.Peek <> -1
num = CDbl(sr.ReadLine)
sum += num
Loop
sr.Close()
txtBox.Text = CStr(sum)
End Sub

The three lines of the file contain the following data: 2, 9, 32.
(A) 12
(B) 43
(C) a run-time error
(D) 0

59. What is wrong with the following simple password program where today's password is
"intrepid"?

13
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim password As String
password = InputBox("Enter today's password:")
Do
lstBox.Items.Add("Incorrect")
password = InputBox("Enter today's password:")
Loop Until password = "intrepid"
lstBox.Items.Add("Password Correct. You may continue.")
End Sub

(A) There is no way to re-enter a failed password.


(B) The Loop Until condition should be passWord <> "intrepid".
(C) It will display "Incorrect." even if the first response is "intrepid".
(D) Nothing

60. How many times will “HI” be displayed when the following lines are executed?
Dim c As Integer = 12
Do
lstBox.Items.Add("HI")
c += 3
Loop Until (c >= 30)

(A) 5
(B) 9
(C) 6
(D) 4
(E) 10

61. What will be displayed by the following program when the button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim j, k As Double
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
j = CDbl(sr.ReadLine)
Do While (j < 5)
k = CDbl(sr.ReadLine)
If k < j Then
j= CDbl(sr.ReadLine)
End If
Loop
txtBox.Text = CStr(k)
End Sub

Assume the six lines of the file DATA.TXT contain the following entries: 3, 4, 1, 5, 2, 6.
(A) 1
(B) 2
(C) 3
(D) 4
(E) 5

62. __________ calculate the number of elements in lists.


(A) Flags

14
(B) Counters
(C) Accumulators
(D) Nested loops

63. _________ calculate the sums of numerical values in lists.


(A) Flags
(B) Counters
(C) Accumulators
(D) Nested loops

64. ___________ can be used to determine when the end of a text file has been reached.
(A) A flag
(B) The Peek method
(C) An accumulator
(D) A nested loop

65. When the streamreader sr reaches the end of a file, sr.Peek has what value?
(A) 0
(B) 1
(C) –1
(D) None of the above

66. A Do…Loop Until block is always executed at least once. (T/F)

67. After the following Dim statement is executed, how many subscripted variables called
myvar(i) will be available?
Dim myVar(7) As Double

(A) 0
(B) 1
(C) 8
(D) 9

68. Which statement is true regarding the following Dim statement?


Dim state(49) As String, population(49) As Double

(A) It is invalid since more than one array is dimensioned by a single Dim statement.
(B) It is invalid since the two arrays must have the same data type.
(C) The subscripts of state() range from 1 to 49.
(D) The subscripts of population() range from 0 To 49.

69. What will be displayed when the following program segment is executed?
Dim a(4) As Double
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
For k As Integer = 0 To 4
a(k) = CDbl(sr.ReadLine)
Next

15
sr.Close()
txtBox.Text = CStr(a(3))

Assume the five rows of the file DATA.TXT contain the following entries: 3, 2, 5, 1, 4.
(A) 1
(B) 2
(C) 3
(D) 4

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


Dim numbers(3) As Double, h As Double = 0
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
For i As Integer = 0 To 3
numbers(i) = CDbl(sr.ReadLine)
Next
sr.Close()
For k As Integer = 0 to 3
h += numbers(k)
Next
txtBox.Text = CStr(h)

Assume the four rows of the file DATA.TXT contain the following entries: 2, 4, 2, 3
(A) 11
(B) 2
(C) 7
(D) 4

71. Write a program that requests a complete phone number in a text box and then displays the
area code in another text box when the button is pressed.

72. A copy center charges 5 cents per copy for the first 100 copies and 3 cents per copy for each
additional copy. Write a program that request the number of copies as input and displays the
total cost (Test the program with quantities of 25 and 125).

73. Construct a user-defined function to carry out the primary task of the program: According to
Plato, a man should marry a woman whose age is half his age plus seven years. Write a
program that requests a man’s age as input and gives the ideal age of his wife.

16
17
Final Exam—Answer Sheet for Multiple Choice

Name:__________________________________________________ Score: ____________

1. ______ 2. ______ 3. ______ 4. ______

5. ______ 6. ______ 7. ______ 8. ______

9. ______ 10. ______ 11. ______ 12. ______

13. ______ 14. ______ 15. ______ 16. ______

17. ______ 18. ______ 19. ______ 20. ______

21. ______ 22. ______ 23. ______ 24. ______

25. ______ 26. ______ 27. ______ 28. ______

29. ______ 30. ______ 31. ______ 32. ______

33. ______ 34. ______ 35. ______ 36. ______

37. ______ 38. ______ 39. ______ 40. ______

41. ______ 42. ______ 43. ______ 44. ______

45. ______ 46. ______ 47. ______ 48. ______

49. ______ 50. ______ 51. ______ 52. ______

53. ______ 54. ______ 55. ______ 56. ______

57. ______ 58. ______ 59. ______ 60. ______

61. ______ 62. ______ 63. ______ 64. ______

65. ______ 66. ______ 67. ______ 68. ______

69. ______ 70. ______

18

You might also like