C++ Chapter 6-8

25 July 2022
4.7 (114 reviews)
126 test answers

Unlock all answers in this set

Unlock answers (122)
question
This is a collection of statements that performs a specific task. A) infinite loop B) variable C) constant D) function E) None of these
answer
function
question
A function ________ contains the statements that make up the function. A) definition B) prototype C) call D) expression E) parameter list
answer
definition
question
A function can have zero to many parameters, and it can return this many values. A) zero to many B) no C) only one D) a maximum of ten E) None of these
answer
only one
question
A function is executed when it is: A) defined B) prototyped C) declared D) called E) None of these
answer
called
question
In a function header, you must furnish: A) data type(s) of the parameters B) data type of the return value C) the name of function D) names of parameter variables E) All of these
answer
all of these
question
Functions are ideal for use in menu-driven programs. When a user selects a menu item, the program can ________ the appropriate function. A) call B) prototype C) define D) declare E) None of these
answer
call
question
This type of variable is defined inside a function and is not accessible outside the function. A) global B) reference C) local D) counter E) None of these
answer
local
question
The value in this type of local variable persists between function calls. A) global B) internal C) static D) dynamic E) None of these
answer
static
question
These types of arguments are passed to parameters automatically if no argument is provided in the function call. A) Local B) Default C) Global D) Relational E) None of these
answer
default
question
When used as parameters, these types of variables allow a function to access the parameter's original argument. A) reference B) floating-point C) counter D) undeclared E) None of these
answer
reference
question
) This statement causes a function to end. A) end B) terminate C) return D) release E) None of these
answer
return
question
________ functions may have the same name, as long as their parameter lists are different. A) Only two B) Two or more C) Zero D) Un-prototyped E) None of these
answer
two or more
question
This function causes a program to terminate, regardless of which function or control mechanism is executing. A) terminate() B) return() C) continue() D) exit() E) None of these
answer
exit ( )
question
Given the following function definition: 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; A) 1 2 3 B) 1 6 3 C) 3 6 3 D) 1 14 9 E) None of these
answer
1 6 3
question
This is a statement that causes a function to execute. A) for loop B) do-while loop C) function prototype D) function call E) None of these
answer
function call
question
It is a good programming practice to ________ your functions by writing comments that describe what they do. A) execute B) document C) eliminate D) prototype E) None of these
answer
document
question
A(n) ________ is information that is passed to a function, and a(n) ________ is information that is received by a function. A) function call, function header B) parameter, argument C) argument, parameter D) prototype, header E) None of these
answer
argument, parameter
question
Which of the following statements about global variables is true? A) A global variable is accessible only to the main function. B) A global variable is declared in the highest-level block in which it is used. C) A global variable can have the same name as a variable that is declared locally within a function. D) If a function contains a local variable with the same name as a global variable, the global variable's name takes precedence within the function. E) All of these are true.
answer
A global variable can have the same name as a variable that is declared locally within a function.
question
A function ________ eliminates the need to place a function definition before all calls to the function. A) header B) prototype C) argument D) parameter E) None of these
answer
prototype
question
A ________ variable is declared outside all functions. A) local B) global C) floating-point D) counter E) None of these
answer
global
question
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. A) persist B) execute C) communicate D) change E) None of these
answer
persist
question
A ________ argument is passed to a parameter when the actual argument is left out of the function call. A) false B) true C) null D) default E) None of these
answer
default
question
If a function does not have a prototype, default arguments may be specified in the function ________. A) call B) header C) execution D) return type E) None of these
answer
header
question
EXIT_FAILURE and ________ are named constants that may be used to indicate success or failure when the exit() function is called. A) EXIT_TERMINATE B) EXIT_SUCCESS C) EXIT_OK D) RETURN_OK E) None of these
answer
EXIT_SUCCESS
question
The value in a ________ variable persists between function calls. A) dynamic B) local C) counter D) static local
answer
static local
question
This is a dummy function that is called instead of the actual function it represents. A) main function B) stub C) driver D) overloaded function
answer
stub
question
What is the output of the following program? #include using namespace std; void showDub(int); int main() { int x = 2; showDub(x); cout << x << endl; return 0; } void showDub(int num) { cout << (num * 2) << endl; } A) 2 2 B) 4 2 C) 2 4 D) 4 4
answer
4 2
question
What is the output of the following program? #include using namespace std; void doSomething(int); int main() { int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; } void doSomething(int num) { num = 0; cout << num << endl; } A) 2 0 2 B) 2 2 2 C) 0 0 0 D) 2 0 0
answer
2 0 2
question
What is the output of the following program? #include using namespace std; void doSomething(int&); int main() { int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; } void doSomething(int& num) { num = 0; cout << num << endl; } A) 2 0 2 B) 2 2 2 C) 0 0 0 D) 2 0 0
answer
2 0 0
question
Which line in the following program contains the prototype for the showDub function? 1 #include 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 } A) 4 B) 6 C) 10 D) 15
answer
4
question
Which line in the following program contains the header for the showDub function? 1 #include 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 } A) 4 B) 6 C) 10 D) 15
answer
15
question
Which line in the following program contains a call to the showDub function? 1 #include 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 } A) 4 B) 6 C) 10 D) 15
answer
10
question
Look at the following function prototype. int myFunction(double); What is the data type of the function's parameter variable? A) int B) double C) void D) Can't tell from the prototype
answer
double
question
Look at the following function prototype. int myFunction(double); What is the data type of the function's return value? A) int B) double C) void D) Can't tell from the prototype
answer
int
question
Look at the following function prototype. int myFunction(double, double, double); How many parameter variables does this function have? A) 1 B) 2 C) 3 D) Can't tell from the prototype
answer
3
question
What is the output of the following program? #include using namespace std; int getValue(int); int main() { int x = 2; cout << getValue(x) << endl; return 0; } int getValue(int num) { return num + 5; } A) 5 B) 2 C) 7 D) "getValue(x)"
answer
7
question
Here is the header for a function named computeValue: void computeValue(int value) Which of the following is a valid call to the function? A) computeValue(10) B) computeValue(10); C) void computeValue(10); D) void computeValue(int x);
answer
computeValue(10);
question
When a function is called, flow of control moves to the function's prototype.
answer
false
question
A parameter is a special-purpose variable that is declared inside the parentheses of a function definition.
answer
true
question
A local variable and a global variable may not have the same name within the same program.
answer
false
question
A static variable that is defined within a function is initialized only once, the first time the function is called.
answer
true
question
It is possible for a function to have some parameters with default arguments and some without.
answer
true
question
A function's return data type must be the same as the function's parameter(s).
answer
false
question
One reason for using functions is to break programs into manageable units, or modules.
answer
true
question
You must furnish an argument with a function call.
answer
false
question
Global variables are initialized to zero by default.
answer
true
question
Local variables are initialized to zero by default.
answer
false
question
It is not considered good programming practice to declare all of your variables globally.
answer
true
question
You may use the exit() function to terminate a program, regardless of which control mechanism is executing.
answer
true
question
Unlike regular variables, these can hold multiple values. A) constants B) named constants C) arrays D) floating-point variables E) None of these
answer
arrays
question
The individual values contained in array are known as ________. A) parts B) elements C) numbers D) constants E) None of these
answer
elements
question
To access an array element, use the array name and the element's ________. A) data type B) subscript C) name D) value E) None of these
answer
subscript
question
Which of the following is a valid C++ array definition? A) int array[0]; B) float $payments[10]; C) void numbers[5]; D) int array[10]; E) None of these
answer
int array[10];
question
The statement: int grades[ ] = { 100, 90, 99, 80}; shows an example of: A) default arguments B) an illegal array declaration C) an illegal array initialization D) implicit array sizing E) None of these
answer
implicit array sizing
question
By using the same ________ you can build relationships between data stored in two or more arrays. A) array name B) data C) subscript D) arguments E) None of these
answer
subscript
question
The name of an array stores the ________ of the first array element. A) memory address B) value C) element number D) data type E) None of these
answer
memory address
question
A two-dimensional array is like ________ put together. A) an array and a function B) several identical arrays C) two functions D) two arrays of different types E) None of these
answer
several identical arrays
question
A two-dimensional array can be viewed as ________ and ________. A) rows, columns B) arguments, parameters C) increments, decrements D) All of these E) None of these
answer
rows, columns
question
If you leave out the size declarator in an array definition: A) you must furnish an initialization list B) you are not required to initialize the array elements C) all array elements default to zero values D) your array will contain no elements
answer
you must furnish an initialization list
question
Which of the following is a valid C++ array definition? A) int scores[0]; B) float $payments[10]; C) int readings[4.5]; D) int scores [10]; E) None of these
answer
int scores [10];
question
An element of a two-dimensional array is referred to by ________ followed by ________. A) the array name, the column number of element B) the row subscript of the element, the column subscript of the element C) a comma, a semicolon D) the row subscript of element, the array name E) None of these
answer
the row subscript of the element, the column subscript of the element
question
When writing functions that accept multi-dimensional arrays as arguments, ________ must be explicitly stated in the parameter list. A) all dimensions B) all but the first dimension C) the size declarator of the first dimension D) all element values E) None of these
answer
all but the first dimension
question
An array can store a group of values, but the values must be: A) the same data type B) each of a different data type C) constants D) integers E) None of these
answer
the same data type
question
An array's size declarator must be a ________ with a value greater than ________. A) number, one B) number, zero C) constant integer expression, zero D) variable, -1 E) None of these
answer
constant integer expression, zero
question
Subscript numbering in C++________. A) can be set at runtime B) can begin with a programmer-defined value C) varies from program to program D) begins with zero E) None of these
answer
begins with zero
question
Arrays may be ________ at the time they are ________. A) resized, executed B) re-scoped, deleted C) initialized, declared D) pre-compiled, typecast E) None of these
answer
initialized, declared
question
Given the following declaration, where is the value 77 stored in the scores array? int scores[] = {83, 62, 77, 97}; A) scores[0] B) scores[1] C) scores[2] D) scores[4]
answer
scores[2]
question
An array can easily be stepped through by using a ________. A) for loop B) reference variable C) named constant D) null value E) None of these
answer
for loop
question
The range-based for loop, in C++ 11, is designed to work with a built-in variable known as the ________. A) counter variable B) i variable C) iterator D) range variable E) None of these
answer
range variable
question
To assign the contents of one array to another, you must use ________. A) the assignment operator with the array names B) the equality operator with the array names C) a loop to assign the elements of one array to the other array D) Any of these E) None of these
answer
a loop to assign the elements of one array to the other array
question
To pass an array as an argument to a function, pass the ________ of the array. A) contents B) size, expressed as an integer C) name D) value of the first element E) None of these
answer
name
question
A two-dimensional array can have elements of ________ data type(s). A) one B) two C) four D) Any of these E) None of these
answer
one
question
A two-dimensional array of characters can contain ________. A) strings of the same length B) strings of different lengths C) uninitialized elements D) All of these E) None of these
answer
all of these
question
A(n) ________ can be used to specify the starting values of an array. A) initialization list B) array name C) subscript D) element E) None of these
answer
initialization list
question
The ________ is automatically appended to a character array when it is initialized with a string constant. A) array name B) number of elements C) value of the first element D) null terminator E) None of these
answer
null terminator
question
An array with no elements is ________. A) legal in C++ B) illegal in C++ C) automatically furnished one element, with a value of zero D) automatically furnished one value—the null terminator E) None of these
answer
illegal in C++
question
An array of string objects that will hold 5 names would be declared using which statement? A) string names[5]; B) string names(5); C) string names5; D) String[5] names; E) None of these will work.
answer
string names[5];
question
It is ________ to pass an argument to a function that contains an individual array element, such as numbers[3]. A) illegal in C++ B) legal in C++ C) not recommended by the ANSI committee D) not good programming practice E) None of these
answer
illegal in C++
question
What is the last legal subscript that can be used with the following array? int values[5]; A) 0 B) 5 C) 6 D) 4
answer
4
question
How many elements does the following array have? int bugs[1000]; A) 1000 B) 999 C) 1001 D) Cannot tell from the code
answer
1000
question
What will the following code display? int numbers[] = {99, 87, 66, 55, 101 }; cout << numbers[3] << endl; A) 55 B) 66 C) 101 D) 87
answer
55
question
What will the following code display? int numbers[] = { 99, 87, 66, 55, 101 }; for (int i = 1; i < 4; i++) cout << numbers[i] << endl; A) 99 87 66 55 101 B) 87 66 55 101 C) 87 66 55 D) Nothing. This code has an error.
answer
87 66 55
question
What will the following code do? const int SIZE = 5; double x[SIZE]; for(int i = 2; i <= SIZE; i++) { x[i] = 0.0; } A) Each element in the array is initialized to 0.0 B) Each element in the array, except the first, is initialized to 0.0 C) Each element in the array, except the first and the last, is initialized to 0.0 D) An error will occur when the code runs
answer
An error will occur when the code runs
question
Which statement correctly defines a vector object for holding integers? A) vector v; B) int vector v; C) int v; D) vector v;
answer
vector v;
question
Which statement correctly uses C++ 11 to initialize a vector of ints named n with the values 10 and 20? A) vector n(10, 20); B) vector n = {10, 20}; C) vector n { 10, 20 }; D) int vector n ({10}, {20});
answer
vector n { 10, 20 };
question
What does the following statement do? vector v(10); A) It creates a vector object and initializes all of its elements to the value 10. B) It creates a vector object with a starting size of 10. C) It creates a vector object and initializes the first element with the value 10. D) It creates a vector object that can store only values of 10 or less.
answer
It creates a vector object with a starting size of 10.
question
What will the following C++ 11 code display? vector 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.
answer
3 5
question
What does the following statement do? vector v(10, 2); A) It creates a vector object and initializes all the first two elements with the values 10 and 2. B) It creates a vector object with a starting size of 2 and the first element initialized with the value 10. C) It creates a vector object with a starting size of 10 and the first element initialized with the value 2. D) It creates a vector object with a starting size of 10 and all elements are initialized with the value 2.
answer
It creates a vector object with a starting size of 10 and all elements are initialized with the value 2.
question
This vector function is used to insert an item into a vector. A) insert_item B) add_item C) store D) push_back
answer
push_back
question
This vector function returns the number of elements in a vector. A) size B) num_elements C) elements D) length
answer
size
question
This vector function removes an item from a vector. A) remove_item B) delete_item C) erase D) pop_back
answer
pop_back
question
This vector function returns true if the vector has no elements. A) has_no_elements B) null_size C) empty D) is_empty
answer
empty
question
The amount of memory used by an array depends upon the array's data type and the number of elements in the array.
answer
true
question
The statement: double money[25.00]; is a valid C++ array definition.
answer
false
question
An array initialization list must be placed on one single line.
answer
false
question
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;
answer
false
question
When you pass an array as an argument to a function, the function can modify the contents of the array.
answer
true
question
C++ limits the number of array dimensions to two.
answer
false
question
If you attempt to store data past an array's boundaries, it is guaranteed that the compiler will issue an error.
answer
false
question
An individual array element can be processed like any other type of C++ variable.
answer
true
question
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.
answer
true
question
In C++ 11, the range-based for loop is best used in situations where you need the element subscript for some purpose.
answer
false
question
Although two-dimensional arrays are a novel idea, there is no known way to pass one to a function.
answer
false
question
Each individual element of an array can be accessed by the array name and an element number, called a subscript.
answer
true
question
If an array is partially initialized, the uninitialized elements will be set to zero.
answer
true
question
A vector object automatically expands in size to accommodate the items stored in it.
answer
true
question
A ________ algorithm is a method of locating a specific item of information in a larger collection of data. A) sort B) search C) standard D) linear E) None of these
answer
search
question
The advantage of a linear search is its ________. A) complexity B) efficiency C) simplicity D) speed E) None of these
answer
simplicity
question
A(n) ________ search is more efficient than a ________ search. A) character, string B) integer, double C) binary, linear D) linear, binary E) None of these
answer
binary, linear
question
A binary search begins with the ________ element of an array. A) first B) last C) largest D) middle E) None of these
answer
middle
question
The ________ sort usually performs fewer exchanges than the ________ sort. A) bubble, selection B) binary, linear C) selection, bubble D) ANSI, ASCII E) None of these
answer
selection, bubble
question
Array elements must be ________ before a binary search can be performed. A) summed B) set to zero C) sorted D) positive numbers E) None of these
answer
sorted
question
Using a linear search to find a value that is stored in the last element of an array of 20,000 elements, ________ element(s) must be compared. A) 20,000 B) only the first C) only half D) 2000 E) None of these
answer
20,000
question
A(n) ________ search uses a loop to sequentially step through an array. A) binary B) unary C) linear D) relative E) None of these
answer
linear
question
Data that is sorted in ascending order is ordered ________. A) from lowest to highest value B) from highest to lowest value C) always with a binary sort algorithm D) always with a linear sort algorithm E) None of these
answer
from lowest to highest value
question
Regardless of the algorithm being used, a search through an array is always performed ________. A) from lowest to highest element B) from highest to lowest element C) beginning with the middle element D) using a binary search E) None of these
answer
none of these
question
When an array is sorted from highest to lowest, it is said to be in ________ order. A) reverse B) forward C) descending D) ascending E) None of these
answer
descending
question
The ________ is adequate for searching through small arrays. A) binary search B) linear search C) unary search D) bubble sort E) None of these
answer
linear search
question
________ algorithms are used to arrange random data into some order. A) Standard search B) Linear C) Sorting D) Binary search E) None of these
answer
sorting
question
The bubble sort is an easy way to arrange data into ascending order, but it cannot arrange data into descending order.
answer
false
question
The number of comparisons made by a binary search is expressed in powers of two.
answer
true
question
In the average case, an item is just as likely to be found near the beginning of an array as near the end.
answer
true
question
A linear search can only be implemented with integer values.
answer
false
question
Before you can perform a selection sort, the data must be stored in ascending order.
answer
false
question
Before you can perform a bubble sort, the data must be stored in descending order.
answer
false
question
Using a binary search, you are more likely to find an item than if you use a linear search.
answer
false