9618/22/O/N/22 question 4: worked solution (October/November 2022, 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. Q24 9618/22/O/N/22 original Q4 Structured · 7 marks Worked solution (a) Follow the arrows: the decision "Is Index < 7" with the arrow looping back is a WHILE loop. The decision "Is Average > Last" is an IF inside it. INPUT UserID Average ← GetAverage(UserID) Total ← 0 Index ← 4 WHILE Index < 7 Last ← SameMonth[Index] IF Average > Last THEN Total ← Total + Average ELSE Total ← Total + Last ENDIF Index ← Index + 1 ENDWHILE CALL Update(UserID, Total) UserID input, and Average assigned from GetAverage(UserID) [1] Total set to 0 and Index set to 4 [1] Conditional loop that runs for Index from 4 to 6 [1] Last assigned from SameMonth[Index] inside the loop [1] IF … THEN … ELSE … ENDIF inside the loop [1] Correct assignments to Total, Index incremented, and CALL Update(UserID, Total) after the loop [1] A FOR Index ← 4 TO 6 … NEXT Index loop also scores, and a REPEAT … UNTIL Index = 7 loop also scores. (b) Write: pre-condition loop (also accepted: count-controlled loop ). The test is made before the loop body. [1] KEY IDEA A decision box with a line looping back is a loop; a decision box with two separate branches is an IF. TOTAL 7 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Audere Prep. Tap the picture to open it on YouTube.