9618/22/M/J/24 question 6: worked solution (May/June 2024, paper 22)
Show as plain textHide plain text
Cambridge AS Level Computer Science 9618 · 10.3 Files Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 3 of 4. Q58 9618/22/M/J/24 original Q6 Structured · 10 marks Worked solution (a) If the title has 16 characters or fewer, return it unchanged. Otherwise remove words from the end until the title is shorter than 14 characters, then add three dots. FUNCTION Trim(Name : STRING) RETURNS STRING CONSTANT Dots = "..." CONSTANT Space = " " IF LENGTH(Name) <= 16 THEN RETURN Name ENDIF WHILE LENGTH(Name) > 13 REPEAT Name ← LEFT(Name, LENGTH(Name) - 1) UNTIL RIGHT(Name, 1) = Space ENDWHILE Name ← LEFT(Name, LENGTH(Name) - 1) Name ← Name & Dots RETURN Name ENDFUNCTION Function heading, parameter, return type and ending [1] If the length is 16 or less , the original title is returned [1] A conditional loop that repeats until the string is short enough (less than 14) [1] An inner loop (or second condition) that finds the word to remove from the end [1] Characters are stripped back to a space [1] The space in front of the removed word is also removed [1] The three dots are joined on and the result is returned [1] (b)(i) Write: the file becomes very large , because redundant zeros are stored [1] (b)(ii) Write one of these: put a separator (delimiter) character between the values, or make the first character show the length of each sample [1] (b)(iii) Write: the algorithm to store and extract the samples is more complex and slower to run [1] KEY IDEA Trim a string by removing words from the end until it fits, and remember to remove the space too. TOTAL 10 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Pseudocode Pro. Tap the picture to open it on YouTube.