Cambridge AS Level Computer Science 9618 · 10.2 Arrays

Q22 · 9618/21/M/J/23 Q6

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

Q229618/21/M/J/23original Q6Structured · 6 marks
Question 6 from 9618/21/M/J/23

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

Mark scheme for 9618/21/M/J/23 question 6
VIDEO
▶ Starts at Q6 (43:33)

Starts at Q6 (43:33) · 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.