C++ Module 6 (ch 7 and 8)
What will the following code display? int numbers[4] = {99, 87}; cout << numbers[3] << endl;
0
How many elements does the following array have? int values[1000];
1000
Using a linear search to find a value that is stored in the last element of an array that contains 20,000 elements, ________ elements must be compared.
20,000
What will the following code display? int numbers[] = {99, 87, 66, 55, 101}; cout << numbers[3] << endl;
55
What will the following C++11 code display? vector<int> numbers {3,5}; for (int val : numbers) cout << val << endl; A.) 5 5 5 B.) 3 3 3 3 3 C.) 3 5 D.) Nothing. This code has an error.
C
Which of the following is a valid C++ array definition? A.)int array[0]; B.)float $payments[10.23]; C.)int numbers[5.6]; D.)int scores[25]; E.)None of these
D
What does the following statement do? vector<int> v(10);
It creates a vector object with a starting size of 10.
An element of a two-dimensional array is referred to by ________ followed by ________.
The correct answer is: the row subscript of the element, the column subscript of the element
The following function should swap the values contained in two integer variables, num1 and num2. What, if anything, is wrong with this function? void swap (int num1, int num2) { int temp = num2; num2 = num1; num1 = temp; }
The swap function must use reference parameters.
Subscript numbering in C++ _________
begins with zero
The following is the pseudocode for which type of algorithm? Set first to 0 Set last to the last subscript in the array Set found to falseSet position to -1 While found is not true and first <= last Set middle to the subscript halfway betweenarray[first] and array[last] If array[middle] = the desired value Set found = true Set position to middle e Else if array[middle] > desired value Set last = (middle - 1) Else Set first = (middle + 1) End If End While Return Position
binary search
A(n) _____ search is more efficient than a(n) _____ search
binary, linear
When an array is sorted from highest to lowest, it is said to be in
descending order
An array can easily be stepped through by using a
for loop
Data that is to be sorted in ascending order is ordered
from lowest value to highest value
This following statement shows an example of ________. int grades][ ] = {100, 90, 99, 80};
implicit array sizing
It is ________ to pass an argument to a function that contains an individual array element, such as scores[3].
legal in C++
The name of an array stores the ________ of the first array element.
memory address
To pass an array as an argument to a function, pass the ________ of the array.
name
This vector function returns the number of elements in a vector.
size
Algorithms used to arrange random data in some order are ________ algorithms.
sorting
An array of string objects that will hold five names would be declared with which of the following statements?
string names[5];
To access an array element, use the array name and the element's ________.
subscript
What statement correctly defines a vector object for holding integers?
vector<int> v;
Unlike regular variables, ________ can hold multiple values.
arrays
A two-dimensional array can have elements of ________ data type(s).
one
This vector function is used to insert an item into a vector.
push_back
A ________ algorithm is a method of locating a specific item of information in a larger collection of data.
search
The following is the pseudocode for which type of algorithm? For start = each array subscript, from the first to the next-to-last minIndex = start minValue = array[start] For index = start + 1 to size -1 If array[index] < minValue minValue = array[index] minIndex = index End if End for Swap array[minIndex] with array[start] End for
selection sort
The ________ sort usually performs fewer exchanges than the ________ sort.
selection, bubble