Skip to main content
A-LevelComputer ScienceProgramming9618/41 · May/June 2025 · Q225 Marks

A program reads data from a text file, splits the data depending on its content and stores the separated data into different files. The text file TheData.txt contains 72 lines of data. Each line of data has an integer number and a string colour that are separated by a comma. For example, the first line in the file is: 10,red The integer is 10 and the string is "red" The file contains six different colours: red, green, blue, orange, yellow, pink.

  1. (a)The function ReadData(): • prompts the user to enter a filename and reads this filename from the user • opens the file and reads each line of data into a 1D array • returns the populated 1D array. The function needs to work for a file that contains an unknown number of lines. Write program code for ReadData()[7]
  2. (b)The procedure SplitData() takes a 1D string array as a parameter with the identifier DataArray The procedure declares six 1D arrays: one array for each colour that appears in the file (red, green, blue, orange, yellow, pink). The procedure accesses each string in DataArray. The data in each string is split into the integer and the colour. The integer is stored in the array that matches the colour. For example, the first string in DataArray has the integer 10 and the colour red, so the integer 10 is stored in the array for the colour red. Write program code for SplitData()[6]
  3. (c)The procedure StoreData(): • takes two parameters: a 1D array DataToStore and a filename • opens the text file with the filename that is passed as a parameter • appends each item of data from DataToStore to a new line in the text file • uses exception handling when opening and writing data to the text file. Write program code for StoreData()[5]
  4. (d)Each of the six colours has a blank text file where the numbers will be stored. The names of these six text files are: • Blue.txt • Green.txt • Orange.txt • Pink.txt • Red.txt • Yellow.txt The procedure SplitData() needs amending to call StoreData() six times, with each of the six colour arrays and the name of the text file that corresponds to that colour. For example, StoreData() will be called with the red array and the file name "Red.txt" Write program code to amend SplitData()[2]
  5. (e)(i)The main program calls ReadData() and then SplitData() Write program code for the main program.[3]
  6. (e)(ii)Test your program. Input the text "TheData.txt" when prompted. Take a screenshot of the output(s) and a screenshot showing the content of the file that stores the red numbers. Copy and paste the screenshot(s) into part 2(e)(ii) in the evidence document.[2]

Mark scheme

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

  1. [7] 1 mark each to max 7
  2. [7] • Function header (and end)
  3. [7] • Prompt to enter filename and reading input
  4. [7] • Opening the file (to read) and closing the file in an appropriate place
  5. [7] • Looping until EOF ...
  6. [7] • ... reading each line in the file ...
  7. [7] • (removing line break and) inserting in array
  8. [7] • Returning populated array
  9. [7] • Exception handling try catch with appropriate output
  10. [6] 1 mark each
  11. [6] • Procedure header (and end) taking (1D array) DataArray (of strings) as a parameter
  12. [6] • Declaration/use of 6 1D arrays (equivalent), one for each colour
  13. [6] • Looping through each line in parameter DataArray ...
  14. [6] • splitting by comma
  15. [6] • Comparing 2nd value/colour to each colour to select array ...
  16. [6] • storing 1st value/integer in correct array
  17. [5] 1 mark each
  18. [5] • Procedure header taking (1D) array and filename as parameters, opening file to append and closing file (in appropriate place)
  19. [5] • Looping through each item in array parameter ...
  20. [5] • writing to the file
  21. [5] • with new line break between each line
  22. [5] • Using exception handling try and catch with suitable output
  23. [2] 1 mark each
  24. [2] • Calling StoreData with one array and filename
  25. [2] • Calling StoreData with remaining 5 arrays and filename
  26. [3] 1 mark each
  27. [3] • Calling ReadData() ...
  28. [3] • and storing/using return value
  29. [3] • Calling SplitData() with returned array as a parameter
  30. [2] 1 mark screenshots showing
  31. [2] • Prompt and input of filename TheData.txt
  32. [2] • Screenshot of data in red file. Filename must be shown in same screenshot as data

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

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