Quiz #3

advertisement
ITS 2591
C++ Programming I
Quiz #3
True/False
For each of the following five statements determine whether each is true or false. Select A on the
Scantron form for true and B for false.
1. ______ The left operand of the extraction operator must be an input stream variable.
2. ______ The statement cout << num; is equivalent to the statement num << cout;
3. ______ The number of input data extracted by cin and >> depends on the number of variables appearing
in the cin statement.
4. ______ Conditional statements help incorporate decision making into programs.
5. ______ The expression !(x < 0) is true only if x is a positive number.
Multiple Choice
Choose the best answer for each of the following multiple choice questions and fill in the
corresponding letter on the Scantron form.
6. Suppose that x is an int variable and y is a double variable and the input is:
10 20.7
Choose the values after the following statement executes: cin >> x >> y;.
a.
b.
c.
d.
x
x
x
x
=
=
=
=
10,
10,
10,
10,
y
y
y
y
=
=
=
=
20
20.0
20.7
21.0
7. Suppose that alpha is an int variable and ch is a char variable and the input is:
17 A
What are the values after the following statements execute?
cin >> alpha;
cin >> ch;
a.
b.
c.
d.
alpha
alpha
alpha
alpha
=
=
=
=
17, ch = ' '
1, ch = 7
17, ch = 'A'
17, ch = 'a'
8. Suppose that x and y are int variables. Which of the following is a valid input statement?
a.
b.
c.
d.
cin >> x >> cin >> y;
cin >> x >> y;
cin << x << y;
cout << x << y;
9. Which of the following is the “not equal to” relational operator?
a.
b.
c.
d.
!
|
!=
&
10. Suppose that x is an int variable. Which of the following expressions always evaluates to true?
a.
b.
c.
d.
(x
(x
(x
(x
> 0) || ( x <= 0)
>= 0) || (x == 0)
> 0) && ( x <= 0)
> 0) && (x == 0)
Quiz #3
Answer Section
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
A
B
A
A
B
C
C
B
C
A
Download