Cambridge A Level Computer Science 9618 — 2025 Oct/Nov Paper 4 · Variant 1
9618/41/O/N/25 · 3 questions · 75 marks · ≈84 min
The question paper and its mark scheme, free to read here and free to download. This is Cambridge’s own paper, exactly as it was sat.
Question paper12 pages












Mark scheme36 pages
Answers below. Sit the paper first if you are practising.




































Questions as text
Q1 · A program stores integers in a stack
1 A program stores integers in a stack. The stack is represented as a 1D array of 30 elements with the identifier Stack The global pointer TopOfStack stores the index of the last element inserted into the stack. TopOfStack is initialised to –1 (a) Write program code to declare Stack, initialise each element in the array with a null value and declare and initialise TopOfStack Save your program as Question1_N25. Copy and paste the program code into part 1(a) in the evidence document. [2] (b) The function Push() takes an integer parameter. If the stack is full, the function returns FALSE. If the stack is not full, the parameter is inserted into the stack, the pointer is updated and the function returns TRUE Write the program code for Push() Save your program. Copy and paste the program code into part 1(b) in the evidence document. [4] (c) The function Pop() returns the next integer in the stack and updates the pointer as appropriate. If there is no data in the stack, the function returns the value –999 Write program code for Pop() Save your program. Copy and paste the program code into part 1(c) in the evidence document. [4] (d) The main program generates 40 random integers between 0 and 1000 (inclusive) and attempts to insert each one into the stack using the appropriate function. If the return value from the function call indicates the stack is full, no more integers are generated and "Stack full" is output. Write program code for the main program. Save your program. Copy and paste the program code into part 1(d) in the evidence document. [4] (e) The procedure FindValues(): • pops each integer from the stack until the stack is empty • finds and outputs the largest number that was in the stack in an appropriate message • finds and outputs the smallest number that was in the stack in an appropriate message. Write program code for FindValues() Save your program. Copy and paste the program code into part 1(e) in the evidence document. [4] (f) (i) Extend the main program to call FindValues() Save your program. Copy and paste the program code into part 1(f)(i) in the evidence document. [1] (ii) Test your program. Take a screenshot of the output(s). Save your program. Copy and paste the screenshot(s) into part 1(f)(ii) in the evidence document. [1]
Mark scheme: Question Answer Marks 1(a) 1 mark each 2 • (Global) 1D array initialised with 30 null values • (Global) TopofStack initialised with –1 Example program code Java public static Integer[] Stack = new Integer[30]; public static Integer TopOfStack; public static void main(String args[]){ for(Integer X = 0; X < 30; X++){ Stack[X] = null; } TopOfStack = -1; } VB.NET Dim Stack(29) As Integer Dim TopOfStack As Integer Sub Main(args As String()) For x = 0 To 29 Stack(x) = Nothing Next TopOfStack = -1 End Sub Python Stack = [None for x in range(30)] TopOfStack = -1 1(b) 1 mark each 4 • Function header (and end) taking one parameter, returning Boolean in all instances • Checking if stack is full (TopOfStack = 29) and, if it is, returning FALSE • Incrementing TopofStack • (Otherwise) Storing parameter in incremented TopOfStack position and returning TRUE Example program code Java public static Boolean Push(Integer DataToPush){ if(TopOfStack < 29){ TopOfStack++; Stack[TopOfStack] = DataToPush; return true; } return false; } VB.NET Function Push(DataToPush) If TopOfStack < 29 Then TopOfStack = TopOfStack + 1 Stack(TopOfStack) = DataToPush Return True End If Return False End Function 1(b) Python def Push(DataToPush): global Stack global TopOfStack if TopOfStack < 29: TopOfStack = TopOfStack + 1 Stack[TopOfStack] = DataToPush return True else: return False 1(c) 1 mark each 4 • Function header (and end) returning integer in all cases • Checking if stack empty (TopofStack = –1) and returning -999 when true • (Otherwise) Accessing and returning item at TopOfStack (before it's decremented) • Decrementing TopofStack Example program code Java public static Integer Pop(){ Integer DataReturn; if(TopOfStack == -1){ return -999; } DataReturn = Stack[TopOfStack]; TopOfStack--; return DataReturn; } VB.NET Function Pop() If TopOfStack = -1 Then Return -999 Else Dim DataReturn As Integer = Stack(TopOfStack) TopOfStack = TopOfStack - 1 Return DataReturn End If End Function 1(c) Python def Pop(): global Stack global TopOfStack if TopOfStack == -1: return -999 else: DataReturn = Stack[TopOfStack] TopOfStack = TopOfStack - 1 return DataReturn 1(d) 1 mark each 4 • Looping 40 times • Generating random number between 0 and 1000 inclusive inside the loop • Calling Push() with each random number and storing/using return value … … if return value is FALSE output Stack full and breaking out of loop Example program code Java for(Integer X = 0; X < 40; X++){ Pushed = Push(RandomNumber.nextInt(1001)); if(Pushed == false){ System.out.println("Stack full"); X = 40; } } VB.NET For x = 0 To 39 Pushed = Push(RandomNumber.Next(0, 1000)) If Pushed = False Then Console.WriteLine("Stack full") x = 40 End If Next Python for x in range(40): Pushed = Push(random.randint(0,1000)) if Pushed == False: print("Stack full") break 1(e) 1 mark each 4 • Procedure header (and end) and output of highest and lowest include appropriate messages • Calls Pop() until there are no items left in stack (return value = –999 // TopOfStack = -1) and storing/using return values • Finds and outputs highest value from returned values • Finds and outputs lowest value from returned values Example program code Java public static void FindValues(){ Integer Highest; Integer Lowest; Highest = Pop(); Lowest = Highest; Integer ReturnValue = Highest; while(ReturnValue != -999){ if(ReturnValue > Highest){ Highest = ReturnValue; } if(ReturnValue < Lowest){ Lowest = ReturnValue; } ReturnValue = Pop(); } System.out.println("The highest value is " + Highest + " and the lowest value is " + Lowest); } 1(e) VB.NET Sub FindValues() Dim Highest, Lowest As Integer Highest = Pop() Lowest = Highest Dim ReturnValue As Integer = Highest While ReturnValue <> -999 If ReturnValue > Highest Then Highest = ReturnValue End If If ReturnValue < Lowest Then Lowest = ReturnValue End If ReturnValue = Pop() End While Console.WriteLine("The highest value is " & Highest & " and the lowest value is " & Lowest) End Sub Python def FindValues(): Highest = Pop() Lowest = Highest ReturnValue = Lowest while(ReturnValue != -999): if ReturnValue > Highest: Highest = ReturnValue if ReturnValue < Lowest: Lowest = ReturnValue ReturnValue = Pop() print("The highest value is", Highest, "and the lowest value is", Lowest) 1(f)(i) 1 mark for calling FindValues() 1 Example program code Java FindValues(); VB.NET FindValues() Python FindValues() 1(f)(ii) 1 mark for a screenshot of output showing 1 Stack full output once Lowest value output in an appropriate message Highest value output in an appropriate message Lowest and Highest must be 0–1000 inclusive
Q2 · A program stores data about trains and train stations using Object-Oriented Programming…
2 A program stores data about trains and train stations using Object-Oriented Programming (OOP). The class Train stores the data about the trains: Train TrainIDNumber : String stores the train ID number Route : Integer stores the route number the train is travelling Constructor() initialises TrainIDNumber and Route to the parameter values GetTrainIDNumber() returns the train ID number GetRoute() returns the route number the train is travelling (a) (i) Write program code to declare the class Train and its constructor. Do not declare the other methods. All attributes should be private. Use your programming language appropriate constructor. If you are writing in Python, include attribute declarations using comments. Save your program as Question2_N25. Copy and paste the program code into part 2(a)(i) in the evidence document. [4] (ii) The methods GetTrainIDNumber() and GetRoute() return the appropriate attribute. Write program code for GetTrainIDNumber() and GetRoute() Save your program. Copy and paste the program code into part 2(a)(ii) in the evidence document. [3] (b) The program is tested with four trains: train ID number route 12ADV 134 33ART 20 9FKF 3 21VBC 24 Write program code to declare an instance of Train for each of the four trains. Save your program. Copy and paste the program code into part 2(b) in the evidence document. [2] (c) The class Station stores the data about the stations: Station StationID : String stores the station ID NumberPlatforms : Integer stores the number of platforms at the station Trains[0:9] : Train stores the trains currently at the station platforms NumberTrains : Integer stores the number of trains currently at the station platforms Constructor() initialises StationID and NumberPlatforms to the parameter values, initialises Trains to an empty array and NumberTrains to 0 GetTrains() returns a string containing data about the trains currently at the station platforms AddTrain() takes a Train parameter and stores it if there is a platform available; each platform can only have one train (i) Write program code to declare the class Station and its constructor. Do not declare the other methods. All attributes should be private. Use your programming language appropriate constructor. If you are writing in Python, include attribute declarations using comments. Save your program. Copy and paste the program code into part 2(c)(i) in the evidence document. [3] (ii) The method AddTrain() takes a Train parameter. The method compares the attributes NumberTrains and NumberPlatforms to identify if there is a platform available (a platform currently with no train). The method returns FALSE if there are no platforms available. If there is a platform available, the method: • stores the Train parameter in the array Trains • updates the appropriate attribute(s) • returns TRUE Write program code for AddTrain() Save your program. Copy and paste the program code into part 2(c)(ii) in the evidence document. [4] (iii) The method GetTrains() returns the string "There are no trains" if there are no trains at the station platforms. If there are trains at the station platforms, the method returns a string in the format: The trains at station <StationID> are: <TrainIDNumber> on route number <Route> The line <TrainIDNumber> on route number <Route> is repeated for each train at the station platforms. For example: If the station with the station ID "NT1" has two trains with the train ID numbers "48RTG", "6UFH", the method will produce this output: The trains at station NT1 are: 48RTG on route number 43 6UFH on route number 12 Write program code for GetTrains() Save your program. Copy and paste the program code into part 2(c)(iii) in the evidence document. [6] (d) The program is tested with two stations: number of station ID platforms STH 2 NTH 1 (i) Write program code to amend the main program to declare an instance of Station for each of the two stations. Save your program. Copy and paste the program code into part 2(d)(i) in the evidence document. [2] (ii) The four trains attempt to stop at the following stations in the order given: • Train 12ADV, station STH • Train 33ART, station STH • Train 9FKF, station STH • Train 21VBC, station NTH Write program code to amend the main program to: • add each train to the given station using AddTrain() • output "Station is full" for any train where the return value indicates it cannot be added to the station • output the trains at each station using GetTrains() Save your program. Copy and paste the program code into part 2(d)(ii) in the evidence document. [4] (iii) Test your program. Take a screenshot of the output(s). Save your program. Copy and paste the screenshot(s) into part 2(d)(iii) in the evidence document. [2]
Mark scheme: 2(a)(i) 1 mark each 4 • Class header (and end) • Declaration of 2 private attributes with correct data types • Constructor header (and end) within class with 2 parameters … • … assigning parameters to attributes Example program code Java class Train{ private String Number; private Integer Route; public Train(String pNumber, Integer pRoute){ Number = pNumber; Route = pRoute; }} VB.NET Class Train Private TrainIDNumber As String Private Route As Integer Sub New(pNumber, pRoute) TrainIDNumber = pNumber Route = pRoute End Sub End Class Python class Train(): def __init__(self, pNumber, pRoute): self.__TrainIDNumber = pNumber #string self.__Route = pRoute #integer 2(a)(ii) 1 mark each 3 • One get method header (and end) with no parameter … • … returning correct attribute • Second correct get method Example program code Java public String GetTrainNumber(){ return Number; } public Integer GetRoute(){ return Route; } VB.NET Function GetTrainIDNumber() Return TrainIDNumber End Function Function GetRoute() Return Route End Function Python def GetTrainIDNumber(self): return self.__TrainIDNumber def GetRoute(self): return self.__Route 2(b) 1 mark each 2 • One instance of train with correct arguments and stored in a variable/structure • Remaining three instances correct Example program code Java Train FirstTrain = new Train("12ADV", 134); Train SecondTrain = new Train("33ART", 20); Train ThirdTrain = new Train("9FKF", 3); Train FourthTrain = new Train("21VBC", 24) VB.NET Dim FirstTrain As Train = New Train("12ADV", 134) Dim SecondTrain As Train = New Train("33ART", 20) Dim ThirdTrain As Train = New Train("9FKF", 3) Dim FourthTrain As Train = New Train("21VBC", 24) Python FirstTrain = Train("12ADV",134) SecondTrain = Train("33ART",20) ThirdTrain = Train("9FKF",3) FourthTrain = Train("21VBC",24) 2(c)(i) 1 mark each 3 • Class header (and end) with four private attributes with appropriate data types • Constructor header (and end) within class taking 2 parameters … • … assigning parameters to attributes, initialising NumberTrains to 0, initialising Trains to an empty array Example program code Java class Station{ private String StationID; private Integer NumberPlatforms; private Train[] Trains = new Train[10]; private Integer NumberTrains; public Station(String pID, Integer pNumberOfPlatforms){ StationID = pID; NumberPlatforms = pNumberOfPlatforms; NumberTrains = 0; }} VB.NET Class Station Private StationID As String Private NumberPlatforms As Integer Private Trains(9) As Train Private NumberTrains As Integer Sub New(pID, pNumberOfPlatforms) StationID = pID NumberPlatforms = pNumberOfPlatforms NumberTrains = 0 End Sub End Class 2(c)(i) Python class Station(): def __init__(self, pID, pNumberOfPlatforms): self.__StationID = pID #string self.__NumberPlatforms = pNumberOfPlatforms #integer self.__Trains = [] #train 10 elements self.__NumberTrains = 0 #integer 2(c)(ii) 1 mark each 4 • Method header (and close) taking one Train parameter • Checking if all platforms are full and returning FALSE • (Otherwise) Storing parameter in array Trains … • … incrementing NumberTrains and returning True Example program code Java public Boolean AddTrain(Train NewTrain){ if(NumberTrains >= NumberPlatforms){ return false; } Trains[NumberTrains] = NewTrain; NumberTrains++; return true; } VB.NET Function AddTrain(NewTrain) If NumberTrains >= NumberPlatforms Then Return False End If Trains(NumberTrains) = NewTrain NumberTrains = NumberTrains + 1 Return True End Function Python def AddTrain(self, NewTrain): if self.__NumberTrains >= self.__NumberPlatforms: return False else: self.__Trains.append(NewTrain) self.__NumberTrains += 1 return True 2(c)(iii) 1 mark each 6 • Method header (and close) and returning a string in all cases • Checking if no trains and returning "There are no trains" • (Otherwise) Looping through each train in the station … • … accessing train ID number and route number using get methods • … creating a string with ID number and route number for each train • … returning correctly formatted string Example program code Java public String GetTrains(){ if(NumberTrains == 0){ return "There are no trains"; } String OutputLine = "The trains at station " + StationID + " are: \n"; for(Integer x =0; x < NumberTrains; x++){ OutputLine = OutputLine + Trains[x].GetTrainNumber() + " on route number " + Trains[x].GetRoute() + "\n"; } return OutputLine; } VB.NET Function GetTrains() If NumberTrains = 0 Then Return "There are no trains" End If Dim OutputLine As String = "The trains at station " & StationID & " are:" & vbNewLine For x = 0 To NumberTrains - 1 OutputLine = OutputLine & Trains(x). GetTrainIDNumber() & " on route number " & Trains(x).GetRoute() & vbNewLine Next Return OutputLine End Function 2(c)(iii) Python def GetTrains(self): if self.__NumberTrains == 0: return "There are no trains" OutputLine = "The trains at station " + self.__StationID + " are: \n" for x in range(self.__NumberTrains): OutputLine = OutputLine + self.__Trains[x]. GetTrainIDNumber() + " on route number " + str(self.__Trains[x].GetRoute()) + "\n" return OutputLine 2(d)(i) 1 mark each 2 • One instance of Station created with correct arguments and stored • Second correct instance and stored Example program code Java Station SouthStation = new Station("STH", 2); Station NorthStation = new Station("NTH", 1); VB.NET Dim SouthStation As Station = New Station("STH", 2) Dim NorthStation As Station = New Station("NTH", 1) Python SouthStation = Station("STH",2) NorthStation = Station("NTH",1) 2(d)(ii) 1 mark each 4 • Calling AddTrain for 3 correct trains for station STH once • Calling AddTrain for 1 correct train for station NTH once • Outputting "Station is full" if any return value is FALSE • Calling GetTrains() for both stations and outputting return values Example program code Java Boolean ReturnValue = SouthStation.AddTrain(FirstTrain); if(ReturnValue == false) { System.out.println("Station is full"); } ReturnValue = SouthStation.AddTrain(SecondTrain); if(ReturnValue == false) { System.out.println("Station is full"); } ReturnValue = SouthStation.AddTrain(ThirdTrain); if(ReturnValue == false) { System.out.println("Station is full"); } ReturnValue = NorthStation.AddTrain(FourthTrain); if(ReturnValue == false) { System.out.println("Station is full"); } System.out.println(SouthStation.GetTrains()); System.out.println(NorthStation.GetTrains()); VB.NET Dim ReturnValue As Boolean = SouthStation.AddTrain(FirstTrain) If ReturnValue = False Then Console.WriteLine("Station is full") End If ReturnValue = SouthStation.AddTrain(SecondTrain) If ReturnValue = False Then 2(d)(ii) Console.WriteLine("Station is full") End If ReturnValue = SouthStation.AddTrain(ThirdTrain) If ReturnValue = False Then Console.WriteLine("Station is full") End If ReturnValue = NorthStation.AddTrain(FourthTrain) If ReturnValue = False Then Console.WriteLine("Station is full") End If Console.WriteLine(SouthStation.GetTrains()) Console.WriteLine(NorthStation.GetTrains()) Python ReturnValue = SouthStation.AddTrain(FirstTrain) if ReturnValue == False: print("Station is full") ReturnValue = SouthStation.AddTrain(SecondTrain) if ReturnValue == False: print("Station is full") ReturnValue = SouthStation.AddTrain(ThirdTrain) if ReturnValue == False: print("Station is full") ReturnValue = NorthStation.AddTrain(FourthTrain) if ReturnValue == False: print("Station is full") print(SouthStation.GetTrains()) print(NorthStation.GetTrains()) 2(d)(iii) 1 mark each, screenshot(s) showing: 2 • One output of "Station is full" • Output of correct data for both stations (in correct format) e.g.
Q3 · A program stores records in the 2D array HashTable
3 A program stores records in the 2D array HashTable. Each record is stored at a specific index of the array that is calculated using a hashing algorithm with the record’s key field. The array has 100 × 10 elements. The hashing algorithm uses the key to generate an index between 0 and 99 (inclusive). If two key fields generate the same index, there is a collision. Any records that have a collision are stored in the next space in the same index. For example: In this table two record keys generated the same hash value of 1. Four record keys generated the same hash value of 3. Index 0 1 2 3 4 5 … 9 0 record 1 record record 2 3 record record record record 4 … 99 The program uses Object-Oriented Programming (OOP). (a) The class Record stores data about the records: Record Key : Integer stores the integer key field for the data Data : String stores the string data Constructor() initialises Key and Data to its parameter values The attributes Key and Data are public. Write program code to declare the class Record and its constructor. Use your programming language appropriate constructor. Save your program as Question3_N25. Copy and paste the program code into part 3(a) in the evidence document. [2] (b) The procedure InitialiseHashTable() initialises each element in the array to an empty or null record. Write program code to declare the global 2D array HashTable and the procedure InitialiseHashTable() Save your program. Copy and paste the program code into part 3(b) in the evidence document. [2] (c) The function Hash(): • takes an integer key field as a parameter • calculates and returns the hash value of the key field. The hash value is the result from the formula: key MOD 100 Write program code for Hash() Save your program. Copy and paste the program code into part 3(c) in the evidence document. [2] (d) The procedure InsertData(): • takes an object of type Record as a parameter • calculates the hash value for the parameter using the appropriate function • stores the parameter in the correct position in HashTable You can assume there will be no more than 10 objects that generate the same hash value. Write program code for InsertData() Save your program. Copy and paste the program code into part 3(d) in the evidence document. [4] (e) The file "HashTableData.txt" stores 200 key values and string data items in the format: key,string For example, the first row in the text file is: 528,permission The key is 528 and the string data is "permission" The procedure ReadData(): • opens the text file and reads each line • splits each line into the key and data • calls InsertData() with an object containing each key and matching data. Write program code for ReadData() Save your program. Copy and paste the program code into part 3(e) in the evidence document. [5] (f) The function GetRecord(): • takes an integer key field as a parameter • calculates the hash value for the key field using the appropriate function • searches the hash table for the record with the matching key field • returns the data for the record if the record is found • returns "Not found" if the record is not found. Write program code for GetRecord() Save your program. Copy and paste the program code into part 3(f) in the evidence document. [5]
Mark scheme: 3(a) 1 mark each 2 • Class header (and end) and constructor header (and end) in class • Constructor takes two parameters and stores each in attributes Example program code Java class Record{ public Integer Key; public String Data; public Record(Integer pKey, String pData){ Key = pKey; Data = pData; } } VB.NET Class Record Dim Key As Integer Dim Data As String Sub New(pKey, pData) Key = pKey Data = pData End Sub End Class Python class Record: def __init__(self, pKey, pData): self.Key = pKey #integer self.Data = pData #string 3(b) 1 mark each 2 • 2D array of 100 10 elements of type Record • Procedure InitialiseHashTable() header (and end) and initialises each element in the 2D array to an empty/null record in procedure Example program code Java public static Record[][] HashTable = new Record[100][10]; public static void InitialiseHashTable(){ Record EmptyRecord = new Record(-1,"-1"); for(Integer X = 0; X < 100; X++){ for(Integer Y = 0; Y < 10; Y++){ HashTable[X][Y] = EmptyRecord; } } } VB.NET Dim HashTable(99, 9) As Record Sub InitialiseHashTable() Dim EmptyRecord As Record = New Record(-1, "") For X = 0 To 99 For Y = 0 To 9 HashTable(X, Y) = EmptyRecord Next Next End Sub Python HashTable = [] def InitialiseHashTable(): global HashTable HashTable = [[Record(-1,"")]*10 for i in range(100)] 3(c) 1 mark each 2 • Function header (and end) taking one parameter and returning calculated hash • …. hash calculated correctly from parameter Example program code Java public static Integer Hash(Integer TheKey){ return(TheKey % 100); } VB.NET Function Hash(Key) Return Key Mod 100 End Function Python def Hash(Key): return Key % 100 3(d) 1 mark each 4 • Procedure header (and end) taking one Record parameter • Calling Hash() using key from parameter and storing/using return value • Accessing HashTable[return][0] and storing parameter if no collision … … if collision: iterating through 2nd dimension to find empty index and store parameter in that position Example program code Java public static void InsertData(Record RecordData){ Integer HashValue = Hash(RecordData.Key); for(Integer X = 0; X < 10; X++){ if(HashTable[HashValue][X].Key.equals(-1)){ HashTable[HashValue][X] = RecordData; X = 10; } } } VB.NET Function InsertData(RecordData) Dim HashValue As Integer = Hash(RecordData.Key) For X = 0 To 9 If HashTable(HashValue, X).Key = -1 Then HashTable(HashValue, X) = RecordData X= 10 End If Next X End Function 3(d) Python def InsertData(RecordData): global HashTable HashValue = Hash(RecordData.Key) for X in range(0, 10): if HashTable[HashValue][X].Key == -1: HashTable[HashValue][X] = RecordData 3(e) 1 mark each to max 5 5 • Procedure header (and end), opening file and closing file (in appropriate place) • Iterating through each line in file // reading each line in from file • Splitting each line read in by comma … • … creating Record object with each key and data as arguments … • … calling InsertData() with each object • Try, catch with appropriate output and all file access within try Example program code Java public static void ReadData(){ String[] Data = new String[3]; Integer NewKey; Integer NewItem1; Integer NewItem2; Record TheRecord; try{ FileReader File = new FileReader("HashTableData.txt"); try{ BufferedReader Reader = new BufferedReader(File); String Line= Reader.readLine(); while (Line != null){ Line = Line.replace("\n",""); Data = Line.split(","); TheRecord = new Record(Integer.parseInt(Data[0]), Data[1]); InsertData(TheRecord); Line= Reader.readLine(); } Reader.close(); }catch(IOException ex){} }catch(FileNotFoundException e){System.out.println("File not found");} } 3(e) VB.NET Sub ReadData() Dim Line As String Dim Data(3) As String Dim TheRecord As Record Dim FileReader As New System.IO.StreamReader("HashTableData.txt") While Not FileReader.EndOfStream Line = FileReader.ReadLine() Data = Split(Line, ",") TheRecord = New Record(Integer.Parse(Data(0)), Data(1)) InsertData(TheRecord) End While FileReader.Close() End Sub Python def ReadData(): global HashTable File = open("HashTableData.txt") for Line in File: Data = Line.strip() Data = Line.split(",") InsertData(Record(int(Data[0]), Data[1])) File.close() 3(f) 1 mark each 5 • Function header (and end) taking one parameter and returning string in all cases • Calling Hash() with parameter and storing/using return value • Iterating through 2nd dimension at HashTable[return value] and comparison to parameter … • … returning data if found/equal • … returning "Not found" if not found by the end of the dimension Example program code Java public static String GetRecord(Integer Key){ Integer HashValue = Hash(Key); for(Integer X = 0; X < 10; X++){ if(HashTable[HashValue][X].Key.equals(Key)){ return(HashTable[HashValue][X].Data); } } return "Not found"; } VB.NET Function GetRecord(Key) Dim HashValue As Integer = Hash(Key) For X = 0 To 9 If HashTable(HashValue, X).Key = Key Then Return HashTable(HashValue, X).Data End If Next X Return "Not found" End Function 3(f) Python def GetRecord(Key): global HashTable HashValue = Hash(Key) for X in range(0, 10): if HashTable[HashValue][X].Key == Key: return HashTable[HashValue][X].Data return "Not found" 3(g)(i) 1 mark each 3 • Calling InitialiseHashTable() then ReadData() • Taking five (integer) inputs • Calling GetRecord() with each input and outputting return value Example program code Java public static void main(String args[]){ InitialiseHashTable(); ReadData(); Scanner scanner = new Scanner(System.in); for(Integer X = 0; X < 5; X++){ System.out.println("Enter key field"); System.out.println(GetRecord(Integer.parseInt(scanner.nextLine()))); } } VB.NET Sub Main(args As String()) InitialiseHashTable() ReadData() For X = 0 To 5 Console.WriteLine("Enter key field") Console.WriteLine(GetRecord(Console.ReadLine())) Next End Sub 3(g)(i) Python InitialiseHashTable() ReadData() for x in range(5): Key = int(input("Enter key field ")) print(GetRecord(Key)) 3(g)(ii) 1 mark each for screenshot(s) showing 2 • Input of the 4 integers and matching word output 528 permission 1128 peace 1828 precedent 1062 up • Input of 39 and output of Not found e.g.
What you needed in this session
Cambridge’s own grade thresholds for 2025 Oct/Nov, Paper 4 · Variant 1. A higher threshold means an easier paper — the bar moves with how the cohort did.