9618/21/O/N/25 question 4: worked solution (October/November 2025, 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. Q38 9618/21/O/N/25 original Q4 Structured · 9 marks Worked solution (a) Input the first value and store it. Then keep inputting while the array is not full and each value is bigger than the one before. PROCEDURE Store() DECLARE ThisNum, LastNum : REAL DECLARE Index : INTEGER INPUT ThisNum LastNum ← ThisNum Number[1] ← ThisNum INPUT ThisNum Index ← 2 WHILE Index < 21 AND ThisNum > LastNum Number[Index] ← ThisNum LastNum ← ThisNum Index ← Index + 1 IF Index < 21 THEN INPUT ThisNum ENDIF ENDWHILE OUTPUT Index - 1, " values were stored in the array" ENDPROCEDURE Local variables declared: Index as INTEGER, ThisNum and LastNum as REAL [1] First value input and assigned to the first element [1] Attempt at a conditional loop with both tests (array not full, value larger than previous) [1] Completely correct conditional loop with both tests [1] Inside the loop: value assigned to the current element when larger, and the next value input [1] After the loop: output of the count of values stored with a message [1] A count-controlled FOR loop with a BREAK (or similar exit) also scores. (b)(i) Any two of these: The number of values is not fixed , so it is not limited to the size of the array [1] The data is stored permanently (non-volatile), so another program can use it without the values being typed in again [1] (b)(ii) Each real value must be converted to a string before it is written. [1] KEY IDEA An array has a fixed size and loses its data when the program ends; a text file can grow and keeps its data, but holds strings. TOTAL 9 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by CSFeedbySirNisarAli. Tap the picture to open it on YouTube.