9618/23/O/N/25 question 4: worked solution (October/November 2025, paper 23)

Show as plain text

Cambridge AS Level Computer Science 9618 · 11.1 Programming Basics Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 1 of 3. Q36 9618/23/O/N/25 original Q4 Structured · 6 marks Worked solution (a) Each number takes 3 characters plus a comma, so the next number starts 4 characters later. Stop when the end of the string is reached or the array is full (20 elements). PROCEDURE Store() DECLARE Index, StartPos, ThisNum : INTEGER DECLARE ThisString : STRING Index ← 1 StartPos ← 1 WHILE StartPos < LENGTH(NumString) AND Index <= 20 ThisString ← MID(NumString, StartPos, 3) ThisNum ← STR_TO_NUM(ThisString) Data[Index] ← ThisNum Index ← Index + 1 StartPos ← StartPos + 4 ENDWHILE ENDPROCEDURE All local variables declared [1] Conditional loop that stops at the end of the string [1] ... and when the array is full [1] MID used to take the next three characters from the right place [1] Substring converted to an integer and stored in the array element [1] Index increased by 1 and StartPos by 4 inside the loop [1] Other ways also score, for example a FOR loop to 20 with a test for the end of the string, or reading one character at a time and testing for a comma. KEY IDEA Take the string three characters at a time, jumping 4 each time to skip the comma, and stop at the end of the string or when the array is full. TOTAL 6 marks Official mark scheme VIDEO ▶ Topic lesson A lesson on this topic · by ZAINEMATICS. Tap the picture to open it on YouTube.