Test 2
For file input/output in a program, the program must include the header file iofstream.
False
If the expression in an assert statement evaluates to true, the program terminates.
False
In C++, both ! and != are relational operators.
False
In a switch statement, every case must have a break.
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
Manipulators without parameters are part of the header file iomanip.
False
The extraction operator >> skips only all leading blanks when searching for the next data in the input stream.
False
The function ignore is used specifically to skip only numbers in a line.
False
The symbol > is a logical operator.
False
The value of the expression 'a' < 'A' is true.
False
To use a parameterized manipulator, the program must include the header file iostream.
False
You can use the function readline to read a string containing blanks.
False
if (score = 50) grade = 'Z';
False
When you want to process only partial data, you can use the stream function ____ to discard a portion of the input.
Ignore
The appearance of = in place of == resembles a(n) ____.
Silent Killer
The stream function putback lets you put the last character extracted from the input stream by the get function back into the input stream.
True
To use the manipulator setprecision, the program must include the header file iomanip.
True
cin is called an istream object.
True
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.get(ch1); cin.putback(ch1); cin >> ch2;
W
Suppose that alpha is an int variable and ch is a char variable and the input is: 17 A What are the values after the following statements execute? cin >> alpha; cin >> ch;
alpha = 17, ch = 'A'
int score; string grade; if (score >= 65) grade = "pass"; else grade = "fail"; If score is equal to 75, the value of grade is "pass" .
true
Suppose that x is an int variable, y is a double variable and ch is a char variable and the input is: 1 5A 73.2 Choose the values after the following statement executes: cin >> x >> ch >> y;
x = 15, ch = 'A', y = 73.2
Suppose that x is an int variable, y is a double variable, z is an int variable, and the input is: 15 76.3 14 Choose the values after the following statement executes:
x = 15, y = 76.3, z = 14
Suppose that x and y are int variables, z is a double variable, and 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 = 12.0
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;
x = 4, ch = 2, y = 12 ****** WRONG
Suppose that x is an int variable and y is a double variable and the input is: 10 20.7 Choose the values after the following statement executes: cin >> x >> y;.
x=10, y=20.7
A program uses repetition to implement a branch.
False
During program execution, when entering character data such as letters, you need to enter the single quotes around the character.
False
Which of the following operators has the highest precedence?
!
Which of the following is the "not equal to" relational operator?
!=
You can disable assert statements by using which of the following?
#define NDEBUG
For a program to use the assert function, it must include which of the following?
#include <cassert>
Suppose that ch1, ch2, and ch3 are variables of the type char and the input is: A B C Choose the value of ch3 after the following statement executes: cin >> ch1 >> ch2 >> ch3;
'C'
What is the output of the following code? if (6 > 8) { cout << " ** " << endl ; cout << "****" << endl; } else if (9 == 4) cout << "***" << endl; else cout << "*" << endl;
*** *** WRONG
Which of the following expressions correctly determines that x is greater than 10 and less than 20?
10 < x && x < 20 ***
cout << "123456789012345678901234567890" << endl cout << setfill('#') << setw(10) << "Mickey" << setfill(' ') << setw(10) << "Donald" << setfill('*') << setw(10) << "Goofy" << endl;
123456789012345678901234567890 ####Mickey Donald*****Goofy
int num; int alpha = 10; cin >> num; switch (num) { case 3: alpha++; break; case 4: case 6: alpha = alpha + 3; case 8: alpha = alpha + 4; break; default: alpha = alpha + 5; } cout << alpha << endl;
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
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
Suppose that x = 25.67, y = 356.876, and z = 7623.9674. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(2); cout << x << ' ' << y << ' ' << z << endl;
25.67 356.88 7623.97
int x = 35; int y = 45; int z; if (x > y) z = x + y; else z = y - x; cout << x << " " << y << " " << z << endl;
35 45 10
What is the value of x after the following statements execute? int x; x = (5 <= 3 && 'A' < 'F') ? 3 : 4
4
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
Which of the following is a relational operator?
==
The expression in an if statement is sometimes called a(n) ____.
Decision
C++ comes with a wealth of functions, called predefined functions, that are written by other programmers.
True
Entering a char value into an int variable causes serious errors, called input failure.
True
In C++, the logical operator AND is &&.
True
On most systems, when the program terminates, the files are closed automatically.
True
The function peek returns the next character in the input stream; it does not remove the character from the input stream.
True
The left operand of the extraction operator must be an input stream variable.
True
The number of input data extracted by cin and >> depends on the number of variables appearing in the cin statement.
True
You can disable the manipulator left by using the stream function unsetf.
true
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, alpha is an int variable, and 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
Suppose that x and y are int variables. Which of the following is a valid input statement?
cin >> x >> y; ***
Every if statement must have a corresponding else.
false
If cin and the extraction operator reads two or more numbers from the input stream, the numbers must be separated by lines.
false
In C++, !, &&, and || are called relational operators.
false
Including a semicolon before the action statement in a one-way selection causes a syntax error.
false
The expression (x >= 0 && x <= 100) evaluates to false if either x < 0 or x >= 100.
false
The result of a logical expression cannot be assigned to an int variable, but it can be assigned to a bool variable.
false
n C++, all relational operators are evaluated before logical operators.
false
Which of the following will cause a logical error if you are attempting to compare x to 5?
if (x = 5)
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");
Manipulators without parameters are part of the ____ header file.
iostream
What does <= mean?
less than or equal to
In C++, the dot is an operator called the ____ operator.
member access
Suppose that outFile is an ofstream variable and output is to be stored in the file outputData.out. Which of the following statements opens the file outputData.out and associates outFile to the output file?
outFile.open("outputData.out");
char lastInitial = 'A'; switch (lastInitial) { case 'A': cout << "section 1" <<endl; break; case 'B': cout << "section 2" <<endl; break; case 'C': cout << "section 3" <<endl; break; case 'D': cout << "section 4" <<endl; break; default: cout << "section 5" <<endl; }
section 1
char lastInitial = 'S'; switch (lastInitial) { case 'A': cout << "section 1" <<endl; break; case 'B': cout << "section 2" <<endl; break; case 'C': cout << "section 3" <<endl; break; case 'D': cout << "section 4" <<endl; break; default: cout << "section 5" <<endl; }
section 5
In a ____ control structure, the computer executes particular statements depending on some condition(s).
selection
____ is a parameterized stream manipulator.
setfill
The conditional operator ?: takes ____ arguments.
three
A compound statement functions as if it was a single statement.
true
A control structure alters the normal sequential flow of execution in a program.
true
Conditional statements help incorporate decision making into programs.
true
In C++, && has a higher precedence than ||.
true
In the C++ statement, cin.get(u); u must be a variable of type char.
true
Suppose P and Q are logical expressions. The logical expression P && Q is true if both P and Q are true.
true
Suppose found = true and num = 6. The value of the expression (!found) || (num > 6) is false.
true
The extraction operator >> is a binary operator.
true
The operators != and == have the same order of precedence.
true
The value of the expression 7 + 8 <= 15 is true.
true
When reading data into a char variable, after skipping any leading whitespace characters, the extraction operator >> finds and stores only the next character; reading stops after a single character.
true