Programming final exam
Suppose that x is an int variable, y is a double variable, and z is an int variable. The input is: 15 76.3 14 Choose the values after the following statement executes: cin >> x >> y >> z;
x = 15, y = 76.3, z = 14
Suppose that alpha and beta are int variables. The statement alpha = --beta; is equivalent to the statement(s) ____.
beta = beta - 1; alpha = beta;
The ____ statement can be used to eliminate the use of certain (flag) variables.
break
Suppose that x is an int variable, y is a double variable, and ch is a char variable. The input is: 15A 73.2 Choose the values after the following statement executes: cin >> x >> ch >> y;
x = 15, ch = 'A', y = 73.2
Which of the following statements declares the studentGrade variable?
enum grades {A, B, C, D, F} studentGrade;
A(n) ____-controlled while loop uses a bool variable to control the loop.
flag
When a continue statement is executed in a ____, the update statement always executes.
for loop
Given the following code namespace globalType { void printResult(); } which of the following statements is needed to access printResult?
globalType::printResult();
What is the initial statement in the following for loop? (Assume that all variables are properly declared.) int i; for (i = 1; i < 20; i++) cout << "Hello World"; cout << "!" << endl;
i = 1;
Which of the following will cause a logical error if you are attempting to compare x to 5?
if (x = 5)
Which of the following is a legal identifier?
program_1
Main memory is called ____.
random access memory
The identifiers in the system-provided header files such as iostream, cmath, and iomanip are defined in the namespace ____.
std
Which executes first in a do...while loop?
the statement
Suppose x is 5 and y is 7. Choose the value of the following expression: (x != 7) && (x <= y)
true
In C++, you can create aliases to a previously defined data type by using the ____ statement.
typedef
Suppose that x is an int variable and y is a double variable. The input is: 10 20.7 Choose the values after the following statement executes: cin >> x >> y;.
x = 10, y = 20.7
A comma is also called a statement terminator.
FALSE
A mixed arithmetic expression contains all operands of the same type.
FALSE
An operator that has only one operand is called a unique operator.
FALSE
Assume that all variables are properly declared. The following for loop executes 20 times. for (i = 0; i <= 20; i++) cout << i;
FALSE
C++ programs have always been portable from one compiler to another.
FALSE
If the expression in an assert statement evaluates to true, the program terminates.
FALSE
In C++, both ! and != are relational operators.
FALSE
In C++, reserved words are the same as predefined identifiers.
FALSE
In an output statement, each occurrence of endl advances the cursor to the end of the current line on an output device.
FALSE
In the statement cin >> x;, x can be a variable or an expression.
FALSE
It is a good idea to redefine cin and cout in your programs.
FALSE
The command that does the linking on Visual C++ Express (2013 or 2016) and Visual Studio 2015 is Make or Remake.
FALSE
The devices that feed data and programs into computers are called output devices.
FALSE
The extraction operator >> skips only all leading blanks when searching for the next data in the input stream.
FALSE
The following is a valid C++ enumeration type: enum places {1ST, 2ND, 3RD, 4TH};.
FALSE
The following statement creates an anonymous type: enum {1ST, 2ND, 3RD, 4TH} places;
FALSE
The following statements will result in input failure if the input values are not on a separate line. (Assume that x and y are int variables.) cin >> x; cin >> y;
FALSE
The operators !, &&, and || are called relational operators.
FALSE
The result of a logical expression cannot be assigned to an int variable, but it can be assigned to a bool variable.
FALSE
The statement in the body of a while loop acts as a decision maker.
FALSE
Which of the following operators has the highest precedence?
!
____ is a valid char value.
'A'
Suppose that ch1, ch2, and ch3 are variables of the type char. The input is: A B C What is the value of ch3 after the following statements execute? cin.get(ch1); cin.get(ch2); cin.get(ch3);
'B'
Suppose that x is an int variable. Which of the following expressions always evaluates to true?
(x > 0) || ( x <= 0)
What is the output of the following C++ code? num = 10; while (num > 10) num = num - 2; cout << num << endl;
10
Suppose sum and num are int variables, and the input is 18 25 61 6 -1. What is the output of the following code? sum = 0; cin >> num; while (num != -1) { sum = sum + num; cin >> num; } cout << sum << endl;
110
What is the output of the following statements? cout << "123456789012345678901234567890" << endl cout << setfill('#') << setw(10) << "Mickey" << setfill(' ') << setw(10) << "Donald" << setfill('*') << setw(10) << "Goofy" << endl;
123456789012345678901234567890 ####Mickey Donald*****Goofy
Suppose j, sum, and num are int variables, and the input is 26 34 61 4 -1. What is the output of the code? sum = 0; cin >> num; for (int j = 1; j <= 4; j++) { sum = sum + num; cin >> num; } cout << sum << endl;
125
The expression static_cast<int>(6.9) + static_cast<int>(7.9) evaluates to ____.
13
The length of the string "Hello There. " is ____.
13
Suppose that x = 1565.683, y = 85.78, and z = 123.982. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(3) << x << ' '; cout << setprecision(4) << y << ' ' << setprecision(2) << z << endl;
1565.683 85.7800 123.98
Assume you have three int variables: x = 2, y = 6, and z. Choose the value of z in the following expression: z = (y / x > 0) ? x : y;.
2
What is the output of the following C++ code? int x = 55; int y = 5; switch (x % 7) { case 0: case 1: y++; case 2: case 3: y = y + 2; case 4: break; case 5: case 6: y = y - 3; } cout << y << endl;
2
Consider the following statements: string str = "ABCDEFD"; string::size_type position; After the statement position = str.find('D'); executes, the value of position is ____.
3
The value of the expression 17 % 7 is ____.
3
The value of the expression 33/10, assuming both values are integral data types, is ____.
3
Consider the declaration: enum sports {BASKETBALL, FOOTBALL, HOCKEY, BASEBALL, SOCCER}; Which of the following statements is true?
FOOTBALL <= SOCCER
Consider the following code. // Insertion Point 1 using namespace std; const float PI = 3.14; int main() { //Insertion Point 2 float r = 2.0; float area; area = PI * r * r; cout << "Area = " << area <<endl; return 0; } // Insertion Point 3 In this code, where does the include statement belong?
Insertion Point 1
The devices that the computer uses to display results are called ____ devices.
OUTPUT
Which statement below about prototypes and headers is true?
Prototypes end with a semicolon, but headers do not.
Choose the output of the following C++ statement: cout << "Sunny " << '\n' << "Day " << endl;
Sunny Day
A control structure alters the normal sequential flow of execution in a program.
TRUE
Assume that all variables are properly declared. The following statement in a value-returning function is legal. if (x % 2 == 0) return x; else return x + 1;
TRUE
Entering a char value into an int variable causes serious errors, called input failure.
TRUE
In C++, a function prototype is the function heading without the body of the function.
TRUE
In C++, namespace is a reserved word.
TRUE
In the case of the sentinel-controlled while loop, the first item is read before the while loop is entered.
TRUE
Suppose P and Q are logical expressions. The logical expression P && Q is true if both P and Q are true.
TRUE
Suppose a = 5. After the execution of the statement ++a; the value of a is 6.
TRUE
The basic commands that a computer performs are input (get data), output (display result), storage, and performance of arithmetic and logical operations.
TRUE
The following is a legal C++ enumeration type: enum colorType {BLUE, GREEN, PINK, YELLOW, RED};
TRUE
To develop a program to solve a problem, you start by analyzing the problem.
TRUE
Using functions greatly enhances a program's readability because it reduces the complexity of the function main.
TRUE
Suppose that alpha, beta, and gamma are int variables and the input is: 100 110 120 200 210 220 300 310 320 What is the value of gamma after the following statements execute? cin >> alpha; cin.ignore(100, '\n'); cin >> beta; cin.ignore(100,'\n'); cin >> gamma;
300
What is the next Fibonacci number in the following sequence? 1, 1, 2, 3, 5, 8, 13, 21, ...
34
What is the value of x after the following statements execute? int x = 5; int y = 30; do x = x * 2; while (x < y);
40
Suppose that x = 55.68, y = 476.859, and z = 23.8216. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(3); cout << x << ' ' << y << ' ' << setprecision(2) << z << endl;
55.680 476.859 23.82
The statement: return 2 * 3 + 1, 1 + 5; returns the value ____.
6
The statement: return 37, y, 2 * 3; returns the value ____.
6
The expression static_cast<int>(9.9) evaluates to ____.
9
In C++, ____ is called the scope resolution operator.
::
The ____ is the brain of the computer and the single most expensive piece of hardware in your personal computer.
CPU
Suppose that x and y are int variables, ch is a char variable, and the input is: 4 2 A 12 Choose the values of x, y, and ch after the following statement executes: cin >> x >> ch >> y;
This statement results in input failure
Suppose that ch1 and ch2 are char variables and the input is: WXYZ What is the value of ch2 after the following statements execute? cin >> ch1; ch2 = cin.peek(); cin >> ch2;
X
A step-by-step problem-solving process in which a solution is arrived at in a finite amount of time is called a(n) ____.
algorithm
Suppose that alpha and beta are int variables and alpha = 5 and beta = 10. After the statement alpha *= beta; executes, ____.
alpha = 50
Suppose that x is an int variable, ch is a char variable, and the input is: 276. Choose the values after the following statement executes: cin >> ch >> x;
ch = '2', x = 76
Suppose that ch1 and ch2 are char variables, and alpha is an int variable. The input is: A 18 What are the values after the following statement executes? cin.get(ch1); cin.get(ch2); cin >> alpha;
ch1 = 'A', ch2 = ' ', alpha = 18
Given the function prototype: float test(int, int, int); which of the following statements is legal?
cout << test(7, 14, 23);
Given the following function prototype: double tryMe(double, double); which of the following statements is valid? Assume that all variables are properly declared.
cout << tryMe(2.0, 3.0);
____ loops are called posttest loops.
do...while
Consider the following program segment. ifstream inFile; //Line 1 int x, y; //Line 2 ... //Line 3 inFile >> x >> y; //Line 4 Which of the following statements at Line 3 can be used to open the file progdata.dat and input data from this file into x and y at Line 4?
inFile.open("progdata.dat");
A loop that continues to execute endlessly is called a(n) ____ loop.
infinite
The declaration int a, b, c; is equivalent to which of the following?
int a,b,c;
Which of the following function prototypes is valid?
int funcExp(int x, float v);
Which of the following function prototypes is valid?
int funcTest(int, int, float);
You can use either a(n) ____ or a ____ to store the value of a logical expression.
int, bool
Manipulators without parameters are part of the ____ header file.
iostream
A program that loads an executable program into main memory is called a(n) ____.
loader
In ____ structures, the computer repeats particular statements a certain number of times depending on some condition(s).
looping
In C++, the dot is an operator called the ____ operator.
member access
A(n) ____ consists of data and the operations on those data.
object
Suppose that x and y are int variables, and z is a double variable. The input is: 28 32.6 12 Choose the values of x, y, and z after the following statement executes: cin >> x >> y >> z;
x = 28, y = 32, z = 0.6