9618/21/O/N/23 question 6: worked solution (October/November 2023, paper 21)
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. Q83 9618/21/O/N/23 original Q6 Structured · 9 marks Worked solution (a) Join the new string on, but output first if it would not fit, or if the Boolean is TRUE. PROCEDURE MyOutput(NewString : STRING, EOL : BOOLEAN) IF LENGTH(MyString) + LENGTH(NewString) > 255 THEN OUTPUT MyString MyString ← NewString ELSE MyString ← MyString & NewString ENDIF IF EOL = TRUE THEN OUTPUT MyString MyString ← "" ENDIF ENDPROCEDURE Procedure heading with both parameters, and ending [1] Concatenated string produced [1] Check whether the resulting string would be longer than 255 characters [1] If so, output the old MyString [1] ... and put NewString into MyString [1] Otherwise concatenate NewString onto MyString [1] Test the Boolean: if TRUE output MyString ... [1] ... and reset MyString to an empty string (also scores, but only seven marks are available). (b) Write: a new MyString is created each time the procedure is called [1] Write: so the previous contents are lost and the string never builds up [1] KEY IDEA A global variable keeps its value between calls, but a local variable starts again each time. TOTAL 9 marks Official mark scheme VIDEO ▶ Starts at Q6 (37:37) Starts at Q6 (37:37) · by Pseudocode Pro. Tap the picture to open it on YouTube.