2210/22/M/J/23 question 7: worked solution (May/June 2023, paper 22)

Show as plain text

Cambridge O Level Computer Science 2210 · 8.1 Programming concepts Worked solution from the Programming Paper 2 Algorithms, Programming and Logic booklet, Part 1 of 3. Q20 2210/22/M/J/23 original Q7 Structured · 10 marks Worked solution (a) Totalling is the line that adds to Total. The count-controlled loop is a FOR loop. The post-condition loop is REPEAT … UNTIL. Totalling: line 07 [1] Count-controlled loop: lines 04 and 12 (or 16 and 18) [1] Post-condition loop: lines 02 and 20 [1] (b) Error 1: line 07 uses Number, not the array element. Correction: Total ← Total + Number[Counter] * Counter [1] Error 2: line 08 tests for 0, but the stop value is -1. Correction: IF Number[Counter] = -1 (or < 0) [1] Error 3: line 16 starts the loop at 0, but there is no Number [0] . Correction: FOR Counter ← 1 TO 5 [1] (c) Place: directly after the digit is input (around lines 05 and 06, before line 07). [1] REPEAT OUTPUT "Enter a digit ", Counter INPUT Number[Counter] UNTIL Number[Counter] = ROUND(Number[Counter], 0) AND (Number[Counter] = -1 OR (Number[Counter] > 0 AND Number[Counter] < 10)) Loop (REPEAT … UNTIL or any working loop) that asks again [1] Checks the number is greater than 0 and less than 10 (a single digit) [1] Allows -1 and checks the input is a whole number (or checks for length of one digit) [1] KEY IDEA Check each input straight after it is entered, using a loop that repeats until the value is valid. TOTAL 10 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by CS BY AQIB KHAN. Tap the picture to open it on YouTube.