9618/21/M/J/23 question 6: worked solution (May/June 2023, paper 21)

Show as plain text

Cambridge AS Level Computer Science 9618 · 10.2 Arrays Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 2 of 4. Q22 9618/21/M/J/23 original Q6 Structured · 6 marks Worked solution Use an outer loop for the 128 columns and an inner loop for the 6 users. Add up only the values above 10, count them, then divide. PROCEDURE Mix() DECLARE Count, Total, ThisUser, ThisSample : INTEGER FOR ThisSample ← 1 TO 128 Count ← 0 Total ← 0 FOR ThisUser ← 1 TO 6 IF Sample[ThisUser, ThisSample] > 10 THEN Count ← Count + 1 Total ← Total + Sample[ThisUser, ThisSample] ENDIF NEXT ThisUser Result[ThisSample] ← INT(Total / Count) NEXT ThisSample ENDPROCEDURE Count and Total declared and set to 0 before the inner loop [1] Outer loop that runs 128 times [1] Inner loop that runs 6 times [1] Test for a sample greater than 10 inside the loop [1] If true, add to Total and increase Count [1] Average calculated after the inner loop (inside the outer loop) and stored in Result, converted to an integer with INT() or DIV [1] Other correct ways also score. KEY IDEA Reset the running total and count for each column, only include values above 10, and store the average after the inner loop. TOTAL 6 marks Official mark scheme VIDEO ▶ Starts at Q6 (43:33) Starts at Q6 (43:33) · by Pseudocode Pro. Tap the picture to open it on YouTube.