Deck 3: Expressions and Interactivity
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/45
Play
Full screen (f)
Deck 3: Expressions and Interactivity
1
The cin << statement will stop reading input when it encounters a newline character.
True
2
What will be displayed after the following statements execute?
Int num1 = 5;
Int num2 = 3;
Cout << "The result is " << (num1 * num2 + 10) << endl;
A) The result is 5 * 3 + 10
B) The result is (num1 * num2 + 10)
C) The result is 25
D) The result is 65
E) None of these
Int num1 = 5;
Int num2 = 3;
Cout << "The result is " << (num1 * num2 + 10) << endl;
A) The result is 5 * 3 + 10
B) The result is (num1 * num2 + 10)
C) The result is 25
D) The result is 65
E) None of these
C
3
In C++, it is impossible to display the number 34.789 in a field of 9 spaces with 2 decimal places of precision.
False
4
What is the value of x after the following code executes?
Int x = 0;
Int y = 5;
Int z = 4;
X = x + y + z * 2;
A) 18
B) 0
C) 13
D) 26
E) unknown
Int x = 0;
Int y = 5;
Int z = 4;
X = x + y + z * 2;
A) 18
B) 0
C) 13
D) 26
E) unknown
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
5
Arithmetic operators that share the same precedence have right to left associativity.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
6
The following statement will output $5.00 to the screen:
cout << setprecision(5) << dollars << endl;
cout << setprecision(5) << dollars << endl;
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
7
Associativity is either right to left or
A) top to bottom
B) front to back
C) left to right
D) undeterminable
E) None of these
A) top to bottom
B) front to back
C) left to right
D) undeterminable
E) None of these
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
8
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.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
9
The __________ operator always follows the cin object, and the __________ operator follows the cout object.
A) binary, unary
B) conditional, binary
C) >>, <<
D) <<, >>
E) None of these
A) binary, unary
B) conditional, binary
C) >>, <<
D) <<, >>
E) None of these
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
10
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.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
11
Which of the following will allow the user to input the values 15 and 20 and have them stored in variables named base and height, respectively?
A) cin << base << height;
B) cin base, height;
C) cin >> base >> height;
D) cin base >> cin height;
E) None of these
A) cin << base << height;
B) cin base, height;
C) cin >> base >> height;
D) cin base >> cin height;
E) None of these
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
12
The fixed manipulator causes a number to be displayed in scientific notation.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
13
Which of the following must be included in any program that uses the cin object?
A) compiler
B) the header file iostream
C) linker
D) brackets
E) None of these
A) compiler
B) the header file iostream
C) linker
D) brackets
E) None of these
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
14
When a user types values at the keyboard, those values are first stored
A) as ASCII characters
B) in the header file iostream
C) in the keyboard buffer
D) as integers
E) None of these
A) as ASCII characters
B) in the header file iostream
C) in the keyboard buffer
D) as integers
E) None of these
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
15
When a program uses the setw manipulator, the iosetwidth header file must be included in a preprocessor directive.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
16
What is the value of result after the following statement executes?
Result = (3 * 5) % 4 + 24 / (15 - (7 - 4));
A) -6.4
B) 5
C) 1.6
D) 2.25
E) None of these
Result = (3 * 5) % 4 + 24 / (15 - (7 - 4));
A) -6.4
B) 5
C) 1.6
D) 2.25
E) None of these
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
17
In the following statement, what will be executed first according to the order of precedence?
Result = 6 - 3 * 2 + 7 - 10 / 2;
A) 6 - 3
B) 3 * 2
C) 2 + 7
D) 10 / 2
E) 7 - 10
Result = 6 - 3 * 2 + 7 - 10 / 2;
A) 6 - 3
B) 3 * 2
C) 2 + 7
D) 10 / 2
E) 7 - 10
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
18
When C++ is working with an operator, it strives to convert the operands to the same type.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
19
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.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
20
The __________ causes a program to wait until information is typed at the keyboard and the [Enter] key is pressed.
A) output stream
B) cin object
C) cout object
D) preprocessor
E) None of these
A) output stream
B) cin object
C) cout object
D) preprocessor
E) None of these
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
21
What is the value of number after the following statements execute?
Int number = 10;
Number += 5;
Number -= 2;
Number *= 3;
A) 3
B) 30
C) 39
D) 2
E) None of these
Int number = 10;
Number += 5;
Number -= 2;
Number *= 3;
A) 3
B) 30
C) 39
D) 2
E) None of these
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
22
When the final value of an expression is assigned to a variable, it will be converted to
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
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
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
23
What is true about the following statement?
Cout << setw(4) << num4 << " ";
A) It allows four spaces for the value in num4.
B) It outputs "setw(4)" before the value in num4.
C) It is incorrect because it should use setw(10).
D) It is incorrect because it should use setw(num4).
Cout << setw(4) << num4 << " ";
A) It allows four spaces for the value in num4.
B) It outputs "setw(4)" before the value in num4.
C) It is incorrect because it should use setw(10).
D) It is incorrect because it should use setw(num4).
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
24
__________ reads a line of input, including leading and embedded spaces, and stores it in a string object.
A) cin.get
B) getline
C) cin.getline
D) get
E) None of these
A) cin.get
B) getline
C) cin.getline
D) get
E) None of these
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
25
When C++ is working with an operator, it strives to convert operands to the same type. This is known as
A) type correction
B) type conversion
C) promotion
D) demotion
E) None of these
A) type correction
B) type conversion
C) promotion
D) demotion
E) None of these
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
26
Which of the following statements will read an entire line of input into the string object, address?
A) cin << address;
B) cin address;
C) cin.get(address);
D) getline(cin, address);
E) cin.get(length >> width >> height);
A) cin << address;
B) cin address;
C) cin.get(address);
D) getline(cin, address);
E) cin.get(length >> width >> height);
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
27
Which of the following statements will allow the user to enter three values to be stored in variables length, width, and height, in that order?
A) cin << length, width, height;
B) cin.get(height, width, length);
C) cin.get(length, width, height);
D) cin >> length; width; height;
E) cin.get(length >> width >> height);
A) cin << length, width, height;
B) cin.get(height, width, length);
C) cin.get(length, width, height);
D) cin >> length; width; height;
E) cin.get(length >> width >> height);
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
28
How many characters will the following statement read into the variable myString?
Cin >> setw(10) >> myString;
A) 9
B) 10
C) 11
D) however many characters are in myString
E) None of these
Cin >> setw(10) >> myString;
A) 9
B) 10
C) 11
D) however many characters are in myString
E) None of these
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
29
Which of the following statements will pause the screen until the [Enter] key is pressed?
A) cin;
B) cin.getline();
C) cin.get();
D) cin.ignore();
E) cin.input();
A) cin;
B) cin.getline();
C) cin.get();
D) cin.ignore();
E) cin.input();
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
30
You can control the number of significant digits in your output with the __________ manipulator.
A) setprecision
B) set_precision
C) to_fixed
D) setfixed()
E) None of these
A) setprecision
B) set_precision
C) to_fixed
D) setfixed()
E) None of these
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
31
When a variable is assigned a number that is too large for its data type, it
A) underflows
B) overflows
C) reverses
D) converts
E) None of these
A) underflows
B) overflows
C) reverses
D) converts
E) None of these
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
32
What is the value of cube after the following code executes?
Double cube, side;
Side = 5.0;
Cube = pow(side, 3.0);
A) 25.0
B) 15.0
C) 125.0
D) 8.0
E) unknown
Double cube, side;
Side = 5.0;
Cube = pow(side, 3.0);
A) 25.0
B) 15.0
C) 125.0
D) 8.0
E) unknown
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
33
This manipulator is used to establish a field width for the value that follows it:
A) field_width
B) set_field
C) setw
D) iomanip
E) None of these
A) field_width
B) set_field
C) setw
D) iomanip
E) None of these
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
34
What is the value of average after the following code executes?
Double average;
Average = 1.0 + 2.0 + 3.0 / 3.0;
A) 2.0
B) 3.0
C) 4.0
D) 2
E) unknown
Double average;
Average = 1.0 + 2.0 + 3.0 / 3.0;
A) 2.0
B) 3.0
C) 4.0
D) 2
E) unknown
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
35
This manipulator forces cout to print digits in fixed-point notation:
A) setprecision(2)
B) setw(2)
C) fixed
D) setfixed(2)
E) None of these
A) setprecision(2)
B) setw(2)
C) fixed
D) setfixed(2)
E) None of these
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
36
Which statement is equivalent to the following?
Number = number * 2;
A) number = pow(number, 2);
B) number *= 2;
C) number = number * number;
D) number * 2 = number;
E) None of these
Number = number * 2;
A) number = pow(number, 2);
B) number *= 2;
C) number = number * number;
D) number * 2 = number;
E) None of these
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
37
What is the value of x after the following code executes?
Int x;
X = 3 / static_cast(4.5 + 6.4);
A)0.3
B) 0
C)0.275229
D)3.3
E) None of these
Int x;
X = 3 / static_cast
A)0.3
B) 0
C)0.275229
D)3.3
E) None of these
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
38
Which statement is equivalent to the following?
Number += 1;
A) number = number + 1;
B) number = 1;
C) number + 1;
D) number =+ 1;
E) None of these
Number += 1;
A) number = number + 1;
B) number = 1;
C) number + 1;
D) number =+ 1;
E) None of these
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
39
This manipulator causes the field to be left justified with padding spaces printed to the right:
A) left_justify
B) right
C) left
D) left_pad
E) None of these
A) left_justify
B) right
C) left
D) left_pad
E) None of these
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
40
Which of the following functions tells the cin object to skip one or more characters in the keyboard buffer?
A) cin.ignore
B) cin.jump
C) cin.hop
D) cin.skip
E) None of these
A) cin.ignore
B) cin.jump
C) cin.hop
D) cin.skip
E) None of these
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
41
A debugging process where you, the programmer, pretend you are a computer and step through each statement while recording the value of each variable at each step is known as
A) error checking
B) hand writing
C) hand tracing
D) error handling
E) None of these
A) error checking
B) hand writing
C) hand tracing
D) error handling
E) None of these
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
42
The function pow(x, y), requires which header file?
A) cstdlib
B) cstring
C) iostream
D) cmath
E) iomanip
A) cstdlib
B) cstring
C) iostream
D) cmath
E) iomanip
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
43
Which of the following functions will return the value of x, rounded to the nearest whole number?
A) abs(x)
B) fmod(x)
C) sqrt(x)
D) round(x)
E) whole(x)
A) abs(x)
B) fmod(x)
C) sqrt(x)
D) round(x)
E) whole(x)
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
44
To use the rand()function, you must include the __________ header file?
A) cstdlib
B) cstring
C) iostream
D) cmath
E) iomanip
A) cstdlib
B) cstring
C) iostream
D) cmath
E) iomanip
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
45
Which line in the following program will cause a compiler error?
1 #include
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 }
A) line 6
B) line 7
C) line 8
D) line 9
E) there will be no compiler error
1 #include
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 }
A) line 6
B) line 7
C) line 8
D) line 9
E) there will be no compiler error
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck