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

Q115 · 2210/23/O/N/25 Q4

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

Q1152210/23/O/N/25original Q4Structured · 14 marks
Question 4 from 2210/23/O/N/25

Worked solution

(a)

Input both numbers, work out the total with the booking fee, and output it.

OUTPUT "Please enter the number of adult tickets "
INPUT Adult
OUTPUT "Please enter the number of child tickets "
INPUT Child
Total ← (Adult * 12.99) + (Child * 7.99) + 1.99
OUTPUT "The total cost is ", Total

Input of the number of adult tickets and child tickets [1]

Total of adult and child ticket costs calculated [1]

Booking fee of 1.99 added [1]

Total output with an appropriate message [1]

(b)

Put the adult input inside a loop that repeats while the number is too small.

REPEAT
    OUTPUT "You need at least one adult ticket. Enter the number of adult tickets "
    INPUT Adult
UNTIL Adult >= 1

Add a REPEAT ... UNTIL loop (or a WHILE loop) [1]

With the correct condition, for example UNTIL Adult >= 1 (or WHILE Adult < 1) [1]

With a suitable message asking the user to enter the number again [1]

The INPUT of Adult is inside the loop so it is asked again each time [1]

(c)(i)

The person needs A (tall enough) AND B (old enough) AND NOT C (no medical condition).

Write: X = (A AND B) AND (NOT C)

A AND B [1]

AND NOT C [1]

(c)(ii)

X is 1 only when A = 1, B = 1 and C = 0.

ABCA AND BNOT CX
000010
001000
010010
011000
100010
101000
110111
111100

X correct in rows 1 and 2 [1]

X correct in rows 3 and 4 [1]

X correct in rows 5 and 6 [1]

X correct in rows 7 and 8 [1]

KEY IDEATurn the rules into a logic expression (AND for all rules, NOT for the opposite) and use it to fill in the truth table.
TOTAL 14 marks

Official mark scheme

Mark scheme for 2210/23/O/N/25 question 4
VIDEO
▶ 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.