Worked solution from the Programming Paper 2 Algorithms, Programming and Logic booklet, Part 2 of 3.
Many answers are accepted. Example answers:
Variable: PassengerID (or StartStage) [1]
Use: stores the unique ID number of the passenger (or the start stage of the journey that is input) [1]
Describe each array with its name, data type, sample data and use. Example:
| Array name | Data type | Sample data | Use |
|---|---|---|---|
| JourneyStage1 | string | C1 | to store the code for the home to start station |
| PriceStage1 | real | 1.50 | to store the price of the first stage of the journey |
Name of an array given [1]
Data type of the array given [1]
Sample data for the array given [1]
Use of the array given [1]
At least two complete arrays, each with all of these [1]
Any three of these:
Use a validation check, for example a range, type, presence, length or format check [1]
If the check fails, output an error message and ask for the code to be entered again [1]
Use a loop (WHILE or REPEAT) to repeat the input until an acceptable code is entered [1]
Also credited: an IF statement to test whether the check fails, and more than one appropriate check described.
Tasks 1 and 2 are done, so the cost is already stored. Apply the discount for the time, show the details and let the passenger correct them.
IF CollectedTime[Index] > 10:00
THEN
JourneyCost[Index] ← JourneyCost[Index] * 0.6
ENDIF
OUTPUT "Your journey cost is: ", JourneyCost[Index]
OUTPUT "Your journey details are: ", PassengerID[Index], JourneyTime[Index], JourneyCodes[Index], JourneyID[Index]
OUTPUT "Are these details correct? (Y or N)"
INPUT Correct
WHILE Correct = "N" DO
OUTPUT "Correct passenger ID"
INPUT PassengerID[Index]
OUTPUT "Correct journey time"
INPUT JourneyTime[Index]
OUTPUT "Correct journey codes"
INPUT JourneyCodes[Index]
OUTPUT "Your revised journey details are: ", PassengerID[Index], JourneyTime[Index], JourneyCodes[Index]
OUTPUT "Are these details correct? (Y or N)"
INPUT Correct
ENDWHILEAny six of these points score one each:
Conditional statement that checks the departure time against 10:00 [1]
Calculates the 40% discount (multiplies the price by 0.6) [1]
Calculates the discounted total price [1]
Outputs the discounted total price [1]
Outputs the booking details with suitable messages [1]
Input with a prompt for the passenger to confirm the details [1]
Also credited: an action after the confirmation input, the booking data entered again if it is wrong, and the journey details checked again. PRINT is accepted for OUTPUT.
Explain each change. Any four of these:
Declare and use a counter to store the number of bookings for each passenger [1]
Update (add 1 to) the counter each time that passenger makes a booking [1]
Use an IF statement to check the number of bookings [1]
… for the right condition, for example more than 10 (or equal to 10) [1]
Applying the extra 10% discount to the total price of future journeys is also credited.
▶ Topic lesson
A lesson on this topic · by Craig'n'Dave. 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.