Worked solution from the Programming Paper 2 Algorithms, Programming and Logic booklet, Part 1 of 3.
Name two variables, give a data type and say what each one is used for.
Variable 1: hourArrived, data type integer [1]
Use: to work out the price from the number of hours parked [1]
Variable 2: priceToPay, data type real [1]
Use: stores the result of the price calculation [1]
The two checks must be different. Examples that score:
Day: presence check [1]
Justification: the day must be entered so the price can be worked out [1]
Hour: range check [1]
Justification: the hour must be between 8 and 23 [1]
Write how the program checked the 5th digit of the number. Any four of these.
All 5 digits of the parking number are input [1]
Each of the first 4 digits is multiplied by a weight based on its position, with the method for splitting up the digits described [1]
The results are added together and divided by 11 [1]
The remainder gives the correct 5th digit, which is checked against the 5th digit input; if they match the number is valid [1]
Ask for the payment, repeat until it is at least the price, then add it to the total.
OUTPUT "Please enter payment"
INPUT amount
WHILE amount < priceToPay DO
OUTPUT "Insufficient payment, please enter new payment"
INPUT amount
ENDWHILE
totalPayment ← totalPayment + amountInput the amount paid [1]
Check the amount is greater than or equal to the price to pay [1]
If it is too small, ask for payment to be entered again until a valid amount is input [1]
If it is enough, add the amount to the daily total [1]
Explain the evening charge. Any four of these.
Add the number of hours chosen to the arrival hour [1]
Check if the result is greater than 16 [1]
If it is, work out the price up to 16 using the current price in force, then add the evening charge [1]
If it is not, work out the price as usual [1]
▶ Whole paper
Video solution of the whole paper · by Zafar Ali Khan (ZAK). 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.