Chapter 7

Ace your homework & exams now with Quizwiz!

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

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

UTAH

Variable arrays can only be one- or two-dimensional. (T/F)

F

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

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

F

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

F

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.

Britain, Brahms, and Bach

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

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

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

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

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

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)

Dartmouth and Yale

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

F

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

F

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

F

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

F

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

Parr, Leno

The ReDim statement causes an array to lose its current contents unless the word ReDim is followed by the keyword

Preserve

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.

Santa Maria and Nina

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

T

What two numbers are displayed in the list box when the button is clicked on? Dim nums() 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

4 and 5

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)

4 and 8

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

50.00% and 100.00%

After the following Dim statement is executed, how many elements will the array myVar have? Dim myVar(7) As Double

8

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

8 and 10

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

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)

gluttony and greed

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

height, depth, width

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.

1

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

11

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

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)

11110

How many elements are in the array declared by Dim myArray(3, 2) As Double

12

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

15

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)

1776 and 1492

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 year in query lstBox.Items.Add(year) Next Function Is20thCentury(num As Integer) As Boolean If (num >= 1900) and (num < 2000) Then Return True Else Return False End IF End Function

1929 and 1945

In the line of code Dim scores() As Integer = {55, 33, 12} the upper bound of the array scores is which of the following?

2

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.

2 and 3

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)

2 and 8

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)

2 and 8

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

27, 33, 5, 79, 8

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.

3

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

Which of the following declarations creates a two-dimensional array? (A) Dim newVar(2, (B) Dim newVar As (C) Dim newVar(2) (D) Dim newVar(2)

A

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

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)

Arizona and Arizona

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 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

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

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

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 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

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

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)tThe highest dimension of the array

C

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

F

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

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

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

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

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

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

In the line of code Dim scores() As Integer = {55, 33, 12} the upper bound of the array scores is 12. (T/F)

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)

F

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

F

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

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

F

Thestatement Dim newlist(10) As String is used to declare an array where each element has the value 10. (T/F)

F

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)

GLUTTONY and ANGER

Which of the following methods is used to change the words in a column header of a DataGridView control?

HeaderText

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

Indian and Arctic

What is displayed in the message box by the following code? Dim message As String Dim teamNames() As String = {"Packers", "Jets", "Seahawks"} ReDim Preserve teamName(1) message = teamNames(1) MessageBox.Show(message)

Jets

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(borought.Min)

Manhatten and Bronx

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

New Mexico

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

T

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

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

T

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

T

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

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

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

T

The following pair of statement is valid. (T/F) x = CInt(InputBox("Enter number of items (must be a positive integer)")) ReDim myArray(x - 1)

T

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

T

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

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

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)

Yale and Brown

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)

Yale and Brown

In the line of code For index As Integer = 0 to (score.Count - 1) the Count method is used to carry out which of the following tasks?

determine the largest subscript in the array

Each individual variable in the list student(0), student(1), student(2) is known as a(n)

element

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

What two names are displayed in the list box when the button is clicked on? Dim krispies() 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

snap and pop


Related study sets

Culture, Spirituality, and Alternative/Complementary Modalities

View Set

BUSI301: Business Law (B07) Chapter 10

View Set

Statistics for the Behavior Sciences Midterm

View Set

Social 7 "Voices and Visions" Final Exam Review

View Set

OB - STI(ch 5), Newborn (ch. 18)

View Set

Exam 2 - COUN 593 Child and Adolescent Problems and Treatment

View Set

NURS320 MedSurg Final Exam Review: Gas Exchange, Perfusion, and Blood Administration

View Set

STANDARD COSTING AND VARIANCE ANALYSIS

View Set

CompTIA Security+ Cert. (SY0-501): Practice Tests #3

View Set