Deck 9: Arrays
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/60
Play
Full screen (f)
Deck 9: Arrays
1
If a one-dimensional array contains five elements,its Length property contains the number 5 but its highest subscript is 3.
False
2
The data in a two-dimensional array are not required to have the same data type.
False
3
The data used to initialize the elements of an array is enclosed in ____.
A)[ ]
B){ }
C)( )
D)" "
A)[ ]
B){ }
C)( )
D)" "
B
4
An array is defined as follows: Dim numbers(3)As Integer
How many elements does the array have?
A)one
B)two
C)three
D)four
How many elements does the array have?
A)one
B)two
C)three
D)four
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
5
Assigning initial values to an array is often referred to as ____.
A)sorting the array
B)populating the array
C)assigning the array
D)declaring the array
A)sorting the array
B)populating the array
C)assigning the array
D)declaring the array
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
6
When a run time error occurs,the computer displays an error message and the application ends abruptly.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
7
The following statement will declare an array.What is the index value for the first element? Dim lakes(5)
A)0
B)1
C)4
D)5
A)0
B)1
C)4
D)5
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
8
If a one-dimensional array contains five elements,its highest subscript is ____.
A)4
B)5
C)6
D)7
A)4
B)5
C)6
D)7
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
9
The following statement will declare an array that has ____ elements. Dim lakes(5)As Integer
A)four
B)five
C)six
D)seven
A)four
B)five
C)six
D)seven
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
10
The statement ____ assigns the string "Madrid" to the first element in the strCities array.
A)strCities(0) = Madrid
B)strCities(0) = "Madrid"
C)strCities(1) = Madrid
D)strCities(0) = {Madrid}
A)strCities(0) = Madrid
B)strCities(0) = "Madrid"
C)strCities(1) = Madrid
D)strCities(0) = {Madrid}
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
11
Storing data in an array decreases the efficiency of your code.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
12
A(n)____ is a group of variables that have the same name and data type,and are related in some way.
A)subscript
B)string
C)array
D)run time error
A)subscript
B)string
C)array
D)run time error
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
13
Before you can use an array,you first must declare it.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
14
When an array is sorted in descending order,the first element in the array contains the smallest value and the last element contains the largest value.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
15
An advantage of using the For Each…Next statement to process an array is that your code does not need to keep track of the array subscripts or even know the number of array elements.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
16
A simple variable is unrelated to any other variable in memory.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
17
An array called state()is loaded as follows: Dim state()As String = {"Ohio","Michigan","California","Arizona"}
What is the value of the subscript used to reference "Arizona"?
A)1
B)2
C)3
D)4
What is the value of the subscript used to reference "Arizona"?
A)1
B)2
C)3
D)4
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
18
Which of the following correctly shows the syntax for storing data in a one-dimensional array?
A)arrayname = value
B)arrayname(subscript) = value
C)arrayname = {value}
D)arrayname(subscript) = {value}
A)arrayname = value
B)arrayname(subscript) = value
C)arrayname = {value}
D)arrayname(subscript) = {value}
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
19
A two-dimensional array resembles a table in that the variables (elements)are in rows and columns.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
20
If the array's data type is Integer,each element in the array is initialized using the keyword Nothing.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
21
Based on the statement below,which of the following If clauses determines whether the intSub variable contains a valid subscript for the array? Dim strColors()As String = {"red","green","blue"}
A)If intSub > 0 AndAlso intSub < 2 Then
B)If intSub >= 0 AndAlso intSub =< 2 Then
C)If intSub > 0 AndAlso intSub < 3 Then
D)If intSub >= 0 AndAlso intSub =< 3 Then
A)If intSub > 0 AndAlso intSub < 2 Then
B)If intSub >= 0 AndAlso intSub =< 2 Then
C)If intSub > 0 AndAlso intSub < 3 Then
D)If intSub >= 0 AndAlso intSub =< 3 Then
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
22
The statement ____ assigns the string "Paris" to the element located in the first row,second column in the strCities array.
A)strCities(1, 1) = {Paris}
B)strCities(0, 1) = "Paris"
C)strCities(0, 0) = (Paris)
D)strCities(1, 0) = "Paris"
A)strCities(1, 1) = {Paris}
B)strCities(0, 1) = "Paris"
C)strCities(0, 0) = (Paris)
D)strCities(1, 0) = "Paris"
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
23
The syntax ____ assigns either the value entered in the txtSales control (converted to Decimal)or the number 0 to the third element in the decSales array.
A)Decimal.TryParse(txtSales.Text, decSales(3))
B)Decimal.TryParse(txtSales.Text, decSales(0))
C)Decimal.TryParse(txtSales.Text, decSales(2))
D)TryParse(txtSales.Text, decSales(1))
A)Decimal.TryParse(txtSales.Text, decSales(3))
B)Decimal.TryParse(txtSales.Text, decSales(0))
C)Decimal.TryParse(txtSales.Text, decSales(2))
D)TryParse(txtSales.Text, decSales(1))
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
24
Based on the code below,intScores(2,0)is initialized to ____. Dim intScores(,)As Integer = {{75,90},{9,25},{23,56},{6,12}}
A)25
B)23
C)56
D)75
A)25
B)23
C)56
D)75
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
25
Based on the code below,intScores(3,0)is initialized to ____. Dim intScores(,)As Integer = {{75,90},{9,25},{23,56},{6,12}}
A)6
B)12
C)23
D)56
A)6
B)12
C)23
D)56
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
26
The intSub variable keeps track of array subscripts and is initialized to 0.The intHighSub variable contains the highest subscript for the strToppings array.Which of the following statements will traverse the strToppings array?
A)Do While intSub >= intHighSub
B)For intHighSub As Integer = 0 To intSub
C)Do While intSub <= intHighSub
D)For intSub As Integer = 1 To intHighSub
A)Do While intSub >= intHighSub
B)For intHighSub As Integer = 0 To intSub
C)Do While intSub <= intHighSub
D)For intSub As Integer = 1 To intHighSub
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
27
An array's ____ method returns an integer that indicates the highest subscript in the specified dimension in the array.
A)Sort
B)Reverse
C)TryParse
D)GetUpperBound
A)Sort
B)Reverse
C)TryParse
D)GetUpperBound
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
28
Which of the following statements declares a class-level one-dimensional array named strToppings that stores the 14 available pizza toppings?
A)Dim strToppings(13) As String
B)Private strToppings(13) As String
C)Dim strToppings(14) As String
D)Private strToppings(14) As String
A)Dim strToppings(13) As String
B)Private strToppings(13) As String
C)Dim strToppings(14) As String
D)Private strToppings(14) As String
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
29
Using an invalid subscript will result in a ____.
A)run time error
B)breakpoint
C)logic error
D)design-time error
A)run time error
B)breakpoint
C)logic error
D)design-time error
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
30
Consider the following array: Dim numbers(,)As Integer = {{1,2},{3,4},{4,5},{6,7},{8,9}}
What row index value would be required to create this two-dimensional array?
A)2
B)3
C)4
D)5
What row index value would be required to create this two-dimensional array?
A)2
B)3
C)4
D)5
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
31
Two or more arrays whose elements are related by their positions in the arrays are referred to as ____ arrays.
A)parallel
B)two-dimensional
C)accumulator
D)related
A)parallel
B)two-dimensional
C)accumulator
D)related
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
32
To arrange the elements in an array in ascending order,you use the ____ method.
A)Array.Arrange
B)Array.Ascending
C)Array.Sort
D)Array.Arrange
A)Array.Arrange
B)Array.Ascending
C)Array.Sort
D)Array.Arrange
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
33
Based on the code below,intScores(3,1)is initialized to ____. Dim intScores(,)As Integer = {{75,90},{9,25},{23,56},{6,12}}
A)6
B)12
C)23
D)56
A)6
B)12
C)23
D)56
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
34
Based on the code below,intScores(1,1)is initialized to ____. Dim intScores(,)As Integer = {{75,90},{9,25},{23,56},{6,12}}
A)9
B)25
C)75
D)90
A)9
B)25
C)75
D)90
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
35
Based on the code below,intScores(2,1)is initialized to ____. Dim intScores(,)As Integer = {{75,90},{9,25},{23,56},{6,12}}
A)25
B)23
C)56
D)75
A)25
B)23
C)56
D)75
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
36
To refer to the element located in the first row,first column in a two-dimensional array named strProducts,you use ____.
A)strProducts(0, 0)
B)strProducts{0, 1}
C)strProducts(1, 1)
D)strProducts[0, 0]
A)strProducts(0, 0)
B)strProducts{0, 1}
C)strProducts(1, 1)
D)strProducts[0, 0]
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
37
Based on the code below,intScores(0,0)is initialized to ____. Dim intScores(,)As Integer = {{75,90},{9,25},{23,56},{6,12}}
A)9
B)25
C)75
D)90
A)9
B)25
C)75
D)90
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
38
You do not need to specify the highest array subscript in the ____ statement.
A)Do...Loop
B)For...Next
C)For Each...Next
D)While...Wend
A)Do...Loop
B)For...Next
C)For Each...Next
D)While...Wend
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
39
The strRoom and strRate arrays are parallel arrays.If Deluxe is stored in the third element in the strRoom array,where is its rate (115)stored?
A)strRate(0)
B)strRate(1)
C)strRate(2)
D)strRate(3)
A)strRate(0)
B)strRate(1)
C)strRate(2)
D)strRate(3)
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
40
Consider the following array: Dim numbers(,)As Integer = {{1,2},{3,4},{4,5},{6,7},{8,9}}
What value will the following expression yield for total?
Total = numbers(1,1)+ numbers(2,0)
A)4
B)6
C)8
D)12
What value will the following expression yield for total?
Total = numbers(1,1)+ numbers(2,0)
A)4
B)6
C)8
D)12
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
41
Write the statement to declare a procedure-level two-dimensional array named dblRates using the following table of data:


Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
42
You have decided the Daily "Chef's Specials" need to be stored in a two-dimensional array rather than two parallel one-dimensional arrays.Which of the following statements will declare the array as a procedure-level array named strDailySpecial? The number of rows is based on the number of days in the week,and Sunday remains the first element for the days of the week.
A)Dim strDailySpecial(6, 1) As String
B)Dim strDailySpecial(7, 2) As String
C)Dim strDailySpecial(1, 6) As String
D)Dim strDailySpecial(2, 7) As String
A)Dim strDailySpecial(6, 1) As String
B)Dim strDailySpecial(7, 2) As String
C)Dim strDailySpecial(1, 6) As String
D)Dim strDailySpecial(2, 7) As String
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
43
Write the statements to traverse the strCategory array and display each element's value in the lstCategory control.Use a For Each...Next statement.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
44
How do the elements in parallel one-dimensional arrays relate to each other? Provide an example.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
45
Explain the difference between a simple variable and an array.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
46
Private Sub btnGetHighest_Click(ByVal sender As Object,ByVal e As System.EventArgs)Handles btnGetHighest.Click
' displays the highest prize amount and the
' number of people who won that amount
Dim intPrizes(10)As Integer = {50,25,100,25,100,
25,75,50,40,60}
Dim intHighSub As Integer = intPrizes.GetHighest()
Dim intHighPrize As Integer = intPrizes(0)
Dim intWinners As Integer = 1
For intX As Integer = 1 To intHighSub
If intPrizes(intX)= intHighPrize Then
intWinners *= 1
Else
If intPrizes(intX)< intHighPrize Then
intHighPrize = intPrizes(intX)
intWinners = 1
End If
End If
Next intX
lblHighest.Text = intHighPrize.ToString("C0")
lblWinners.Text = intWinners.ToString
End Sub
' displays the highest prize amount and the
' number of people who won that amount
Dim intPrizes(10)As Integer = {50,25,100,25,100,
25,75,50,40,60}
Dim intHighSub As Integer = intPrizes.GetHighest()
Dim intHighPrize As Integer = intPrizes(0)
Dim intWinners As Integer = 1
For intX As Integer = 1 To intHighSub
If intPrizes(intX)= intHighPrize Then
intWinners *= 1
Else
If intPrizes(intX)< intHighPrize Then
intHighPrize = intPrizes(intX)
intWinners = 1
End If
End If
Next intX
lblHighest.Text = intHighPrize.ToString("C0")
lblWinners.Text = intWinners.ToString
End Sub
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
47
The following array is declared and initialized:
Dim dblMilesPerTrip()As Double = {542,28,79.5,322.6,114}
Write the statements to total the values in the array.
Dim dblMilesPerTrip()As Double = {542,28,79.5,322.6,114}
Write the statements to total the values in the array.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
48
Write the statement to declare a twelve-row,two-column procedure-level array named strLocations,initializing each element to the keyword Nothing.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
49
Write the statement to declare a seven-element procedure-level array named strItemCode with each element initialized to the keyword Nothing.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
50
Daily "Chef's Specials" are stored using two one-dimensional parallel arrays.The days of the week are stored in the strDays array,with Sunday as the first element.The daily special for each day is stored in a parallel array named strSpecial.Which of the following statements assigns Friday's special,which is rigatoni,to the appropriate element?
A)strSpecial(6) = rigatoni
B)strSpecial(5) = rigatoni
C)strSpecial(6) = "rigatoni"
D)strSpecial(5) = "rigatoni"
A)strSpecial(6) = rigatoni
B)strSpecial(5) = rigatoni
C)strSpecial(6) = "rigatoni"
D)strSpecial(5) = "rigatoni"
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
51
Write the statement to declare a five-element procedure-level array named decGPA,and initialize the array with the following values: 2.58,3.85,3.6,1.45,2.75.Then write a statement to assign the number 2.55 to the last element in the array.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
52
Write the statement that assigns the string "Treasurer" to the element located in the third row,second column in the strOfficers array.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
53
Private Sub btnDisplay_Click(ByVal sender As Object,ByVal e As System.EventArgs)Handles btnDisplay.Click
' displays the pay rate associated with a pay code
Dim strCodes()As String = {PT1,PT2,FT1,FT2,FT3}
Dim dblRates()As Integer = {10.5,12,13.5,14}
Dim strSearchForCode As String
Dim intSub As Integer
' assign the code to a variable
txtCode.Text = strSearchForCode
' search the strCodes array for the pay code
' continue searching until the end of the array
' or the pay code is found
Do Until intSub > strCodes.Length OrElse
strSearchForCode = strCodes(intSub)
intSub = intSub + 1
Loop
' determine whether the pay code was found
If intSub < strCodes.Length Then
lblRate.Text = dblRates(1).ToString("C0")
Else
MessageBox.Show("Invalid Pay Code",
"Employee Pay Application",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If
txtCode.Focus()
End Sub
' displays the pay rate associated with a pay code
Dim strCodes()As String = {PT1,PT2,FT1,FT2,FT3}
Dim dblRates()As Integer = {10.5,12,13.5,14}
Dim strSearchForCode As String
Dim intSub As Integer
' assign the code to a variable
txtCode.Text = strSearchForCode
' search the strCodes array for the pay code
' continue searching until the end of the array
' or the pay code is found
Do Until intSub > strCodes.Length OrElse
strSearchForCode = strCodes(intSub)
intSub = intSub + 1
Loop
' determine whether the pay code was found
If intSub < strCodes.Length Then
lblRate.Text = dblRates(1).ToString("C0")
Else
MessageBox.Show("Invalid Pay Code",
"Employee Pay Application",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If
txtCode.Focus()
End Sub
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
54
Write the statement to declare a six-element class-level array named strAnimal,and initialize the array with the following values: dog,cat,mouse,bird,snake,fish.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
55
Describe two advantages to using arrays to store data.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
56
Write the statements to traverse the strCategory array and display each element's value in the lstCategory control.Use a Do...Loop statement.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
57
Write the statement that assigns the length of the strBooks array to the intNumElements variable.Then write the statement that assigns the highest subscript in the array to the intHighestSub variable.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
58
Write the statement to declare a four-element procedure-level array named intNum with each element initialized to 0.Then write the statements necessary to add the number 5 to each element in the intNum array.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
59
Which of the following statements assigns the daily special of lasagna to Tuesday?
A)strDailySpecial(3, 2) = lasagna
B)strDailySpecial(3, 2) = "Tuesday"
C)strDailySpecial(2, 1) = "lasagna"
D)strDailySpecial(3, 2) = "lasagna"
A)strDailySpecial(3, 2) = lasagna
B)strDailySpecial(3, 2) = "Tuesday"
C)strDailySpecial(2, 1) = "lasagna"
D)strDailySpecial(3, 2) = "lasagna"
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
60
The following array is declared and initialized:
Dim dblMilesPerTrip()As Double = {542,28,79.5,322.6,114}
Write the statements to sort the values in the array in descending order.
Dim dblMilesPerTrip()As Double = {542,28,79.5,322.6,114}
Write the statements to sort the values in the array in descending order.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck