1 tom.com



chapter 3

Repeating Actions

True-False Questions

1. The advantage of the dialog output over the console output is that the dialog output is maintained on the screen for later review.

Answer: False Level: Easy

Section: 3-1 Page: 36

2. The end of line symbol (§) is used to start a new line in console output.

Answer: True Level: Easy

Section: 3-1 Page: 37

3. The flowchart element for a dialog input and console input are identical; you can’t tell them apart.

Answer: False Level: Easy

Section: 3-1 Page: 36

4. Console Input/Output is used to keep a visual record of the interactions as long as the program is running.

Answer: True Level: Moderate

Section: 3-1 Page: 37

5. The loop variable of a For loop can never exceed the final value.

Answer: False Level: Moderate

Section: 3-2 Page: 38

6. Some For loops have three exiting flow-arrows.

Answer: False Level: Hard

Section: 3-2 Page: 38

7. Each For loop has an initial, final and step value.

Answer: True Level: Easy

Section: 3-2 Page: 38

8. If you don’t initialize a counter or accumulator, the program will fail.

Answer: False Level: Easy

Section: 3-2 Page: 41

9. A counter is a variable that keeps a running total of a variable of interest, such as the total of all the individual sales.

Answer: False Level: Moderate

Section: 3-2 Page: 41

10. The flowchart element for a For loop is a six-sided figure with two exit arrows.

Answer: True Level: Easy

Section: 3-2 Page: 42

11. An accumulator variable must reside inside a For loop.

Answer: False Level: Hard

Section: 3-2 Page: 42

12. To use a While Loop the programmer must know how many times the body of the loop will be executed.

Answer: False Level: Easy

Section: 3-3 Page: 42

13. A sentinel value is used to indicate that the user is done inputting data.

Answer: True Level: Easy

Section: 3-3 Page: 44

14. Processing the number of students in a class is best done with a While loop because the number of students might change.

Answer: True Level: Moderate

Section: 3-3 Page: 42

15. The body of the While loop will not run if the condition evaluates to true.

Answer: False Level: Easy

Section: 3-3 Page: 42

16. The difference between the pre-test and post-test While loop is that the pre-test will always go through the body of the loop at least once before testing the condition statement.

Answer: False Level: Moderate

Section: 3-3 Page: 42

17. An exit loop statement can be found outside of the body of the loop.

Answer: False Level: Hard

Section: 3-3 Page: 45

18. A nested loop is a loop inside the body of another loop.

Answer: True Level: Easy

Section: 3-4 Page: 46

19. The Count variable of an outer loop can be used as the Final value of an inner loop.

Answer: True Level: Moderate

Section: 3-4 Page: 48

20. Only a loop of the same type can be used as an inner loop.

Answer: False Level: Hard

Section: 3-4 Page: 46

Multiple Choice Questions

21. Which is true of the dialog and console I/O flowchart elements?

a.) The elements are identical.

b.) The elements have the same shape and the dialog has an additional rectangle symbol.

c.) The elements have the same shape and the console has an additional rectangle symbol.

d.) The elements have a different shape.

e.) Only the input elements are identical in shape.

Answer: c Level: Easy

Section: 3-1 Page: 36

22. Which is the end-of-line symbol?

a.) @

b.) %

c.) &

d.) §

e.) ¶

Answer: d Level: Easy

Section: 3-1 Page: 37

23. What is the default value for the step variable of a For loop?

a.) -1

b.) 0

c.) 1

d.) 2

e.) There is no default value.

Answer: c Level: Easy

Section: 3-2 Page: 38

24. Which is not a standard element of a For loop?

a.) sentinel value

b.) initial value

c.) final value

d.) step value

e.) variable name

Answer: a Level: Easy

Section: 3-2 Page: 38

25. Which statement is true?

a.) The step value will display in the flowchart element when its value is 1.

b.) The step value cannot be set to a negative value.

c.) The initial value must be set to a value of 1.

d.) The loop ends when the loop variable equals the final value.

e.) All statements are false.

Answer: e Level: Hard

Section: 3-2 Page: 38

26. Which statement is true?

a.) Every loop must have a counter.

b.) Every loop must have an accumulator.

c.) Counters and accumulators are always found inside loops.

d.) Counters and accumulators are typically found inside loops.

e.) Counters and accumulators are never found inside loops.

Answer: d Level: Moderate

Section: 3-2 Page: 41

27. Which statement is true? .

a.) Counters and accumulators are both updated by 1.

b.) Counters are updated by the value of a variable; accumulators are updated by 1.

c.) Counters are updated by 1; accumulators are updated by the value of a variable.

d.) Counters and accumulators are both updated by the value of a variable.

e.) Neither counters nor accumulators are updated.

Answer: c Level: Moderate

Section: 3-2 Page: 41

28. The body of a While loop: .

a.) will always run with a post-test.

b.) will always run with a pre-test.

c.) might not run with a post-test.

d.) might not run with a pre-test.

e.) Both a and d.

Answer: e Level: Hard

Section: 3-3 Page: 42

29. The best method for validating input is to use the:

a.) For loop.

b.) While loop.

c.) nested loops.

d.) console output.

e.) accumulators.

Answer: b Level: Moderate

Section: 3-3 Page: 42

30. The Exit loop statement:

a.) makes the program stop.

b.) makes the first part of the loop run again.

c.) makes the last part of the loop run again.

d.) makes the first statement after the loop run.

e.) None of the above.

Answer: d Level: Moderate

Section: 3-3 Page: 45

31. Which type of statement cannot be run inside a loop?

a.) Input

b.) Assignment

c.) Output

d.) Other loops

e.) All are valid types of statements.

Answer: e Level: Easy

Section: 3-4 Page: 46

Fill in the Blank Questions

32. Input from the user and output from the program will last in the console I/O for the life of the program .

Level: Moderate

Section: 3-1 Page: 37

33. The end-of-line symbol is visible in the console output expression.

Level: Moderate

Section: 3-1 Page: 37

34. The console ___output___ expression will always finish with an end-of-line expression.

Level: Easy

Section: 3-1 Page: 37

35. Three key numerical elements of the For Next loop are the initial , final , and step values.

Level: Moderate

Section: 3-2 Page: 38

36. The step value will appear in the For loop flowchart element when it is a value __other than one.

Level: Moderate

Section: 3-2 Page: 38

37. If the step value of a For loop is negative, the loop will execute when the loop variable is ___not smaller than___ the final value.

Level: Moderate

Section: 3-2 Page: 42

38. A While loop is useful for checking that the user enters valid data before processing occurs.

Level: Easy

Section: 3-3 Page: 42

39. The Exit loop statement causes program flow to jump to the first statement after the loop.

Level: Easy

Section: 3-3 Page: 45

40. With a ___pre-test___ condition, the body of the While loop may or may not be executed depending on the result of the condition.

Level: Moderate

Section: 3-3 Page: 42

41. With a ___post-test___ condition, the body of the While loop will always execute at least once.

Level: Moderate

Section: 3-3 Page: 42

42. A ___sentinel___ value is used to indicate there is no more data to process.

Level: Easy

Section: 3-3 Page: 44

43. A loop found in the body of another loop is called a(n) nested loop.

Level: Easy

Section: 3-4 Page: 46

44. The first loop encountered in a nested loop pair is called the ___outer___ loop.

Level: Easy

Section: 3-4 Page: 48

Essay Questions

45. Is it necessary to initialize counters and accumulators? Why?

It is not necessary to initialize counters and accumulators because many languages will assign a default value to any variable created. The default value in Visual Basic is zero, which is the value most programmers want the counter and accumulator to start as. Although it is not necessary to initialize these variables, it is a good practice to do so because it makes explicit the intent of the programmer to have the counter and accumulator start with a value of zero.

46. How does a programmer decide to use a While loop versus a For loop?

A For loop is used when the number of repetitions (iterations) through the loop are known before the loop is entered. A program that processes the 30 stocks in the Dow Jones Industrial Average each day can use a For loop because there are always 30 prices to input.

The While loop is used when the number of repetitions is not known at the beginning of the loop. A program that inputs the number of runs scored in each inning of a baseball game should use a While loop because there may be more than nine innings in a game when it goes into extra innings.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download