Quiz 3 (Chapter 3)
Quiz 3 (Chapter 3)
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.
a. True b. False
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.
a. True b. False
3. The cin << statement will stop reading input when it encounters a newline character.
a. True b. False
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.
a. True b. False
5. Arithmetic operators that share the same precedence have right to left associativity.
a. True b. False
6. When C++ is working with an operator, it strives to convert the operands to the same type.
a. True b. False
7. When a program uses the setw manipulator, the iosetwidth header file must be included in a
preprocessor directive.
a. True b. False
9. In C++, it is impossible to display the number 34.789 in a field of 9 spaces with 2 decimal places of
precision.
a. True b. False
12. 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
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
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
15. 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
18. 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
21. 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
22. 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
23. 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
24. 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
25. 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
29. 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
30. 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
31. 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
32. 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
35. 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();
36. 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);
37. 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
38. __________ 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
39. 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);
40. 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
42. To use the rand()function, you must include the __________ header file?
a. cstdlib
b. cstring
c. iostream
d. cmath
e. iomanip
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)
44. 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. line 6
b. line 7
c. line 8
d. line 9
e. there will be no compiler error
45. 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