Skip to main content
A-LevelComputer ScienceProgramming9618/22 · May/June 2022 · Q49 Marks

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().

  1. (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]
  2. (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.

  1. [6] Marks as follows to Max 6:
  2. 1 Procedure heading (including parameter) and ending
  3. 2 Declaration of local variables for three lines AND File OPEN in READ mode AND CLOSE
  4. 3 Loop until EOF(ThisFile)
  5. 4 Read line from file... in a loop
  6. 5 Attempt at a shuffle... in a loop
  7. 6 Correctly shuffle LineX, LineY and LineZ in a loop
  8. 7 OUTPUT the three lines in correct sequence, following reasonable attempt
  9. Alternative (using two loops):
  10. [6] Marks as follows to Max 6:
  11. 1 Procedure heading (including parameter) and ending
  12. 2 Declaration of local variables for three lines AND (at least one) File OPEN in READ mode AND CLOSE
  13. 3 Loop until EOF(ThisFile)
  14. 4 Read line from file and increment Count in a loop
  15. 5 Two separate loops, closing and re-opening the file between loops
  16. 6 Read Count - 3 lines from the file
  17. 7 OUTPUT the last three lines in correct sequence, following reasonable attempt
  18. [3] One mark per point to Max 3:
  19. 1 Change the procedure header to include a (numeric) parameter (as well as the filename)
  20. 2 Replace LineX, Y and Z with an array
  21. 3 Amend shuffle mechanism
  22. 4 Use new parameter to determine first line to output
  23. 5 Output the lines in a loop
  24. Alternative 'two loop' solution to Max 3:
  25. 1 Change the procedure header to include a numeric parameter (as well as the filename)
  26. 2 A loop to count the total number of lines in the file
  27. 3 Ref use of single variable rather than LineX, LineY and LineZ
  28. 4 Close and re-open the file
  29. 5 Use the new parameter value to determine first line to output
  30. 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 →

About this question

Topic
Programming, A-Level Computer Science (syllabus 9618). Structured question, 9 marks.
Source
A-Level Computer Science, May/June 2022 Paper 2 Variant 2, question 4.

Questions and mark schemes are from past examination papers and remain the copyright of the exam board. How Oracle Prep builds its content

Related Computer Science questions

© 2026 Oracle Prep