Worked solution from the Programming Paper 2 Algorithms, Programming and Logic booklet, Part 1 of 3.
Many answers are accepted if they are meaningful. Example answers:
Constant: NumberDays [1]
Value: 14 [1]
Many answers are accepted if they are meaningful. Example answers:
Array: LicenceNumbers [1]
Use: stores the licence numbers of the cars to be parked [1]
Use a range check so the day is between 1 and 14, with a loop that asks again until it is valid.
INPUT Day
WHILE Day < 1 OR Day > 14 DO
OUTPUT "You must enter a number between 1 and 14 inclusive"
INPUT Day
ENDWHILEAny two of these points score one each:
A (range) check for values between 1 and 14 [1]
An error message and the data entered again, with a WHILE or REPEAT loop until it is valid [1]
Also credited: a (type) check that an integer is entered, using an IF statement.
A suitable line of code or construct for the check, as shown [1]
Search the 20 spaces of the chosen day from space 1, and stop at the first free one.
OUTPUT "Enter the number of the day you need parking (1 to 14)"
INPUT Day
OUTPUT "Do you need an accessible space? (Y or N)"
INPUT Accessible
IF Accessible = "Y"
THEN
SpaceAllocated ← FALSE
Space ← (Day - 1) * 20 + 1
WHILE SpaceAllocated = FALSE AND Space <= Day * 20 DO
IF LicenceNumbers[Space] = ""
THEN
OUTPUT "Enter your car licence number"
INPUT LicenceNumbers[Space]
SpaceAllocated ← TRUE
ELSE
Space ← Space + 1
ENDIF
ENDWHILE
IF SpaceAllocated = TRUE
THEN
OUTPUT "You are allocated space ", Space - (Day - 1) * 20
ELSE
OUTPUT "No space available"
ENDIF
ENDIFAny six of these points score one each:
Day number and accessible parking inputs, both with suitable prompts [1]
Conditional statement to check if accessible parking is required [1]
Variable set to the first accessible space [1]
Checks whether the current array element is an available space [1]
A correct loop that checks all the array elements for the day [1]
Car licence number input and stored in the correct array position [1]
Also credited: the loop ends when a space is found or not, output for a space available or no space available, and output of the space allocated.
Explain each change. Any three of these:
Change the maximum constant to 560 (28 days) [1]
Change the message so the user is told to enter a day from 1 to 28 [1]
Alter the validation to allow an input of 1 to 28 [1]
Also credited: make the array that stores licence numbers and names bigger, and make sure all loops that retrieve or erase data use the new full range.
Explain each step. Any four of these:
Initialise counting variable(s) before any spaces are allocated [1]
… one for accessible spaces and one for general spaces [1]
Add 1 to the counter(s) when a space is allocated [1]
… for accessible spaces and for general spaces [1]
Also credited: keep both counters for the full two-week cycle, and output both totals so far 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.