9618/32/M/J/24 question 5: worked solution (May/June 2024, paper 32)

Show as plain text

Cambridge A2 Level Computer Science 9618 · 16.2 Translation Software Worked solution from the System Software Paper 3 Advanced Theory booklet, Part 2 of 2. Q27 9618/32/M/J/24 original Q5 Structured · 9 marks 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 read Stack (bottom → top) a 6 d 6, 9 + 15 a 15, 6 b 15, 6, 3 + 15, 9 c 15, 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 IDEA Build infix from RPN by taking the top two items for each operator, left to right. TOTAL 9 marks Official mark scheme VIDEO ▶ Starts at Q5 (30:23) Starts at Q5 (30:23) · by Pseudocode Pro. Tap the picture to open it on YouTube.