Download as pdf or txt
Download as pdf or txt
You are on page 1of 40

Introduction to Programming Using

Visual Basic 10th Edition Schneider


Test Bank
Go to download the full and correct content document:
https://testbankdeal.com/product/introduction-to-programming-using-visual-basic-10th
-edition-schneider-test-bank/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Introduction to Programming Using Visual Basic 10th


Edition Schneider Solutions Manual

https://testbankdeal.com/product/introduction-to-programming-
using-visual-basic-10th-edition-schneider-solutions-manual/

Introduction to Programming Using Visual Basic 2012 9th


Edition Schneider Test Bank

https://testbankdeal.com/product/introduction-to-programming-
using-visual-basic-2012-9th-edition-schneider-test-bank/

Introduction to Programming Using Visual Basic 2012 9th


Edition Schneider Solutions Manual

https://testbankdeal.com/product/introduction-to-programming-
using-visual-basic-2012-9th-edition-schneider-solutions-manual/

Introduction to Programming Using Python 1st Edition


Schneider Test Bank

https://testbankdeal.com/product/introduction-to-programming-
using-python-1st-edition-schneider-test-bank/
Introduction to Programming Using Python 1st Edition
Schneider Solutions Manual

https://testbankdeal.com/product/introduction-to-programming-
using-python-1st-edition-schneider-solutions-manual/

Programming In Visual Basic 2010 1st Edition Bradley


Test Bank

https://testbankdeal.com/product/programming-in-visual-
basic-2010-1st-edition-bradley-test-bank/

Programming with Microsoft Visual Basic 2012 6th


Edition Zak Test Bank

https://testbankdeal.com/product/programming-with-microsoft-
visual-basic-2012-6th-edition-zak-test-bank/

Programming with Microsoft Visual Basic 2017 8th


Edition Zak Test Bank

https://testbankdeal.com/product/programming-with-microsoft-
visual-basic-2017-8th-edition-zak-test-bank/

Programming with Microsoft Visual Basic 2015 7th


Edition Zak Solutions Manual

https://testbankdeal.com/product/programming-with-microsoft-
visual-basic-2015-7th-edition-zak-solutions-manual/
Chapter 7 Arrays

Section 7.1 Creating and Using Arrays

1. After the following Dim statement is executed, how many elements will the array myVar
have?
Dim myVar(7) As Double
(A) 0
(B) 1
(C) 8
(D) 9
C

2. In the line of code


Dim scores() As Integer = {55, 33, 12}

the upper bound of the array scores is which of the following?


(A) 2
(B) 1
(C) 11
(D) 0
A

3. Each individual variable in the list


student(0), student(1), student(2)
is known as a(n)
(A) subscript.
(B) dimension.
(C) element.
(D) type.
C

4. In the statement
Dim scores(30) As Double

the number 30 designates which of the following?


(A) the highest value of the subscripts of the elements for the array scores
(B) the maximum value that can be assigned to any element in the array scores
(C) the data type for the array scores
(D) the value initially assigned to each element in the array scores
A

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


5. Which statement is true regarding the following Dim statement?
Dim states(49) As String, populations(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 states range from 1 to 49.
(D) The subscripts of populations range from 0 to 49.
D

6. The Count method returns what information about an array?


(A) the highest number that can be used as a subscript for the array
(B) the largest value that can be assigned to an array element
(C) the number of elements in the array
(D) The highest dimension of the array
C

7. In the line of code (where score is an array)


For index As Integer = 0 to (score.Count - 1)

the Count method is used to carry out which of the following tasks?
(A) determine the largest value for each of the elements
(B) determine the largest subscript in the array
(C) determine the smallest value for each of the elements
(D) declare a new array with the name Count
B

8. The ReDim statement causes an array to lose its current contents unless the word ReDim is
followed by the keyword
(A) CInt
(B) MyBase
(C) Preserve
(D) Add
C

9. Like other variables, array variables can be declared and assigned initial values at the same
time. (T/F)
T

10. After an array has been declared, its type (but not its size) can be changed with a ReDim
statement. (T/F)
F

11. If you use the ReDim statement to make an array smaller than it was, data in the eliminated
elements can be retrieved by using the Preserve keyword. (T/F)
F

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


12. The statement Dim nums(2) As Integer = {5, 6, 7} declares an array of three
elements. (T/F)
F

13. What will be the size of the array stones after the following two lines of code are executed?
Dim stones() As String = {"Watts", "Jagger", "Wood", "Richards"}
ReDim Preserve stones(10)
11

14. The statement


Dim newlist(10) As String

is used to declare an array where each element has the value 10. (T/F)
F

15. In the line of code


Function Sum(scores() As Integer) As Integer

the pair of parentheses that follows scores can be removed. (T/F)


F

16. In the line of code


Dim scores() As Integer = {55, 33, 12}

the upper bound of the array scores is 12. (T/F)


F

17. What two names are displayed in the list box when the button is clicked on?
Dim krispies(2) as String

Private Sub frmCereal_Load(...) Handles MyBase.Load


krispies(0) = "snap"
krispies(1) = "crackle"
krispies(2) = "pop"
End Sub
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
lstBox.Items.Add(krispies.Max)
lstBox.Items.Add(krispies.Last)
End Sub
(A) crackle and pop
(B) crackle and snap
(C) snap and crackle
(D) snap and pop
D

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


18. What two numbers are displayed in the list box when the button is clicked on?
Dim nums(2) as Integer

Private Sub frmNumbers_Load(...) Handles MyBase.Load


nums(0) = 5
nums(1) = 3
nums(2) = 4
End Sub
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
lstBox.Items.Add(nums.Average)
lstBox.Items.Add(nums.Max)
End Sub
(A) 4 and 5
(B) 4 and 4
(C) 3 and 5
(D) 3 and 4
A

19. Either a For...Next loop or a For Each loop can be used to display every other value from an
array in a list box. (T/F)
F

20. An array can contain both numeric and string values. (T/F)
F

21. A Function procedure can return a number, but cannot return an array of numbers. (T/F)
F

22. What names are displayed in the list box when the button is clicked on?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim names() As String = IO.File.ReadAllLines("Data.txt")
lstBox.Items.Clear()
For i As Integer = (names.Count - 1) To 0 Step -2
lstBox.Items.Add(names(i))
Next
End Sub
Assume the five lines of the file Data.txt contain the following entries: Bach, Borodin,
Brahms, Beethoven, Britain.
(A) Bach, Brahms, and Britain
(B) Britain, Beethoven, Brahms, Borodin, and Bach
(C) Bach, Borodin, Brahms, Beethoven, and Britain
(D) Britain, Brahms, and Bach
D

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


23. What names are displayed in the list box when the button is clicked on?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim file As String = "Ships.txt"
Dim ships() As String = FillArray(file)
lstBox.Items.Add(ships(2))
lstBox.Items.Add(ships.Min)
End Sub

Function FillArray(file As String) As String()


Dim names() As String = IO.File.ReadAllLines(file)
Return names
End Function
Assume the three lines of the file Ships.txt contain the following entries: Pinta, Nina, Santa
Maria.
(A) Pinta and Nina
(B) Santa Maria and Pinta
(C) Nina and Santa Maria
(D) Santa Maria and Nina
D

24. What numbers are displayed in the list box when the button is clicked on?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim file As String = "Beatles.txt"
Dim fabFour() As String = FillArray(file)
lstBox.Items.Add(Array.IndexOf(fabFour, "Ringo")
lstBox.Items.Add(fabFour.Count - 1)
End Sub

Function FillArray(file As String) As String()


Dim names() As String = IO.File.ReadAllLines(file)
Return names
End Function

Assume the four lines of the file Beatles.txt contain the following entries: John, Paul, Ringo,
George.
(A) 3 and 3
(B) 3 and 4
(C) 2 and 3
(D) 2 and 4
C

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


25. What names are displayed in the list box by the following program segment?
Dim newYork As String = "Manhatten,Bronx,Brooklyn,Queens,Staten Island"
Dim boroughs() As String = newYork.Split(","c)
lstBox.Items.Add(boroughs(0))
lstBox.Items.Add(boroughs.Min)

(A) Brooklyn and Queens


(B) Manhatten and Staten Island
(C) Bronx and Manhatten
(D) Manhatten and Bronx
D

26. What numbers are displayed in the list box by the following program segment?
Dim numbers As String = "1492,1776,1945"
Dim temp() As String = numbers.Split(","c)
Dim nums(2) As Integer
For i As Integer = 0 to 2
nums(i) = CInt(temp(i))
Next
lstBox.Items.Add(nums(1))
lstBox.Items.Add(nums.First)

(A) 1776 and 1492


(B) 1776 and 1776
(C) 1492 and 1492
(D) 1945 and 1492
A

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


Dim nums(8) As Integer
Dim total As Double = 0
For i As Integer = 0 To 8
nums(i) = i
Next
For k As Integer = 1 To 4
total += 10 ^ nums(k)
Next
txtBox.Text = CStr(total)

(A) 10000
(B) 11110
(C) 1110
(D) 0
B

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


28. What will be displayed when the following program segment is executed?
Dim temp() As String = IO.File.ReadAllLines("Data.txt")
Dim n As Integer = temp.Count - 1
Dim a(n) As Double
For k As Integer = 0 To n
a(k) = CDbl(temp(i))
Next
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
A

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


Dim temp() As String = IO.File.ReadAllLines("Data.txt")
Dim n As Integer = temp.Count - 1
Dim numbers(n) As Double, h As Double = 0
For i As Integer = 0 To n
numbers(i) = CDbl(temp(i))
Next
For k As Integer = 0 to n
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
A

30. Given the Dim statement below, which set of statements will initialize all elements of
myArray to 100?
Dim myArray(100) As Double

(A) myArray = 100


(B) For i As Integer = 0 To 100
(i) = 100
Next
(C) For j As Integer = 0 to 100
myArray(j) = 100
Next
(D) myArray() is already initialized to 100 by the Dim statement.
C

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


31. What is the output of the following program segment?
Dim c As Double
Dim temp() As String = IO.File.ReadAllLines("Data1.txt")
Dim n As Integer = temp.Count - 1
Dim a(n) As Double
For i As Integer = 0 To n
a(i) = CDbl(temp(i))
Next
temp() = IO.File.ReadAllLines("Data2.txt")
Dim b(n) As Double
For i As Integer = 0 To n
b(i) = CDbl(temp(i))
Next
For k As Integer = 0 To n
If a(k) = b(k) Then
c += 1
End If
Next
lstBox.Items.Add(c)
Assume the twenty rows of the file Data1.txt contain the following entries: 3, 2, 5, 1, 7, 8, 3,
5, 6, 2, 3, 6, 1, 6, 5, 5, 7, 2, 5, 3.
Assume the twenty rows of the file Data2.txt contain the following entries: 5, 3, 3, 4, 8, 2, 3,
5, 9, 5, 3, 7, 3, 7, 6, 3, 2, 1, 3, 4.
(A) 2
(B) 3
(C) 4
(D) 5
(E) 6
B

32. 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)
MessageBox.Show(message)
(A) Packers
(B) Jets
(C) Seahawks
(D) 2
B

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


33. If the following statement appears in a program, the array scores must have been declared
using the String data type. (T/F)
scores(1) = 87
F

34. Consider the following Dim and assignment statements for myArray(). The assignment
statement will cause a "Subscript out of range" error. (T/F)
Dim myArray(50) As Double
myArray(34) = 51
F

35. 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)
T

36. The following pair of statement is valid. (T/F)


Dim x = CInt(InputBox("Enter number of items (must be a positive integer)"))
ReDim myArray(x - 1)
T

37. A fractional number such as 4.6 is not allowed as a subscript. (T/F)


T

38. Consider the following Visual Basic statements:


Dim nums(4) As Double
For index As Integer = 0 To 4
nums(index) = 1 + (index * 2)
Next
What values are placed in the array by the above statements? (Show each element of the
array and the value for that element.)
nums(0)=1, nums(1)=3, nums(2)=5, nums(3)=7, nums(4)=9

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


38. What is the output of the following program when the button is clicked on?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim result As Double
Dim number(4) As Double
FillArray(number)
result = SumArray(number)
txtBox.Text = CStr(result)
End Sub
Sub FillArray(ByRef anyArray() As Double)
Dim temp() As String = IO.File.ReadAllLines("Data.txt")
For i As Integer = 0 To 4
anyArray(i) = CDbl(temp(i))
Next
End Sub
Function SumArray(anyArray() As Double) As Double
Dim total As Double
total = 0
For i As Integer = 0 To 4 Step 2
total += anyArray(i)
Next
Return total
End Function
Assume the five rows of the file Data.txt contain the following entries: 1, 3, 5, 7, 9
(A) 0
(B) 25
(C) 15
(D) None of the above
C

39. Which of the tasks is the Join function used to carry out in the following statement?
Dim line As String
line = Join(strArrData, ",")
(A) Join concatenates the values of all elements of the array strArrData, and adds a comma
delimiter between successive values.
(B) Join concatenates the values of all elements of line, and adds a comma to the end of the
line.
(C) Join parses or separates out all items of text that are delimited by a comma in
strArrData.
(D) Join parses or separates out all items of text that are delimited by a comma in line.
A

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Section 7.2 Using LINQ with Arrays
1. What names are displayed in the list box by the following lines of code?

Dim oceans() As String = {"Atlantic", "Pacific", "Indian", "Arctic",


"Antartic"}
Dim query = From ocean in oceans
Where ocean.Length = 6
Select ocean
For Each ocean As String In query
lstBox.Items.Add(ocean)
Next
(A) Pacific and Indian
(B) Indian and Arctic
(C) Indian
(D) Atlantic and Pacific
B

2. 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
lstBox.Items.Add(query.Count)
lstBox.Items.Add(query.Average)
(A) 5 and 12
(B) 2 and 12
(C) 2 and 8
(D) 5 and 8
C

3. 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
lstBox.Items.Add(query.Count)
lstBox.Items.Add(query.Average)

(A) 7 and 12
(B) 4 and 8
(C) 2 and 12
(D) 7 and 8
B

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


4. 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
lstBox.Items.Add(query.Count)
lstBox.Items.Add(query.Average)
(A) 5 and 12
(B) 2 and 12
(C) 2 and 8
(D) 5 and 8
C

5. 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
lstBox.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
(A) Colorado
(B) New Mexico
(C) Colorado, New Mexico, Arizona, Utah
(D) No states
B

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


6. 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 state.length < 5
Select state.ToUpper
For Each state in query
lstBox.Items.Add(state)
Next

(A) Utah
(B) COLORADO, NEW MEXICO, ARIZONA, UTAH
(C) UTAH
(D) No states
C

7. What numbers 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 state.EndsWith("o")
Select state.Length
For Each number in query
lstBox.Items.Add(number)
Next

(A) 8 and 10
(B) 8, 10, 7, 4
(C) 8
(D) 29
A

8. What names are displayed in the list box by the following program segment?
Dim tonightShow() As String = {"Allen", "Parr", "Carson", "Leno",
"O'Brien", "Leno"}
Dim query = From host in tonightShow
Where host.Length = 4
Select host
Distinct
For Each host in query
lstBox.Items.Add(host)
Next

(A) Parr, Leno, Leno


(B) Parr, Leno
(C) Leno
(D) No names
B

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


9. What numbers are displayed in the list box by the following program segment?
Dim numbers() As Double = {.5, 1, 2, 2.5}
Dim query = From number in numbers
Where number < 2
Let FormattedPer = number.ToString("P")
Select FormattedPer
For Each percent In query
lstBox.Items.Add(percent)
Next
(A) .5 and 1
(B) 50% and 100%
(C) 50.00%, 100.00%, 200.00%, 250.00%
(D) 50.00% and 100.00%
D

10. What years are displayed in the list box by the following program segment?
Dim years() As Integer = {1492, 1776, 1840, 1929, 1945, 2005}
Dim query = From year in years
Where Is20thCentury(year)
Select year
For Each yr in query
lstBox.Items.Add(yr)
Next

Function Is20thCentury(num As Integer) As Boolean


If (num >= 1900) and (num < 2000) Then
Return True
Else
Return False
End IF
End Function
(A) 1929 and 1945
(B) 1929
(C) 1492, 1776, 1840, 1929, 1945, 2005
(D) No years
A

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


11. 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
Order By state Ascending
Select state
lstBox.Items.Add(query.First)
lstBox.Items.Add(query.Min)

(A) Arizona and Colorado


(B) Arizona and Utah
(C) Colorado and Arizona
(D) Arizona and Arizona
D

12. What words are displayed in the list box by the following program segment?
Dim deadlySins() As String = {"pride", "greed", "anger", "envy",
"lust", "gluttony", "sloth"}
Dim query = From sin in deadlySins
Order By sin Ascending
Where sin.StartsWith("g")
Select sin
lstBox.Items.Add(query.First)
lstBox.Items.Add(query.Max)

(A) gluttony and greed


(B) gluttony and gluttony
(C) pride and gluttony
(D) greed and greed
A

13. What words are displayed in the list box by the following program segment?
Dim deadlySins() As String = {"pride", "greed", "anger", "envy",
"lust", "gluttony", "sloth"}
Dim query = From sin in deadlySins
Order By sin.Length Descending
Select sin.ToUpper
lstBox.Items.Add(query.First)
lstBox.Items.Add(query.Min)

(A) GLUTTONY and GLUTTONY


(B) GLUTTONY and SLOTH
(C) GLUTTONY and ANGER
(D) PRIDE and ENVY
C

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


14. 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
Order By college Descending
Select college
lstBox.Items.Add(query.First)
lstBox.Items.Add(query.Min)

(A) Yale and Brown


(B) Yale and Yale
(C) Brown and Brown
(D) Harvard and Brown
A

15. 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 Descending
Select college
lstBox.Items.Add(query.Last)
lstBox.Items.Add(query.Min)

(A) Dartmouth and Princeton


(B) Yale and Brown
(C) Yale and Cornell
(D) Dartmouth and Yale
B

16. 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
lstBox.Items.Add(query.First)
lstBox.Items.Add(query.Max)

(A) Dartmouth and Princeton


(B) Yale and Brown
(C) Yale and Cornell
(D) Dartmouth and Yale
D

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


17. What words are displayed in the list box by the following program segment?
Dim dimensions() As String = {"width", "height", "depth"}
Dim query = From dimension in dimensions
Order By dimension.Length Descending, dimension Ascending
Select dimension
lstBox.DataSource = query.ToList
lstBox.SelectedIndex = Nothing

(A) width, height, depth


(B) height, depth, width
(C) height, width, depth
(D) depth, width, height
B

18. What numbers are displayed in the list box by the following program segment?
Dim numbers() As Integer = {5, 79, 8, 33, 27}
Dim query = From number in numbers
Let formattedNum = number.ToString("N0")
Order By formattedNum Ascending
Select formattedNum
lstBox.DataSource = query.ToList
lstBox.SelectedIndex = Nothing

(A) 5, 8, 27, 33, 79


(B) 79, 33, 27, 8, 5
(C) 27, 33, 5, 79, 8
(D) 5, 79, 8, 33, 27
C

19. In an ascending ordered array, the value of each element is


(A) less than or equal to the value of the next element.
(B) greater than or equal to the value of the next element.
(C) equal to the value of the next element.
(D) greater than the value of the next element.
A

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


20. Which of the following is NOT an example of an ordered array?
(A) years
1877 1944 2011 4301
(B) cities
Selah Wapato Yakima Zillah
(C) nbrhoods
Hockinson Brush Prairie Dollars Corner Battle Ground
(D) nums
457 457 457 458
C

21. Which of the following is an ordered descending array?


(A) years
1011 1112 1112 1377
(B) cities
Selah Wapato Yakima Zillah
(C) nbrhoods
Parkrose Hockinson Dollars Corner Battle Ground
(D) nums
459 457 457 458
C

22. Arrays are said to be ordered only if the values are in ascending order. (T/F)
F

23. Ascending is the default direction for an Order By clause. (T/F)


T

24. Searching successive elements of an ordered list beginning with the first element is known
as a binary search. (T/F)
F

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Section 7.3 Arrays of Structures

1. 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
(A) You cannot have an array of structures.
(B) Dim carType(30)
(C) Dim car(30) As carType
(D) Dim carType(30) As car
C

2. Consider the following Structure definition and declaration. Which assignment statement
would correctly record that player number 13 had three home runs so far this season?
Structure playerType
Dim fullname As String
Dim team As String
Dim position As String
Dim homerun As Double
Dim average As Double
Dim rbi As Double
End Structure

Dim player(45) As playerType

(A) player(13) = 3
(B) player(13).homerun(3)
(C) playerType(13).homerun = 3
(D) player(13).homerun = 3
(E) None of the above
D

3. Suppose a structure is created with the code


Structure stateUSA
Dim capCity As String
Dim stateNum As Integer
End Structure
in the Declarations section of the Code Editor. Which of the following statements correctly
declares a variable of type stateUSA?
(A) Dim stateUSA As stateWA
(B) Dim stateWA As Structure
(C) Dim stateWA As stateUSA
(D) Dim stateWA As Member
C

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


4. Suppose a structure is created with the code
Structure stateUSA
Dim capCity As String
Dim stateNum As Integer
End Structure
in the Declarations section of the Code window. The code
Dim stateWA As stateUSA
Dim message As String
stateWA.stateNum = 42
stateWA.capCity = "Olympia"
message = stateWA.capCity & " " & stateWA.stateNum
MessageBox.Show(message)
is placed in the Click event procedure for one of the program’s buttons. What output will be
displayed in the message box when the button is clicked on?
(A) 42 Olympia
(B) Olympia42
(C) 42Olympia
(D) Olympia 42
D

5. The members of a structure must all be of the same data type. (T/F)
F

6. Suppose a structure is created with the code


Structure stateUSA
Dim capCity As String
Dim yearFounded As Integer
End Structure
in the Declarations section of the Code window. In this structure, the variable capCity is
known as a member. (T/F)
T

7. Suppose a structure is created with the code


Structure stateUSA
Dim capCity As String
Dim stateNum As Integer
End Structure
in the Declarations section of the Code window. The following statement correctly makes
use of the stateNum member of this structure. (T/F)
Dim stateWA As stateUSA
StateWA.stateNum = 42
T

8. A structure can contain members that are simple variables only; members cannot be arrays.
(T/F)
F

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


9. When a variable with a user-defined data type is passed to a procedure, the corresponding
parameter in the Sub or Function statement must be declared to be of the same data type.
(T/F)
T

10. Suppose a structure and an array are created with the code

Structure Nation
Dim name As String
Dim continent As String
Dim population As Double 'in millions
Dim area As Double 'in square miles
End Structure

Dim nations(192) As Nation


in the Declarations section of the Code editor and the array is filled with data for the 193
member nations of the UN. What will be displayed in the list box when the following code
is executed?
Dim query = From country In nations
Where country.continent = "Africa"
Order By country.population Descending
Select country.name
lstBox.DataSource = query.ToList
lstBox.SelectedIndex = Nothing
(A) the names of the countries in Africa in alphabetical order
(B) the names of the countries in Africa beginning with the name of the least populous
country
(C) the names of the countries in Africa beginning with the name of the most populous
country
(D) the names of the countries in Africa in reverse alphabetical order
C

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


11. Suppose a structure and an array are created with the code

Structure Nation
Dim name As String
Dim continent As String
Dim population As Double 'in millions
Dim area As Double 'in square miles
End Structure

Dim nations(192) As Nation


in the Declarations section of the Code editor and the array is filled with data for the 193
member nations of the UN. What will be displayed in the list box when the following code
is executed?
Dim query = From country In nations
Order By country.area Descending
Select country.name, country.population
lstBox.Items.Add(query.First.name)
lstBox.Items.Add(1000000 * query.First.population)

(A) the name and population of the smallest country in the UN


(B) the name and population of the largest country in the UN
(C) the name and population of the least populous country in the UN
(D) the name and population of the most populous country in the UN
B

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


12. Suppose a structure and an array are created with the code

Structure Nation
Dim name As String
Dim continent As String
Dim population As Double 'in millions
Dim area As Double 'in square miles
End Structure

Dim nations(191) As Nation


in the Declarations section of the Code editor and the array is filled with data for the 192
member nations of the UN. What will be displayed in the DataGridView control when the
following code is executed?
Dim query = From country In nations
Where country.population > 200
Order By country.area Descending
Select country.name, country.continent
dgvNations.DataSource = query.ToList
dgvNations.CurrentCell = Nothing
(A) Two columns, with headers name and continent. The grid will display the countries
(along with their continents) whose populations are greater than 200 million people.
The countries will be displayed in order to their population, beginning with the most
populous country.
(B) Four columns, with each row containing data about a single country whose population
is greater than 200 million people. The countries will be displayed in order of their area,
beginning with the largest country.
(C) Two columns, with headers country.name and country.continent. The grid will display
the countries (along with their continents) whose populations are greater than 200
million people. The countries will be displayed in order to their area, beginning with the
largest country.
(D) Two columns, with headers name and continent. The grid will display the countries
(along with their continents) whose populations are greater than 200 million people.
The countries will be displayed in order to their area, beginning with the largest
country.
D

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


13. Suppose a structure and an array are created with the code

Structure Nation
Dim name As String
Dim continent As String
Dim population As Double 'in millions
Dim area As Double 'in square miles
End Structure

Dim nations(192) As Nation


in the Declarations section of the Code editor and the array is filled with data for the 193
member nations of the UN. What will be displayed in the DataGridView control when the
following code is executed?
Dim query = From country In nations
Where (country.continent = "Europe") And
country.name.StartsWith("S")
Let countryUC = country.name.ToUpper
Let pop = (1000000 * country.population).ToString("N0")
Let area = (country.area).ToString("N0")
Order By countryUC Ascending
Select countryUC, pop, area
dgvNations.DataSource = query.ToList
dgvNations.CurrentCell = Nothing

(A) Three columns, with headers country, population, and area. The grid will display the
countries in Europe (along with their populations and areas) whose names begin with
the letter S. The countries will be displayed capitalized in alphabetical order and their
populations and areas will be formatted with commas as thousands separators.
(B) Four columns, with headers countryUC, continent, pop, and area. The grid will display
the countries in Europe (along with their continents, populations and areas) whose
names begin with the letter S. The countries will be displayed capitalized in alphabetical
order and their populations and areas will be formatted with commas as thousands
separators.
(C) Three columns, with headers countryUC, pop, and area. The grid will display the
countries in Europe (along with their populations and areas) whose names begin with
the letter S. The countries will be displayed capitalized in alphabetical order and their
populations and areas will be formatted with commas as thousands separators.
(D) Three columns, with headers countryUC, pop, and area. The grid will display the
countries in Europe (along with their populations and areas) whose names begin with
the letter S. The countries will be displayed capitalized in reverse alphabetical order and
their populations and areas will be formatted with commas as thousands separators.
C

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


14. Which of the following methods is used to change the words in a column headers of a
DataGridView control?
(A) HeaderText
(B) HeaderName
(C) HeaderContent
(D) HeaderCaption
A

Section 7.4 Two-Dimensional Arrays

1. Given the following array, what value will be assigned to num?

myArray
num = myArray(3,4) 0 1 2 3 4
0 0 1 2 3 4
1 5 6 7 8 9
2 10 11 12 13 14
3 15 16 17 18 19
4 20 21 22 23 24
(A) 19
(B) 4
(C) 24
(D) 0
(E) None of the above
A

2. Assume the array nums has been filled as shown. What is the output of the following
program segment?

nums
0 1 2 3
s = 0 |------------------------
For k As Integer = 0 To 2 0 | 2 3 4 5
s += nums(k, k + 1) |
Next 1 | 6 5 4 3
lstBox.Items.Add(s) |
2 | 2 3 4 5
|
3 | 6 5 4 3
(A) 64
(B) 12
(C) 13
(D) 25
(E) None of the above
B

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


3. How many elements are in the array declared by
Dim myArray(3, 2) As Double
(A) 12
(B) 8
(C) 6
(D) 2
(E) None of the above
A

4. Which of the following types of variables is capable of holding the information contained in
a table that has four rows and four columns?
(A) one-dimensional arrays
(B) simple variables
(C) single-subscripted variables
(D) double-subscripted variables
D

5. Which of the following types of variables can only hold a single item of data?
(A) two-dimensional arrays
(B) simple variables
(C) single-subscripted variables
(D) double-subscripted variables
B

6. Which of the following declarations creates a two-dimensional array?


(A) Dim newVar(2, 2) As Double
(B) Dim newVar As Integer
(C) Dim newVar(2) As Double
(D) Dim newVar(2)
A

7. Which of the following declarations can be used to create a three-dimensional array?


(A) Dim newVar(3, 3) As Double
(B) Dim newVar(2, 2, 2) As Double
(C) Dim newVar(3) As Double
(D) Dim newVar(3)
B

8. Arrays that are capable of holding the contents of a table with several rows and columns, are
known as two-dimensional arrays or double subscripted variables. (T/F)
T

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


9. The statement
Dim nextVar(3, 5) As Double
declares a two-dimensional array that can store a table containing 4 columns and 6 rows of
numeric data. (T/F)
F

10. The statement


Dim nextVar(7, 8) As Double

declares a two-dimensional array that can store a table containing 7 rows and 8 columns of
numeric data. (T/F)
F

11. A two-dimensional array can be declared and initialized at the same time. (T/F)
T

12. If the two-dimensional array nums has three rows and six columns, then the value of
nums.GetUpperBound(0) is 3 and the value of nums.GetUpperBound(1) is 6. (T/F)
F

13. In the two-dimensional array declaration


Dim newVar(,) As Double = {{1, 2, 3}, {4, 5, 2054}, {6, 802, 2786}}
the comma in newVar(,) can be removed. (T/F)
F

14. The ReDim and Preserve keywords can be used with two-dimensional arrays. (T/F)
T

15. Arrays can only be one- or two-dimensional. (T/F)


F

16. ReDim statements cannot be used to change a one-dimensional array into a two-dimensional
array. (T/F)
T

17. ReDim statements can be used to change a one-dimensional array into a three-dimensional
array. (T/F)
F

18. Given the following statements, the first subscript in the second statement references a
column. (T/F)
Dim myArray(15, 20) As Double
myArray(5, 10) = 0
F

19. Two-dimensional arrays are often referred to as tables or matrices. (T/F)


T

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


20. The third statement below is NOT valid. (T/F)
row = 5
col = 3
someArray(col, row) = 25
F

21. Write code using a For...Next loop to fill a 5-by-5 matrix so that the two diagonals have
asterisks (*) in them as shown.
0 1 2 3 4
0 * *
1 * *
2 *
3 * *
4 * *
Ans: For i As Integer = 0 to 4
matrix(i, i) = "*"
matrix(i, 4 - i) = "*"
Next

© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Another random document with
no related content on Scribd:
This eBook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this eBook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is derived


from texts not protected by U.S. copyright law (does not contain a
notice indicating that it is posted with permission of the copyright
holder), the work can be copied and distributed to anyone in the
United States without paying any fees or charges. If you are
redistributing or providing access to a work with the phrase “Project
Gutenberg” associated with or appearing on the work, you must
comply either with the requirements of paragraphs 1.E.1 through
1.E.7 or obtain permission for the use of the work and the Project
Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is posted


with the permission of the copyright holder, your use and distribution
must comply with both paragraphs 1.E.1 through 1.E.7 and any
additional terms imposed by the copyright holder. Additional terms
will be linked to the Project Gutenberg™ License for all works posted
with the permission of the copyright holder found at the beginning of
this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files containing a
part of this work or any other work associated with Project
Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute this


electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1 with
active links or immediate access to the full terms of the Project
Gutenberg™ License.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or expense
to the user, provide a copy, a means of exporting a copy, or a means
of obtaining a copy upon request, of the work in its original “Plain
Vanilla ASCII” or other form. Any alternate format must include the
full Project Gutenberg™ License as specified in paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™ works
unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or providing


access to or distributing Project Gutenberg™ electronic works
provided that:

• You pay a royalty fee of 20% of the gross profits you derive from
the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt that
s/he does not agree to the terms of the full Project Gutenberg™
License. You must require such a user to return or destroy all
copies of the works possessed in a physical medium and
discontinue all use of and all access to other copies of Project
Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™


electronic work or group of works on different terms than are set
forth in this agreement, you must obtain permission in writing from
the Project Gutenberg Literary Archive Foundation, the manager of
the Project Gutenberg™ trademark. Contact the Foundation as set
forth in Section 3 below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on, transcribe
and proofread works not protected by U.S. copyright law in creating
the Project Gutenberg™ collection. Despite these efforts, Project
Gutenberg™ electronic works, and the medium on which they may
be stored, may contain “Defects,” such as, but not limited to,
incomplete, inaccurate or corrupt data, transcription errors, a
copyright or other intellectual property infringement, a defective or
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except


for the “Right of Replacement or Refund” described in paragraph
1.F.3, the Project Gutenberg Literary Archive Foundation, the owner
of the Project Gutenberg™ trademark, and any other party
distributing a Project Gutenberg™ electronic work under this
agreement, disclaim all liability to you for damages, costs and
expenses, including legal fees. YOU AGREE THAT YOU HAVE NO
REMEDIES FOR NEGLIGENCE, STRICT LIABILITY, BREACH OF
WARRANTY OR BREACH OF CONTRACT EXCEPT THOSE
PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE THAT THE
FOUNDATION, THE TRADEMARK OWNER, AND ANY
DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE
TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL,
PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE
NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of receiving it,
you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or entity
that provided you with the defective work may elect to provide a
replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.

1.F.4. Except for the limited right of replacement or refund set forth in
paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the


Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and distribution
of Project Gutenberg™ electronic works, harmless from all liability,
costs and expenses, including legal fees, that arise directly or
indirectly from any of the following which you do or cause to occur:
(a) distribution of this or any Project Gutenberg™ work, (b)
alteration, modification, or additions or deletions to any Project
Gutenberg™ work, and (c) any Defect you cause.

Section 2. Information about the Mission of


Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.
Section 3. Information about the Project
Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.

The Foundation’s business office is located at 809 North 1500 West,


Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many small
donations ($1 to $5,000) are particularly important to maintaining tax
exempt status with the IRS.

The Foundation is committed to complying with the laws regulating


charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states where


we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot make


any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.

Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.

Section 5. General Information About Project


Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.

Project Gutenberg™ eBooks are often created from several printed


editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.

You might also like