C++ Quiz 3
What is the value of number after the following statements execute? int number = 10; number += 5; number -= 2; number *= 3;
39
What is the value of average after the following code executes? double average; average = 1.0 + 2.0 + 3.0 / 3.0;
4.0
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 = 99; 7 MY_VAL = 77; 8 cout << MY_VAL << endl; 9 return 0; 10 }
7
left to right
Associativity is either right to left or
-3
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;
this statement will pause the screen, until the [enter] key is pressed.
Cin.get();
True/False: Arithmetic operators that share the same precedence have right to left associativity. Select one: True False
False
True/False: The cin << statement will stop reading input when it encounters a newline character. Select one: True False
False
True/False: The fixed manipulator causes a number to be displayed in scientific notation. Select one: True False
False
True/False: The following statement will output $5.00 to the screen: cout << setprecision(5)<< dollars << endl; Select one: True False
False
This stream manipulator forces cout to print the digits in fixed-point notation.
Fixed
________ reads a line of input, including leading and embedded spaces, and stores it in a string object.
Getline
3 * 2
In the following C++ statement, what will be executed first according to the order of precedence? result = 6 - 3 * 2 + 7 - 10 / 2;
in any program that uses the cin object, you must include in____.
Iostream header file
When this operator is used with string operands it concatenates them, or joins them together.
+
what will the value of the result be after the following statement executes? Result= 6-3*2+ 7-10/2;
2
2
What will the value of result be after the following statement executes? result = 6 - 3 * 2 + 7 - 10 / 2;
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;
True
When C++ is working with an operator, it strives to convert the operands to the same type.
overflows
When a variable is assigned a number that is too large for its data type, it:
Parentheses
When converting some algebraic expressions to C++, you may need to insert ___________ that do not appear in the algebraic expression.
data type of the variable
When the final value of an expression is assigned to a variable, it will be converted to:
+
When this operator is used with string operands it concatenates them, or joins them together.
Associativity is either right to left or: Select one: a. Top to bottom b. Front to back c. Left to right d. Undeterminable e. None of these
c. (Left to right)
To use the rand() function, you must #include this header file in your program. Select one: a. iostream b. iomanip c. iorand d. cstdlib e. None of these
d. (cstdlib)
The function, pow(x, 5.0), requires this header file. Select one: a. cstdlib b. iostream c. cstring d. cmath e. iomanip
d.(cmath)
When converting some algebraic expressions to C++, you may need to insert ________ that do not appear in the algebraic expression.
Parenthesis
This manipulator is used to establish a field width for the value immediately following it.
Setw
This function tells the cin object to skip one or more characters in the keyboard buffer. Select one: a. cin.ignore b. cin.jump c. cin.hop d. cin.skip; e. None of these
a. (cin.ignore)
When using the sqrt function you must include this header file. Select one: a. cmath b. cstdlib c. cstring d. iostream e. iomanip
a. (cmath)
Which statement is equivalent to the following? number +=1 Select one: a. number = number + 1; b. number + 1; c. number = 1; d. None of these
a. (number = number + 1;)
Which statement is equivalent to the following? x = x * 2 Select one: a. x * 2; b. x *= 2; c. x = x * x; d. None of these
b. (x *= 2;)
The total number of digits that appear before and after the decimal point is sometimes referred to as
significant digits and precision
Which is true about the following statement? Cout << setw(4) << num4 <<" ";
It allows four spaces for the value in the variable num4.
>>, <<
The ______ operator always follows the cin object, and the ______ operator follows the cout object.
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 = 99; 7 MY_VAL = 77; 8 cout << MY_VAL << endl; 9 return 0; 10 }
number = number + 1;
Which statement is equivalent to the following? number += 1;
x *= 2;
Which statement is equivalent to the following? x = x * 2;
getline(cin, address);
Which statement will read an entire line of input into the following string object? string address;
(Parentheses)
You can use these to override the rules of operator precedence in a mathematical expression.
Which is true about the following statement? cout << setw(4) << num4 << " "; Select one: a. It allows four spaces for the value in the variable num4. b. It outputs "setw(4)" before the value in the variable num4. c. It should use setw(10) to output the value in the variable num10. d. It inputs up to four characters stored in the variable num4. e. None of these
a. (It allows four spaces for the value in the variable num4.)
will read up to this many characters into str. cin >> setw(10) >> str; Select one: a. Nine b. Ten c. Eleven d. Eight e. None of these
a. (Nine)
You can use these to override the rules of operator precedence in a mathematical expression. Select one: a. [Brackets] b. (Parentheses) c. {Braces} d. The escape character \ e. None of these Feedback
b. (Parentheses)
The ________ causes a program to wait until information is typed at the keyboard and the Enter key is pressed. Select one: a. Output stream b. cin object c. cout object d. Preprocessor e. None of these
b. (cin object)
This statement will pause the screen, until the [Enter] key is pressed. Select one: a. cin.getline(); b. cin.get(); c. cin.ignore(); d. cin.input(); e. cin;
b. (cin.get();)
When a variable is assigned a number that is too large for its data type, it: Select one: a. underflows b. overflows c. reverses polarity d. exceeds expectations e. None of these
b. (overflows)
________ reads a line of input, including leading and embedded spaces, and stores it in a string object. Select one: a. cin.get b. getline c. cin.getline d. get e. None of these
b.(getline)
When the final value of an expression is assigned to a variable, it will be converted to: Select one: a. The smallest C++ data type b. The largest C++ data type c. The data type of the variable d. The data type of the expression e. None of these
c. (The data type of the variable)
Which statement will read an entire line of input into the following string object? Select one: a. cin << address; b. cin address; c. getline(cin, address); d. cin.get(address); e. None of these
c. (getline(cin, address);)
This manipulator causes the field to be left-justified with padding spaces printed to the right. Select one: a. left_justify b. right c. left d. left_pad e. None of these
c. (left)
This manipulator is used to establish a field width for the value immediately following it. Select one: a. field_width b. set_field c. setw d. iomanip e. None of these
c. (setw)
This stream manipulator forces cout to print the digits in fixed-point notation. Select one: a. setprecision(2) b. setw(2) c. fixed d. setfixed(2) e. None of these
c.(fixed)
You want the user to enter the length, width, and height from the keyboard. Which cin statement is correctly written?
cin >> length >> width >> height;
This function tells the cin object to skip one or more characters in the keyboard buffer.
cin.ignore
When using the sqrt function you must include this header file.
cmath
When this operator is used with string operands it concatenates them, or joins them together. Select one: a. & b. * c. % d. + e. None of these
d. (+)
You want the user to enter the length, width, and height from the keyboard. Which cin statement is correctly written? Select one: a. cin >> length, width, height; b. cin << length, width, height; c. cin << length; width; height; d. cin.get(length, width, height); e. cin >> length >> width >> height;
e. (cin >> length >> width >> height;)
When the final value of an expression is assigned to a variable, it will be converted to:
the data type of the variable
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
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
cin object
The _________ causes a program to wait until information is typed at the keyboard and the Enter key is pressed.
true
The cin >> statement will stop reading input when it encounters a newline character.
Ten
The statement cin >> setw(10) >> str; will read up to this many characters into str
false
The statement cout << setprecision(5) << dollar << endl; will output $5.00 to the screen.
setw
This manipulator is used to establish a field width for the value immediately following it.
fixed
This stream manipulator forces cout to print the digits in fixed-point notation.
cstdlib
To use the rand() function, you must #include this header file in your program.
True/False: When C++ is working with an operator, it strives to convert the operands to the same type. Select one: True False
True
True/False: 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. Select one: True False
True
4.0
What is the value of average after the following code executes? double average; average = 1.0 + 2.0 + 3.0 / 3.0;
39
What is the value of number after the following statements execute? int number = 10; number += 5; number -= 2; number *= 3;
The total number of digits that appear before and after the decimal point is sometimes referred to as: Select one: a. floating points b. significant digits c. precision d. significant digits and precision e. None of these Feedback
d. (significant digits and precision)
Which statement will read an entire line of input into the following string object? string address;
getline(cin, address);
This manipulator causes the field to be left-justified with padding spaces printed to the right.
left
the statement cin>>setw(10)>>str; will read up to this many characters into str.
nine