9618/22/O/N/24 question 5: worked solution (October/November 2024, paper 22)
Show as plain textHide plain text
Cambridge AS Level Computer Science 9618 · 12.3 Program Testing and Maintenance Worked solution from the Software Development Paper 2 Problem-solving and Programming booklet, Part 3 of 3. Q51 9618/22/O/N/24 original Q5 Structured · 7 marks Worked solution (a) Any three of these four statements, each with its reason: Statement: Count ← INT(100 / Number) can fail if Number is 0 , which is a divide by zero [1] Statement: Index ← Data[Number] can fail if Number is outside the array range 1 to 100 (or the lower bound) [1] Statement: ReturnValue ← TO_UPPER(RIGHT(Label, Count)) can fail if Count is negative or larger than the length of Label [1] Another accepted statement: RETURN RetVal fails because RetVal does not exist (the variable is called ReturnValue). Only three marks at most. (b) Write: Construct: a loop (pre-condition or post-condition, such as WHILE or REPEAT) [1] Explanation: the condition to end the loop is never met , so it repeats forever [1] (c) Use one IF statement. Index MOD 2 is 0 or 1, so ELSE covers 1: IF Index MOD 2 = 0 THEN ReturnValue ← TO_UPPER(RIGHT(Label, Count)) ELSE ReturnValue ← "****" ENDIF IF ... THEN ... ELSE ... ENDIF structure [1] Correct test and both assignments in the right branches [1] KEY IDEA Run-time errors come from impossible actions, such as dividing by zero or using an index outside an array, and endless loops freeze a program. TOTAL 7 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Papersdock. Tap the picture to open it on YouTube.