Leo registers the fruit sorted during a packaging run using the pseudocode below.
1 SET Fruit TO ""
2 SET TotalPoints TO 0
3 SET AppleCount TO 0
4 SET BananaPoints TO 0
5 SET BananaCount TO 0
6
7 WHILE Fruit <> "-1" DO
8 RECEIVE Fruit FROM (STRING) KEYBOARD
9 IF Fruit = "banana" THEN
10 SET BananaPoints TO BananaPoints + 5
11 SET BananaCount TO BananaCount + 1
12 ELSE
13 IF Fruit = "apple" THEN
14 SET AppleCount TO AppleCount + 1
15 END IF
16 END IF
17 END WHILE
18
19 SET TotalPoints TO AppleCount + BananaPoints
20
21 SEND ("Total Points: " & TotalPoints) TO DISPLAY
22 SEND ("Apples: " & AppleCount) TO DISPLAY
23 SEND ("Bananas: " & BananaPoints) TO DISPLAY
Leo inputs the sequence: banana, apple, banana, banana, apple, -1
The outputs are not quite what he expects.
Complete the trace table below by determining the values for (a), (b), (c), and (d).
| Fruit | AppleCount | BananaPoints | BananaCount | TotalPoints | DISPLAY |
|---|---|---|---|---|---|
| Initial | 0 | 0 | 0 | 0 | |
| "banana" | 5 | 1 | |||
| "apple" | 1 | ||||
| "banana" | 10 | 2 | |||
| "banana" | 15 | 3 | |||
| "apple" | 2 | ||||
| "-1" | |||||
| (a) | |||||
| (b) | |||||
| (c) | |||||
| (d) |
(a)
(b)
(c)
(d)