Sei sulla pagina 1di 10

Repaso del Cap. 4: Using Looping Structures and Lists – Koneman.

net 1

Multiple-Choice Questions

1. Which looping statement is used to repeat a statement or procedure a specific number


of times?
a. For…Next
b. For…Each…Next
c. Do…Loop
d. While

2. Which statement can you use as an accumulator?


a. decYTDGross += decGross
b. decYTDGross = decGross
c. intTotalScore = intScore
d. decTotalGrades = + decGrade

3. What is the major difference between a ListBox and a ComboBox?


a. A ComboBox displays a list of items.
b. A ListBox does not include a TextBox for data entry.
c. A ListBox includes a TextBox for data entry.
d. None of the above

4. Which of the following is an advantage of a Combo box?


a. It saves space on a form.
b. It always displays a full list.
c. It prevents data entry.
d. It enables you to display multiple lists.

5. Which form control would you use to limit data entry to a predefined list of items?
a. Combo box
b. Text box
c. Items box
d. List box

6. What is the purpose of the SelectionMode property in a list box?


a. specifies what items in a list can be selected
b. specifies what items in a list that are selected
c. specifies how items in a list can be selected
d. specifies when items in a list can be selected

7. What object do you use to add items to the item property of a Listbox or ComboBox
control at design time?
a. the Windows Forms designer
b. the Solutions window
c. the Code window
d. the Windows desktop
8. How do you add items to a collection of a control at run time?
a. use the Add List method
b. use the Collection method
Repaso del Cap. 4: Using Looping Structures and Lists – Koneman.net 2

c. use the Items.Add method


d. use the Add Items method

9. What statement will add an item to a ComboBox?


a. lblCarMake.Items.Add (txtCarMake)
b. cboItems.Add (txtCarMake)
c. Add.Items (txtCarMake)
d. cboCarMake.Items.Add (txtCarMake.Text)

10. Which method is used to remove the contents of a list box?


a. Erase
b. Delete
c. Edit
d. Clear

11. What arguments are required in the Pmt function?


a. rate, term, and principal
b. interest, balance, and depreciation
c. loan balance, monthly payment, and interest
d. deposit, rate, and principal

12. What financial function calculates the portion of a loan payment that applies towards
the principal?
a. DDB
b. IRR
c. PPMT
d. IPMT

13. What financial function calculates the portion of a loan payment that applies to the
loan interest?
a. DDB
b. IRR
c. PPMT
d. IPMT

14. What is a group of objects that are treated as a unit?


a. a container
b. a class
c. a set
d. a collection

15. What is the main difference between the For…Each…Next statement and the For…
Next statement?
a. The For…Each…Next statement references a collection.
b. The For…Next statement is more complex than the For…Each…Next statement.
c. The For…Next statement references a collection.
d. The statements operate the same way.
Repaso del Cap. 4: Using Looping Structures and Lists – Koneman.net 3

16. What is the purpose of an object variable in a For…Each…Next statement?


a. It executes statements in a loop.
b. It sets the value of element to one.
c. It keeps track of each item or object obtained in a collection.
d. It accumulates variable values.

17. What is the purpose of the DirectoryInfo class?


a. to teach about directories
b. to calculate directory data
c. to obtain information about folders on a computer drive
d. to sort directory information

18. What is the purpose of the TabStop property?


a. controls a text box
b. controls a label
c. controls the behavior of the Tab key
d. controls whether or not the Tab key operates

19. What is the purpose of the continuation character?


a. to make your code run more efficiently
b. to make your code easier to read in the Code editor
c. to append lines of code
d. to continue a program after it ends

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


Dim index As Integer = 1
Do While index <> 9
lstBox.Items.Add("Hello")
index += 1
Loop
(A) The test variable should not be changed inside a Do loop.
(B) The test condition will never be true.
(C) This is an infinite loop.
(D) Nothing

21. In analyzing the solution to a program, you conclude that you want to construct
a loop so the loop terminates 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)
(E) Do While (a < 12) And (b = 16)
Repaso del Cap. 4: Using Looping Structures and Lists – Koneman.net 4

22. When VB.NET executes a Do While loop it first checks the truth value of the
_________.
(A) pass
(B) loop
(C) condition
(D) statement

23. A Do While loop checks the While condition before executing the statements in
the loop. (T/F)

24. If the While condition in a Do While loop is false the first time it is
encountered, the statements in the loop are still executed once. (T/F)

25. The following statement is valid. (T/F)


Do While x <> 0

26. 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)

27. A loop written using the structure Do While...Loop can usually be rewritten
using the structure Do...Loop Until. (T/F)
Repaso del Cap. 4: Using Looping Structures and Lists – Koneman.net 5

28. Assume that i and last are Integer variables. Describe precisely the output
produced by the following segment for the inputs 4 and –2.
Dim last, i As Integer
last = CInt(InputBox("Enter terminating value:"))
i = 0
Do While (i <= last)
lstBox.Items.Add(i)
i += 1
Loop

29. The following is an infinite loop. Rearrange the statements so that the loop will
terminate as intended.
x = 0
Do
lstBox.Items.Add(x)
Loop Until x > 13
x += 2

30. What is wrong with the following simple password program where today's
password is "intrepid"?
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

31. In the following code segment, what role does the variable check serve?
Dim counter As Integer, check As Boolean
Do While counter < 20
counter += 1
If counter = 10 Then
check = True
End If
Loop
(A) counter
(B) accumulator
(C) flag
(D) loop control variable
Repaso del Cap. 4: Using Looping Structures and Lists – Koneman.net 6

32. Suppose a variable is to tell whether or not the user wants further information. A
good data type for such a variable is
(A) Boolean
(B) Integer
(C) Double
(D) String

33. In the following code segment, what type of variable is counter?


Dim temp, counter, check As Integer
Do
temp = CInt(sr.ReadLine)
counter += temp
If counter = 10 Then
check = 0
End If
Loop Until (check = 0)
(A) counter
(B) accumulator
(C) flag
(D) loop control variable

34. What numbers will be displayed in the list box by the following code when the
button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim num As Integer = 7
Do
num += 1
lstBox.Items.Add(num)
Loop Until (num > 6)
lstBox.Items.Add(num)
End Sub
(A) 7
(B) 8
(C) 7 and 8
(D) 8 and 8

35. A variable that keeps track of whether a certain situation has occurred is called
(A) a counter
(B) an accumulator
(C) a switch
(D) a flag

36. The following are equivalent While and Until statements. (T/F)
While (num > 2) And (num < 5)
Until (num <= 2) Or (num >= 5)
Repaso del Cap. 4: Using Looping Structures and Lists – Koneman.net 7

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

38. A counter variable is normally incremented or decremented by 1. (T/F)

39. The following program uses a counter to force the loop to end. (T/F)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim r As Double = 1
Dim t As Double = 0
Do While (t < 5000)
t = 2 * t + r
r += 1
lstBox.Items.Add(t)
Loop
End Sub

40. What is one drawback in using non-integer Step sizes?


(A)Round-off errors may cause unpredictable results.
(B) Decimal Step sizes are invalid in VB.NET.
(C) A decimal Step size is never needed.
(D)Decimal Step sizes usually produce infinite loops.

41. When the odd numbers are added successively, any finite sum will be a perfect square (e.g., 1 +
3 + 5 = 9 and 9 = 3^2). What change must be made in the following program to correctly
demonstrate this fact for the first few odd numbers?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim oddNumber, i, j As Integer
Dim sum As Integer = 0
For i = 1 To 9 Step 2 'Generate first few odd numbers
oddNumber = i
For j = 1 To oddNumber Step 2 'Add odd numbers
sum += j
Next
lstBox.Items.Add(sum & " is a perfect square.")
Next
End Sub
(A)Change the Step size to 1 in the first For statement.
(B) Move oddNumber = i inside the second For loop.
(C) Reset sum to zero immediately before the second Next statement."
(D)Reset sum to zero immediately before the first Next statement."

42. What does the following program do with a person's name?


Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim name, test As String
Dim i As Integer
Dim new As String = "" It displays the name
new = "" (A)in reverse order.
name = InputBox("Enter your first name:") (B) in reverse order
For i = 0 To name.Length - 1 Step 2 and skips every other
test = name.Substring(i, 1) letter.
new = test & new (C) as it was entered.
Next (D)as it was entered,
txtBox.Text = new but skips every
End Sub other letter.
Repaso del Cap. 4: Using Looping Structures and Lists – Koneman.net 8

43. Suppose the days of the year are numbered from 1 to 365 and January 1 falls on
a Tuesday as it did in 2002. What is the correct For statement to use if you want only
the numbers for the Thursdays in 2002?
(A) For i = 3 to 365 Step 7
(B) For i = 1 to 365 Step 3
(C) For i = 365 To 1 Step -7
(D) For i = 3 To 365 Step 6

44. Given the following partial program, how many times will the statement
lstBox.Items.Add(j + k + m) be executed?
For j = 1 To 4
For k = 1 To 3
For m = 2 To 10 Step 3
lstBox.Items.Add(j + k + m)
Next
Next
Next
(A) 24
(B) 60
(C) 36
(D) 10
(E) None of the above

45. In a For statement of the form shown below, what is the default step value when
the "Step c" clause is omitted?
For i = a To b Step c
(A) the same as a
(B) the same as b
(C) zero
(D) one

46. Which loop computes the sum of 1/2 + 2/3 + 3/4 + 4/5 + … + 99/100?
(A) For n = 1 To 99
s += n / (1 + n)
Next
(B) For q = 100 To 1
s += (q + 1) /q
Next
(C) For d = 2 To 99
s = 1 / d + d / (d + 1)
Next
(D) For x = 1 To 100
s += 1 / (x + 1)
Next
Repaso del Cap. 4: Using Looping Structures and Lists – Koneman.net 9

47. How many times will PETE be displayed when the following lines are
executed?
For c = 15 to -4 Step -6
lstBox.Items.Add("PETE")
Next
(A) 1
(B) 2
(C) 3
(D) 4

48. How many lines of output are produced by the following program segment?
For i = 1 To 3
For j = 1 To 3
For k = i to j
lstBox.Items.Add("Programming is fun")
Next
Next
Next
(A) 8
(B) 9
(C) 10
(D) 11

49. What is the value of j after the end of the following code segment?
For j = 1 to 23
lstBox.Items.Add("The counter value is " & j)
Next
(A) 22
(B) 23
(C) 24
(D) Unable to determine

50. A For...Next loop with a positive step value continues to execute until what
condition is met?
(A) The control variable is greater than the terminating value.
(B) The control variable is equal to or greater than the terminating value.
(C) The control variable is less than the terminating value.
(D) The control variable is less than or equal to the terminating value.

51. Which of the following are valid for an initial or terminating value?
(A) a numeric literal
(B) info.Length, where info is a String variable
(C) a numeric expression
(D) all of the above
Repaso del Cap. 4: Using Looping Structures and Lists – Koneman.net 10

52. The value of the control variable should not be altered within the body of a
For…Next loop. (T/F)

53. The body of a For...Next loop in VB.NET will always be executed once no
matter what the initial and terminating values are. (T/F)

54. If one For...Next loop begins inside another For...Next loop, it must also end
within this loop. (T/F)

55. The index in a For...Next loop need not be a whole number. (T/F)

56. One must always have a Next statement paired with a For statement. (T/F)

57. If the control variable is greater than the terminating variable when a For...Next
loop begins, the statements within are still executed one time. (T/F)

58. When one For...Next loop is contained within another, the name of the control
variable for each For...Next loop may be the same. (T/F)

59. In a For...Next loop, the initial value should be greater than the terminating
value if a negative step is used. (T/F)

60. If the control variable of a For...Next loop will assume values that are not whole
numbers, then the variable should not be of type Integer. (T/F)

61. What is displayed in the text box when the button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim word As String = "Alphabet"
Dim abbreviation As String = ""
Dim i As Integer
For i = 0 To word.Length - 1
If word.Substring(i, 1).ToUpper <> "A" Then
abbreviation &= word.Substring(i, 1)
End If
Next
txtBox.Text = abbreviation
End Sub

Potrebbero piacerti anche