Quiz 3 Flashcards
(33 cards)
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