Free until 14 Nov · 80% off for the first 100 · Pricing

Computer Science 9618/42 May/June 2023: question paper and mark scheme

Cambridge AS & A Level Computer Science (9618), Paper 4 Practical, May/June 2023. Read both free below, or download them. Done the paper? Get it marked by AI against this mark scheme.

9618_s23_qp_429618_s23_ms_429618/42/M/J/23

Paper
Paper 4 Practical
Total marks
75
Time
2 hours 30 minutes
Code on the paper
9618/42/M/J/23
9618_s23_ms_42.pdf

9618/42 mark scheme, question by question

Each question as it's printed, and the mark scheme's points for it, as text. Diagrams, tables and graphs are in the PDFs above.

Question 114 marks

Question

A 1D array needs to store the names of 10 animals. (a) Write program code to declare the global string array Animals to store 10 items. Save your program as Question1_J2023. Copy and paste the program code into part 1(a) in the evidence document. [2] (b) The main program needs to store the following animals in the array: horse lion rabbit mouse bird deer whale elephant kangaroo tiger Write program code to store these animal names in the array. The names must be in lower case and stored in the order given in the list. Save your program. Copy and paste the program code into part 1(b) in the evidence document. [2] (c) The following pseudocode procedure sorts the array into a descending alphabetical order using only the first character in each animal name. The function LENGTH(DataArray) returns the number of elements in the array DataArray. The function MID(String, Start, Quantity) returns Quantity number of characters from String starting at index Start. The first character in the string is index 0, for example: MID("tiger", 0, 2) will return "ti" There are four incomplete statements in the procedure. PROCEDURE SortDescending() DECLARE ArrayLength : INTEGER DECLARE Temp : STRING ArrayLength LENGTH(Animals) FOR X 0 TO ArrayLength - 1 FOR Y …… TO ArrayLength - X - 1 IF MID(Animals[Y], 0, 1) < MID(Animals[……], 0, 1) THEN Temp Animals[……] Animals[Y] Animals[Y + 1] Animals[Y + 1] …… ENDIF NEXT Y NEXT X ENDPROCEDURE Write program code for the procedure SortDescending(). Save your program. Copy and paste the program code into part 1(c) in the evidence document. [6] (d) (i) Write program code to amend the main program to: • call the procedure SortDescending() • output the sorted contents of the array with each animal name on a new line. Save your program. Copy and paste the program code into part 1(d)(i) in the evidence document. [3] (ii) Test your program. Take a screenshot of the output. Save your program. Copy and paste the screenshot into part 1(d)(ii) in the evidence document. [1]

Mark scheme

1(a) 1 mark each 2 Global array named Animals 10 string elements Example Program code: Java public static String[] Animals = new String[10]; VB.NET Dim Animals(9) As String Python global Animals #array 10 elements string 1(b) 1 mark each 2 Storing all 10 items in the array … … in the correct order and all in lower case Example Program code: Java Animals[0] = "horse"; Animals[1] = "lion"; Animals[2] = "rabbit"; Animals[3] = "mouse"; Animals[4] = "bird"; Animals[5] = "deer"; Animals[6] = "whale"; Animals[7] = "elephant"; Animals[8] = "kangaroo"; Animals[9] = "tiger"; VB.NET Sub Main() Animals(0) = "horse" Animals(1) = "lion" Animals(2) = "rabbit" Animals(3) = "mouse" Animals(4) = "bird" Animals(5) = "deer" Animals(6) = "whale" Animals(7) = "elephant" Animals(8) = "kangaroo" Animals(9) = "tiger" End Sub 1(b) Python #main Animals = [] Animals.append("horse") Animals.append("lion") Animals.append("rabbit") Animals.append("mouse") Animals.append("bird") Animals.append("deer") Animals.append("whale") Animals.append("elephant") Animals.append("kangaroo") Animals.append("tiger") 1(c) 1 mark for each completed statement to MAX 4 6 1 mark each: Use of appropriate string functions to access e.g. MID and length Remainder of procedure correct and following example Pseudocode: PROCEDURE SortDescending() DECLARE ArrayLength : INTEGER DECLARE Temp : STRING ArrayLength ← LENGTH(Animals) FOR X ← 0 TO ArrayLength - 1 FOR Y ← 0 TO (ArrayLength - X - 1) IF MID(Animals[Y], 0, 1) < MID(Animals[Y+1], 0, 1) THEN Temp ← Animals[Y] Animals[Y] ← Animals[Y + 1] Animals[Y + 1] ← Temp ENDIF NEXT Y NEXT X ENDPROCEDURE Example Program code: Java public static void SortDescending(){ Integer ArrayLength = 10; String Temp = ""; for(Integer X = 0; X < ArrayLength - 1; X++){ for(Integer Y = 0; Y < ArrayLength-X-1; Y++){ 1(c) if(Animals[Y].charAt(0) < Animals[Y+1].charAt(0)){ Temp = Animals[Y]; Animals[Y] = Animals[Y+1]; Animals[Y+1] = Temp; } } } } VB.NET Sub SortDescending() Dim ArrayLength As Integer = 10 Dim Temp As String = "" For X = 0 To ArrayLength - 1 For Y = 0 To ArrayLength - X - 2 If Left(Animals(Y), 1) < Left(Animals(Y + 1), 1) Then Temp = Animals(Y) Animals(Y) = Animals(Y + 1) Animals(Y + 1) = Temp End If Next Next End Sub Python def SortDescending(): ArrayLength = 10 for X in range(0, ArrayLength-1): for Y in range(0, ArrayLength-X-1): if(Animals[Y][0] < Animals[Y+1][0]): Temp = Animals[Y] Animals[Y] = Animals[Y + 1] Animals[Y + 1] = Temp 1(d)(i) 1 mark each 3 calling the procedure SortDescending() looping through all array elements outputting each array element on a new line Example Program code: Java SortDescending(); for(Integer X = 0; X < 10; X++){ System.out.println(Animals[X]); } VB.NET SortDescending() For X = 0 to 9 Console.WriteLine(Animals(X)) Next X Python SortDescending() for X in range(0, 10): print(Animals[X]) 1(d)(ii) 1 mark for screenshot e.g. 1

Question 228 marks

Question

A business sells a single product. Customers can purchase one or more of this product. Each sale has an ID and a quantity, for example "ABC" and 2 The business needs a program to store the data about the sales in a circular queue data structure. (a) Write program code to declare a record structure, SaleData, to store the data about each sale. Save your program as Question2_J2023. Copy and paste the program code into part 2(a) in the evidence document. [2] (b) Write program code to: • declare a global array, CircularQueue, of 5 items to store the sale records • declare the global pointers Head and Tail • declare the global variable NumberOfItems • initialise all elements of the array CircularQueue to an empty record, where the ID is null ("") and quantity is -1 • initialise Head, Tail and NumberOfItems to 0 Save your program. Copy and paste the program code into part 2(b) in the evidence document. [4] (c) The function Enqueue(): • takes a new record as a parameter • inserts the record in the circular queue at the element pointed to by Tail • updates pointers and other variables as required • returns −1 if the circular queue is full • returns 1 if the record is stored successfully. Write program code for the function Enqueue(). Save your program. Copy and paste the program code into part 2(c) in the evidence document. [6] (d) The function Dequeue(): • returns a null or empty record if the circular queue is empty • returns the first record in the queue if the circular queue is not empty • updates pointers and other variables as required. Write program code for the function Dequeue(). Save your program. Copy and paste the program code into part 2(d) in the evidence document. [6] (e) The procedure EnterRecord(): • takes an ID and quantity as input and creates a sale record • uses Enqueue() to insert the record in the circular queue • outputs "Full" if the record was not inserted in the circular queue • outputs "Stored" if the record was inserted in the circular queue. Write program code for the procedure EnterRecord(). Save your program. Copy and paste the program code into part 2(e) in the evidence document. [5] (f) The following sale records need to be entered into the program: ID Quantity ADF 10 OOP 1 BXW 5 XXZ 22 HQR 6 LLP 3 (i) Amend the main program to: • use EnterRecord() to input the six records in the table • use Dequeue() to remove one record • output either the ID and quantity of the removed record, or an error message if the circular queue is empty • use EnterRecord() to input the record with the ID "LLP" for a second time • output the ID and quantity for all the records currently stored in the array CircularQueue. Write program code to perform these tasks. Save your program. Copy and paste the program code into part 2(f)(i) in the evidence document. [4] (ii) Test your program. Take a screenshot of the output. Save your program. Copy and paste the screenshot into part 2(f)(ii) in the evidence document. [1]

Mark scheme

2(a) 1 mark each 2 Record declaration named SaleData // class declaration (and end) named SaleData… …SaleID declared as string, Quantity as integer in record // if a class then a constructor assigning attributes SaleID and Quantity Example Program code: Java class SaleData{ private String SaleId; private Integer Quantity; public SaleData(String SaleIDP, Integer Quantityp){ SaleId = SaleIDP; Quantity = Quantityp; } } VB.NET Structure SaleData Public SaleID As String Public Quantity As Integer End Structure Python class SaleData: def __init__(self, SaleIDp, Quantityp): self.SaleID = SaleIDp #string self.Quantity = Quantityp #integer 2(b) 1 mark each 4 Global array CircularQueue of 5 items of type SaleData Global variables Head, Tail and NumberOfItems all initialised to 0 One record declared setting ID to "" and Quantity to -1 … ...stored in all 5 array elements Example Program code: Java public static SaleData[] CircularQueue = new SaleData[5]; public static Integer NumberOfItems = 0; public static Integer Head = 0; public static Integer Tail = 0; public static void main(String args[]){ for(Integer X = 0; X < 5; X++){ CircularQueue[X] = new SaleData("",-1); }} VB.NET Dim CircularQueue(0 To 4) As SaleData Dim NumberOfItems As Integer Dim Head As Integer Dim Tail As Integer Sub Main() NumberOfItems = 0 Head = 0 Tail = 0 For x = 0 To 4 CircularQueue(x).SaleID = "" CircularQueue(x).Quantity = -1 Next End Sub 2(b) Python CircularQueue = [] #SaleData, 5 items global NumberOfItems #int global Head #int global Tail #int #main NumberOfItems = 0 Head = 0 Tail = 0 for x in range(0, 5): CircularQueue.append((SaleData("",-1))) 2(c) 1 mark each 6 Function Enqueue() header (and end) taking one parameter (type SaleData) Checks if queue is full … … and returns -1 (otherwise) Inserts parameter to CircularQueue[Tail] … … increments Tail and resets to 0 if 5 Increments number of items and returns 1 Example Program code: Java public static Integer Enqueue(SaleData RecordToAdd){ if(NumberOfItems == 5){ return -1; }else{ CircularQueue[Tail].SetSaleID(RecordToAdd.GetSaleID()); CircularQueue[Tail].SetQuantity(RecordToAdd.GetQuantity()); if(Tail == 4){ Tail = 0; }else{ Tail++; } NumberOfItems++; return 1; } } VB.NET Function Enqueue(RecordToAdd) If (NumberOfItems = 5) Then Return -1 Else CircularQueue(Tail) = RecordToAdd If (Tail = 4) Then Tail = 0 2(c) Else Tail += 1 End If NumberOfItems += 1 Return 1 End If End Function Python def Enqueue(RecordToAdd): global NumberOfItems #int global Head #int global Tail #int if(NumberOfItems == 5): return -1 else: CircularQueue[Tail] = RecordToAdd if(Tail == 4): Tail = 0 else: Tail +=1 NumberOfItems +=1 return 1 2(d) 1 mark each 6 Function header Dequeue() (and end where appropriate) Checking if queue is empty… ….and returning appropriate empty/null record/object/list element (Otherwise) returning the item at Head Incrementing Head and changing value 0 if it is 4/5 Decrement number of items Example Program code: Java public static SaleData Dequeue(){ SaleData RecordRemoved; RecordRemoved = new SaleData("", -1); if(!(NumberOfItems == 0)){ RecordRemoved.SetSaleID(CircularQueue[Head].GetSaleID()); RecordRemoved.SetQuantity(CircularQueue[Head].GetQuantity()); NumberOfItems--; if(Head == 4){ Head = 0; }else{Head++;} } return RecordRemoved; } VB.NET Function Dequeue() Dim RecordRemoved As SaleData RecordRemoved.SaleID = "" RecordRemoved.Quantity = -1 If Not (NumberOfItems = 0) Then RecordRemoved = CircularQueue(Head) NumberOfItems -= 1 If Head = 4 Then Head = 0 2(d) Else Head += 1 End If End If Return RecordRemoved End Function Python def Dequeue(): global NumberOfItems #int global Head #int global Tail #int RecordRemoved = SaleData("", -1) if not(NumberOfItems == 0): RecordRemoved = CircularQueue[Head] NumberOfItems -=1 if Head == 4: Head = 0 else: Head +=1 return RecordRemoved 2(e) 1 mark each 5 Procedure header EnterRecord (and end where appropriate) (ignore parameters) Takes as input an ID (string) and quantity (integer) Creates a record/object using inputs Calls Enqueue() with record as parameter and stores/uses return value Outputs "Full" and "Stored" in correct places Example Program code: Java public static void EnterRecord(){ System.out.println("Enter ID"); Scanner NewScanner = new Scanner(System.in); String ID = NewScanner.nextLine(); System.out.println("Enter quantity"); Quan = Integer.parseInt(NewScanner.nextLine()); SaleData Record; Record = new SaleData(ID, Quan); if(Enqueue(Record) == -1){ System.out.println("Full");} else{System.out.println("Stored");} } VB.NET Sub EnterRecord() Dim Record As SaleData Console.WriteLine("Enter ID") Record.SaleID = Console.ReadLine() Console.WriteLine("Enter quantity") Record.Quantity = Console.ReadLine() If Enqueue(Record) = -1 Then Console.WriteLine("Full") Else Console.WriteLine("Stored") End If End Sub 2(e) Python def EnterRecord(): ID = input("Enter ID") QuantityP = input("Enter quantity") Record = SaleData(ID, QuantityP) if Enqueue(Record) == -1: print("Full") else: print("Stored") 2(f)(i) 1 mark each to max 4 4 Calling EnterRecord() 6 times before dequeue Calling Dequeue() and storing/using return value … … checking if an empty record is returned and outputting either the ID and quantity of returned record or outputting the error message if empty record Calling EnterRecord() again after dequeue Output the ID and quantity for all the records currently stored in CircularQueue Example Program code: Java EnterRecord(); EnterRecord(); EnterRecord(); EnterRecord(); EnterRecord(); EnterRecord(); SaleData ReturnValue = new SaleData; ReturnValue = Dequeue(); if(ReturnValue.GetSaleID() == ""){ System.out.println("No items"); }else{ System.out.println(ReturnValue.GetSaleID() + " " + ReturnValue. GetQuantity()); } EnterRecord(); for(Integer X = 0; X < 5; X++){ System.out.println(CircularQueue[X].GetSaleID() + " " + CircularQueue[X].GetQuantity()); } VB.NET EnterRecord() EnterRecord() EnterRecord() EnterRecord() 2(f)(i) EnterRecord() EnterRecord() Dim ReturnValue As SaleData = new SaleData ReturnValue = Dequeue() If (ReturnValue.SaleID = "") Then Console.WriteLine("No items") Else Console.WriteLine(ReturnValue.SaleID & " " & ReturnValue.Quantity) End If EnterRecord() For x = 0 To 4 Console.WriteLine(CircularQueue(x).SaleID & " " & CircularQueue(x).Quantity) Next Python EnterRecord() EnterRecord() EnterRecord() EnterRecord() EnterRecord() EnterRecord() ReturnValue = Dequeue() if ReturnValue.SaleID == "": print("No items") else: print(ReturnValue.SaleID, " ", ReturnValue.Quantity) EnterRecord() for x in range(0, 5): print(CircularQueue[x].SaleID, " ", CircularQueue[x].Quantity) 2(f)(ii) 1 mark for screenshot showing: 1 Data for 6 records input 5 messages stating (e.g.) stored and 1 message stating (e.g.) full 1 output of ADF 10 (dequeued) Repeat successful input of LLP 3 Output of the 5 records e.g.

Question 333 marks

Question

A company needs a computer program to store data about its employees. Part of the program is being written using object‑oriented programming. The class Employee stores data about the employees. Each employee has an employee number, a job title and hourly pay rate. The class will also store the amount they are paid each week over a 52‑week year in a 1D array. Employee HourlyPay : REAL stores the amount each employee gets paid each hour EmployeeNumber : STRING stores the employee’s unique number JobTitle : STRING stores the employee’s job title PayYear2022 : ARRAY[0:51] OF REAL stores the amount the employee has been paid each week Constructor() initialises HourlyPay, EmployeeNumber and JobTitle from the values passed as parameters initialises all 52 elements in PayYear2022 to 0.0 GetEmployeeNumber() returns the employee number SetPay() takes the week number and number of hours worked that week as parameters calculates and stores the pay for that week in PayYear2022 GetTotalPay() returns the total of all the values in PayYear2022 (a) (i) Write program code to declare the class Employee. You only need to declare the class and its constructor. Do not declare any other methods. Use your programming language appropriate constructor. If you are writing program code in Python, include attribute declarations using comments. Save your program as Question3_J2023. Copy and paste the program code into part 3(a)(i) in the evidence document. [5] (ii) The method GetEmployeeNumber() returns the employee number. Write program code for the method GetEmployeeNumber(). Save your program. Copy and paste the program code into part 3(a)(ii) in the evidence document. [2] (iii) The method SetPay(): • takes a week number and the number of hours worked that week as parameters • calculates the pay for that week by multiplying the hourly pay by the number of hours worked that week • stores the calculated pay in the appropriate index for that week in PayYear2022. Write program code for the method SetPay(). Save your program. Copy and paste the program code into part 3(a)(iii) in the evidence document. [3] (iv) The method GetTotalPay() returns the total of all the values in PayYear2022. Write program code for the method GetTotalPay(). Save your program. Copy and paste the program code into part 3(a)(iv) in the evidence document. [2] (b) The child class Manager inherits from the parent class Employee. A manager gets a bonus. This bonus value is a percentage, for example 10.0%. When calculating the pay, the number of hours the manager worked that week is increased by the bonus value. Manager stores the bonus value, for example 10.0 represents a BonusValue : REAL 10.0% increase Constructor() takes bonus value, hourly pay, employee number and job title as parameters initialises BonusValue to its parameter value SetPay() takes the week number and number of hours worked as parameters increases the number of hours worked by the bonus value calls the SetPay() method from the parent class (i) Write program code to declare the class Manager. You only need to declare the class and its constructor. Do not declare any other methods. 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 3(b)(i) in the evidence document. [4] (ii) The Manager method SetPay() overrides the method from the parent class and: • takes the week number and number of hours worked as parameters • increases the number of hours worked by the bonus value • calls SetPay() from the parent class. Write program code for the method SetPay(). Save your program. Copy and paste the program code into part 3(b)(ii) in the evidence document. [3] (c) The main program has a global 1D array, EmployeeArray, to store data about eight employees. Each employee is stored as an object of type Employee. The file Employees.txt stores data about the employees, in the order: • hourly pay • employee number • bonus value (where included) • job title. Only employees who are managers have a bonus value saved. For example: • The first employee is a Junior Developer, with employee number 12452 and an hourly pay of $15.22. This employee does not have a bonus value. • The third employee is an Interface Manager, with employee number 02586 and an hourly pay of $22.50. This employee has a bonus value of 5.25%. Write the main program to: • declare the array to store data about 8 employees • read in the data from the file for each employee • instantiate each employee as either Employee (if the employee does not have a bonus value) or Manager (if the employee has a bonus value). Save your program. Copy and paste the program code into part 3(c) in the evidence document. [7] (d) The file HoursWeek1.txt stores the number of hours each employee has worked in week 1, in the order: • employee number • number of hours worked. For example, the first set of data is for employee 21548 who has worked 50.0 hours. The procedure EnterHours(): • reads in the values from the file • finds the location of each employee in EmployeeArray • calls the method SetPay() for each employee. Write program code for EnterHours(). Save your program. Copy and paste the program code into part 3(d) in the evidence document. [4] (e) (i) The main program needs to call EnterHours() and use the method GetTotalPay() to output the employee number and total pay for each of the eight employees. Amend the main program to perform these tasks. Save your program. Copy and paste the program code into part 3(e)(i) in the evidence document. [2] (ii) Test your program. Take a screenshot of the output. Save your program. Copy and paste the screenshot into part 3(e)(ii) in the evidence document. [1]

Mark scheme

3(a)(i) For X = 0 To 51 PayYear2022(X) = 0.00 Next End Sub End Class Python class Employee: #self.__HourlyPay single #self.__EmployeeNumber string #self.__JobTitle string def __init__(self, EmpNumP, PayP, JobP): self.__HourlyPay = PayP self.__EmployeeNumber = EmpNumP self.__JobTitle = JobP self.__PayYear2022 = []#array 52 elements single for x in range(0, 52): self.__PayYear2022.append(0.00) 3(a)(ii) 1 mark each 2 Get method header (and end) with no parameters … … returning employee number (without overriding) Example program code: Java public String GetEmployeeNumber(){ return EmployeeNumber; } VB.NET Public Function GetEmployeeNumber() Return EmployeeNumber End Function Python def GetEmployeeNumber(self): return self.__EmployeeNumber 3(a)(iii) 1 mark each 3 Method header (and close) with two parameters (week number and number of hours) Calculates pay as number of hours (parameter) * HourlyPay (attribute) … stores result in correct index in PayYear2022 Example program code: Java public void SetPay(Integer WeekNumber, Double Hours){ PayYear2022[WeekNumber - 1] = Hours * HourlyPay; } VB.NET Overridable Sub SetPay(WeekNumber, Hours) PayYear2022(WeekNumber - 1) = Hours * HourlyPay End Sub Python def SetPay(self, WeekNumber, Hours): self.__PayYear2022[WeekNumber-1] = Hours * self.__HourlyPay 3(a)(iv) 1 mark each 2 Method header (and close) and returning calculated total (ignore parameters, allow return of any reasonable attempt at calculation) Totalling all elements in PayYear2022 Example program code: Java public Double GetTotalPay(){ Double TotalPay = 0.0; for(Integer X = 0; X < 52; X++){ TotalPay = TotalPay + PayYear2022[X]; } return TotalPay; } VB.NET Public Function GetTotalPay() Dim TotalPay As Single = 0 For X = 0 To 51 TotalPay = TotalPay + PayYear2022(X) Next Return TotalPay End Function Python def GetTotalPay(self): TotalPay = 0 for X in range (0, 52): TotalPay = TotalPay + self.__PayYear2022[X] return TotalPay 3(b)(i) 1 mark each 4 Class Manager header (and end) inheriting from Employee Constructor within class (and end) taking 4 parameters… …calling parent class constructor with 3 values from parameters Declaring BonusValue (real) and assigning parameter to it within constructor Example program code: Java class Manager extends Employee{ private Double BonusValue; public Manager(String EmpNumP, Double PayP, String JobP, Double BonusP){ super(EmpNumP, PayP, JobP); BonusValue = BonusP; } } VB.NET Class Manager Inherits Employee Private BonusValue As Single Sub New(EmpNumP As String, PayP As Single, JobP As String, BonusP As Single) MyBase.New(EmpNumP, PayP, JobP) BonusValue = BonusP End Sub End Class 3(b)(i) Python class Manager(Employee): #BonusValue single def __init__(self, EmpNumP, PayP, JobP, BonusP): super().__init__(EmpNumP, PayP, JobP) self.__BonusValue = BonusP 3(b)(ii) 1 mark each 3 Method SetPay header (and end) taking 2 parameters Calculating hours (from parameter) * bonus as a percentage Overriding / calling parent SetPay with week number from parameter and updated hours as parameters Example program code: Java public void SetPay(Integer WeekNumber, Double Hours){ super.SetPay(WeekNumber, Hours * ((BonusValue / 100) + 1)); } VB.NET Overrides Sub SetPay(WeekNumber, Hours) MyBase.SetPay(WeekNumber, Hours * ((BonusValue / 100) + 1)) End Sub Alternative VB.NET: Overloads Sub SetPay(WeekNumber, Hours) SetPay(WeekNumber, Hours * ((BonusValue / 100) + 1)) End Sub Python def SetPay(self, WeekNumber, Hours): Hours = Hours * (1 + self.__BonusValue / 100) super().SetPay(WeekNumber, Hours) 3(c) 1 mark each to max 7 7 Opening file Employees.txt to read and closing file in an appropriate place Exception handling with appropriate output for opening the file Looping to EOF / 8 times (Attempting to) Read in all lines from the file for each employee For each employee: Instantiating and storing an object of type Manager (not Employee) when bonus is included... …with correct read in values (otherwise) instantiating and storing an object of type Employee … .. with correct read in values Example program code: Java public static void main(String args[]){ Double Pay = 0.0; String ID = ""; Double Bonus = 0.00; String Title = ""; Integer NumberEmployees = 0; String Temp = ""; String TextFile = "Employees.txt"; try{ FileReader f = new FileReader(TextFile); BufferedReader Reader = new BufferedReader(f); for(Integer X = 0; X < 8; X++){ Bonus = 0.00; try{ Pay = Double.parseDouble(Reader.readLine()); ID = Reader.readLine(); Temp = Reader.readLine(); 3(c) try{ Bonus = Double.parseDouble(Temp); Title = Reader.readLine(); EmployeeArray[NumberEmployees] = new Manager(ID, Pay, Title, Bonus); }catch(NumberFormatException e){ Title = Temp; EmployeeArray[NumberEmployees] = new Employee(ID, Pay, Title); } NumberEmployees++; } catch(IOException ex){ } } try{ Reader.close(); }catch(IOException ex){} }catch(FileNotFoundException ex){ System.out.println("No file found"); }} VB.NET Dim Pay As Single Dim ID As String Dim Bonus As Single Dim Title As String Dim NumberEmployees As Integer = 0 Dim Temp As String try Dim TextFile As String = "Employees.txt" Dim FileReader As New System.IO.StreamReader(TextFile) For x = 0 To 7 Pay = CSng(FileReader.ReadLine()) ID = FileReader.ReadLine Temp = FileReader.ReadLine If Single.TryParse(Temp, Bonus) Then Bonus = Temp Title = FileReader.ReadLine() EmployeeArray(NumberEmployees) = New Manager(ID, Pay, Title, Bonus) 3(c) Else Title = Temp EmployeeArray(NumberEmployees) = New Employee(ID, Pay, Title) End If NumberEmployees += 1 Next FileReader.Close() Catch ex As Exception Console.WriteLine("Invalid file") End Try Python #main Pay = 0.00 ID = "" Bonus = 0.00 Title = "" Temp = "" try: TextFile = "Employees.txt" File = open(TextFile, 'r') for x in range(0, 8): Pay = float(File.readline()) ID = File.readline() Temp = File.readline() try: Bonus = float(Temp) Title = File.readline() EmployeeArray.append(Manager(ID, Pay, Title, Bonus)) except: Title = Temp EmployeeArray.append(Employee(ID, Pay, Title)) 3(c) File.close() except IOError: print("Could not find file") 3(d) 1 mark each to max 4 4 Procedure header EnterHours() (ignore parameters) and opening file to read and closing file in appropriate place Exception handling with appropriate output for opening file Looping to EOF/8 times and reading in each line Searching array for employee number … … using GetEmployeeNumber() …calling SetPay() with the number of hours and week number 1 as parameters, for that employee in the array Example program code: Java public static void EnterHours(){ String TextFile = "HoursWeek1.txt"; String EmpID = ""; try{ FileReader f = new FileReader(TextFile); BufferedReader Reader = new BufferedReader(f); for(Integer X = 0; X < 8; X++){ try{ EmpID = Reader.readLine(); for(Integer Y = 0; Y < 8; Y++){ if(Employees[Y].GetEmployeeNumber().equals(EmpID)){ Employees[Y].SetPay(1, Double.parseDouble(Reader.readLine())); } } } catch(IOException ex){ } } try{ Reader.close(); }catch(IOException ex){} }catch(FileNotFoundException e){ System.out.println("File not found"); } } 3(d) VB.NET Sub EnterHours() try Dim TextFile As String = "HoursWeek1.txt" Dim FileReader As New System.IO.StreamReader(TextFile) Dim EmpId As String For X = 0 To 7 EmpId = FileReader.ReadLine() For Y = 0 To 7 If Employees(Y).GetEmployeeNumber = EmpId Then Employees(Y).SetPay(1, CSng(FileReader.ReadLine())) End If Next Next FileReader.Close() Catch ex As Exception Console.WriteLine("Invalid file") End Try End Sub Python def EnterHours(): try: TextFile = "HoursWeek1.txt" File = open(TextFile, 'r') EmpID = "" for X in range(0, 8): EmpID = File.readline() for Y in range(0, 8): if Employees[Y].GetEmployeeNumber() == EmpID: Employees[Y].SetPay(1, float(File.readline())) except IOError: print("Could not find file") 3(e)(i) 1 mark each 2 Calling EnterHours() and looping through each employee … … outputting the employee number and their total pay using GetTotalPay() and GetEmployeeNumber() Example program code: Java EnterHours(); for(Integer X = 0; X < 8; X++){ System.out.println(Employees[Y].GetEmployeeNumber() + " " + Employees[Y].GetTotalPay()); } VB.NET EnterHours() For Y = 0 To 7 Console.WriteLine(Employees(Y).GetEmployeeNumber & " " & Employees(Y).GetTotalPay()) Next Python EnterHours() for(Y in range(0, 8): print(Employees[Y].GetEmployeeNumber(), " ", Employees[Y].GetTotalPay()) 3(e)(ii) 1 mark for screenshot e.g. 1

Checked your answers against these? Let AI mark the whole paper, on your own working.

Mark my 9618/42

How this paper is marked

Examiners follow the generic marking principles at the front of the scheme, then each question's points: method (M), accuracy (A) and independent (B) marks, error carried forward where the scheme allows it, and positive marking, so you're credited for what you got right.

Check your answers against it

Done this paper? Upload your script and CIE Buddy's AI marker marks it question by question against this exact scheme, puts the ticks on your own working and says what each lost mark needed.

9618/42 in other series

Find another Computer Science paper

Every AS & A Level Computer Science mark scheme

Question papers and mark schemes © Cambridge University Press & Assessment. CIE Buddy is independent and not connected to Cambridge.

9618/42 questions

Where can I find the 9618/42 May/June 2023 mark scheme?

On this page, free: the mark scheme for AS & A Level Computer Science 9618/42, May/June 2023 (9618_s23_ms_42), and the question paper (9618_s23_qp_42), to read or download, with each question's marking points written out underneath.

How many marks is 9618/42 out of?

Computer Science 9618/42 for May/June 2023 is out of 75 marks, with 2 hours 30 minutes to answer it.

Can I get my 9618/42 answers marked?

Yes. Upload your answers to 9618/42/M/J/23 as a PDF or photos, and CIE Buddy marks every question against this paper's official mark scheme, using Cambridge's marking rules. You get your score, each lost mark explained on your own script, and the topics to revise. It's a guide, not an official Cambridge grade.