A procedure LastLines() will: • take the name of a text file as a parameter • output the last three lines from that file, in the same order as they appear in the file. Note: • Use local variables LineX, LineY and LineZ to store the three lines from the file. • You may assume the file exists and contains at least three lines. Write pseudocode for the procedure LastLines().
- (a)A procedure LastLines() will: • take the name of a text file as a parameter • output the last three lines from that file, in the same order as they appear in the file. Note: • Use local variables LineX, LineY and LineZ to store the three lines from the file. • You may assume the file exists and contains at least three lines. Write pseudocode for the procedure LastLines().[6]
- (b)The algorithm in part (a) is to be amended. The calling program will pass the number of lines to be output as well as the name of the text file. The number of lines could be any value from 1 to 30. It can be assumed that the file contains at least the number of lines passed. Outline three changes that would be needed. 1 2 3[3]
Mark scheme
Marking points from the official mark scheme (May/June 2022). The mark or mark type is shown in brackets.
- [6] Marks as follows to Max 6:
- 1 Procedure heading (including parameter) and ending
- 2 Declaration of local variables for three lines AND File OPEN in READ mode AND CLOSE
- 3 Loop until EOF(ThisFile)
- 4 Read line from file... in a loop
- 5 Attempt at a shuffle... in a loop
- 6 Correctly shuffle LineX, LineY and LineZ in a loop
- 7 OUTPUT the three lines in correct sequence, following reasonable attempt
- Alternative (using two loops):
- [6] Marks as follows to Max 6:
- 1 Procedure heading (including parameter) and ending
- 2 Declaration of local variables for three lines AND (at least one) File OPEN in READ mode AND CLOSE
- 3 Loop until EOF(ThisFile)
- 4 Read line from file and increment Count in a loop
- 5 Two separate loops, closing and re-opening the file between loops
- 6 Read Count - 3 lines from the file
- 7 OUTPUT the last three lines in correct sequence, following reasonable attempt
- [3] One mark per point to Max 3:
- 1 Change the procedure header to include a (numeric) parameter (as well as the filename)
- 2 Replace LineX, Y and Z with an array
- 3 Amend shuffle mechanism
- 4 Use new parameter to determine first line to output
- 5 Output the lines in a loop
- Alternative 'two loop' solution to Max 3:
- 1 Change the procedure header to include a numeric parameter (as well as the filename)
- 2 A loop to count the total number of lines in the file
- 3 Ref use of single variable rather than LineX, LineY and LineZ
- 4 Close and re-open the file
- 5 Use the new parameter value to determine first line to output
- 6 Output the lines in a loop
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 →