Quiz 3 Flashcards
The ____ statement is used to enter data in a program while it’s running.
A) cout
B) data
C) cin
D) input
cin
in C++, accessing mathematical functions in a program requires including the mathematical header file ____.
A) number
B) cmath
C) cnumber
D) math
cmath
The ____ declaration qualifier specifies that the declared identifier is read-only after it’s initialized.:
A) unchanged
B) fix
C) fixed
D) const
const
In C++, the expression sum = sum + 10 can be written as ____.
A) sum = 10+
B) sum =+ 10
C) sum += 10
D) +sum = 10
C
In C++, the ____ symbol is called the assignment operator.
A) ==
B) =
C)»_space;
D) ->
=
To control the format of numbers displayed by cout, you can include field width ____ in an output stream.
A) escape sequences
B) manipulators
C) dividers
D) separators
manipulators
The stream manipulator ____ sets the floating-point precision to n places.
A) setfill(‘x’)
B) setprecision(n)
C) setw(n)
D) showbase
B
In C++, the mathematical function ____ calculates a number’s square root.
A) sqroot()
B) square()
C) squareRoot()
D) sqrt()
D
In the statement cin»_space; x;, x can be a variable or an expression.
A) True B) False
False
Suppose that x and y are int variables. Which of the following is a valid input statement?
A) cin»_space; x»_space; cin»_space; y;
B) cin»_space; x»_space; y;
C) cin «_space;x «_space;y;
D) cout «_space;x «_space;y;
B
Suppose that alpha, beta, and gamma are int variables and the input is:
100 110 120
200 210 220
300 310 320
What is the value of gamma after the following statements execute?
cin»_space; alpha;
cin.ignore(100, ‘\n’);
cin»_space; beta;
cin.ignore(100,’\n’);
cin»_space; gamma;
A) 100
B) 200
C) 300
D) 320
300
The number of input data extracted by cin and»_space; depends on the number of variables appearing in the cin statement.
A) True B) False
True
When reading data into a char variable, after skipping any leading whitespace characters, the extraction operator»_space; finds and stores only the next character; reading stops after a single character.
A) True
B) False
True
Suppose that x = 25.67, y = 356.876, and z = 7623.9674. What is the output of the following statements?
cout «_space;fixed «_space;showpoint;
cout «_space;setprecision(2);
cout «_space;x «_space;’ ‘ «_space;y «_space;’ ‘ «_space;z «_space;endl;
A) 25.67 356.87 7623.96
B) 25.67 356.87 7623.97
C) 25.67 356.88 7623.97
D) 25.67 356.876 7623.967
C) 25.67 356.88 7623.97
Entering a char value into an int variable causes serious errors, called input failure.
A) True B) False
True
Suppose that x and y are int variables, ch is a char variable, and the input is:
4 2 A 12
Choose the values of x, y, and ch after the following statement executes:
cin»_space; x»_space; ch»_space; y;
A) x = 4, ch = 2, y = 12
B) x = 4, ch = A, y = 12
C) x = 4, ch = ‘ ‘, y = 2
D) This statement results in input failure
D
Suppose that ch1, ch2, and ch3 are variables of the type char. The input is:
A B
C
What is the value of ch3 after the following statements execute?
cin.get(ch1);
cin.get(ch2);
cin.get(ch3);
A) ‘A’
B) ‘B’
C) ‘C’
D) ‘\n’
‘B’
Suppose that x and y are int variables, and z is a double variable. The input is:
28 32.6 12
Choose the values of x, y, and z after the following statement executes:
cin»_space; x»_space; y»_space; z;
A) x = 28, y = 32, z = 0.6
B) x= 28, y = 32, z = 12.0
C) x = 28, y = 12, z = 32.6
D) x = 28, y = 12, z = 0.6
A) x = 28, y = 32, z = 0.6
Suppose that x = 55.68, y = 476.859, and z = 23.8216. What is the output of the following statements?
cout «_space;fixed «_space;showpoint;
cout «_space;setprecision(3);
cout «_space;x «_space;’ ‘ «_space;y «_space;’ ‘ «_space;setprecision(2) «_space;z «_space;endl;
A) 55.680 476.859 23.82
B) 55.690 476.860 23.82
C) 55.680 476.860 23.82
D) 55.680 476.859 23.821
A) 55.680 476.859 23.82
Suppose that x is an int variable, y is a double variable, and z is an int variable. The input is:
15 76.3 14
Choose the values after the following statement executes:
cin»_space; x»_space; y»_space; z;
A) x = 15, y = 76, z = 14
B) x = 15, y = 76, z = 0
C) x = 15, y = 76.3, z = 14
D) x = 15.0, y = 76.3, z = 14.0
C) x = 15, y = 76.3, z = 14
Using a mathematical library function without including the preprocessor statement #include <cmath> is a common programming error in C++.</cmath>
A) True B) False
True
When a manipulator requiring an argument is used, the ____ header file must be included as part of the program.
A) istream
B) iostream
C) ostream
D) iomanip
D) iomanip
Suppose that x is an int variable, y is a double variable, and ch is a char variable. The input is:
15A 73.2
Choose the values after the following statement executes:
cin»_space; x»_space; ch»_space; y;
A) x = 15, ch = ‘A’, y = 73.2
B) x = 15, ch = ‘A’, y = 73.0
C) x = 15, ch = ‘a’, y = 73.0
D) This statement results in an error because there is no space between 15 and A.
A) x = 15, ch = ‘A’, y = 73.2
The extraction operator»_space; skips only all leading blanks when searching for the next data in the input stream.
A) True B) False
False
Suppose that x = 1565.683, y = 85.78, and z = 123.982. What is the output of the following statements?
cout «_space;fixed «_space;showpoint;
cout «_space;setprecision(3) «_space;x «_space;’ ‘;
cout «_space;setprecision(4) «_space;y «_space;’ ‘ «_space;setprecision(2) «_space;z «_space;endl;
A) 1565.683 85.8000 123.98
B) 1565.680 85.8000 123.98
C) 1565.683 85.7800 123.98
D) 1565.683 85.780 123.980
C) 1565.683 85.7800 123.98
Suppose that ch1 and ch2 are char variables, and alpha is an int variable. The input is:
A 18
What are the values after the following statement executes?
cin.get(ch1);
cin.get(ch2);
cin»_space; alpha;
A) ch1 = ‘A’, ch2 = ‘ ‘, alpha = 18
B)ch1 = ‘A’, ch2 = ‘1’, alpha = 8
C) ch1 = ‘A’, ch2 = ‘ ‘, alpha = 1
D) ch1 = ‘A’, ch2 = ‘\n’, alpha = 1
A) ch1 = ‘A’, ch2 = ‘ ‘, alpha = 18
The operator used to force converting a value to another type is the ____ operator.
A) binary
B) single
C) logical
D) cast
cast
Assignment statements can be used to perform arithmetic computations.
A) True
B) False
True
When the ++ operator appears before a variable it’s called a(n) ____ increment operator.
A) suffix
B) prefix
C) postfix
D) infix
B) Prefix
Suppose that alpha is an int variable and ch is a char variable. The input is:
17 A
What are the values after the following statements execute?
cin»_space; alpha;
cin»_space; ch;
A) alpha = 17, ch = ‘ ‘
B) alpha = 1, ch = 7
C) alpha = 17, ch = ‘A’
D) alpha = 17, ch = ‘a’
C) alpha = 17, ch = ‘A’
Suppose that ch1 and ch2 are char variables and the input is:
WXYZ
What is the value of ch2 after the following statements execute?
cin.get(ch1);
cin.putback(ch1);
cin»_space; ch2;
A) W
B) X
C) Y
D) Z
not x or y
When you want to process only partial data, you can use the stream function ____ to discard a portion of the input.
A) clear
B) skip
C) delete
D) ignore
ignore
Suppose that x is an int variable, ch is a char variable, and the input is:
276.
Choose the values after the following statement executes:
cin»_space; ch»_space; x;
A) ch = ‘2’, x = 76
B) ch = ‘276’, x = ‘.’
C) ch = ‘ ‘, x = 276
D) ch = ‘b’, x = 76
A) ch = ‘2’, x = 76