Quiz 3 Flashcards

(33 cards)

1
Q

The ____ statement is used to enter data in a program while it’s running.

A) cout

B) data

C) cin

D) input

A

cin

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

in C++, accessing mathematical functions in a program requires including the mathematical header file ____.

A) number

B) cmath

C) cnumber

D) math

A

cmath

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The ____ declaration qualifier specifies that the declared identifier is read-only after it’s initialized.:

A) unchanged

B) fix

C) fixed

D) const

A

const

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In C++, the expression sum = sum + 10 can be written as ____.

A) sum = 10+

B) sum =+ 10

C) sum += 10

D) +sum = 10

A

C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In C++, the ____ symbol is called the assignment operator.

A) ==

B) =

C)&raquo_space;

D) ->

A

=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A

manipulators

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The stream manipulator ____ sets the floating-point precision to n places.

A) setfill(‘x’)

B) setprecision(n)

C) setw(n)

D) showbase

A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In C++, the mathematical function ____ calculates a number’s square root.

A) sqroot()

B) square()

C) squareRoot()

D) sqrt()

A

D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In the statement cin&raquo_space; x;, x can be a variable or an expression.

A) True
B) False
A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Suppose that x and y are int variables. Which of the following is a valid input statement?

A) cin&raquo_space; x&raquo_space; cin&raquo_space; y;

B) cin&raquo_space; x&raquo_space; y;

C) cin &laquo_space;x &laquo_space;y;

D) cout &laquo_space;x &laquo_space;y;

A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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&raquo_space; alpha;
cin.ignore(100, ‘\n’);
cin&raquo_space; beta;
cin.ignore(100,’\n’);
cin&raquo_space; gamma;

A) 100

B) 200

C) 300

D) 320

A

300

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The number of input data extracted by cin and&raquo_space; depends on the number of variables appearing in the cin statement.

A) True
B) False
A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When reading data into a char variable, after skipping any leading whitespace characters, the extraction operator&raquo_space; finds and stores only the next character; reading stops after a single character.
A) True
B) False

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Suppose that x = 25.67, y = 356.876, and z = 7623.9674. What is the output of the following statements?

cout &laquo_space;fixed &laquo_space;showpoint;
cout &laquo_space;setprecision(2);
cout &laquo_space;x &laquo_space;’ ‘ &laquo_space;y &laquo_space;’ ‘ &laquo_space;z &laquo_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

A

C) 25.67 356.88 7623.97

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Entering a char value into an int variable causes serious errors, called input failure.

A) True
B) False
A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

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&raquo_space; x&raquo_space; ch&raquo_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

17
Q

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’

18
Q

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&raquo_space; x&raquo_space; y&raquo_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

A) x = 28, y = 32, z = 0.6

19
Q

Suppose that x = 55.68, y = 476.859, and z = 23.8216. What is the output of the following statements?

cout &laquo_space;fixed &laquo_space;showpoint;
cout &laquo_space;setprecision(3);
cout &laquo_space;x &laquo_space;’ ‘ &laquo_space;y &laquo_space;’ ‘ &laquo_space;setprecision(2) &laquo_space;z &laquo_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

A) 55.680 476.859 23.82

20
Q

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&raquo_space; x&raquo_space; y&raquo_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

A

C) x = 15, y = 76.3, z = 14

21
Q

Using a mathematical library function without including the preprocessor statement #include <cmath> is a common programming error in C++.</cmath>

A) True
B) False
22
Q

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

23
Q

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&raquo_space; x&raquo_space; ch&raquo_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

​A) x = 15, ch = ‘A’, y = 73.2

24
Q

The extraction operator&raquo_space; skips only all leading blanks when searching for the next data in the input stream.

A) True
B) False
25
Suppose that x = 1565.683, y = 85.78, and z = 123.982. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(3) << x << ' '; cout << setprecision(4) << y << ' ' << setprecision(2) << z << 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
26
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 >> 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
27
The operator used to force converting a value to another type is the ____ operator. A) binary B) single C) logical D) cast
cast
28
Assignment statements can be used to perform arithmetic computations. A) True B) False
True
29
When the ++ operator appears before a variable it’s called a(n) ____ increment operator. A) suffix B) prefix C) postfix D) infix
B) Prefix
30
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 >> alpha; cin >> 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'
31
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 >> ch2; A) W B) X C) Y D) Z
not x or y
32
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
33
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 >> ch >> x; A) ch = '2', x = 76 B) ch = '276', x = '.' C) ch = ' ', x = 276 D) ch = 'b', x = 76
A) ch = '2', x = 76