cop2000 quiz 6, cop2000 quiz 7, cop2000 quiz 8
which line in the following program contains the prototype showDub function? 1 #include <iostream> 2 using namespace std; 3 void showDub (int); 4 int main ( ) 5 { 6 int x = 2; 7 showDub(x); 8 cout << x << endl; 9 return 0; 10 } 11 void showDub (int num) 12 { 13 cout << (num * 2) << endl; 14 }
3
The name of an array stores the ________ of the first array element.
memory address
An array can store a group of values, but the values must be
the same data type
Global variables are initialized to zero by default.
true
It is not considered good programming practice to declare all of your variables globally.
true
Before you can perform a selection sort, the data must be stored in ascending order.
false
C++ limits the number of array dimensions to two.
false
In C++ 11, the range-based for loop is best used in situations where you need the element subscript for some purpose.
false
The bubble sort is an easy way to arrange data into ascending order, but it cannot arrange data into descending order.
false
Using a binary search, you are more likely to find an item than if you use a linear search
false
When a function is called, flow of control moves to the function's prototype.
false
You must furnish an argument with a function call.
false
A ________ algorithm is a method of locating a specific item of information in a larger collection of data.
search
The ________ sort usually performs fewer exchanges than the ________ sort.
selection bubble
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
This vector function returns the number of elements in a vector.
size
An element of a two-dimensional array is referred to by
the row subscript of the element followed by the column subscript of the element
What will the following code display? int numbers[4] = {99, 87}; cout << numbers[3] << endl;
0
given the following function: void calc (int a, int b) { int c; c = a + 2; a = a * 3; b = c + a; } What is the output of the following code fragment that invokes calc ( ): int x = 1; int y = 2; int z = 3; calc(x, y); cout << x << " " << y << " " << z << endl;
1 6 3
which line in the following program contains the header for the showDub function? 1 #include <iostream> 2 using namespace std; 3 void showDub (int); 4 int main ( ) 5 { 6 int x = 2; 7 showDub(x); 8 cout << x << endl; 9 return 0; 10 } 11 void showDub (int num) 12 { 13 cout << (num * 2) << endl; 14 }
11
What will the following code display? #include <iostream> using namespace std; void doSomething (int); int main ( ) { int x = 2; cout << x << endl; return 0; } void doSomething (int num) { num = 0; cout << num << endl;
2 0 2
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
A ________ search is more efficient than a ________ search.
binary linear
a function is executed when it is
called
these types of arguments are passed to parameters automatically if no argument is provided in the function call.
default
a function ________ contains the statements that make up the function.
definition
When an array is sorted from highest to lowest, it is said to be in
descending order
it is good programming practice to ________ your functions by writing comments that describe what they do.
document
what is the data type of the following function prototype's parameter variable? int myFunction(double);
double
this function causes a program to terminate, regardless of which function or control mechanism is executing.
exit ( )
A function's return data type must be the same as the function's parameter(s).
false
A linear search can only be implemented with integer values
false
A local variable and a global variable may not have the same name within the same program.
false
Although two-dimensional arrays are a novel idea, there is no known way to pass one to a function.
false
An array initialization list must be placed on one single line.
false
Before you can perform a bubble sort, the data must be stored in descending order
false
If you attempt to store data past an array's boundaries, it is guaranteed that the compiler will issue an error.
false
Local variables are initialized to zero by default.
false
Data that is to be sorted in ascending order is ordered
from lowest value to highest value
if a function does NOT have a prototype, default arguments may be specified in the ________.
function header
This following statement shows an example of ________. int grades ] [ ] = { 100, 90, 99, 80} ;
implicit array sizing
A(n) ________ can be used to specify the starting values of an array.
initialization list
what is the data type of the following function prototype's return value? int myFunction(double);
int
What does the following statement do? vector<int> v(10);
it creates a vector object with a starting size of 10
It is ________ to pass an argument to a function that contains an individual array element, such as scores[3].
legal in C++
which line in the following program contains a call to the showDub function? 1 #include <iostream> 2 using namespace std; 3 void showDub(int); 4 int main() 5 { 6 int x = 2; 7 showdub (x); 8 cout << x << endl; 9 return 0; 10 } 11 void showDub (int num) 12 { 13 cout << (num * 2) << endl; 14 }
line 7
A(n) ________ search uses a loop to sequentially step through an array
linear
The _________ is adequate for searching through small arrays.
linear
this type of variable is defined inside a function and is NOT accessible outside the function.
local
Regardless of the algorithm being used, a search through an array is always performed
none of these
A two-dimensional array can have elements of ________ data type(s).
one
a function can have no parameters, one parameter, or many parameters and can return ________ value(s).
only one
if a function is called more than once in a program, the values stored in the function's local variables do NOT ________ between function calls.
persist
a function ________ eliminates the need to place a function definition before all calls to the function.
prototype
This vector function is used to insert an item into a vector.
push_back
The advantage of a linear search is its ____________
simplicity
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] ;
this is a dummy function that is called instead of the actual function it represents:
stub
To access an array element, use the array name and the element's ________.
subscript
A parameter is a special-purpose variable that is declared inside the parentheses of a function definition.
true
A static variable that is defined within a function is initialized only once, the first time the function is called.
true
A vector object automatically expands in size to accommodate the items stored in it.
true
If an array is partially initialized, the uninitialized elements will be set to zero.
true
In C++ 11, you cannot use a range-based for loop to modify the contents of an array unless you declare the range variable as a reference.
true
In the average case, an item is just as likely to be found near the beginning of an array as near the end
true
When you pass an array as an argument to a function, the function can modify the contents of the array.
true
You may use the exit() function to terminate a program, regardless of which control mechanism is executing.
true
________ functions may have the same name as long as their parameter lists are different.
two or more
Which statement correctly defines a vector object for holding integers?
vector<int> v;
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.
Unlike regular variables, ________ can hold multiple values.
arrays
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 false Set position to -1 While found is not true and first is less than or equal to last Set middle to the subscript halfway between array[first] and array[last] If array[middle] equals the desired value Set found to true Set position to middle Else If array[middle] is greater than the desired value Set last to middle - 1 Else Set first to middle + 1 End If End While Return position
binary search
Assume array1 and array2 are the names of arrays. To assign the contents of array2 to array1, you would use the following statement.array1 = array2;
false
A binary search begins with the _________ element of an array
middle
To pass an array as an argument to a function, pass the ________ of the array.
name
An individual array element can be processed like any other type of C++ variable.
true
Each individual element of an array can be accessed by the array name and an element number, called a subscript.
true
It is possible for a function to have some parameters with default arguments and some without.
true
One reason for using functions is to break programs into manageable units, or modules.
true
The number of comparisons made by a binary search is expressed in powers of two
true
The number of comparisons made by a binary search is expressed in powers of two.
true