Cambridge A2 Level Computer Science 9618 · 16.2 Translation Software

Q27 · 9618/32/M/J/24 Q5

Worked solution from the System Software Paper 3 Advanced Theory booklet, Part 2 of 2.

Q279618/32/M/J/24original Q5Structured · 9 marks
Question 5 from 9618/32/M/J/24

Worked solution

(a)

Bracket (7 - 2 + 8) is done from the left: 7 2 - then + 8. [1]

Then (9 - 5), then /: 7 2 - 8 + 9 5 - / [1]

(b)

a = 6, b = 3, c = 7, d = 9.

Item readStack (bottom → top)
a6
d6, 9
+15
a15, 6
b15, 6, 3
+15, 9
c15, 9, 7
-15, 2
*30

6 and 9 pushed, then 15 after + [1]

6 and 3 pushed, then 9 after + [1]

7 pushed, then 2 after - [1]

Final multiplication gives 30 [1]

Marks are given for correct stack stages like these.

(c)

Read left to right: a c - gives (a - c); then b + that gives b + (a - c), which can be written (a – c + b).

(a – c + b) [1]

d b + gives (d + b), multiplied by the first part [1]

Then divide by c: (a – c + b) * (d + b) / c, or with full brackets (((a – c) + b) * (d + b)) / c [1]

KEY IDEABuild infix from RPN by taking the top two items for each operator, left to right.
TOTAL 9 marks

Official mark scheme

Mark scheme for 9618/32/M/J/24 question 5
VIDEO
▶ Starts at Q5 (30:23)

Starts at Q5 (30:23) · by Pseudocode Pro. 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.