Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 3 of 4.
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.
▶ Whole paper
Video solution of the whole paper · by CS BY AQIB KHAN. Tap the picture to open it on YouTube.
Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.