9618/22/O/N/21 question 4: worked solution (October/November 2021, paper 22)

Show as plain text

Cambridge AS Level Computer Science 9618 · 11.2 Constructs Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 2 of 3. Q39 9618/22/O/N/21 original Q4 Structured · 11 marks Worked solution (a) Question Answer Line with a variable being incremented 19 Type of loop structure pre-condition Number of functions used 3 Parameters passed to STR_TO_NUM() 1 Procedure other than Check() Result Line 19 (21 or 23 also accepted) [1] Pre-condition loop (WHILE) [1] 3 functions: LENGTH, MID and STR_TO_NUM [1] 1 parameter [1] Result [1] (b) Write three of these features: Meaningful variable names [1] Indentation / white space / blank lines [1] Capital letters for keywords [1] (c)(i) Write: a count-controlled loop (FOR ... NEXT) [1] Justification: the number of repeats is known, as it is the length of InString [1] (c)(ii) The FOR loop sets and adds to Index itself, so the Index ← 1 line and the Index ← Index + 1 line are not needed. Write 15 and 23 [1] KEY IDEA Use a count-controlled FOR loop when the number of repeats is known in advance. TOTAL 11 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.