Skip to main content
A-LevelComputer ScienceProgramming9618/23 · May/June 2023 · Q819 Marks

A computer shop assembles desktop computers, using items bought from several suppliers. A text file Stock.txt contains information about each item. Information for each item is stored as a single line in the Stock.txt file in the format: <ItemNum><SupplierCode><Description> Item information is as follows: | | Format | Comment | |:---|:---|:---| | ItemNum | 4 numeric characters | unique number for each item in the range "0001” to "5999" inclusive | | SupplierCode | 3 alphabetic characters | code to identify the supplier of the item | | Description | a string | a minimum of 12 characters | The file is organised in ascending order of ItemNum and does not contain all possible values in the range. The programmer has defined the first program module as follows: | Module | Description | |:---|:---| | ChangeSupp() | • called with two parameters Code1 and Code2 of type string that represent valid supplier codes | • creates a new file NewStock.txt from the contents of the file Stock.txt where any reference to Code1 is replaced by Code2 | • returns a count of the number of items that have had their supplier code changed |

  1. (a)Write pseudocode for module ChangeSupp().[8]
  2. (b)A new module is required: | Module | Description | |:---|:---| | Report_1() | • takes a parameter of type string that represents a SupplierCode | • searches the Stock.txt file for each line of item information that contains the given SupplierCode | • produces a formatted report of items for the given SupplierCode, for example, for supplier DRG, the output could be: Report for Supplier: DRG Item | Description ---|--- 1234 | USB Printer Cable 3m 1273 | 32GB USB Flash Drive 1350 | Mouse Mat 320 x 240mm Number of items listed: 3 Write pseudocode for module Report_1().[6]
  3. (c)(i)The format of the output from module Report_1() from part (b) is changed. The number of items listed is moved to the top of the report as shown in the example: Report for Supplier: DRG Number of items listed: 3 Item | Description ---|--- 1234 | USB Printer Cable 3m 1273 | 32GB USB Flash Drive 1350 | Mouse Mat 320 x 240mm Explain why this new layout would increase the complexity of the algorithm.[2]
  4. (c)(ii)The algorithm will be modified to produce the report in the new format. The modified algorithm will be implemented so that the file Stock.txt is only read once. Describe the modified algorithm.[3]

Mark scheme

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

  1. [8] FUNCTION ChangeSupp(Code1, Code2 : STRING) RETURNS INTEGER
  2. [8] DECLARE Count : INTEGER
  3. [8] DECLARE ThisLine, ThisCode : STRING
  4. [8] OPENFILE "Stock.txt" FOR READ
  5. [8] OPENFILE "NewStock.txt" FOR WRITE
  6. [8] Count ← 0
  7. [8] WHILE NOT EOF("Stock.txt")
  8. [8] READFILE("Stock.txt ", ThisLine) // brackets optional
  9. [8] ThisCode ← MID(ThisLine, 5, 3)
  10. [8] IF ThisCode = Code1 THEN
  11. [8] ThisLine ← LEFT(ThisLine, 4) & Code2
  12. [8] & RIGHT(ThisLine, LENGTH(ThisLine) - 7)
  13. [8] Count ← Count + 1
  14. [8] ENDIF
  15. [8] WRITEFILE("NewStock.txt", ThisLine) // brackets optional
  16. [8] ENDWHILE
  17. [8] CLOSEFILE "NewStock.txt"
  18. [8] CLOSEFILE "Stock.txt"
  19. [8] RETURN Count
  20. [8] ENDFUNCTION
  21. [8] MP1 Open both files, in correct modes, and subsequently close
  22. [8] MP2 Conditional loop until EOF (“Stock.txt")
  23. [8] MP3 Read a line from Stock.txt AND extract ThisCode in a loop
  24. [8] MP4 Test ThisCode = Code1 AND if true, increment Count (must have been Initialised) in a loop
  25. [8] MP5 Update ThisLine using substring functions and '&' in a loop
  26. [8] MP6 completely correct update of ThisLine in a loop
  27. [8] MP7 Write ThisLine to NewStock.txt in a loop
  28. [8] MP8 Return count after loop
  29. [6] PROCEDURE Report_1(Supp : STRING)
  30. [6] DECLARE Count : INTEGER
  31. [6] DECLARE ThisItemNum, ThisDesc, ThisLine, ThisCode : STRING
  32. [6] Count ← 0
  33. [6] OPENFILE "Stock.txt" FOR READ
  34. [6] OUTPUT "Report for Supplier:" & Supp
  35. [6] OUTPUT "" //Blank line as per example
  36. [6] OUTPUT "Item Description"
  37. [6] OUTPUT "" //Blank line as per example
  38. [6] WHILE NOT EOF("Stock.txt")
  39. [6] READFILE("Stock.txt", ThisLine)
  40. [6] ThisCode ← Mid(ThisLine, 5, 3)
  41. [6] IF ThisCode = Supp THEN
  42. [6] ThisItemNum ← LEFT(ThisLine, 4)
  43. [6] ThisDesc ← RIGHT(ThisLine, LENGTH(ThisLine) - 7)
  44. [6] OUTPUT ThisItem & " " & ThisDesc
  45. [6] Count ← Count + 1
  46. [6] ENDIF
  47. [6] ENDWHILE
  48. [6] CLOSEFILE "Stock.txt"
  49. [6] OUTPUT "" //Blank line as per example
  50. [6] OUTPUT "Number of items listed: ", Count
  51. [6] ENDPROCEDURE
  52. [6] MP1 Output report header (blank lines optional) – Must contain the parameter code
  53. [6] MP2 Conditional loop until EOF("Stock.txt")
  54. [6] MP3 Read a line from Stock.txt AND extract SupplierCode in a loop
  55. [6] MP4 Test if SupplierCode = Supp then increment count (must have been Initialised)
  56. [6] MP5 Extract AND output item and description in a loop
  57. [6] MP6 Output the final line with count
  58. [2] Max 2 marks
  59. [2] MP1 Must 'calculate' the count before any item + description output / after the file is read once
  60. [2] MP2 Lines to be output have to be stored ...
  61. [2] MP3 The file has to be read twice
  62. [3] One mark per point:
  63. [3] MP1 Loop through the file calculating the count
  64. [3] MP2 Save 'selected' items in an array
  65. [3] MP3 (After all lines have been read), output the header lines / count
  66. [3] MP4 Loop through the array to output each array element

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, 19 marks.
Source
A-Level Computer Science, May/June 2023 Paper 2 Variant 3, 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