CSCI 1933 Practice Final
The ________ causes the contents of another file to be inserted into a program.
#include directive
What is the modulus operator?
%
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); 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 showDub(x);
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? a) >name = (Jane); b) name=Jane; c) name='Jane'; d) name = "Jane";
name = "Jane";
If you place a semicolon after the test expression in a while loop, it is assumed to be a(n):
null statement
The do-while loop is a(n) ________ loop that is ideal in situations where you always want the loop to iterate at least once.
post-test
When the increment operator precedes its operand, as in ++num1, the expression is in this mode.
prefix
Even when there is no power to the computer, data can be held in:
secondary storage
This vector function returns the number of elements in a vector.
size
A for statement contains three expressions: initialization, test, and
update
You may define a ________ in the initialization expression of a for loop.
variable
In C++ 11, the ________ tells the compiler to determine the variable's data type from the initialization value.
variable's name
When a relational expression is false, it has the value ________.
zero
True/False: A variable called "average" should be declared as an integer data type because it will probably hold data that contains decimal places.
False
True/False: C++ 11 introduces an alternative way to define variables, using the template key word and an initialization value.
False
True/False: Escape sequences are always stored internally as a single character.
False
True/False: If you do not follow a consistent programming style, your programs will generate compiler errors.
False
True/False: The condition that is tested by a while loop must be enclosed in parentheses and terminated with a semicolon.
False
True/False: You may not use the break and continue statements within the same set of nested loops.
False
These are used to declare variables that can hold real numbers.
Floating point data types
Besides decimal, two other number systems you might encounter in C++ programs are:
Hexadecimal and Octal
What will the following code display? cout << "Monday"; cout << "Tuesday"; cout << "Wednesday";
MondayTuesdayWednesday
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 while loop is this type of loop.
Pre-test
A statement that starts with a # symbol is called a:
Preprocessor directive
Computer programs are also known as:
Software
What will the following code display? int number = 7; cout << "The number is " << "number" << endl;
The number is number
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
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 is a control structure that causes a statement or group of statements to repeat.
loop
What will be the value of result after the following code has been executed? int a = 60; int b = 15; int result = 10; if (a=b) result*=2;
20
What will the value of x be after the following statements execute? int x; x=18.0/4;
4
What will the following code display? int number = 6 int x = 0; x = --number; cout <<x<< endl;
5
Assuming you are using a system with 1-byte characters, how many bytes of memory will the following string literal occupy? "William"
8
Look at the following statement. while (x++ < 10) Which operator is used first?
<
If you want a user to enter exactly 20 values, which loop would be the best to use? a)for b)do-while c)infinite d)while e)none of these
A) For loop
The while loop has two important parts: an expression that is tested for a true or false value, and: A) a statement or block that is repeated as long as the expression is true B) a statement or block that is repeated only if the expression is false C) one line of code that is repeated once, if the expression is true D) a statement or block that is repeated once, if the expression is true
A) a statement or block that is repeated as long as the expression is true
This operator increments the value of its operand, then uses the value in context. A) prefix increment B) postfix increment C) prefix decrement D) postfix decrement E) None of these
A) prefix increment
These are operators that add and subtract one from their operands. A) plus and minus B) ++ and -- C) binary and unary D) conditional and relational E) None of these
B) ++ and --
What is the output of the following code segment? n = 1; while (n <= 5) cout << n << ' '; n++; A) 1 2 3 4 5 B) 1 1 1... and on forever C) 2 3 4 5 6 D) 1 2 3 4 E) 2 3 4 5
B) 1 1 1... and on forever
This statement may be used to stop a loop's current iteration and begin the next one.
Continue
This is a variable that is regularly incremented or decremented each time a loop iterates.
Counter
The purpose of a memory address is:
To identify the location of a byte in memory
True/False: A preprocessor directive does not require a semicolon at the end.
True
True/False: Each individual element of an array can be accessed by the array name and an element number, called a subscript.
True
True/False: Escape sequences are always stored internally as a single character.
True
True/False: You may use the exit() function to terminate a program, regardless of which control mechanism is executing.
True
The name for a memory location that may hold data is:
Variable
________ represent storage locations in the computer's memory.
Variables
To assign the contents of one array to another, you must use ________.
a loop to assign the elements of one array to another array.
A loop that is inside another loop is called:
a nested loop
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
Every complete C++ program must have a ________. a) comment b) function named <font face="Courier New">main</font> c) preprocessor directive d)symbolic constant e)<font face ="Courier New">cout</font> statement
b) function named <font face="Courier New">main</font>
This means to increase a value by one.
increment