Asdsadsawewqewqweqw
Asdsadsawewqewqweqw
Chapter Three
MULTIPLE CHOICE
1. 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 the above
ANS: B
2. 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 the above
ANS: C
3. In any program that uses the cin object, you must include the ___________.
a. compiler
b. iostream header file
c. linker
d. >> and << operators
e. None of the above
ANS: B
4. ___________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
ANS: B
5. When this operator is used with string operands it concatenates them, or joins them together.
a. &
b. *
c. %
d. +
e. None of the above
ANS: D
a. .3
b. 0
c. .275229
d. 3.3
e. None of these
ANS: B
7. This function 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 the above
ANS: A
9. You want the user to enter the length, width, and height from the keyboard. Which
cin statement is correctly written?
a. cin << length, width, height;
b. cin.get(length, width, height);
c. cin >> length >> width >> height;
d. cin >> length, width, height;
e. cin << length; width; height;
ANS: B
10. You can use these to override the rules of operator precedence in a mathematical
expression.
a. [Brackets]
b. (Parentheses)
c. {Braces}
d. The escape character \
e. None of these
ANS: B
11. In the following C++ 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. 7 - 10
e. 10 / 2
ANS: B
12. 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 the above
ANS: C
13. When a variable is assigned a number that is too large for its data type, it:
a. underflows
b. overflows
c. reverses polarity
d. exceeds expectations
e. None of the above
ANS: B
14. This manipulator is used to establish a field width for the value immediately following it.
a. field_width
b. set_field
c. setw
d. iomanip
e. None of the above
ANS: C
15. 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
ANS: C
16. This statement will pause the screen, until the [Enter] key is pressed.
a. cin;
b. cin.getline();
c. cin.get();
d. cin.ignore();
e. cin.input();
ANS: C
17. To use the rand() function, you must #include this header file in your program.
a. iostream
b. iomanip
c. iorand
d. cstdlib
e. None of these
ANS: D
18. 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;
a. 0
b. 1
c. 2
d. –3
e. None of these
ANS: D
19. Which statement will read an entire line of input into the following string object?
string address;
21. When converting some algebraic expressions to C++, you may need to insert ___________
that do not appear in the algebraic expression.
a. Parentheses
b. Exponents
c. Calculations
d. Coercions
e. None of the above
ANS: A
23. The total number of digits that appear before and after the decimal point is sometimes
referred to as:
a. floating points
b. significant digits
c. precision
d. b and c
e. None of these
ANS: D
24. This stream manipulator forces cout to print the digits in fixed-point notation.
a. setprecision(2)
b. setw(2)
c. fixed
d. setfixed(2)
e. None of these
ANS: C
25. When using the sqrt function you must include this header file.
a. cstdlib
b. cmath
c. cstring
d. iostream
e. iomanip
ANS: B
27. What will the value of result be after the following statement executes?
result = 6 - 3 * 2 + 7 - 10 / 2 ;
a. 8 c. 1.5
b. 6 d. 2
ANS: D
28. 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;
a. 13 c. 0
b. 18 d. unknown
ANS: A
29. 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 c. 1.5
b. 4.0 d. 6.0
ANS: B
number += 1;
x = x * 2;
a. x * 2; c. x = x * x;
b. x *= 2; d. None of these
ANS: B
32. What is the value of number after the following statements execute?
a. 3 c. 15
b. 30 d. 2
ANS: C
33. 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;
7 MY_VAL = 77;
8 cout << MY_VAL << endl;
9 return 0;
10 }
a. 6 c. 9
b. 8 d. 7
ANS: A
34. 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 = 77;
7 MY_VAL = 99;
8 cout << MY_VAL << endl;
9 return 0;
10 }
a. 6 c. 9
b. 8 d. 7
ANS: D
TRUE/FALSE
1. 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.
ANS: T
2. 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.
ANS: T
Starting Out With C++ From Control Structures Through Objects 7th Edition Tony Gaddis Test B
3. The cin << statement will stop reading input when it encounters a newline character.
ANS: T
4. 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.
ANS: F
5. Arithmetic operators that share the same precedence have right to left associativity.
ANS: F
6. When C++ is working with an operator, it strives to convert the operands to the same type.
ANS: T
7. When a program uses the setw manipulator, the iosetwidth header file must be included
in a preprocessor directive.
ANS: F
8. The statement
ANS: F
9. In C++, it is impossible to display the number 34.789 in a field of 9 spaces with 2 decimal
places of precision.
ANS: F
ANS: F