Each line of a text file contains data organised into fixed-length fields as shown: <Field 1><Field 2><Field 3> An algorithm is required to search for the first instance of a given value of Field 2 and, if found, to output the corresponding values for Field 1 and Field 3. Describe the algorithm needed. Do not include pseudocode statements in your answer.
- (a)Each line of a text file contains data organised into fixed-length fields as shown: <Field 1><Field 2><Field 3> An algorithm is required to search for the first instance of a given value of Field 2 and, if found, to output the corresponding values for Field 1 and Field 3. Describe the algorithm needed. Do not include pseudocode statements in your answer.[6]
Mark scheme
Marking points from the official mark scheme (May/June 2022). The mark or mark type is shown in brackets.
- [6] (a) One mark per point to Max 6
- [6] (a) 1 Open file in read mode
- [6] (a) 2 Set up a conditional loop, repeating until the value is found or the EOF() is reached
- [6] (a) 3 Read a line from the file in a loop
- [6] (a) 4 Extract Field 2
- [6] (a) 5 Description of how Field 2 could be extracted e.g. using substring function and lengths of Field 1 and Field 2
- [6] (a) 6 Compare extracted field with search value
- [6] (a) 7 If search value found, extract Field 1and Field 3 and output them
- [6] (a) 8 Close the file after loop has finished
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →