• Home
  • Textbooks
  • C# Programming: From Problem Analysis to Program Design
  • Advanced Collections

C# Programming: From Problem Analysis to Program Design

Barbara Doyle

Chapter 8

Advanced Collections - all with Video Answers

Educators


Chapter Questions

01:14

Problem 1

When three values are contained within the square brackets, the last number represents
the number of:
a. classes
b. rows
c. planes
d. columns
e. none of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
04:14

Problem 2

Which of the following array declarations would enable you to store the high and low
temperatures for each day of one full week?
a. int temp1Lo, temp2Lo, temp3Lo, temp4Lo, temp5Lo, temp6Lo,
temp7Lo, temp1Hi, temp2Hi, temp3Hi, temp4Hi, temp5Hi,
temp6Hi, temp7Hi;
b. int temp [7, 2] = new int [7, 2];
c. temp int [ , ] = new temp[7, 2];
d. int [ , ] temp = new temp [7, 2];
e. int [ , ] temp = new temp [8, 3];

Ernest Castorena
Ernest Castorena
Numerade Educator
03:23

Problem 3

Assume a two-dimensional array called num is declared to hold four rows and
seven columns.Which of the following statements correctly assigns the value 100 to
the third physical column of each row?
a. for(x = 0; x < 3; ++x) num [x, 2] = 100
b. for(x = 0; x < 4; ++x) num [x, 2] = 100;
c. for(x = 1; x < 4; ++x) num [x, 2] = 100;
d. for(x = 1; x < 5; ++x) num [x, 2] = 100;
e. none of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
05:10

Problem 4

Choose the statement that does not apply to the following declaration:
doubleƒ[ , ]ƒtotalCostOfItemsƒ=ƒ
ƒƒƒƒ{{109.95,ƒ169.95,ƒ1.50,ƒ89.95}{27.9, 18.6, 26.8, 98.5}};
a. declares a two-dimensional array of floating-point values
b. establishes the maximum number of rows as 4
c. sets the array element totalCostOfItems [0, 1] to 169.95
d. declares an area in memory where data of double type can be stored
e. all are correct

Ernest Castorena
Ernest Castorena
Numerade Educator
00:44

Problem 5

What value is returned by the method named result?
int result(int [ , ] anArray)
{
intƒjƒ=ƒ0,
i = 0;
for(int r = 0; r < anArray.GetLength(0); r++)
for(int c = 0; c < anArray.GetLength(1); c++)
if (anArray[r, c] < anArray[i, j])
{
i = r;
j = c;
}
return i;
}
a. the row index of the largest element of array anArray
b. the value of the largest element of array anArray
c. the row index of the smallest element of array anArray
d. the column index of the smallest element of array anArray
e. the index of the last element greater than its predecessor

Aditya Sood
Aditya Sood
Numerade Educator
03:02

Problem 6

What is the largest dimension an array can be declared to store values?
a. 10
b. 100
c. 3
d. 5
e. there is no limit

Ernest Castorena
Ernest Castorena
Numerade Educator
02:34

Problem 7

Using the following declaration:
charƒ[ƒ,ƒ]ƒnƒ=ƒ{{'a',ƒ'b',ƒ'c',ƒ'd',ƒ'e'},ƒ
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ{'f',ƒ'g',ƒ'h',ƒ'i',ƒ'j'}};
What does n[1, 1] refer to?
a. a
b. f
c. b
d. g
e. none of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
01:51

Problem 8

A two-dimensional array is a list of data items that . ___________
a. all have the same type
b. all have different names
c. all are integers
d. all are originally set to null ('\0')
e. none of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
02:31

Problem 9

Using the following declaration:
int [,] x = {{12, 13, 14, 15}, {16, 17, 18, 19}};
What does x[2, 4] refer to?
a. 19
b. 18
c. '\0'
d. 0
e. none of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
02:51

Problem 10

Which of the following adds 95 to the array element that is currently storing 14?
int [, ,] x = {{12, 13}, {14, 15}, {16, 17}, {18, 19}};
a. x[2] += 95;
b. x[1, 0] += 95;
c. x[1, 0 += 95];
d. x = 14 + 95;
e. none of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
02:57

Problem 11

How many components are allocated by the following statement?
double [ , ] values = new double [3, 2];
a. 32
b. 3
c. 5
d. 6
e. none of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
01:19

Problem 12

Given the declaration for values in number 11 above, how would you store 0 in the last
physical location?
a. values = 0;
b. values[6] = 0;
c. values[3, 2] = 0;
d. values[2, 1] = 0;
e. none of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
03:23

Problem 13

If you declare an array as int [,] anArray = new int[5, 3];
you can double the value stored in anArray [2, 1] with the statement:
a. anArray [2, 1] = anArray [5, 1] * 2;
b. anArray = anArray * 2;
c. anArray [2, 1] *= anArray [2, 1]ƒ*ƒ2;
d. anArray [2, 1] *= 2;
e. none of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
03:12

Problem 14

With the following declaration:
intƒ[ƒ,ƒ]ƒpointsƒ=ƒ
ƒƒƒƒ{{300,ƒ100,ƒ200,ƒ400,ƒ600},ƒ
ƒƒƒƒƒ{550,ƒ700,ƒ900,ƒ800,ƒ100}};
The statement points [1, 3] = points [1, 3] + 10; will
a. replace the 300 amount with 310 and 900 with 910
b. replace the 500 amount with 510
c. replace the 900 amount with 910
d. replace the 800 amount with 810
e. none of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
02:55

Problem 15

With the following declaration:
intƒ[ƒ,ƒ]ƒpointsƒ=ƒ
ƒƒƒƒƒƒƒƒ{{300,ƒ100,ƒ200,ƒ400,ƒ600},
ƒƒƒƒƒƒƒƒƒ{550,ƒ700,ƒ900,ƒ200,ƒ100}};
The statement points [0, 4] = points [0, 4-2]; will
a. replace the 400 amount with 2
b. replace the 300 and 600 with 2
c. replace the 600 with 200
d. result in an error
e. none of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
03:11

Problem 16

With the following declaration:
intƒ[ƒ,ƒ]ƒpointsƒ=ƒ
ƒƒƒƒƒƒƒ{{300,ƒ100,ƒ200,ƒ400,ƒ600},
ƒƒƒƒƒƒƒƒ{550,ƒ700,ƒ900,ƒ200,ƒ100}};
The statement Console.Write(points [1, 2] + points [0, 3]); will
a. display 900400
b. display 1300
c. display “points[1, 2] + points[0, 3]”
d. result in an error
e. none of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
02:13

Problem 17

When you pass an element from an ArrayList to a method, the method receives:
a. a copy of the ArrayList
b. the address of the ArrayList
c. a copy of the value in the element of the ArrayList
d. the address of the element in the ArrayList
e. none of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
01:55

Problem 18

When you pass the entire ArrayList to a method, the method receives:
a. a copy of the ArrayList
b. the address of the ArrayList
c. a copy of the first value in the ArrayList
d. the address of each of the elements in the ArrayList
e. none of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
01:13

Problem 19

To convert all the uppercase letters in a string to their lowercase counterpart, you can
use the ___________ method of the string class.
a. IsLower( )
b. ConvertLower( )
c. Lower( )
d. ToLower( )
e. none of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
01:14

Problem 20

Which method in the ArrayList class can be used to place a value onto the end
of the ArrayList?
a. AddLast( )
b. AddLastIndex( )
c. Add( )
d. Insert( )
e. none of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
00:44

Problem 21

Which method in the ArrayList class can be used to get or set the number of
elements that an ArrayList can contain?
a. Length( )
b. Size( )
c. Dimension( )
d. Rank( )
e. Capacity( )

Ernest Castorena
Ernest Castorena
Numerade Educator
01:54

Problem 22

Which class includes methods to create a dynamic one-dimensional structure?
a. Array
b. string
c. array
d. ArrayList
e. all of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
01:37

Problem 23

A correct method call to a method that has the following heading would be:
intƒresult(int[,]ƒanArray,ƒintƒnum)
a. Console.Write(result(anArray, 3));
b. result(anArray, 30);
c. Console.Write(result(anArray[ ], 3));
d. result(anArray[ ], 30);
e. none of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
00:40

Problem 24

With two-dimensional arrays a limitation on the foreach statement is that it can:
a. only be used for read-only access
b. only be used with integral type arrays
c. not be used with multidimensional arrays
d. only be used with arrays smaller than 1000 elements
e. not be used with dynamic arrays

Ernest Castorena
Ernest Castorena
Numerade Educator
00:54

Problem 25

In order to retrieve a value stored in an object of the Queue class, you would use
which method?
a. Pop( );
b. Push( );
c. Dequeue( );
d. Enqueue( );
e. none of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
01:13

Problem 26

Use the following string to answer questions a through e.
stringƒsValueƒ=ƒ“TodayƒisƒtheƒfirstƒDayƒofƒ“
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ+ƒ“the rest of yourƒlife.”
a. Create a new string that has all lowercase characters except the word Day. Day
should be all uppercase.
b. Create a new string array that contains the eight elements. Each word from the
sValue string should be in a separate array cell.

c. Remove the period from the last array element created in Step b. Display the con-
tents of the new array verifying its removal.

d. Surround the sValue string with three asterisks on each end.
e. Replace the word first with the word best in the sValue string.

Ernest Castorena
Ernest Castorena
Numerade Educator
02:59

Problem 27

Using the following declaration:
intƒ[,]ƒanArrayƒ=ƒ{{34,ƒ55,ƒ67,ƒ89,ƒ99}, {22, 68, 11, 19, 45}};
What would be the result of each of the following output statements?
a. Console.WriteLine(anArray.Length);
b. Console.WriteLine(anArray[1, 2]);
c. Console.WriteLine(anArray[0, anArray.GetLength(0) - 2]);
d. Console.WriteLine(anArray[0, 2ƒ+ƒ1]ƒ*ƒanArray[0, 0]);
e. Console.WriteLine(anArray.Rank);

Ernest Castorena
Ernest Castorena
Numerade Educator
01:39

Problem 28

Using the following declarations, write solutions for Steps a through e.
intƒ[ƒ,ƒ]ƒcArrayƒ=ƒnew intƒ[ƒ2,ƒ3];
stringƒ[ƒ,ƒ,ƒ]ƒdArrayƒ=ƒnew stringƒ[ƒ5,ƒ2,ƒ6];
a. Write a foreach loop to display the contents of cArray.
b. Write a for loop to increment each element in cArray by 5.
c. Write a foreach loop to display the contents of dArray.
d. Can you use a foreach loop to initialize all elements of dArray with zero? If so,
show your code. If not, explain why.
e. Write a for loop to initialize all elements in dArray to zero.

Manik Pulyani
Manik Pulyani
Numerade Educator
11:29

Problem 29

Create array declarations for the following problem specifications.
a. An array to hold the name of the largest 3 cities for 5 states. Initialize with the
5 states closest to your campus.
b. A single array to hold the names of 10 people.You should be able to reference each
person's first name without having to use string manipulation methods to split
the data apart.
c. A single array to store keys for five exams each consisting of 15 true/false
questions.

RO
Reynald Oliveria
Numerade Educator
05:46

Problem 30

Explain the difference between the .NET Hashtable and Dictionary classes.

Willis James
Willis James
Numerade Educator