COP Exam 2
false
A function's return data type must be the same as the function's parameters T/F
False
A local variable and a global variable may not have the same name within the same program T/F
true
A parameter is a special purpose variable that is declared inside the parentheses of a function definition T/F
initialization list
A(n) BLANK can be used to specify the starting values of an array
argument, parameter
A(n) ________ is information that is passed to a function, and a(n) ________ is information that is received by a function.
initialized, declared
Arrays may be ________ at the time they are ________.
int temp= num2; num2=num1; num1=temp;
Assume you have two integer variables, num1 and num2. Which of the following is the correct way to swap the values in these two variables
subscript
By using the same BLANK you can build relationships between data stored in two or more arrays
call
Functions are idea for menu-driven programs. When the user selects a menu item, theprogram can BLANK the appropriate function
scores [2]
Given the following declaration, where is the value 77 stored in the scores array? int scores [] = {83, 62, 77, 97, 86}
1 6 3
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 segment that invokes calc(): int x=1; int y=2; int z =3; calc (x,y); cout << x << " " << y << " " << z << endl;
computeValue(10);
Given the following header for a function named computeValue, which of hte following is a valid call to the function? void computerValue(int value)
all of these
In a function header you must furnish: 1) data types of hte parameters 2) the name of function 3) names of parameter variables 4) data type of hte return value 5) all of these
3
In the following function prototype, how many parameter variables does this function have? int myFunction (doublem double, double);
none of these
Regardless of the algorithm being used a search through an array is always performed
True
T/F The number of comparisons made by a binary search is expressed in powers or two
False
T/F Using a binary search you ar emore likely to find an item than if you use al inear search
False
T/F a linear search can only be implemented with integer values
false
T/F a linear search can only be implemented with integer values
false
T/F before you can perform a bubbl esort, the data must be stored indescending order
false
T/F before you can perform a selection sort, the data must be stored in ascending order
True
T/F in the average case an item is just as likelyt o be found near the beginning of an array as near the end
False
T/F the bubble sort is an easy way to arrange data into ascending order but it cannot arrange data into descending order
selection, bubble
The BLANK sort usually performs fewer exchanges than the BLANK sort
binary search
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 ootp 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 tomiddle -1 else set first to middle +1 end if end while return position
exit ()
This function causes a program to terminate, regardless of which function or control mechanisms is executing
return
This statement causes a function to end
double
What is the data type of the following function prototype's parameter variable? int myFunction9double0;
from lowest value to highest value
data that is to be sorted in ascending order is ordered
from lowest to highest value
data that is to be sorted in ascending order is ordered how
Two or more
how many functions may have the same name as long as their parameter lists are different
function header
if a function does NOT have a prototype, default arguments may be specified in the BLANK
persist
if a function is called more than once in.a program, the values stored in the function's local variables do NOT BLANK between functin calls
elements
individual values contained in an array are known as BLANK
legal in C++
it is BLANK to pass an argument to a function that contains an individual array element, such as scores[3]
document
it is good programming to practice to BLANK your functions by writing comments that describe what they do
true
it is possible for a function to have some parameters with defualt arguments and some without T/F
null terminator
the BLANK is automatically appended to a character array when it is initialized with a string constant
linear search
the BLANK search is adequate for searching through small arrays
simplicity
the advantage of a linear search is its what
it creates a vector object with a starting size of 10
what does the following statement do? vector v(10);
3 5
what will the following c++11 code display? vector numbers {3, 5}; for (int val: numbers) cout << val << endl;
55
what will the following code display? int numbers []= {99, 87, 66, 55, 101}; cout << numbers [3] << endl;
false
when a function is called, flow of control moves to the function's prototype T/F
descending order
when an array is sorted fro highest to lowest, it is said to be in what order
reference
when used as parameters, these types of variables allow a function to access the parameter's original argument
a function call
which of the following causes a function to execute
int sizes[10];
which of the following is a valid C++ array definition
global variable can have same name as a local variable
which of the following statements about global variables is true
vector <int> v;
which statement correctly defines a vector object for holding integers?
25/5 = 5
What is the output after the following code executes? int numerator =5; int denominator =25; int temp =0; temp = numerator; numerator = denominator; denominator = temp; cout << numerator << "/" << denominator << "=" << (numerator/denominator) << endl;
2 0 2
What is the output of the following program #include <iostream> 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; }
7
What will the following code display? #include using namespace std; int getValue (int); int main () { int x=2; cout << getValue(x) << endl; retiurn 0; } int getValue (int num) { return num +5; }
2 0 0
What will the following code display? #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; }
2 2
What will the following code display? #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; }
Line 11
Which line in the following program contains the header for the showDub function? 1. #include 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 3
Which line in the following program contains the prototype showDub function? 1. #include 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. }
search
a BLANK algorithm is a method of locationg a specifit item of information in a larger collection of data
binary, linear
a BLANK search is more efficient than a VBLANK search
linear
a BLANK search uses a loop to sequentially step through an array
global
a BLANK variable is declared outside all functions
middle
a binary search begins with the BLANK element of an array
definition
a function BLANK contains the statments that make up the function
Prototype
a function BLANK eliminates the need to place a function definition before all calls to the function
only one
a function can have no parameters, one parameter, or many parameters and can return BLANK value(s)
called
a function is executed when it is BLANK
one
a two-dimensional array can have elements of BLANK data type(s)
rows and columns
a two-dimensionsl array can be viewed as
sorting
algorithms used to arrange random data in some order are BLANK algorithms
a for loop
an array can easily be stepped through by using a what
the same data type
an array can store a group of values, but the values must be BLANK
constant, 0
an array's size declarator must be a BLANK with a value greater than BLANK
sorted
array elements must BLANK before a binary search can be performed
linear search
the following is the pseduocode for which type of algorithm set found to false set position to -1 set index to 0 while found is false and index < number of elements if list[index] is equal to search value found = true position =index end if add 1 to index end while return to position
bubble sort
the following is the pseudocode for which type of algorithm for maxElement = eac hsubscript in the array, from the last to the first for index=0 To maElement -1 if array[index] > array[index+1] swap array[index] with array[index+1] end if end for end for
selection sort
the following is the pseudocode for which type of algorithm? For start = each array subscript, form the first to he 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
memory address
the name of an array stores the BLANK of the first array element
the range variable
the range-baded for loop in C++11 is designed to work with a built-in variable known as
Static local
the value in a BLANK variable persists between function calls
static
the value in this type of variable persister between function calls.
default
these types of arguments are passed to parameters automatically if no argument is provided in teh function call
default
these types of arguments are passed to parameters automatically if no argument is provided in the function call
implicit array sizing
this following statement shows an example of BLANK int grades [] = {100, 90, 99, 80};
stub
this is a dummy function that is called instead of the actual function it represents:
push_back
this vector functio is used to insert an item into a vector
empty
this vector function returns true if the vector has no elements
subscript
to access an array element use the array name and the element's BLANK
name
to pass an array as an argument to a function, pass the BLANK of the array
20,000
using a linear search to find a value that is stored in the last element of an array that contains 20,000 elements, BLANK elements must be compared