Name:
Class:
Date:
Page 1
Indicate whether the statement is true or false.
1. The update read is often an exact copy of the priming read.
a.
True
b.
False
2. An accumulator is a numeric variable used for counting something.
a.
True
b.
False
3. When you decrement a value stored in an accumulator, you add a number to it.
a.
True
b.
False
4. The update read initializes the loop condition by providing its first value.
a.
True
b.
False
5. The while loop is an example of a posttest loop.
a.
True
b.
False
6. Values that are used to end loops are referred to as sentinel values.
a.
True
b.
False
7. The for loop can be used to code pretest loops.
a.
True
b.
False
8. The selection structure is used when a programmer wants to repeatedly process one or more program instructions.
a.
True
b.
False
9. Another name for an endless loop is an infinite loop.
a.
True
b.
False
10. In a posttest loop, the condition is evaluated before the instructions within the loop are processed.
a.
True
b.
False
Indicate the answer choice that best completes the statement or answers the question.
11. What statement can be used to code a pretest loop in C++?
a.
switch
b.
while
Name:
Class:
Date:
Page 2
c.
do
d.
next
12. What type of variable is used for adding together a series of values?
a.
counter
b.
accumulator
c.
ticker
d.
initializer
13. When a counter is incremented or decremented, what process is occurring to the variable?
a.
counting
b.
accumulating
c.
initializing
d.
updating
14. What type of value is used to update a counter?
a.
constant
b.
negative
c.
variable
d.
floating point
15. What must happen in a pretest loop before the instructions in the loop are processed?
a.
the condition must evaluate to a value greater than 0
b.
the condition must evaluate to true
c.
the condition must evaluate to a value less than 0
d.
the condition must evaluate to false
16. What can you do to stop an endless loop in a C++ program?
a.
press Ctrl+c
b.
type break
c.
press End
d.
type end
17. In a repetition structure, what is the requirement for not repeating the instructions called?
a.
break condition
b.
sentinel value
c.
loop exit condition
d.
looping condition
18. How many arguments can the for clause contain?
a.
1
b.
2
c.
3
d.
4
19. Which two C++ statements can be used to code pretest loops?
a.
if, while
b.
switch, if
c.
for, while
d.
for, switch
20. Which of the following would be a good sentinel value used in a loop that uses a miles per hour value as the looping
condition?
a.
100
b.
1000
c.
0
d.
-1
21. In regards to the repetition structure, which of the following is true?
a.
each case statement has a break statement
b.
every sentinel value has a corresponding initial
value
c.
every increment operation has a corresponding
decrement operation
d.
every looping condition has an opposing loop
exit condition
22. Which of the following is another name for a sentinel value?
Name:
Class:
Date:
Page 3
a.
trip value
b.
exiting value
c.
priming value
d.
looping value
23. In a pretest loop, what initializes the loop condition by providing its first value?
a.
sentinel value
b.
update read
c.
priming read
d.
none of the above
24. The condition in a while loop must evaluate to what type of value?
a.
integer
b.
string
c.
char
d.
Boolean
25. What should you do to a counter variable before it is used the first time in a program?
a.
restore it
b.
process it
c.
initialize it
d.
update it
26. A loop whose instructions are processed indefinitely is referred to as which of the following?
a.
for statement
b.
infinite loop
c.
terminal loop
d.
while statement
27. In a repetition structure, what is the requirement for repeating the instructions called?
a.
infinite loop
b.
sentinel value
c.
exit condition
d.
looping condition
28. What is the correct order of the possible arguments in a for statement?
a.
update, initilization, condition
b.
initialization, condition, update
c.
condition, initialization, update
d.
condition, update, initialization
29. What is a possible result of not including an update read statement in a while loop?
a.
finite loop
b.
infinite loop
c.
syntax error
d.
compiler error
30. Which character is used to separate each clause in a for statement?
a.
comma
b.
colon
c.
semicolon
d.
space
31. Although not required, it is good programming practice to mark the end of the loop with a(n) _____.
a.
cout statement
b.
semicolon
c.
comment
d.
end statement
32. In a pretest loop, what should you include in the loop body to ensure that there is a way to enter the sentinel value after
the loop body instructions are processed the first time?
a.
priming read
b.
update read
c.
trailer value
d.
trip value
33. When implementing a loop, where is the assignment statement that updates a counter or accumulator placed?
a.
after the body of a loop
b.
before the body of a loop
Name:
Class:
Date:
Page 4
c.
inside the body of a loop
d.
outside the body of a loop
34. What is used to terminate a counter-controlled loop?
a.
counter
b.
sentinel value
c.
updater
d.
boolean value
35. In a for statement, which argument or arguments are required?
a.
condition
b.
initialization and update
c.
initialization
d.
initialization and condition
36. What type of structure allows you to repeat a set of instructions multiple times?
a.
sequence
b.
decision
c.
loop
d.
nested
37. Write a for statement to sum the integers 1 through 10 given the following:
int sum = 0;
Use the variable count as the counter variable within the statement.
38. Why are pretest and posttest loops are also called top-driven and bottom-driven loops, respectively? Explain your
answer.
39. What is the result of the following set of code?
int count = 10;
while (count < 10)
{
cout << count << endl;
count = count1;
}
40. What are two pretest loop statements available in C++ and why would you use one versus the other?
41. What happens if you omit an update read within a loop?
42. Write a while statement to sum the integers 1 through 10 given the following:
int count = 1;
int sum = 0;
43. Write the for statement to print the integers 1 through 10 on the screen, in reverse order, one per line.
Use the variable count as the counter variable within the statement.
44. Given the code below, write the while statement to print the integers 1 through 10 on the screen, one per line.
int count = 1;
Name:
Class:
Date:
Page 5
45. What is the result of the following set of code?
int count = 1;
while (count <= 10)
{
cout << count << endl;
}
46. What is a repetition structure and why might a programmer need to use one?
Name:
Class:
Date:
Page 6
Name:
Class:
Date:
Page 7
Name:
Class:
Date:
Page 8