Cambridge O Level Computer Science 2210 · 7.9 Writing and amending algorithms

Q88 · 2210/22/M/J/21 Q1

Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 8 of 8.

Q882210/22/M/J/21original Q1Structured · 20 marks
Question 1 from 2210/22/M/J/21

Worked solution

(a)

Write one array, for example:

Array: TrainUpPassengers [1]

Data type: integer [1]

Use: stores the number of passengers on each train journey up the mountain [1]

Any meaningful array that fits Task 1 scores, if the data type and use match.

(b)

Write two checks. For each, give a description, normal data and erroneous data:

Type check: checks the number entered is a whole number (integer) [1]

Normal data: 34 [1]

Erroneous data: two or 1.5 [1]

Range check: checks the number is between 1 and 480 inclusive [1]

Normal data: 34 [1]

Erroneous data: 500 [1]

Also accepted: a presence check (erroneous data: nothing entered) or a length check (3 digits or fewer; normal 345, erroneous 3456). A range check of 1 to 80 also scores.

(c)

Ask for the tickets and trains, check there is room, work out the price with the group discount, then update the arrays.

OUTPUT "How many tickets"
INPUT NoTickets
OUTPUT "Which train up the mountain? 1, 2, 3 or 4"
INPUT UpNumber
OUTPUT "Which train down the mountain? 1, 2, 3 or 4"
INPUT DownNumber
IF (DownNumber = 4 AND TrainUp[UpNumber] + NoTickets <= 480 AND TrainDown[DownNumber] + NoTickets <= 640) OR (TrainUp[UpNumber] + NoTickets <= 480 AND TrainDown[DownNumber] + NoTickets <= 480)
  THEN
    Cost ← (NoTickets - NoTickets DIV 10) * 50
    TrainUp[UpNumber] ← TrainUp[UpNumber] + NoTickets
    TrainDown[DownNumber] ← TrainDown[DownNumber] + NoTickets
    TrainUpTotal[UpNumber] ← TrainUpTotal[UpNumber] + Cost / 2
    TrainDownTotal[DownNumber] ← TrainDownTotal[DownNumber] + Cost / 2
ENDIF

Input of the number of tickets, with a suitable prompt [1]

Input of the train up and the train down, with suitable prompts [1]

Check that tickets are available on the selected trains [1]

If available, the price is calculated, including the discount if required [1]

Total passengers (seats used) updated for the up train and the down train [1]

Total cost updated for the up train and the down train [1]

Any six points score. A flowchart showing the same steps is accepted.

(d)

Explain each step and give the programming statement that does it. Write any five of these:

How the program displayed the number of passengers for a journey [1]

... and how this was done for all the trains (a loop) [1]

How the program displayed the money taken for a journey [1]

... and how this was done for all the trains [1]

How the program calculated the total number of passengers [1]

Also credited: calculating the total money taken, selecting the journey with the most passengers, dealing with two or more equally popular trains, and displaying the results with suitable messages.

KEY IDEACheck there is room first, then work out the price with the group discount and update every total that depends on it.
TOTAL 20 marks

Official mark scheme

Mark scheme for 2210/22/M/J/21 question 1
VIDEO
▶ Whole paper

Video solution of the whole paper · by CS BY AQIB KHAN. 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.