CSIS 208 Quiz 4 Liberty University
- Unless otherwise specified, Visual Basic assigns the value 0 to each element of a numeric array when it is declared with a Dim statement. (T/F)
- Assuming the following statement, what is the For…Next loop’s counter variable?
For yr As Integer = 1 To 5 - If the counter variable of a For…Next loop will assume values that are not whole numbers, then the variable must not be of type Integer. (T/F)
- The ReDim statement causes an array to lose its current contents unless the word ReDim is followed by the keyword
- The step value of a For…Next loop can be given by a numeric literal, variable, or expression. (T/F)
- Consider the following structure definition. Which Dim statement would correctly declare an array of this structure for elements having subscripts from 0 through 30?
Structure carType
Dim yr As Integer
Dim make As String
Dim model As String
End Structure - Arrays are said to be ordered only if the values are in ascending order. (T/F)
- What numbers are displayed in the list box by the following program segment?
Dim numbers() As Integer = {4, 7, 9, 3, 1}
Dim query = From number in numbers
Where number > 6
Select number
Items.Add(query.Count)
lstBox.Items.Add(query.Average) - What is displayed in the message box by the following code?
Dim message As String
Dim teamNames() As String = {“Packers”, “Jets”, “Seahawks”}
ReDim Preserve teamNames(1)
message = teamNames(1)
Show(message) - The ReDim and Preserve keywords can be used with two-dimensional arrays. (T/F)
- In the line of code
Function Sum(scores() As Integer) As Integer
the pair of parentheses that follows scores can be removed. (T/F) - The number of items in ListBox1 is ListBox1.Items.Count. (T/F)
- A structure can contain members that are simple variables only; members cannot be arrays. (T/F)
- Do…Loop Until block is always executed at least once. (T/F)
- What states are displayed in the list box by the following program segment?
Dim states() As String = {“Colorado”, “New Mexico”, “Arizona”, “Utah”}
Dim query = From state in states
Where ContainsE(state)
Select state
For Each state in query
Items.Add(state)
Next
Function ContainsE(word As String) As Boolean
If word.IndexOf(“E”) <> -1 Or word.IndexOf(“e”) <> -1 Then
Return True
Else
Return False
End If
End Function - What numbers are displayed in the list box by the following program segment?
Dim numbers() As Integer = {4, 7, 9, 3, 1, 9, 7}
Dim query = From number in numbers
Where number > 6
Select number
Items.Add(query.Count)
lstBox.Items.Add(query.Average) - In a For…Next loop, the initial value should be greater than or equal to the terminating value if a negative step is used and the body of the loop is to be executed at least once. (T/F)
- What colleges are displayed in the list box by the following program segment?
Dim ivies() As String = {“Harvard”, “Princeton”, “Yale”, “Dartmouth”,
“Brown”, “Columbia”, “Univ. of PA”, “Cornell”}
Dim query = From college in ivies
Where college.Length <= 9
Order By college.Length Descending, college Ascending
Select college
Items.Add(query.First)
lstBox.Items.Add(query.Max) - Which of the following are valid for an initial or terminating value of a For…Next loop?
- What numbers are displayed in the list box by the following program segment?
Dim numbers() As Integer = {4, 7, 9, 3, 1, 7, 7}
Dim query = From number in numbers
Where number > 6
Select number
Distinct
Items.Add(query.Count)
lstBox.Items.Add(query.Average)