Cambridge AS Level Computer Science 9618 · 10.2 Arrays

Q20 · 9618/21/O/N/22 Q5

Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 2 of 4.

Q209618/21/O/N/22original Q5Structured · 5 marks
Question 5 from 9618/21/O/N/22

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 IDEAUse 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

Mark scheme for 9618/21/O/N/22 question 5
VIDEO
▶ Whole paper

Video solution of the whole paper · by Pseudocode Pro. Tap the picture to open it on YouTube.

Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.