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

Question 2(c) 2025 · May-June · Paper 42 · 13 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 answer for Question 2

Part (c)

Question 1

mark each

Question 2

  • Function header (and close where appropriate), taking one (integer) parameter and returning the calculated value
  • Calculation of parameter MOD 200
✓
Example program code:
✓
Java
✓
public static Integer CalculateHash(Integer TheKey){
✓
return(TheKey % 200);
✓
}
✓
VB.NET
✓
Function CalculateHash(Key)
✓
Return Key Mod 200
✓
End Function
✓
Python
✓
def CalculateHash(Key):
✓
return Key % 200
✓
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 (c)

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

The hash value is calculated from the key field using the formula: Key MOD 200

The function CalculateHash() takes a key field as a parameter and calculates and returns the hash value for the key field.

Write program code for CalculateHash()

Save your program.

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

[2]
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_42.pdf

Keep practising this topic