CS2250 Final Exam
Before you can perform a selections sort, the data must be stored in ascending order
False
The bubble sort is an easy way to arrange data into ascending order, but it cannot arrange data into descending order.
False
The scope of a variable declared in a for loop's initialization expression always extends beyond the body of the loop.
False
Using a binary search, you are more likely to find an item than if you use a linear search
False
size of an array
(number of elements) * (number of bytes for each element)
What will the following loop display? int x = 0; while (x<5) { cout<<x<< endl; x++; }
0 1 2 3 4
Which line in the following program contains a call to the showDub Function? 1 #include <iostream> 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 }
10
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.
20000
How many times will the following loop display "Hello"? for int i = 0; i<=20, i++) cout << "Hello" << endl;
21
What will the following code display? Int x = 0; for (int count = 0; count < 3; count++) x +=count; cout<<x<<endl;
3
function call
A statement that executes a function. It consists of the function name followed by an argument list.
In a function header, you must furnish:
All of these { data type(s) of the parameters, data type of the return value, the name of function, name of parameter variables }
to access an array element, use the array name and the element's:
Subscript
range-based for loop
a loop that iterates once for each element in an array
The while loop has two important parts: an expression that is tested for a true or false value, and:
a statement or block that is repeated as long as the expression is true
tests[i]++;
adds 1 to tests[i]
Unlike regular variables, these can hold multiple values.
arrays
a(n)_________ search is more efficient than a(n) ______ search
binary, linear
this statement causes a loop to terminate early
break
a function _______ contains the statements that make up the function.
definition
look at the following function prototype int myFunction(double); What is the data typeof the function's parameter variable?
double
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
When a function is called, flow of control moves to the function's prototype.
false
you may not use the break and continue statements within the same set of nested loops.
false
Copy an array
for (i = 0; i < ARRAY_SIZE: i++) newTests [i] = tests[i];
This is a collection of statements that performs a specific task.
function
A ____________ variable is declared outside all functions
global
tests[i++];
increment i, no effect on tests
In a for statement, this expression is executed only once
initialization
It is ________ to pass an argument to a function that contains an individual array element, such as numbers[3].
legal in C++
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
The _________ is automatically appended to a character array when it is initializated with a string constant
null terminator
the do-while loop is considered a(n) ________ loop
post-test
a two-dimensional array can be viewed as __________ and ___________
rows, columns
The ______ sort usually preforms fewer exchanges than the ______ sort
selection, bubble
function definition
statement that make up a function
The value in this type of local variable persists between function calls.
static
An array of string objects that will hold 5 names would be declared using which statement?
string names[5];
By using the same ________ you can build relationships between data stored in two or more arrays.
subscript
An array can store a group of values, but the values must be:
the same data type
Every time you pass a variable or an array you pass a copy of that variable/array
true
It is not considered good programming practice to declare all of your variables globally.
true
When you pass an array as an argument to a function, the function can modify the contents of the array.
true
an individual array element can be processed like any other type of C++ variable
true
one reason for using functions is to break programs into manageable units, or modules
true
you may use the exit() function to terminate a program, regardless of which control mechanism is executing.
true
A for statement contains three expressions: initialization, test, and
update