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

Show as plain text

Cambridge AS Level Computer Science 9618 · 9.2 Algorithms Worked solution from the Algorithm Design and Problem-solving Paper 2 Problem-solving and Programming booklet, Part 2 of 2. Q36 9618/22/M/J/24 original Q2 Structured · 10 marks Worked solution (a) Fill the shapes like this: First decision: is Num1 > Num2 AND Num1 > Num3 ? [1] Yes: set Ans to Num1 [1] No leads to a second decision: is Num2 > Num3 ? Yes: set Ans to Num2; No: set Ans to Num3 [1] Process box after the three branches join: set Average to (Num1 + Num2 + Num3) / 3 (do not use DIV) [1] Output parallelogram: OUTPUT a message with Ans and Average [1] (b) The outer loop repeats until Flag is TRUE. Inside it, Port goes 1 to 3 (the flowchart stops when Port = 4). Flag ← GetStat() WHILE Flag <> TRUE FOR Port ← 1 TO 3 CALL Reset(Port) NEXT Port Flag ← GetStat() ENDWHILE Outer conditional loop that tests Flag [1] Flag assigned from GetStat() inside the loop (and before it) [1] Inner loop that counts Port [1] Inner loop runs for 3 iterations (Port 1, 2, 3) [1] CALL Reset(Port) inside the loop [1] A REPEAT ... UNTIL Flag = TRUE with an IF around the FOR loop also scores. KEY IDEA Read a flowchart's decisions and loops carefully, then match them to WHILE or FOR loops. TOTAL 10 marks Official mark scheme VIDEO ▶ Starts at Q2 (13:11) Starts at Q2 (13:11) · by Pseudocode Pro. Tap the picture to open it on YouTube.