Question 2(d) 2025 · May-June · Paper 42 · 17 marks
Reveal official mark-scheme answer


Official answer for Question 2
Part (d)
Question 1
mark each:
Question 6
- Procedure header (and end where appropriate) taking one record as a parameter
- Calling CalculateHash() with key from parameter record and storing/using return value
- Checking if HashTable at return value from CalculateHash is empty record …
- … if it is empty, store parameter in location
- … otherwise, locating next free space in Spare …
- … and storing in that index only (i.e. not in all other free spaces)
Show text version of question
Question 2
Part (d)
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.
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.
(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.
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 (d)
The procedure InsertIntoHash():
- takes a record of type NewRecord as a parameter
- uses CalculateHash() to calculate the hash value for the key field in the record
- checks if the hash value index in HashTable currently stores an empty record
○ if the index stores an empty record, store the parameter in this index ○ if the index does not store an empty record, store the parameter in Spare
You can assume there will always be enough space in Spare to store any collisions.
Write program code for InsertIntoHash()
Save your program.
Copy and paste the program code into part 2(d) in the evidence document.
Why this question appears here
60% 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_42.pdf
