9618/22/M/J/22 question 7: worked solution (May/June 2022, paper 22)
Show as plain textHide plain text
Cambridge AS Level Computer Science 9618 · 11.3 Structured Programming Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 3 of 3. Q71 9618/22/M/J/22 original Q7 Structured · 6 marks Worked solution (a) Use RIGHT to cut off the front, then LEFT to keep only the characters needed. FUNCTION MID(InString : STRING, Start, Num : INTEGER) RETURNS STRING DECLARE MidString : STRING DECLARE InStringLen : INTEGER InStringLen ← LENGTH(InString) MidString ← RIGHT(InString, InStringLen - Start + 1) MidString ← LEFT(MidString, Num) RETURN MidString ENDFUNCTION Function heading and ending with parameters and return type [1] Correct use of one of the substring functions [1] Correct use of both functions in the right order [1] Return the substring [1] Using LEFT first (length Start + Num - 1) and then RIGHT (length Num) also scores. (b) Any two checks: Check that Start and Num are 1 or more (positive) [1] Check that the string is long enough for the operation (Start + Num - 1 is not more than its length) [1] KEY IDEA Cut away the start with RIGHT, then keep the wanted length with LEFT. TOTAL 6 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Awab Aqib. Tap the picture to open it on YouTube.