Worked solution from the Programming Paper 2 Algorithms, Programming and Logic booklet, Part 1 of 3.
Many answers are accepted if they are meaningful and linked to Task 1. Example answers:
Constant: MaxSalad [1]
Value: 3 [1]
Use: stores the most salad items a baguette can have [1]
Variable: OrderNumber [1]
Data type: integer [1]
Use: stores the next order number available [1]
Show the fillings, accept only a valid choice, then ask how many salads (0 to 3) and take each salad.
REPEAT
OUTPUT "Beef 1, Chicken 2, Cheese 3, Egg 4, Tuna 5, Turkey 6"
OUTPUT "Please enter your choice of filling"
INPUT Filling
IF Filling < 1 OR Filling > 6
THEN
OUTPUT "Error, please try again"
ENDIF
UNTIL Filling >= 1 AND Filling <= 6
REPEAT
OUTPUT "How many salads do you want (0 to 3)?"
INPUT NumSalad
UNTIL NumSalad >= 0 AND NumSalad <= 3
OUTPUT "Lettuce 1, Tomato 2, Sweetcorn 3, Cucumber 4, Peppers 5"
WHILE NumSalad > 0 DO
OUTPUT "Please enter your choice of salad"
INPUT SaladType
IF SaladType >= 1 AND SaladType <= 5
THEN
Salad[NumSalad] ← SaladType
NumSalad ← NumSalad - 1
ELSE
OUTPUT "Error"
ENDIF
ENDWHILEAny five of these points score one each:
Display the fillings available [1]
Prompt and entry of the filling choice [1]
Only one correct filling accepted [1]
Prompt and entry of the number of salads, accepting only 0 to 3 [1]
Only correct salad choices accepted, for the number of salads asked for [1]
Also credited: the salads displayed, and at least one error message for wrong data.
Any three of these.
There is a way to input the filling choice [1]
The input is checked to be a correct filling, for example with a CASE statement [1]
If it is not, a suitable error message is output [1]
A way to enter it again is also credited, for example REPEAT … UNTIL.
Any two of these.
Store three sizes of baguette, for example add the third size to the array [1]
Change the prompt so it shows the three sizes [1]
Changing the selection statement (IF, REPEAT or WHILE) to accept a third size is also credited.
Any four of these.
Check the total for each filling, for example with a FOR loop [1]
Use two variables, one for the most popular and one for the least popular filling [1]
Use an IF statement to pick the largest total as the most popular [1]
Use an IF statement to pick the smallest total as the least popular [1]
Also credited: use these totals with the number of baguettes sold to work out percentages, and display the results with suitable messages.
▶ Topic lesson
A lesson on this topic · by Mr Bulmer's Learning Zone. Tap the picture to open it on YouTube.
Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.