Past-paper question · 2025 May-June · Paper 42 · Q2(e)

Question 2(e) 2025 · May-June · Paper 42 · 16 marks

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

Official answer for Question 2

Part (e)

Question 1

mark each to max 5

Question 5

  • Procedure header (and end where appropriate), opening and closing file HashData.txt
  • Reading in all lines of data …
  • … splitting each line by commas
  • Creating record with correct values with each line read in from file
  • Calling InsertIntoHash() with each record they have created
  • Exception handling for opening and reading from file with appropriate catch and output.
✓
Example program code:
✓
Java
✓
public static void CreateHashTable(){
✓
String[] Data = new String[3];
✓
Integer NewKey;
✓
Integer NewItem1;
✓
Integer NewItem2;
✓
try{
✓
FileReader File = new FileReader("HashData.txt");
✓
try{
✓
BufferedReader Reader = new BufferedReader(File);
✓
String Line= Reader.readLine();
✓
while (Line != null){
✓
Line = Line.replace("\n","");
✓
Data = Line.split(",");
✓
NewKey = Integer.parseInt(Data[0]);
✓
NewItem1 = Integer.parseInt(Data[1]);
✓
NewItem2 = Integer.parseInt(Data[2]);
✓
NewRecord ReadData = new NewRecord(NewKey, NewItem1, NewItem2);
✓
InsertIntoHash(ReadData);
✓
Line= Reader.readLine();
✓
}
✓
Reader.close();
✓
}catch(IOException ex){}
✓
}catch(FileNotFoundException e){System.out.println("File not found");}
✓
}
✓
9618/42
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2025
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks
✓
VB.NET
✓
Sub CreateHashTable()
✓
Dim Line As String
✓
Dim Data(3) As String
✓
Dim TheRecord As NewRecord
✓
Try
✓
Dim FileReader As New System.IO.StreamReader("HashData.txt")
✓
While Not FileReader.EndOfStream
✓
Line = FileReader.ReadLine()
✓
Data = Split(Line, ",")
✓
TheRecord.Key = Integer.Parse(Data(0))
✓
TheRecord.Item1 = Integer.Parse(Data(1))
✓
TheRecord.Item2 = Integer.Parse(Data(2))
✓
InsertIntoHash(TheRecord)
✓
End While
✓
FileReader.Close()
✓
Catch ex As Exception
✓
Console.WriteLine("Cannot open file")
✓
End Try
✓
End Sub
✓
Python
✓
def CreateHashTable():
✓
global HashTable
✓
global Spare
✓
try:
✓
File = open("HashData.txt")
✓
for Line in File:
✓
Data = Line.strip()
✓
Data = Line.split(",")
✓
InsertIntoHash(Record(int(Data[0]), int(Data[1]), int(Data[2])))
✓
File.close()
✓
except:
✓
print("Cannot open file")
✓
9618/42
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2025
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9618_s25_ms_42.pdf →

Show text version of question

Question 2

Part (e)

Question 2

The total is initialised to the first value in the stack: 10

total = 10

The next two values are: + 3

total = 10 + 3 = 13

The next two values are: – 2

total = 13 – 2 = 11

The final total is 11 and this is returned.

Write program code for the function Calculate() to:

  • take each value from the stack
  • calculate and return the final total.

Save your program.

Copy and paste the program code into part 1(e) in the evidence document.

[7]

Question 5

Part (f)

(i)

Write program code to extend the main program to:

  • take a filename as input from the user
  • call ReadData() with the input filename
  • call Calculate()
  • output the final total.

Save your program.

Copy and paste the program code into part 1(f)(i) in the evidence document.

[2]

(ii)

Test your program twice with the file names:

StackData.txt SecondStack.txt

Take a screenshot of the output(s).

Save your program.

Copy and paste the screenshot into part 1(f)(ii) in the evidence document.

[2]

Question 6

2 A program stores data in a 1D array of records, HashTable. The array has space for 200 records. Each data item is stored in a specific index of the array that is calculated using an algorithm. The index is calculated from the key field using the formula: Key MOD 200

If two key fields generate the same index, there is a collision. Any records that have a collision are stored in a second array, Spare. This array has space for 100 records. When a collision is detected, the record is stored in the next free space in Spare.

Part (e)

The text file HashData.txt stores up to 200 rows of data to be stored into the hash table.

Each row contains three integer numbers separated by commas.

The first number is the key field, the second number is item 1 and the third number is item 2.

For example:

The first row in the text file contains: 646, 12, 568

The key field is 646, item 1 is 12 and item 2 is 568

The procedure CreateHashTable():

  • opens the file HashData.txt
  • creates a record for each row of data in the file
  • calls InsertIntoHash() with each record.

Write program code for CreateHashTable()

Save your program.

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

[5]

Question 8

Topic relevance

Why this question appears here

71% assigned-topic match · Data types and structures › Data types and records

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_42.pdf

Keep practising this topic