COP2000 Final Exam
An array initialization list must be placed on one single line T or F?
False
An array with no elements is legal T or F?
False
Arithmetic operators that share the same precedence have right to left associativity T of F?
False
Assume array1 and array2 are the names of arrays. To assign the contents of array2 to array1, you would use the following statement T or F? array1=array2
False
The fixed manipulator causes a number to be displayed in scientific notation T or F?
False
Where does a binary search begin?
In the middle
This directive is used to create an "include guard," which allows a program to be conditionally compiled. This prevents a header file from accidentally being included more than once.
#ifndef
What is the symbol for modulus?
%
Character constants in C++ are always enclosed in .
'single quotation marks'
When this operator is used with string operands it concatenates them, or joins them together.
+
Assume that x is an int variable. What value is assigned to x after the following assignment statement is executed? -3 + 4 % 6/5 = x
-3
What is the output of the following code segment? n=1; while(n=5) cout<<n<<' '; n++;
111...
What is the output of the following program? #include <iostream> using namespace std; int getValue(int); int main() {int x=2; cout<<getValue(x)<<endl; return 0; } int getValue(int num) { return num+5 }
7
What will the following code display? int number=6 cout<<++number<<endl;
7
What will the value of result be after the following statement executes? 6 - 3*2 + 7 - 10/2;
8
What will the following code display? int numbers[ ]={99,87,66,55,101}; for(int i=1;i<4;i++) cout<<numbers[i]<<endl;
87 66 55
Look at the following statement while(x++<10) What operator is used first?
<
The first step in using the string class is to #include what header file?
<string>
What symbol is used to represent equality?
==
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 what statement?
string names[5];
By using the same-----you can build relationships between data stored in two or more arrays.
subscript
To access an array element, use the array name and the element's -------.
subscript
An element of a two-dimensional array is referred to by ------followed by--------.
The row subscript of the element, the column subscript of the element.
A global variable can have the same name as a variable that is declared locally T or F?
True
A preprocessor directive does not require a semicolon at the end T or F?
True
An individual array element can be processed like any other type of C++ variable T or F?
True
If an array is partially initialized, the uninitialized elements will be set to zero T or F?
True
The cin<<statement will stop reading input when it encounters a newline character Tor F?
True
When the fixed manipulator is used, the value specified by the setprecision manipulator will be the number of digits to appear after the decimal point T or F?
True
The control sequence is used to skip over to the next horizontal tab stop.
\t
This is a variable that is regularly incremented or decremented each time a loop iterates
counter
What will be the output of the following code segment if the user enters 0? int x=-1 cout<<"Enter a 0 or a 1 from the keyboard: "; cin>>x; if (x) cout<<"true"<<endl; else cout<<"flase<<endl;
false
This is a variable, usually a boolean or an integer, that signals when a condition exists.
flag
This is a collection of statements that performs a specific task.
function
Which statement will read an entire line of input into the following string object?
getline(cin,address);
if a function does not have a prototype, default arguments may be specified in the function .
header
The statement int grades[ ]={100,90,99,80}; shows an example of----.
implicit array sizing
The numeric data types in C++ can be broken into two general categories:
integer and floating point
In any program that used the cin object, you must include the .
iostream header file
The while loop contains 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
This variable is defined inside a function and is not accessible outside of the function
local
The name of an array stores the ------ of the first array element.
memory address
Assume that myCar is an instance of the Car class, and that the Car class has a member function named accelerate. What is a valid call to the accelerate member function?
myCar.accelerate();
To pass an array as an argument to a function, pass the ----- of the array.
name
In memory, C++ automatically places a at the end of string literals.
null terminator
A function can have zero to many parameters, and it can return this many values.
only one
A file must be before data can be written to or read from it.
opened
When a variable is assigned a number that is too large for its data type, it:
overflows
If a function is called more than once in a program, the values stored in the function's local variable do not ---- between function calls.
persist
The do-while loop is considered a loop.
post-test
When the increment operator precedes its operand, as in ++num1, the expression is in the mode.
prefix
This is used to protect important data.
private access specifier
A function eliminates the need to place a function definition before all calls to the function.
prototype
Given the following declaration, where is 77 stored in the scored array? int scored[ ]={83,62,77,97};
scores[2]
A------algorithm is a method of locating a specific item of information in a larger collect of data.
search
The-----sort usually performs fewer exchanges than the------sort.
selection, bubble
This manipulator is used to establish a field width for the value immediately following it.
setw
A two-dimensional array is like------- put together.
several identical arrays
What is the advantage of a linear search?
simplicity
How many times will the following loop display "Hello"? for(int i=1;i<20;i++) count<<"Hello!"<<endl;
19
cookie=number%children if number = 38 and children = 4, what is the value of cookies?
2
Assume x is 5, y is 6, and z is 8, which of the following is false? 1. x==5 2. 7<=(x+2) 3. z<=4 4. (1+x)!=y 5. z>=8 6. x>=0 7. x<=(y*2)
3 and 4 are false
In the following C++ statement, what will be executed first according to the order of precedence? 6 - 3 * 2 + 7 - 10/2
3*2
What is the last legal subscript that can be used with the following array? int values[5];
4
What's the output of the following code if an 11 is entered? int number; cin>>number; if(number>0) cout<<"C++"; else cout<<"Soccer"; cout<<"is"; cout<< "fun";
C++ is fun
These types of arguments are passed to parameters automatically if no argument is provided in the function call.
Default
EXIT_FAILURE and--------- are named constants that may be used to indicate success or failure when the exit() function is called.
EXIT_SUCCESS
Relational operators allow you to ________ numbers.
compare
There are data items whose values do not change while the program is running.
Literals
What will the following code display? cout<<"Monday"; cout<<"Tuesday"; cout<<"Wednesday";
MondayTuesdayWednesday
A class may have this many default constructors
Only one
A------ is a member function that is automatically called when a class object is--------.
constructor, created
In OOP terminology, an object's member variables are often called its------, and its a member functions are sometimes referred to as its behaviors, or ---------.
attributes, methods
Without this statement appearing in a switch construct, the program "falls through" all of the statements below the one with the matching case expression.
break
This term will pause the screen until the [Enter] key is pressed.
cin.ignore();
In a procedural program, you typically have-------- stored in a collection of variables, and a set of ----- that perform operations on the data.
data, functions
When an array is sorted from highest to lowest, it is said to be in ------ order.
descending
This automatically called when an object is destroyed.
destructor function
Members of a class object are accessed with the ...
dot operator
Which of the following defines a double-precision floating point variable names payCheck?
double payCheck;
This function causes a program to terminate, regardless of which function or control mechanism is executing.
exit()
The constructor function always has the same name as...
the class
An array can store a group of values, but the values must be
the same data type
A for a statement contains three expressions: initialization, test, and
update
What expression states that x is less than or equal to y?
x<=y
If you leave out the size declarator in an array definition...
you must furnish an initialization list.
What operator is known as the logical OR operator?
||