Control Flow Constructs - Quiz

The answers you selected are indicated below, along with text that explains the correct answers.
1. The following pseudocode presents an example of which control flow construct?
If the service was good
  Leave a 15% tip
Otherwise
  Leave a 10% tip
Please select the best answer.
  A. Decision
  B. Compilation
  C. Repetition
  The correct answer is A. This pseudocode describes the decision you might make in determining the size of tip.
Answer B is incorrect because compilation refers to translating source code to machine code. Answer C is incorrect because repetition refers to repeatedly performing a task.

2. Which of the control flow constructs is used to execute the same statements over and over?
Please select the best answer.
  A. Decision
  B. Compilation
  C. Repetition
  The correct answer is C. The repetition construct is used to execute the same statements over and over.
Answer A is incorrect because the decision construct is used to conditionally execute statements. Answer B is incorrect because compilation refers to translating source code to machine code.

3. Consider the following pseudocode for a program involving cookies, marbles, and a hat. Assuming that when the program starts the cookie jar contains 3 cookies and the hat is empty, what will the hat contain when the program completes?
While the cookie jar is not empty
  Put a red marble in the hat
  If the hat contains an even number of marbles
    Put a blue marble in the hat
  Eat a cookie from the jar

Please select the best answer.
  A. 2 red marbles and 1 blue marble
  B. 3 red marbles and 1 blue marble
  C. 3 red marbles and 2 blue marbles
  The correct answer is C. Because there are 3 cookies, the statements:
Put a red marble in the hat
If the hat contains an even number of marbles
   Put a blue marble in the hat
Eat a cookie from the jar

will be executed 3 times. The first time these statements are executed, 1 red marble is placed in the hat. The second time these statements are executed, 1 red marble and 1 blue marble are placed in the hat. The third, and final, time these statements are executed, 1 red marble and 1 blue marble are placed in the hat. Thus when the program completes, the hat will contain 3 red marbles and 2 blue marbles.