COP1334C INTRO TO C++
This step will uncover any syntax errors in your program.
Compiling
If you attempt to store data past an array's boundaries, it is guaranteed that the compiler will issue an error.
False
If you do not follow a consistent programming style, your programs will generate compiler errors.
False
If you want to know the length of the string that is stored in a string object, you can call the object's size member function.
False
The default section is required in a switch statement.
False
These are data items whose values do not change while the program is running.
Literals
If you place a semicolon after the statement if (x < y)
The compiler will interpret the semicolon as a null statement.
When the final value of an expression is assigned to a variable, it will be converted to:
The data type of the variable
_______ must be included in any program that uses the cout object.
The header file iostream
When a program lets the user know that an invalid choice has been made, this is known as:
input validation
Which of the following is a valid C++ array definition?
int scores [10]; int array[10];
This is a control structure that causes a statement or group of statements to repeat.
loop
The do-while loop is considered a(n) _________ loop.
post-test
Given the following declaration, where is 77 stored in the scores array? int scores[]={83, 62, 77, 97}:
scores[2]
What is the value of average after the following code executes? double average; average = 1.0 + 2.0 + 3.0 / 3.0;
4.0
What is the value stored at x, given the statements: int x; x = 3 / static_cast<int>(4.5 + 6.4);
0
What is the output of the following code segment? n = 1; for ( ; n <= 5; ) cout << n << ' '; n++;
1 1 1 ... and on forever
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? (All variables are of type int) x = 1; y = 2; z = 3; calc(x, y); cout << x << " " << y << " " << z << endl;
1 6 3
How many elements does the following array have? int bugs[1000];
1000
What is the output of the following statement? cout << 4 * (15 / (1 + 3)) << endl;
12
What will the value of x be after the following statements execute? int x; x = 18.0 / 4;
4.5
What will the following code display? int numbers[] = {99, 87, 66, 55, 101 }; cout << numbers[3] << endl;
55
1 #include < iostream > 2 using namespace std; 3 4 int main( ) 5 { 6 const int MY_VAL; 7 MY_VAL = 7; 8 cout << MY_VAL << endl; 9 return 0; 10 } What is the value of MY_VAL at line 7 in this program?
7
Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 const int MY_VAL = 77; 7 MY_VAL = 99; 8 cout << MY_VAL << endl; 9 return 0; 10 }
7
Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 const int MY_VAL; 7 MY_VAL = 77; 8 cout << MY_VAL << endl; 9 return 0; 10 }
7
This operator is used in C++ to represent equality.
==
The ______ operator always follows the cin object, and the ______ operator follows the cout object.
>>, <<
An array initialization list must be placed on one single line.
False
Associativity is either right to left or
Left to right
It is possible for a function to have some parameters with default arguments and some without.
True
When C++ is working with an operator, it strives to convert the operands to the same type
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.
True
When you pass an array as an argument to a function, the function can modify the contents of the array.
True
If you want a user to enter exactly 20 values, which loop would be the best to use?
for
To allow file access in a program, you must #include this header file.
fstream
An array with no elements is
illegal in C++
A(n) ____________ can be used to specify the starting values of an array.
initialization list
Arrays may be ___________ at the time they are __________
initialized, declared
How would you consolidate the following declaration statements into one statement? int x = 7; int y = 16; int z = 28;
int x = 7, y = 16, z = 28;
The numeric data types in C++ can be broken into two general categories:
integer and floating point
When a variable is assigned a number that is too large for its data type, it:
overflows
This is a special value that marks the end of a list of values.
sentinel
A two-dimensional array is like ______________ put together.
several identical arrays
A character literal is enclosed in ________ quotation marks, whereas a string literal is enclosed in ________ quotation marks.
single, double
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
This statement lets the value of a variable or expression determine where the program will branch to.
switch
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
This is a pre-test loop that is ideal in situations where you do not want the loop to iterate if the condition is false from the beginning.
while
Which statement is equivalent to the following? x = x * 2;
x *= 2;
A function's return data type must be the same as the function's parameter(s).
False
A local variable and a global variable may not have the same name within the same program.
False
A variable called "average" should be declared as an integer data type because it will probably hold data that contains decimal places.
False
A while loop is somewhat limited, because the counter can only be incremented by one each time through the loop.
False
Although two-dimensional arrays are a novel idea, there is no known way to pass one to a function.
False
Arithmetic operators that share the same precedence have right to left associativity.
False
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
C++ limits the number of array dimensions to two.
False
In programming, the terms "line" and "statement" always mean the same thing.
False
Machine language is an example of a high-level language
False
Pseudocode is a form of program statement that will always evaluate to "false."
False
The increment and decrement operators can be used in mathematical expressions; however, they cannot be used in relational expressions.
False
The preprocessor executes after the compiler.
False
The statement cout << setprecision(5) << dollars << endl; will output $5.00 to the screen.
False
The statement double money[25)00]; is a valid C++ array definition.
False
When a function is called, flow of control moves to the function's prototype.
False
When a program uses the setw manipulator, the iosetwidth header file must be included in a preprocessor directive
False
You must furnish an argument with a function call.
False
Besides decimal, two other number systems you might encounter in C++ programs are:
Hexadecimal and Octal
Which is true about the following statement? cout << setw(4) << num4 << " ";
It allows four spaces for the value in the variable num4.
Which is true about the following statement? cout << setw(4) << num4 << " ";
It allows four spaces for the value in the variable num4.
Of the following, which is a valid C++ identifier?
June1997 _employee_number ___department myExtraLongVariableName
In a C++ program, two slash marks ( // ) indicate:
The beginning of a comment
What will the following code display? int numbers[4] = { 99, 87 }; cout << numbers[3] << endl;
0
What is assigned to the variable a given the statement below with the following assumptions: x = 10, y = 7, and z, a, and b are all int variables. a = x >= y;
1
What will the following program segment display? int funny = 7, serious = 15; funny = serious % 2; if (funny != 1) { funny = 0; serious = 0; } else if (funny == 2) { funny = 10; serious = 10; } else { funny = 1; serious = 1; } cout << funny << " " << serious << endl;
1 1
This function in C++ allows you to identify how many bytes of storage on your computer system an integer data value requires.
sizeof
The value in this type of local variable persists between function calls.
static
The value in a(n) _______ variable persists between function calls.
static local
This may be used to write information to a file.
stream insertion operator
The first step in using the string class is to #include the ___________ header file.
string
An array of string objects that will hold 5 names would be declared using which statement?
string names[5];
This is a dummy function that is called instead of the actual function it represents.
stub
What will following segment of code output? int x = 5; if (x = 2) cout << "This is true!" << endl; else cout << "This is false!" << endl; cout << "This is all folks!" << endl;
This is true! This is all folks!
A CPU really only understands instructions that are written in machine language
True
A parameter is a special-purpose variable that is declared inside the parentheses of a function definition.
True
A preprocessor directive does not require a semicolon at the end.
True
A static variable that is defined within a function is initialized only once, the first time the function is called.
True
A while loop's body can contain multiple statements, as long as they are enclosed in braces.
True
An expression that has any value other than 0 is considered true by an if statement.
True
An individual array element can be processed like any other type of C++ variable.
True
An initialization expression may be omitted from the for loop if no initialization is required.
True
Both of the following if statements perform the same operation. if (sales > 10000) commissionRate = 0)15; if (sales > 10000) commissionRate = 0)15;
True
C++ does not have a built in data type for storing strings of characters.
True
Each individual element of an array can be accessed by the array name and an element number, called a subscript.
True
Escape sequences are always stored internally as a single character.
True
Floating point constants are normally stored in memory as doubles.
True
Global variables are initialized to zero by default.
True
If an array is partially initialized, the uninitialized elements will be set to zero.
True
If the sub-expression on the left side of an && operator is false, the expression on the right side will not be checked.
True
If the sub-expression on the left side of the || operator is true, the expression on the right side will not be checked.
True
If you want to know the length of the string that is stored in a string object, you can call the object's size member function.
True
In C++, it is impossible to display the number 34.789 in a field of 9 spaces with 2 decimal places of precision.
True
In C++, key words are written in all lowercase letters.
True
One reason for using functions is to break programs into manageable units, or modules.
True
Software engineering is a field that encompasses designing, writing, testing, debugging, documenting, modifying, and maintaining computer programs.
True
The amount of memory used by an array depends upon the array's data type and the number of elements in the array.
True
The cin << statement will stop reading input when it encounters a newline character.
True
The only difference between the get function and the >> operator is that get reads the first character typed, even if it is a space, tab, or the [Enter] key.
True
When typing in your source code into the computer, you must be very careful since most of your C++ instructions, header files, and variable names are case sensitive.
True
You should be careful when using the equality operator to compare floating point values because of potential round-off errors.
True
_________ functions may have the same name, as long as their parameter lists are different.
Two or more
Programmer-defined names of memory locations that may hold data are:
Variables
___ represent storage locations in the computer's memory.
Variables
What will the following segment of code output? You can assume the user enters a grade of 90 from the keyboard. cout << "Enter a test score: "; cin >> test_score; if (test_score < 60); cout << "You failed the test!" << endl; if (test_score > 60) cout << "You passed the test!" << endl; else cout << "You need to study for the next test!";
You failed the test! You passed the test!
Which character signifies the beginning of an escape sequence?
\
Which escape sequence causes the cursor to move to the beginning of the current line?
\r
This control sequence is used to skip over to the next horizontal tab stop.
\t
To assign the contents of one array to another, you must use
a loop to assign the elements of one array to the other array
A loop that is inside another loop is called:
a nested loop
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
This is a variable that is regularly incremented or decremented each time a loop iterates.
counter
The ______ is/are used to display information on the computer's screen.
cout object
To use the rand() function, you must #include this header file in your program.
cstdlib
If you intend to place a block of statements within an if statement, you must place these around the block.
curly braces { }
During which stage does the central processing unit retrieve from main memory the next instruction in the sequence of program instructions?
fetch
This stream manipulator forces cout to print the digits in fixed-point notation.
fixed
This is a variable, usually a boolean or an integer, that signals when a condition exists.
flag
This loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop.
for
An array can easily be stepped through by using a
for loop
This is a collection of statements that performs a specific task.
function
This is a statement that causes a function to execute.
function call
Every complete C++ program must have a ________.
function named main
reads a line of input, including leading and embedded spaces, and stores it in a string object.
getline
A ___________ variable is declared outside all functions.
global
If a function does not have a prototype, default arguments may be specified in the function ___________.
header
Which statement allows you to properly check the char variable code to determine whether it is equal to a "C" and then output "This is a check" and then advance to a new line?
if (code == 'C') cout << "This is a check\n";
To read data from a file, you define an object of this data type.
ifstream
The statement int grades[ ] = { 100, 90, 99, 80}; shows an example of
implicit array sizing
This means to increase a value by one.
increment
Something within a while loop must eventually cause the condition to become false, or a(n) __________ results.
infinite loop
In a for statement, this expression is executed only once.
initialization
In any program that uses 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 manipulator causes the field to be left-justified with padding spaces printed to the right.
left
It is __________ to pass an argument to a function that contains an individual array element, such as numbers[3].
legal in C++
Assume that a program has the following variable definition: char letter; Which of the following statements correctly assigns the character Z to the variable?
letter = 'Z';
This type of variable is defined inside a function and is not accessible outside the function.
local
These operators connect two or more relational expressions into one, or reverse the logic of an expression.
logical
The name of an array stores the __________ of the first array element.
memory address
To pass an array as an argument to a function, pass the _________ of the array.
name
Assume that a program has the following string object definition: string name; Which of the following statements correctly assigns a string literal to the string object?
name = "Jane";
When an if statement is placed within the conditionally-executed code of another if statement, this is known as:
nesting
If you place a semicolon after the test expression in a while loop, it is assumed to be a(n):
null statement
The ______________ is automatically appended to a character array when it is initialized with a string constant.
null terminator
Which statement is equivalent to the following? number += 1;
number = number + 1;
To write data to a file, you define an object of this data type.
ofstream
A two-dimensional array can have elements of _________ data type(s).
one
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
Assuming outFile is a file stream object and number is a variable, which statement writes the contents of number to the file associated with outFile?
outFile << number;
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
The do-while loop is a __________ loop that is ideal in situations where you always want the loop to iterate at least once.
post-test
The while loop is this type of loop.
pre-test
When the increment operator precedes its operand, as in ++num1, the expression is in this mode.
prefix
This operator increments the value of its operand, then uses the value in context.
prefix increment
A function __________ eliminates the need to place a function definition before all calls to the function.
prototype
When used as parameters, these types of variables allow a function to access the parameter's original argument.
reference
This statement causes a function to end.
return
A two-dimensional array can be viewed as ___________ and _____________
rows, columns
A variable's ___________ is the part of the program that has access to the variable)
scope
The ________ of a variable is limited to the block in which it is declared.
scope
This manipulator is used to establish a field width for the value immediately following it.
setw
The total number of digits that appear before and after the decimal point is sometimes referred to as:
significant digits and precision
The statements written by the programmer are called:
Source code
The statements in the body of a while loop may never be executed, whereas the statements in the body of a do-while loop will be executed:
at least once
Which of the following is a preprocessor directive?
#include <iostream>
What is the modulus operator?
%
This operator represents the logical AND.
&&
When this operator is used with string operands it concatenates them, or joins them together.
+
These are operators that add and subtract one from their operands.
++ and --
Assume that x is an int variable) What value is assigned to x after the following assignment statement is executed? x = -3 + 4 % 6 / 5;
-3
This operator performs a logical NOT operation.
!
This operator takes an operand and reverses its truth or falsehood.
!
What will the following program display? #include <iostream> using namespace std; int main() { int a = 0, b = 2, x = 4, y = 0; cout << (a == b) << " "; cout << (a != b) << " "; cout << (b <=x) << " "; cout << (y > a) << endl; return 0; }
0 1 1 0
What is the value of number after the following statements execute? int number = 10; number += 5; number -= 2; number *= 3;
15
Look at the following statement. while (x++ < 10) Which operator is used first?
<
A set of well-defined steps for performing a task or solving a problem is known as a(n):
Algorithm
A two-dimensional array of characters can contain
All of these
Input values should always be checked for
All of these: 1) Appropriate range 2) Reasonableness 3) Division by zero, if division is taking place
In a function header, you must furnish
All of these: 1) data type(s) of the parameters 2) data type of the return value 3) the name of function 4) names of parameter variables
What will the following code do? const int SIZE = 5; double x[SIZE]; for(int i = 2; i <= SIZE; i++) { x[i] = 0)0; }
An error will occur when the code runs
In C++ the = operator indicates
Assignment
What will the following segment of code output if 11 is entered at the keyboard? int number; cin >> number; if (number > 0) cout << "C++"; else cout << "Soccer"; cout << " is "; cout << "fun" << endl;
C++ is fun
For every opening brace in a C++ program, there must be a:
Closing brace
These types of arguments are passed to parameters automatically if no argument is provided in the function call.
Default
This term refers to the programmer reading the program from the beginning and steping through each statement.
Desk Checking
EXIT_FAILURE and __________ are named constants that may be used to indicate success or failure when the exit() function is called.
EXIT_SUCCESS
What will the following segment of code output? score = 40; if (score > 95) cout << "Congratulations!\n"; cout << "That's a high score!\n"; cout << "This is a test question!" << endl;
That's a high score! This is a test question!
Subscript numbering in C++
begins with zero
What will be the output of the following code segment after the user enters 0 at the keyboard? int x = -1; cout << "Enter a 0 or a 1 from the keyboard: "; cin >> x; if (x) cout << "true" << endl; else cout << "false" << endl;
false
x = x * 2;
x *= 2;
What is the output of the following segment of code if 4 is input by the user when asked to enter a number? int num; int total = 0; cout << "Enter a number from 1 to 10: "; cin >> num; switch (num) { case 1: case 2: total = 5; case 3: total = 10; case 4: total = total + 3; case 8: total = total + 6; default: total = total + 4; } cout << total << endl;
13
What will the value of x be after the following statements execute? int x = 0; int y = 5; int z = 4; x = y + z * 2;
13
After execution of the following code, what will be the value of input_value if the value 0 is entered at the keyboard at run time? cin >> input_value; if (input_value > 5) input_value = input_value + 5; else if (input_value > 2) input_value = input_value + 10; else input_value = input_value + 15;
15
In the C++ instruction, cookies = number % children; given the following declaration statement: int number = 38, children = 4, cookies; what is the value of cookies after the execution of the statement?
2
What will the value of result be after the following statement executes? result = 6 - 3 * 2 + 7 - 10 / 2 ;
2
Given the following code segment, what is output after "result = "? int x = 1, y = 1, z = 1; y = y + z; x = x + y; cout << "result = " << (x < y ? y : x) << endl;
3
In a broad sense, the two primary categories of programming languages are:
Low-level and High-level
What will the following code display? cout << "Monday"; cout << "Tuesday"; cout << "Wednesday";
MondayTuesdayWednesday
A variable whose value can be either true or false is of this data type
bool
This statement causes a loop to terminate early.
break
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
A file _________ is a small holding section of memory that file-bound information is first written to.
buffer
Functions are ideal for use in menu-driven programs. When a user selects a menu item, the program can ________ the appropriate function.
call
A function is executed when it is
called
Which data type typically requires only one byte of storage?
char
The _________ causes a program to wait until information is typed at the keyboard and the Enter key is pressed
cin object
This statement will pause the screen, until the [Enter] key is pressed.
cin.get();
Assuming dataFile is a file stream object, the statement dataFile.close();
closes a file
When using the sqrt function you must include this header file.
cmath
Relational operators allow you to ____________ numbers
compare
Relational operators allow you to ____________ numbers.
compare
An array's size declarator must be a(n)_________ with a value greater than _________
constant integer expression, zero
In the following C++ statement, what will be executed first according to the order of precedence? result = 6 - 3 * 2 + 7 - 10 / 2 ;
3 * 2
Assuming x is 5, y is 6, and z is 8, which of the following is false? x == 5; 7 <= (x + 2); z < = 4; (1 + x) != y; z >= 8; x >= 0; x <= (y * 2)
3 and 4 are False
Which one of the following would be an illegal variable name?
3dGraph
What is the last legal subscript that can be used with the following array? int values[5];
4
Which of the following statements about global variables is true?
A global variable can have the same name as a variable that is declared locally within a function.
An example of a secondary storage device is:
A hard disk
The programmer usually enters source code into a computer using:
A text editor
What statement best describes a variable and its primary purpose?
A variable is a named storage location in the computer's memory used for holding a piece of information.
_______________ are used to translate each source code instruction into the appropriate machine language instruction.
Compilers
When converting some algebraic expressions to C++, you may need to insert ___________ that do not appear in the algebraic expression.
Parentheses
Which of the following is not one of the five major components of a computer system?
Preprocessor
A statement that starts with a # is called a:
Preprocessor directive
A(n) ____________ is a set of instructions that the computer follows to solve a problem.
Program
This is used in a program to mark the beginning or ending of a statement, or separate items in a list.
Punctuation
This is a volatile type of memory, used for temporary storage
RAM
Whereas < is called a relational operator, x < y is called a(n)________________
Relational expression
This is used to mark the end of a complete C++ programming statement.
Semicolon
In programming terms, a group of characters inside a set of quotation marks is called a:
String literal
When writing functions that accept multi-dimensional arrays as arguments, _______________ must be explicitly stated in the parameter list.
all but the first dimension
Given that x = 2, y = 1, and z = 0, what will the following cout statement display? cout << "answer = " << (x || !y && z) << endl;
answer = 1
A(n) _________ is information that is passed to a function, and a(n) _________ is information that is received by a function.
argument, parameter
Unlike regular variables, these can hold multiple values.
arrays
This statement may be used to stop a loop's current iteration and begin the next one.
continue
A(n) _________ argument is passed to a parameter when the actual argument is left out of the function call.
default
A function __________ contains the statements that make up the function.
definition
You must have a ___________ for every variable you intend to use in a program.
definition
It is a good programming practice to ____________ your functions by writing comments that describe what they do.
document
Which of the following defines a double-precision floating point variable named payCheck?
double payCheck;
The individual values contained in array are known as
elements
This function causes a program to terminate, regardless of which function or control mechanism is executing.
exit()
An array can store a group of values, but the values must be
the same data type
The default section of a switch statement performs a similar task as the _______ portion of an if/else if statement.
trailing else
A for statement contains three expressions: initialization, test, and
update
You may define a __________ in the initialization expression of a for loop.
variable
Which statement is equivalent to the following? x = x * 2;
x *= 2;
If you leave out the size declarator in an array definition:
you must furnish an initialization list
When a relational expression is false, it has the value
zero
This operator is known as the logical OR operator.
||
The float data type is considered _____ precision, and the double data type is considered _______ precision.
single, double
The _____ causes the contents of another file to be inserted into a program.
#include directive
Character constants in C++ are always enclosed in _____
'single quotation marks'
You can use these to override the rules of operator precedence in a mathematical expression.
(Parentheses)
What will the following code display? int x = 0, y = 1, z = 2; cout << x << y << z << endl;
012
Look at the following program and answer the question that follows it. 1 // This program displays my gross wages. 2 // I worked 40 hours and I make $20.00 per hour. 3 #include <iostream> 4 using namespace std; 5 6 int main() 7 { 8 int hours; 9 double payRate, grossPay; 10 11 hours = 40; 12 payRate = 20.0; 13 grossPay = hours * payRate; 14 cout << "My gross pay is $" << grossPay << endl; 15 return 0; 16 } Which line(s) in this program cause output to be displayed on the screen?
14
What will the value of x be after the following statements execute? int x; x = 18 % 4;
2
What is the value of number after the following statements execute? int number = 2; number += 5; number -= 2; number *= 3;
30
What will the value of x be after the following statements execute? int x; x = 18 / 4;
4
In C++, it is impossible to display the number 34.789 in a field of 9 spaces with 2 decimal places of precision.
False
The C++ language requires that you give variables names that indicate what the variables are used for.
False
The fixed manipulator causes a number to be displayed in scientific notation.
False
These are used to declare variables that can hold real numbers.
Floating point data types
What will the following code display? cout << "Four\n" << "score\n"; cout << "and" << "\nseven"; cout << "\nyears" << " ago" << endl;
Four score and seven years ago
What will the following code display? cout << "Four " << "score "; cout << "and " << "seven/n"; cout << "years" << "ago" << endl;
Four score and seven/nyearsago
What will the following code display? cout << "Four" << "score" << endl; cout << "and" << "seven" << endl; cout << "years" << "ago" << endl;
Fourscore andseven yearsago
In memory, C++ automatically places a ___________ at the end of string literals.
Null terminator
In the process of translating a source file into an executable file, which of the following is the correct sequence?
Source code, preprocessor, modified source code, compiler, object code, linker, executable code
This is a set of rules that must be followed when constructing a program.
Syntax
Internally, the CPU consists of two parts:
The Control Unit and the Arithmetic and Logic Unit
What will the following code display? int number = 7; cout << "The number is " << "number" << endl;
The number is number
A preprocessor directive does not require a semicolon at the end
True
The function, pow(x, 5.0), requires this header file
cmath
Unix and Windows 2000 are examples of ____ operating systems.
multi-tasking
Assume that a program has the following string object definition: String name; Which of the following statements correctly assigns a string literal to the string object?
name = "Jane";
If you use a C++ key word as an identifier, your program will:
not compile