Chapter 4 Self Quiz

advertisement
Chapter 4 Self-Quiz
True/False
Indicate whether the statement is true or false.
____
1. Both selection and repetition statements allow the programmer to alter the normal sequential flow of control.
____
2. The relationship 3 < 4 is always true, therefore the relationship has a value of 0.
____
3. The logical operators AND, OR and NOT are used to create more complex relational expressions.
____
4. The NOT operator is a binary operator.
____
5. Tests for equality of single-precision and double-precision values and variables using the relational operator
== are usually reliable.
____
6. The if-else statement directs the computer to select between two statements based on the result of a
comparison.
____
7. All statements contained within a compound statement constitute a single block of code.
____
8. if-else statements can not contain compound statements.
____
9. Boolean values true and false are represented by the integer values 0 and 1 respectively.
____ 10. C++ has always had a built-in Boolean data type with two Boolean values, true and false.
____ 11. if-else statements can not contain other if-else statements.
____ 12. An if-else chain is stopped once a true condition is found.
____ 13. An if-else chain can not be continued indefinitely by repeatedly making the last statement another ifelse statement.
____ 14. Once an entry point has been located by the switch statement further case evaluations will continue.
____ 15. Using the assignment operator, =, in place of the relational operator, ==, is a commonly made C++
programming error.
Multiple Choice
Identify the choice that best completes the statement or answers the question.
____ 16. Relational expressions are also called ____.
a. options
c. conditions
b. choices
d. paths
____ 17. The value of a relational expression such as hours > 40 depends on the ____ stored in the variable
hours.
a. condition
c. value
b. sign
d. relationship
____ 18. ____ letters is essential in alphabetizing names.
a. Comparing
c. Deleting
b. Capitalizing
d. Adding
____ 19. Many ____ numbers cannot be represented exactly in binary form using a finite number of bits.
a. small
c. integer
____ 20.
____ 21.
____ 22.
____ 23.
____ 24.
____ 25.
____ 26.
____ 27.
____ 28.
____ 29.
____ 30.
b. large
d. decimal
For single-precision and double-precision operands, the general expression operand_1 == operand_2
should be replaced by this condition:
a. operand_1 – operand_2 < EPSILON
b. abs(operand_1 – operand_2) < EPSILON
c. operand_2 – operand_1 < EPSILON
d. operand_1 – operand_2 >= EPSILON
Using the abs() function requires including the ____ header file.
a. iostream
c. cmath
b. system
d. math
A(n) ____ statement is a sequence of single statements between braces.
a. Boolean
c. compound
b. conditional
d. if-else
If age is initialized to equal 18, the statement age == 40 has a value of ____.
a. 0
c. 18
b. 1
d. 30
C++ treats any nonzero value as ____.
a. true
b. false
c. either true or false
d. None of the above, because you cannot make a general statement about this
Including one or more if statements inside an existing if statement is called a ____ if statement.
a. compound
c. nested
b. complex
d. chain
In the absence of braces in an if-else statement, each else is associated with the ____ unpaired if.
a. next
c. shortest
b. last
d. closest
In a C++ program, statement indentation is ____ as far as the compiler is concerned.
a. required
c. irrelevant
b. invalid
d. standardized
In an if-else chain, the final else is ____.
a. a default or catch-all case
c. required
b. recommended
d. not used
____ case labels may be contained within a switch statement.
a. Up to 1
c. Up to 100
b. Up to 10
d. Any number of
If break statements are omitted from a switch statement, ____ cases following the matching case value
are executed.
a. no
c. all
b. some
d. two
Chapter 4 Self-Quiz
Answer Section
TRUE/FALSE
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
T
F
T
F
F
T
T
F
F
F
F
T
F
F
T
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
REF:
REF:
REF:
REF:
REF:
REF:
REF:
REF:
REF:
REF:
REF:
REF:
REF:
REF:
REF:
137
138
139
140
142
143
148
149
153
153
158
159
160
169
173
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
REF:
REF:
REF:
REF:
REF:
REF:
REF:
REF:
REF:
REF:
REF:
REF:
REF:
REF:
REF:
138
139
139
142
142
142
146
151-152
152
158
159
159
159
168
169
MULTIPLE CHOICE
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
C
C
A
D
B
C
C
A
A
C
D
C
A
D
C
Download