Past-paper question · 2025 May-June · Paper 41 · Q2(c)

Question 2(c) 2025 · May-June · Paper 41 · 5 marks

Original past-paper question for 2(C)
Original past-paper question for 2(C)
Reveal official mark-scheme answer Official mark-scheme answer for 2(C)Official mark-scheme answer for 2(C)

Official answer for Question 2

Part (c)

Question 1

mark each

Question 5

  • Procedure header taking (1D) array and filename as parameters, opening file to append and closing file (in appropriate
✓
place)
  • Looping through each item in array parameter …
  • … writing to the file
  • … with new line break between each line
  • Using exception handling try and catch with suitable output
✓
Example program code:
✓
Python
✓
def StoreData(DataToStore, FileName):
✓
try:
✓
File = open(FileName,"a+")
✓
for Item in DataToStore:
✓
File.write(Item)
✓
File.write("\n")
✓
File.close()
✓
except:
✓
print("Cannot create or write to file")
✓
VB.NET
✓
Sub StoreData(DataToStore(), FileName)
✓
Dim FileWriter As IO.StreamWriter = New IO.StreamWriter(FileName, False)
✓
Dim x As Integer = 0
✓
Try
✓
While DataToStore(x) IsNot Nothing
✓
FileWriter.WriteLine(DataToStore(x))
✓
x = x + 1
✓
End While
✓
FileWriter.Close()
✓
Catch ex As Exception
✓
Console.WriteLine("Cannot open or write to file")
✓
End Try
✓
End Sub
✓
9618/41
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2025
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks
✓
Java
✓
public static void StoreData(String[] DataToStore, String FileName){
✓
File TheFile = new File(FileName);
✓
try{
✓
FileWriter FW = new FileWriter(TheFile, true);
✓
Integer X = 0;
✓
while(DataToStore[X] != null){
✓
FW.write(DataToStore[X]);
✓
X++;
✓
FW.write("\n");
✓
}
✓
FW.close();
✓
}catch(IOException ex){
✓
System.out.println("Cannot open or write to file");
✓
}
✓
}
✓
9618/41
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2025
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9618_s25_ms_41.pdf →

Show text version of question

Question 2

Part (c)

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

Save your program.

Copy and paste the program code into part 2(c) in the evidence document.

[5]
Topic relevance

Why this question appears here

71% assigned-topic match · Programming › Structured programming

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

Keep practising this topic