9618/21/O/N/22 question 5: worked solution (October/November 2022, 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. Q20 9618/21/O/N/22 original Q5 Structured · 5 marks Worked solution Step through Array1 three values at a time. Add the three values, divide by 3, make it an INTEGER and store it in the next place in Array2. PROCEDURE Summarise() DECLARE Value : REAL DECLARE IxA, IxB : INTEGER IxB ← 1 FOR IxA ← 1 TO 598 STEP 3 Value ← Array1[IxA] + Array1[IxA + 1] + Array1[IxA + 2] Value ← Value / 3 Array2[IxB] ← INT(Value) IxB ← IxB + 1 NEXT IxA ENDPROCEDURE Procedure heading and ending, with both index variables declared [1] Loop that goes through every element of Array1 (for example STEP 3) [1] Adds three consecutive values from Array1 and divides by 3 , inside the loop [1] Result converted to an integer (for example INT) [1] Result assigned to the correct element of Array2, and the Array2 index increased, inside the loop [1] KEY IDEA Use two indexes: one stepping through the input in steps of 3, and one stepping through the output one at a time. TOTAL 5 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Pseudocode Pro. Tap the picture to open it on YouTube.