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
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/40
Play
Full screen (f)
Deck 3: Expressions and Interactivity
1
The ________ operator always follows the cin object, and the ________ operator follows the cout object.
A) input, endl
B) getChar, printChar
C) >> , <<
D) >> , >>
E) << , >>
A) input, endl
B) getChar, printChar
C) >> , <<
D) >> , >>
E) << , >>
C
2
________ can be used to override the rules of operator precedence.
A) Some operators
B) Parentheses
C) Operands
D) Associativity
E) Nothing
A) Some operators
B) Parentheses
C) Operands
D) Associativity
E) Nothing
B
3
The following pair of C++ statements is legal.
const double taxRate;
taxRate = .05;
const double taxRate;
taxRate = .05;
False
4
In any program that uses the cin object, you must #include
A) the iostream header file.
B) the fstream header file.
C) >> and << operators.
D) named constants.
E) none of the above.
A) the iostream header file.
B) the fstream header file.
C) >> and << operators.
D) named constants.
E) none of the above.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
5
The cin object can be used to input more than one value in a single statement.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
6
Which of the following statements doubles the value stored in answer?
A) answer += 2;
B) answer *= 2;
C) answer = answer * 2;
D) All three of the above
E) Both B and C, but not A
A) answer += 2;
B) answer *= 2;
C) answer = answer * 2;
D) All three of the above
E) Both B and C, but not A
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
7
When the final value of an expression is assigned to a variable, it will be converted to
A) the smallest possible data type.
B) the largest possible data type.
C) the data type of the variable.
D) the data type of the expression.
E) none of the above.
A) the smallest possible data type.
B) the largest possible data type.
C) the data type of the variable.
D) the data type of the expression.
E) none of the above.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
8
________ causes a program to wait until information is typed at the keyboard and the Enter key is pressed.
A) An input device
B) The cin object
C) The cout object
D) A preprocessor
E) Nothing
A) An input device
B) The cin object
C) The cout object
D) A preprocessor
E) Nothing
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
9
The only difference between C-strings and string objects is how they are declared and internally stored. They are used exactly the same way.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
10
The following two statements will assign the same value to result.
result = a + b * c;
result = b * c + a;
result = a + b * c;
result = b * c + a;
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
11
Which of the following statements will assign number a value from 90 - 100.
A) number = rand() % 90 + 10;
B) number = rand() % 90 + 11;
C) number = rand() % 10 + 90;
D) number = rand() % 11 + 90;
E) None of the above.
A) number = rand() % 90 + 10;
B) number = rand() % 90 + 11;
C) number = rand() % 10 + 90;
D) number = rand() % 11 + 90;
E) None of the above.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
12
Which of the following expressions will evaluate to 2.5?
A) static_cast(5/2)
B) static_cast(5)/2
C) 5/static_cast(2)
D) All three of the above
E) Both B and C, but not A
A) static_cast
B) static_cast
C) 5/static_cast
D) All three of the above
E) Both B and C, but not A
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
13
Program code that can be evaluated to a value is called a(n)
A) operation.
B) line.
C) evaluator.
D) result.
E) expression.
A) operation.
B) line.
C) evaluator.
D) result.
E) expression.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
14
The ________ stream manipulator can be used to establish a field width for the value immediately following it.
A) cin
B) setField
C) setw
D) iomanip
E) width
A) cin
B) setField
C) setw
D) iomanip
E) width
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
15
The following C++ statement will assign 1.5 to the result variable.
int result = 3.0 / 2.0;
int result = 3.0 / 2.0;
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
16
Hand tracing a program is
A) a program design technique.
B) a program run-time testing technique.
C) a program debugging technique.
D) creating a drawing of what a program's output screen will look like.
E) none of the above.
A) a program design technique.
B) a program run-time testing technique.
C) a program debugging technique.
D) creating a drawing of what a program's output screen will look like.
E) none of the above.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
17
Which of the following will allow an entire line of text to be read into a string object, even if it contains embedded blanks?
A) getline()
B) cin >>
C) cin.get()
D) cin.ignore()
E) both A and B, but not C or D.
A) getline()
B) cin >>
C) cin.get()
D) cin.ignore()
E) both A and B, but not C or D.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
18
In C++, a value can be raised to a power by using
A) the ^ operator.
B) the exp operator.
C) the power operator.
D) the pow function.
E) the square function.
A) the ^ operator.
B) the exp operator.
C) the power operator.
D) the pow function.
E) the square function.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
19
When an operator's operands are of different data types, such as int and double, C++ automatically converts one of them so that they are the same data type.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
20
To use stream manipulators, you should include the ________ header file.
A) stream
B) fstream
C) format
D) iomanip
E) iostream
A) stream
B) fstream
C) format
D) iomanip
E) iostream
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
21
The statement cout << setw(4) << num4 << " ";
A) outputs the value of num4 rounded to 4 decimal places.
B) outputs "setw(4)" before the value in the variable num4.
C) outputs the first 4 digits of the number stored in num4.
D) outputs the value stored in num4 four times.
E) does none of above.
A) outputs the value of num4 rounded to 4 decimal places.
B) outputs "setw(4)" before the value in the variable num4.
C) outputs the first 4 digits of the number stored in num4.
D) outputs the value stored in num4 four times.
E) does none of above.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
22
The following statement sets sum1, sum2, and sum3 all to zero.
sum1 = sum2 = sum3 = 0;
sum1 = sum2 = sum3 = 0;
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
23
When a C++ expression is evaluated, binary operations are performed before unary operations.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
24
The following two expressions evaluate to the same thing:
c + a * b
c + (a * b)
c + a * b
c + (a * b)
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
25
The cin object lets the user enter a string that contains embedded blanks.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
26
If the value of dollars is 5.0, the following statement will output 5.00 to the monitor:
cout << fixed << showpoint << setprecision(4) << dollars << endl;
cout << fixed << showpoint << setprecision(4) << dollars << endl;
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
27
In C++, the 5 basic arithmetic operators are
addition (+), subtraction (-), multiplication (*), division (/), and exponentiation (^).
addition (+), subtraction (-), multiplication (*), division (/), and exponentiation (^).
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
28
The following 4 lines of C++ code, use strings. string firstName; // Define a string object
Char lastName[7]; // Define a C-string
FirstName = "Abraham"; // Assign a value to the string object
LastName = "Lincoln"; // Assign a value to the C-string
Which of the following statements is /are True?
A) The string object is defined incorrectly because no size is given for it.
B) The 2 string definitions are correct, but the 2 assignment statements are wrong.
C) The string object is assigned a value correctly, but the C-string is not.
D) The C-string is assigned a value correctly, but the string object is not.
E) All 4 lines of code are correct.
Char lastName[7]; // Define a C-string
FirstName = "Abraham"; // Assign a value to the string object
LastName = "Lincoln"; // Assign a value to the C-string
Which of the following statements is /are True?
A) The string object is defined incorrectly because no size is given for it.
B) The 2 string definitions are correct, but the 2 assignment statements are wrong.
C) The string object is assigned a value correctly, but the C-string is not.
D) The C-string is assigned a value correctly, but the string object is not.
E) All 4 lines of code are correct.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
29
Operator associativity is either left to right or
A) top to bottom.
B) front to back.
C) right to left.
D) inside to outside.
E) nothing else; it is always left to right.
A) top to bottom.
B) front to back.
C) right to left.
D) inside to outside.
E) nothing else; it is always left to right.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
30
The following pair of C++ statements will cause 3.5 to be output.
double number = 7 / 2;
cout << number;
double number = 7 / 2;
cout << number;
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
31
When converting some algebraic expressions to C++, you may need to insert ________ and ________ that do not appear in the algebraic expression.
A) values, exponents
B) operators, calculations
C) operators, operands
D) operators, parentheses
E) operands, parentheses
A) values, exponents
B) operators, calculations
C) operators, operands
D) operators, parentheses
E) operands, parentheses
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
32
The following statement sets the value of total to -3.
total -= 3;
total -= 3;
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
33
The ________ object causes data to be input from the keyboard.
A) cin
B) cout
C) keyboard buffer
D) standard input
E) dataIn
A) cin
B) cout
C) keyboard buffer
D) standard input
E) dataIn
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
34
To use the sqrt() function, or other mathematical library functions, you must #include the ________ header file in your program.
A) iostream
B) iomanip
C) cmath
D) algebra
E) mathlib
A) iostream
B) iomanip
C) cmath
D) algebra
E) mathlib
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
35
Which of the following statements about named constants is/are True?
A) A named constant must be initialized with a value at the time it is declared.
B) The identifier name of a named constant can only contain capital letters and underscores.
C) The initial value of a named constant, cannot be changed during the program execution.
D) All 3 of the above statements are True.
E) Statements A and C are True, but B is not.
A) A named constant must be initialized with a value at the time it is declared.
B) The identifier name of a named constant can only contain capital letters and underscores.
C) The initial value of a named constant, cannot be changed during the program execution.
D) All 3 of the above statements are True.
E) Statements A and C are True, but B is not.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
36
When an operator has two operands of different data types, C++ always converts them both to double before performing the operation.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
37
The cin object must be followed by
A) a single stream insertion (<<) operator.
B) one or more stream insertion operators (<<).
C) a single stream extraction (>>) operator.
D) one or more stream extraction (>>) operators.
E) no operators.
A) a single stream insertion (<<) operator.
B) one or more stream insertion operators (<<).
C) a single stream extraction (>>) operator.
D) one or more stream extraction (>>) operators.
E) no operators.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
38
When an arithmetic expression contains two or more different operators, such as * and +, the order in which the operations is done is determined by
A) left to right order.
B) operator precedence.
C) operator associativity.
D) the programmer.
E) the compiler.
A) left to right order.
B) operator precedence.
C) operator associativity.
D) the programmer.
E) the compiler.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
39
The following statement number = rand() % 5 + 10;
Assigns number a value in the range of
A) 5 - 10
B) 0 - 15
C) 5 - 15
D) 10 - 15
E) none of the above.
Assigns number a value in the range of
A) 5 - 10
B) 0 - 15
C) 5 - 15
D) 10 - 15
E) none of the above.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
40
What does the following C++ expression evaluate to?
6 - 6 / 3 + 3
A) 0
B) 3
C) 5
D) 7
E) None of the above
6 - 6 / 3 + 3
A) 0
B) 3
C) 5
D) 7
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck