Question 2(b) 2025 · May-June · Paper 41 · 6 marks
Reveal official mark-scheme answer




Official answer for Question 2
Part (b)
Question 1
mark each
Question 6
- Procedure header (and end) taking (1D array) DataArray (of strings) as a parameter
- Declaration/use of 6 1D arrays (equivalent), one for each colour
- Looping through each line in parameter DataArray …
- … splitting by comma
- Comparing 2nd value/colour to each colour to select array …
- … storing 1st value/integer in correct array
Show text version of question
Question 2
Part (b)
Question 2
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.
Part (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()
Save your program.
Copy and paste the program code into part 2(b) in the evidence document.
Question 5
Why this question appears here
76% assigned-topic match · Data types and structures › Arrays
Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.
Permanent source page: Educate A Change · From 9618_s25_qp_41.pdf
