Skip to content
MathsGenie logo
Open app

Course home

  1. IGCSE
  2. Computer Science Edexcel
  3. Question bank

Algorithms

EasyMedium
123456789101112131415161718
Question 12

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).

FruitAppleCountBananaPointsBananaCountTotalPointsDISPLAY
Initial0000
"banana"51
"apple"1
"banana"102
"banana"153
"apple"2
"-1"
(a)
(b)
(c)
(d)
a.

(a)

[1]
b.

(b)

[1]
c.

(c)

[1]
d.

(d)

[1]

Algorithms Questions

  1. IGCSE
  2. /Computer Science
  3. /Algorithms