Deck 7: Class Templates Array and Vector; Catching Exceptions

Full screen (f)
exit full mode
Question
Linear search can be used on:

A) Unsorted arrays.
B) Sorted arrays.
C) Integer arrays.
D) Any of the above.
Use Space or
up arrow
down arrow
to flip the card.
Question
Using square brackets ([]) to retrieve vector elements __________ perform bounds checking; using member function at to retrieve vector elements __________ perform bounds checking.

A) Does not, does not.
B) Does not, does.
C) Does, does not.
D) Does, does.
Question
Which of the following is not true of class template vector?

A) The size of a vector can be changed after it is declared.
B) A vector can be assigned to another vector by using the assignment operator.
C) A vector object can be initialized with a copy of another vector by invoking the copy constructor.
D) A vector can store only data of type int.
Question
Which of the following tasks cannot be performed using a range-based for loop?

A) Calculating the product of all the values in an array.
B) Displaying all even element values in an array.
C) Incrementing the value stored in each element of the array.
D) Accessing the element's subscript.
Question
You can sort an array with the Standard Library's:

A) sort function.
B) sort_array function.
C) array_sort function.
D) None of the above.
Question
A double subscripted array declared as array, 3> values; has how many elements?

A) 15
B) 13
C) 10
D) 8
Question
When using exception handling, place any code that might throw an exception in a __________.

A) catch block
B) try statement.
C) throw block.
D) what statement.
Question
In a typical nested for loop (not a range-based for loop) used to process a two-dimensional array, following the end of each execution of the inner for loop:

A) The outer for loop initializes its counter variable.
B) The outer for loop increments its counter variable.
C) The inner for loop initializes its counter variable.
D) The inner for loop increments its counter variable.
Question
Constant variables:

A) Can be assigned values in executable statements.
B) Do not have to be initialized when they are declared.
C) Can be used to specify array sizes, thereby making programs more scalable.
D) Can be used to specify array sizes, but this makes programs harder to understand.
Question
Assume that the array named items contains the integer values 0, 2, 4, 6 and 8. Which of the following set of statements uses the range-based for loop to display each value in items?

A) for (int i = 0; i }
B) for (int item : items) { cout <}
C) for (int item : items) { cout <}
D) for (int item : items.size()){ cout <}
Question
Which of the following is not a correct way to initialize the array named n?

A) array n{0, 7, 0, 3, 8};
B) array n{0, 7, 0, 3, 8, 2};
C) array n{7};
D) array n{9, 1, 9};
Question
An array is not:

A) A consecutive group of memory locations.
B) Subscripted by integers.
C) Made up of different data types.
D) None of the above.
Question
Which statement would be used to declare a 10-element integer array c?

A) array c<12>;
B) array c;
C) array<12> c;
D) array c;
Question
In order to calculate the __________ of an array of values, the array values must first be summed.

A) Average.
B) Minimum.
C) Maximum.
D) Distribution.
Question
Which statement about exception handling is false?

A) Call the exception object's what member function to get the error message that's stored in the exception object.
B) Bounds checking is performed at execution time with vector member function at, and if a subscript is within the bounds of the array, the member function throws an out_of_bounds exception.
C) The catch block contains the code that handles an exception if one occurs.
D) None of the above statements in false.
Question
Which of the following does not declare a 2-by-2 array and set all four of its elements to 0?

A) array, 2> b; b[0][0] = b[0][1] = b[1][0] = b[1][1] = 0;
B) array, 2> b = {0};
C) array, 2> b; for (auto const &row : b) {
For (auto &element : row) {
Element = 0;
}
}
D) All of the above initialize all four of the array elements to 0.
Question
Which of the following is false?

A) The last element of an array has position number one less than the array size.
B) The position number contained within square brackets is called a subscript.
C) A subscript cannot be an expression.
D) All of the above.
Question
Referencing elements outside the array bounds with the [] operator:

A) Can result in changes to the value of an unrelated variable.
B) Is impossible because C++ checks to make sure it does not happen.
C) Is a syntax error.
D) Enlarges the size of the array.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/18
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 7: Class Templates Array and Vector; Catching Exceptions
1
Linear search can be used on:

A) Unsorted arrays.
B) Sorted arrays.
C) Integer arrays.
D) Any of the above.
D
2
Using square brackets ([]) to retrieve vector elements __________ perform bounds checking; using member function at to retrieve vector elements __________ perform bounds checking.

A) Does not, does not.
B) Does not, does.
C) Does, does not.
D) Does, does.
B
3
Which of the following is not true of class template vector?

A) The size of a vector can be changed after it is declared.
B) A vector can be assigned to another vector by using the assignment operator.
C) A vector object can be initialized with a copy of another vector by invoking the copy constructor.
D) A vector can store only data of type int.
D
4
Which of the following tasks cannot be performed using a range-based for loop?

A) Calculating the product of all the values in an array.
B) Displaying all even element values in an array.
C) Incrementing the value stored in each element of the array.
D) Accessing the element's subscript.
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
5
You can sort an array with the Standard Library's:

A) sort function.
B) sort_array function.
C) array_sort function.
D) None of the above.
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
6
A double subscripted array declared as array, 3> values; has how many elements?

A) 15
B) 13
C) 10
D) 8
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
7
When using exception handling, place any code that might throw an exception in a __________.

A) catch block
B) try statement.
C) throw block.
D) what statement.
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
8
In a typical nested for loop (not a range-based for loop) used to process a two-dimensional array, following the end of each execution of the inner for loop:

A) The outer for loop initializes its counter variable.
B) The outer for loop increments its counter variable.
C) The inner for loop initializes its counter variable.
D) The inner for loop increments its counter variable.
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
9
Constant variables:

A) Can be assigned values in executable statements.
B) Do not have to be initialized when they are declared.
C) Can be used to specify array sizes, thereby making programs more scalable.
D) Can be used to specify array sizes, but this makes programs harder to understand.
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
10
Assume that the array named items contains the integer values 0, 2, 4, 6 and 8. Which of the following set of statements uses the range-based for loop to display each value in items?

A) for (int i = 0; i }
B) for (int item : items) { cout <}
C) for (int item : items) { cout <}
D) for (int item : items.size()){ cout <}
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
11
Which of the following is not a correct way to initialize the array named n?

A) array n{0, 7, 0, 3, 8};
B) array n{0, 7, 0, 3, 8, 2};
C) array n{7};
D) array n{9, 1, 9};
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
12
An array is not:

A) A consecutive group of memory locations.
B) Subscripted by integers.
C) Made up of different data types.
D) None of the above.
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
13
Which statement would be used to declare a 10-element integer array c?

A) array c<12>;
B) array c;
C) array<12> c;
D) array c;
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
14
In order to calculate the __________ of an array of values, the array values must first be summed.

A) Average.
B) Minimum.
C) Maximum.
D) Distribution.
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
15
Which statement about exception handling is false?

A) Call the exception object's what member function to get the error message that's stored in the exception object.
B) Bounds checking is performed at execution time with vector member function at, and if a subscript is within the bounds of the array, the member function throws an out_of_bounds exception.
C) The catch block contains the code that handles an exception if one occurs.
D) None of the above statements in false.
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
16
Which of the following does not declare a 2-by-2 array and set all four of its elements to 0?

A) array, 2> b; b[0][0] = b[0][1] = b[1][0] = b[1][1] = 0;
B) array, 2> b = {0};
C) array, 2> b; for (auto const &row : b) {
For (auto &element : row) {
Element = 0;
}
}
D) All of the above initialize all four of the array elements to 0.
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
17
Which of the following is false?

A) The last element of an array has position number one less than the array size.
B) The position number contained within square brackets is called a subscript.
C) A subscript cannot be an expression.
D) All of the above.
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
18
Referencing elements outside the array bounds with the [] operator:

A) Can result in changes to the value of an unrelated variable.
B) Is impossible because C++ checks to make sure it does not happen.
C) Is a syntax error.
D) Enlarges the size of the array.
Unlock Deck
Unlock for access to all 18 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 18 flashcards in this deck.