9618/21/M/J/22 question 5: worked solution (May/June 2022, paper 21)

Show as 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. Q46 9618/21/M/J/22 original Q5 Structured · 6 marks Worked solution Describe the algorithm Describe the steps in words, with no pseudocode. Any six of these points: Open the file in read mode [1] Set up a conditional loop that repeats until the value is found or the end of the file ( EOF ) is reached [1] Read a line from the file inside the loop [1] Extract Field 2 from the line [1] Compare the extracted field with the search value [1] If it matches, extract Field 1 and Field 3 and output them [1] Other points that also score: say how Field 2 is extracted, for example with a substring function using the lengths of Field 1 and Field 2; close the file after the loop has finished. KEY IDEA Read line by line, cut out the fixed-length field with a substring, compare it, and stop at the first match. TOTAL 6 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.