Skip to main content
A-LevelComputer ScienceProgramming9618/21 · May/June 2024 · Q815 Marks

A teacher is designing a program to process pseudocode projects written by her students. Each student project is stored in a text file. The process is split into a number of stages. Each stage performs a different task and creates a new file named as shown: File name Comment MichaelAday_src.txt student project file produced by student Michael Aday MichaelAday_S1.txt file produced by stage 1 MichaelAday_S2.txt file produced by stage 2 The teacher has defined the first program module as follows: Module Description DeleteComment() • called with a parameter of type string representing a line of pseudocode from a student's project file • returns the line after removing any comments Note on comments: A comment starts with two forward slash characters and includes all the remaining characters on the line. The following example shows a string before and after the comment has been removed: Before: IF X2 > 13 THEN //check if limit exceeded After: IF X2 > 13 THEN

  1. (a)Complete the pseudocode for module DeleteComment(). FUNCTION DeleteComment(Line : STRING) RETURNS STRING ENDFUNCTION[8]
  2. (b)A second module is defined: Module Description Stage_1() • called with a parameter of type string representing a student name • creates a new stage 1 file • copies each line from the student's project file to the stage 1 file after removing any comment from each line • does not write blank lines to the stage 1 file • returns the number of lines written to the stage 1 file Write pseudocode for module Stage_1(). Module DeleteComment() must be used in your solution.[7]

Mark scheme

Marking points from the official mark scheme (May/June 2024). The mark or mark type is shown in brackets.

  1. [8] FUNCTION DeleteComment(Line : STRING) RETURNS STRING
  2. DECLARE NewLine, TwoChars : STRING
  3. DECLARE Count, TrimTo : INTEGER
  4. CONSTANT Comment = "//"
  5. NewLine ← Line
  6. TrimTo ← 0
  7. Count ← 1
  8. WHILE Count < LENGTH(Line) AND TrimTo = 0
  9. TwoChars ← MID(Line, Count, 2) // extract 2 chars
  10. IF TwoChars = Comment THEN
  11. TrimTo ← Count
  12. ENDIF
  13. Count ← Count + 1
  14. ENDWHILE
  15. IF TrimTo <> 0 THEN
  16. NewLine ← LEFT(Line, TrimTo - 1)
  17. ENDIF
  18. RETURN NewLine
  19. ENDFUNCTION
  20. Mark as follows:
  21. 1 Loop to length of Line (parameter) // length of Line -1
  22. 2 Terminate loop on first double slash
  23. 3 Attempt to extract one/two characters in a loop
  24. 4 Check for "//" after attempt at extraction in a loop
  25. 5 Record start position of comment // Calculate amount of trim required
  26. 6 Attempt to trim Line from start of comment
  27. 7 Completely correct trimmed Line from start of comment
  28. 8 Return Line after a reasonable overall attempt
  29. [7] FUNCTION Stage_1(StudentName : STRING) RETURNS INTEGER
  30. DECLARE OldFile, NewFile, Line : STRING
  31. DECLARE Count : INTEGER
  32. OldFile ← StudentName & " src.txt"
  33. NewFile ← StudentName & " S1.txt"
  34. OPENFILE OldFile FOR READ
  35. OPENFILE NewFile FOR WRITE
  36. Count ← 0
  37. WHILE NOT EOF(OldFile)
  38. READFILE OldFile, Line
  39. Line ← DeleteComment(Line)
  40. IF LENGTH(Line) <> 0 THEN
  41. WRITEFILE NewFile, Line
  42. Count ← Count + 1
  43. ENDIF
  44. ENDWHILE
  45. CLOSEFILE OldFile
  46. CLOSEFILE NewFile
  47. RETURN Count
  48. ENDFUNCTION
  49. Mark as follows:
  50. 1 Generate filenames condone missing "_"
  51. 2 Open both files in correct modes and subsequently close
  52. 3 Loop to EOF(OldFile)
  53. 4 Read a line from OldFile and execute DeleteComment() in a loop
  54. 5 Skip blank lines after DeleteComment() in a loop
  55. 6 Write Line to stage 1 file and increment Count
  56. 7 Return the number of lines after a reasonable attempt at counting

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, 15 marks.
Source
A-Level Computer Science, May/June 2024 Paper 2 Variant 1, question 8.

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