9618/42 · October/November 2024 · Worked solutions

Step-by-step solutions based on the mark scheme (not a mark-scheme dump).

Question 1

Paper page 2 for Q1
Original paper page 2

Part 1(a)(i) — solution

  1. Class EventItem header (and end where appropriate)
  2. 3 private attributes with suitable data types
  3. Constructor header (and end where appropriate) with 3 (min) parameters within class declaration …
  4. … assigning parameters to attributes within constructor

Visual Basic (VB.NET)

Class EventItem
                    Private EventName As String
                    Private EventType As String
                    Private Difficulty As Integer
                    Sub New(pName, pType, pDifficulty)
                       EventName = pName
                       EventType = pType
                       Difficulty = pDifficulty
                    End Sub
                End Class

 University Press & Assessment 2024                       Page 4 of 39

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Python

class EventItem():
                     def __init__(self, pName, pType, pDifficulty):
                         self.__EventName = pName #String
                         self.__EventType = pType #String
                         self.__Difficulty = pDifficulty #Integer

Mark points

  • Class EventItem header (and end where appropriate)
  • 3 private attributes with suitable data types
  • Constructor header (and end where appropriate) with 3 (min) parameters within class declaration …
  • … assigning parameters to attributes within constructor

Part 1(a)(i) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 1(a)(ii) — solution

  1. 1 get method with no parameter …
  2. … return correct attribute (without changing)
  3. Remaining 2 correct get methods returning the attributes

Python

def GetName(self):
                         return self.__EventName
                     def GetEventType(self):
                         return self.__EventType
                     def GetDifficulty(self):
                         return self.__Difficulty

 University Press & Assessment 2024                       Page 5 of 39

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Mark points

  • 1 get method with no parameter …
  • … return correct attribute (without changing)
  • Remaining 2 correct get methods returning the attributes

Part 1(a)(ii) — solution

VB.NET Function GetName() Return EventName End Function Function GetEventType() Return EventType End Function Function GetDifficulty() Return Difficulty End Function

Visual Basic (VB.NET)

Function GetName()
                    Return EventName
                End Function
                Function GetEventType()
                    Return EventType
                End Function
                Function GetDifficulty()
                    Return Difficulty
                End Function

Mark points

  • Include the ideas shown in the solution above.

Part 1(b)(i) — solution

  1. 1D array name Group with (min 5 elements and of type EventItem)

Visual Basic (VB.NET)

Dim Group(4) As EventItem

Python

Group = [] #type Event, 5 spaces

Mark points

  • 1D array name Group with (min 5 elements and of type EventItem)

Part 1(b)(ii) — solution

  1. Any 1 instance of EventItem declared with values passed in correct order …
  2. … stored in the array Group …
  3. … remaining 4 correctly instantiated and stored in Group

Visual Basic (VB.NET)

Group(0) = New EventItem("Bridge", "jump", 3)
                Group(1) = New EventItem("Water wade", "swim", 4)
                Group(2) = New EventItem("100 mile run", "run", 5)
                Group(3) = New EventItem("Gridlock", "drive", 2)
                Group(4) = New EventItem("Wall on wall", "jump", 4)

Python

Group.append(EventItem("Bridge", "jump", 3))
                Group.append(EventItem("Water wade", "swim", 4))
                Group.append(EventItem("100 mile run", "run", 5))
                Group.append(EventItem("Gridlock", "drive", 2))
                Group.append(EventItem("Wall on wall", "jump", 4))

Mark points

  • Any 1 instance of EventItem declared with values passed in correct order …
  • … stored in the array Group …
  • … remaining 4 correctly instantiated and stored in Group

Part 1(c) — solution

  1. Class Character declared (and end where appropriate)
  2. 5 private attributes with correct data types
  3. Constructor header (and end) taking (min) 5 parameters and parameters assigned to attributes
  4. Get method (with no parameter) returning name attribute

Mark points

  • Class Character declared (and end where appropriate)
  • 5 private attributes with correct data types
  • Constructor header (and end) taking (min) 5 parameters and parameters assigned to attributes
  • Get method (with no parameter) returning name attribute

Part 1(c) — solution

  1. self.__CName = pName #string
  2. self.__Jump = pJump #integer chance of success
  3. self.__Swim = pSwim #integer chance of success
  4. self.__Run = pRun #integer chance of success
  5. self.__Drive = pDrive #integer chance of success
  6. CName = pName
  7. Jump = pJump
  8. Swim = pSwim
  9. Run = pRun
  10. Drive = pDrive

Visual Basic (VB.NET)

Class Character
                        Private CName As String
                        Private Jump As Integer
                        Private Swim As Integer
                        Private Run As Integer
                        Private Drive As Integer
                        Sub New(pName, pJump, pSwim, pRun, pDrive)
                            CName = pName
                            Jump = pJump
                            Swim = pSwim
                            Run = pRun
                            Drive = pDrive
                        End Sub

                            Function GetName()
                                 Return CName
                            End Function

                End Class

 University Press & Assessment 2024                       Page 8 of 39

9618/42                                           Cambridge International AS & A Level – Mark Scheme                             October/November 2024

Python

class Character():
                     def __init__(self, pName, pJump, pSwim, pRun, pDrive):
                         self.__CName = pName #string
                         self.__Jump = pJump #integer chance of success
                         self.__Swim = pSwim #integer chance of success
                         self.__Run = pRun #integer chance of success
                         self.__Drive = pDrive #integer chance of success
                     def GetName(self):
                         return self.__CName #STRING

Mark points

  • self.__CName = pName #string
  • self.__Jump = pJump #integer chance of success
  • self.__Swim = pSwim #integer chance of success
  • self.__Run = pRun #integer chance of success
  • self.__Drive = pDrive #integer chance of success
  • CName = pName
  • Jump = pJump
  • Swim = pSwim
  • Run = pRun
  • Drive = pDrive

Part 1(c) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 1(d) — solution

  1. Method header CalculateScore (and end where appropriate) taking (min) 2 parameters
  2. Selection on the type of event using the parameter
  3. … if skill value is  = difficulty return 100
  4. …otherwise subtracting skill value from the difficulty and return correct value 80 (diff 1), 60 (diff 2), 40 (diff 3) and 20
  5. Using the correct attributes and parameters throughout

Mark points

  • Method header CalculateScore (and end where appropriate) taking (min) 2 parameters
  • Selection on the type of event using the parameter
  • … if skill value is  = difficulty return 100
  • …otherwise subtracting skill value from the difficulty and return correct value 80 (diff 1), 60 (diff 2), 40 (diff 3) and 20
  • Using the correct attributes and parameters throughout

Part 1(d) — solution

  1. if Type == "jump":
  2. Chance = self.__Jump
  3. elif Type == "swim":
  4. Chance = self.__Swim
  5. elif Type == "run":
  6. Chance = self.__Run
  7. Chance = self.__Drive
  8. if Chance >= Difficulty:
  9. Difference = Difficulty - Chance
  10. if Difference == 1:
  11. elif Difference == 2:
  12. elif Difference == 3:
  13. elif Difference == 4:

Python

def CalculateScore(self, Type, Difficulty):
                        if Type == "jump":
                            Chance = self.__Jump
                        elif Type == "swim":
                            Chance = self.__Swim
                        elif Type == "run":
                            Chance = self.__Run
                        else:
                            Chance = self.__Drive
                        if Chance >= Difficulty:
                            return 100
                        else:
                            Difference = Difficulty - Chance
                            if Difference == 1:
                                return 80
                            elif Difference == 2:
                                return 60
                            elif Difference == 3:
                                return 40
                            elif Difference == 4:
                                return 20
                            else:
                                return 0

 University Press & Assessment 2024                       Page 10 of 39

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Mark points

  • if Type == "jump":
  • Chance = self.__Jump
  • elif Type == "swim":
  • Chance = self.__Swim
  • elif Type == "run":
  • Chance = self.__Run
  • Chance = self.__Drive
  • if Chance >= Difficulty:
  • Difference = Difficulty - Chance
  • if Difference == 1:
  • elif Difference == 2:
  • elif Difference == 3:
  • elif Difference == 4:

Part 1(d) — solution

  1. If Type = "jump" Then
  2. Chance = Jump
  3. ElseIf Type = "swim" Then
  4. Chance = Swim
  5. ElseIf Type = "run" Then
  6. Chance = Run
  7. Chance = Drive
  8. If Chance >= Difficulty Then
  9. Difference = Difficulty - Chance
  10. If Difference = 1 Then
  11. ElseIf Difference = 2 Then
  12. ElseIf Difference = 3 Then
  13. ElseIf Difference = 4 Then

Visual Basic (VB.NET)

Function CalculateScore(Type, Difficulty)
                    Dim Chance As Integer
                    Dim Difference As Integer
                    If Type = "jump" Then
                         Chance = Jump
                    ElseIf Type = "swim" Then
                         Chance = Swim
                    ElseIf Type = "run" Then
                         Chance = Run
                    Else
                         Chance = Drive
                    End If
                    If Chance >= Difficulty Then
                         Return 100
                    Else
                         Difference = Difficulty - Chance
                         If Difference = 1 Then
                              Return 80
                         ElseIf Difference = 2 Then
                              Return 60
                         ElseIf Difference = 3 Then
                              Return 40
                         ElseIf Difference = 4 Then
                              Return 20
                         Else
                              Return 0
                         End If
                    End If
                End Function

 University Press & Assessment 2024                       Page 11 of 39

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Mark points

  • If Type = "jump" Then
  • Chance = Jump
  • ElseIf Type = "swim" Then
  • Chance = Swim
  • ElseIf Type = "run" Then
  • Chance = Run
  • Chance = Drive
  • If Chance >= Difficulty Then
  • Difference = Difficulty - Chance
  • If Difference = 1 Then
  • ElseIf Difference = 2 Then
  • ElseIf Difference = 3 Then
  • ElseIf Difference = 4 Then

Part 1(d) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 1(e)(i) — solution

  1. Creating one new instance of Character with correct name and values for 1 character and storing
  2. 2nd correct instance of Character and storing

Visual Basic (VB.NET)

Dim P1 As Character = New Character("Tarz", 5, 3, 5, 1)
                Dim P2 As Character = New Character("Geni", 2, 2, 3, 4)

Python

P1 = Character("Tarz", 5, 3, 5, 1)
                P2 = Character("Geni", 2, 2, 3, 4)

Mark points

  • Creating one new instance of Character with correct name and values for 1 character and storing
  • 2nd correct instance of Character and storing

Part 1(e)(ii) — solution

  1. Looping through each event in Group (or checking each of the 5 events manually)
  2. Using CalculateScore() for each Character object with parameters of type and difficulty
  3. …comparing the return values from the two function calls …
  4. …incrementing points for winning player and outputting their name and message stating they have won for each
  5. …outputting message if it's a draw
  6. Comparing the total points for each character after all events checked and outputting name of player with most points
  7. Using get methods correctly throughout

Mark points

  • Looping through each event in Group (or checking each of the 5 events manually)
  • Using CalculateScore() for each Character object with parameters of type and difficulty
  • …comparing the return values from the two function calls …
  • …incrementing points for winning player and outputting their name and message stating they have won for each
  • …outputting message if it's a draw
  • Comparing the total points for each character after all events checked and outputting name of player with most points
  • Using get methods correctly throughout

Part 1(e)(ii) — solution

  1. P1Points = 0
  2. P2Points = 0
  3. P1EventScore = P1.CalculateScore(Group[x].GetEventType(), Group[x].GetDifficulty())
  4. P2EventScore = P2.CalculateScore(Group[x].GetEventType(), Group[x].GetDifficulty())
  5. P1Points = P1Points + 1
  6. P2Points = P2Points + 1

Python

P1Points = 0
                P2Points = 0
                for x in range(0, 5):
                     P1EventScore = P1.CalculateScore(Group[x].GetEventType(), Group[x].GetDifficulty())
                     P2EventScore = P2.CalculateScore(Group[x].GetEventType(), Group[x].GetDifficulty())
                     if P1EventScore > P2EventScore:
                         P1Points = P1Points + 1
                         print(P1.GetName(), "you win this event")
                     elif P2EventScore > P1EventScore:
                         P2Points = P2Points + 1
                         print(P2.GetName(), "you win this event")
                     else:
                         print("This event is a draw")

                if P1Points > P2Points:
                    print(P1.GetName(), "you have won with", P1Points)
                elif P2Points> P1Points:
                    print(P2.GetName(), "you have won with", P2Points)
                else:
                    print("It's a draw")

 University Press & Assessment 2024                       Page 14 of 39

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Mark points

  • P1Points = 0
  • P2Points = 0
  • P1EventScore = P1.CalculateScore(Group[x].GetEventType(), Group[x].GetDifficulty())
  • P2EventScore = P2.CalculateScore(Group[x].GetEventType(), Group[x].GetDifficulty())
  • P1Points = P1Points + 1
  • P2Points = P2Points + 1

Part 1(e)(ii) — solution

  1. Dim P1 As Character = New Character("Tarz", 5, 3, 5, 1)
  2. Dim P2 As Character = New Character("Geni", 2, 2, 3, 4)
  3. Dim P1Points As Integer = 0
  4. Dim P2Points As Integer = 0
  5. Dim P1EventScore As Integer = 0
  6. Dim P2EventScore As Integer = 0
  7. For x = 0 To 4
  8. P1EventScore = P1.CalculateScore(Group(x).GetEventType(), Group(x).GetDifficulty())
  9. P2EventScore = P2.CalculateScore(Group(x).GetEventType(), Group(x).GetDifficulty())
  10. P1Points = P1Points + 1
  11. P2Points = P2Points + 1

Visual Basic (VB.NET)

Dim P1 As Character = New Character("Tarz", 5, 3, 5, 1)
                Dim P2 As Character = New Character("Geni", 2, 2, 3, 4)
                Dim P1Points As Integer = 0
                Dim P2Points As Integer = 0
                Dim P1EventScore As Integer = 0
                Dim P2EventScore As Integer = 0
                For x = 0 To 4
                     P1EventScore = P1.CalculateScore(Group(x).GetEventType(), Group(x).GetDifficulty())
                     P2EventScore = P2.CalculateScore(Group(x).GetEventType(), Group(x).GetDifficulty())
                     If P1EventScore > P2EventScore Then
                          P1Points = P1Points + 1
                          Console.WriteLine(P1.GetName() & " you win this event")
                     ElseIf P2EventScore > P1EventScore Then
                          P2Points = P2Points + 1
                          Console.WriteLine(P2.GetName() & " you win this event")
                     Else
                          Console.WriteLine("This event is a draw")
                     End If
                Next x
                If P1Points > P2Points Then
                     Console.WriteLine(P1.GetName() & " you have won with " & P1Points)
                ElseIf P2Points > P1Points Then
                     Console.WriteLine(P2.GetName() & " you have won with " & P2Points)
                Else
                     Console.WriteLine("It's a draw")
                End If

 University Press & Assessment 2024                       Page 15 of 39

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Mark points

  • Dim P1 As Character = New Character("Tarz", 5, 3, 5, 1)
  • Dim P2 As Character = New Character("Geni", 2, 2, 3, 4)
  • Dim P1Points As Integer = 0
  • Dim P2Points As Integer = 0
  • Dim P1EventScore As Integer = 0
  • Dim P2EventScore As Integer = 0
  • For x = 0 To 4
  • P1EventScore = P1.CalculateScore(Group(x).GetEventType(), Group(x).GetDifficulty())
  • P2EventScore = P2.CalculateScore(Group(x).GetEventType(), Group(x).GetDifficulty())
  • P1Points = P1Points + 1
  • P2Points = P2Points + 1

Part 1(e)(ii) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 1(e)(iii) — solution

1 mark for output showing the correct winner for each event, the final winner’s name (and their points) 1 e.g. University Press & Assessment 2024 Page 17 of 39 9618/42 Cambridge International AS & A Level – Mark Scheme October/November 2024

Mark points

  • Include the ideas shown in the solution above.

Part 1 — solution

mark for correct values returned in correct places

Mark points

  • Include the ideas shown in the solution above.

Part 1 — solution

  1. IF AQueue.HeadPointer = -1 THEN

Mark points

  • IF AQueue.HeadPointer = -1 THEN

Question 2

Paper page 8 for Q2
Original paper page 8

Part 2(a) — solution

  1. Record structure or class with constructor Queue (and end where appropriate) …
  2. … containing a 1D array of (100) integers QueueArray
  3. … containing HeadPointer and TailPointer as integers

Visual Basic (VB.NET)

Structure Queue
                    Dim QueueArray() As Integer
                    Dim HeadPointer As Integer
                    Dim TailPointer As Integer
                End Structure

Python

class Queue:
                     def __init__(self):
                         self.QueueArray = []
                         HeadPointer = 0 #integer
                         TailPointer = 0 #integer
                         for x in range(0, 100):
                             self.QueueArray.append(-1)

Mark points

  • Record structure or class with constructor Queue (and end where appropriate) …
  • … containing a 1D array of (100) integers QueueArray
  • … containing HeadPointer and TailPointer as integers

Part 2(b) — solution

  1. New Queue record/object created/instance of class
  2. Queue field/attribute head pointer initialised to –1, tail pointer to 0
  3. All 100 array field/attribute elements initialised with –1

Visual Basic (VB.NET)

Dim TheQueue As New Queue
                        TheQueue.HeadPointer = -1
                        TheQueue.TailPointer = 0
                        ReDim TheQueue.QueueArray(100)
                        For x = 0 To 99
                             TheQueue.QueueArray(x) = -1
                        Next

Python

class Queue:
                    def __init__(self):
                        self.QueueArray = []
                        for x in range(0, 100):
                             self.QueueArray.append(-1)

                        self.HeadPointer = -1
                        self.TailPointer = 0
                TheQueue= Queue()

Mark points

  • New Queue record/object created/instance of class
  • Queue field/attribute head pointer initialised to –1, tail pointer to 0
  • All 100 array field/attribute elements initialised with –1

Part 2(b) — solution

  1. HeadPointer = -1;
  2. TailPointer = 0;
  3. for(Integer x = 0; x < 100; x++){
  4. QueueArray[x] = -1;
  5. queue TheQueue = new queue();

Mark points

  • HeadPointer = -1;
  • TailPointer = 0;
  • for(Integer x = 0; x < 100; x++){
  • QueueArray[x] = -1;
  • queue TheQueue = new queue();

Part 2(c) — solution

1 mark for each completed statement to max 3 5

Mark points

  • Include the ideas shown in the solution above.

Part 2(c) — solution

  1. if AQueue.HeadPointer == -1:
  2. AQueue.HeadPointer = 0
  3. AQueue.QueueArray[AQueue.HeadPointer] = TheData
  4. AQueue.TailPointer +=1
  5. AQueue.QueueArray[AQueue.TailPointer] = TheData
  6. AQueue.TailPointer = AQueue.TailPointer + 1
  7. If AQueue.HeadPointer = -1 Then
  8. AQueue.QueueArray(AQueue.TailPointer) = TheData
  9. AQueue.HeadPointer = 0
  10. AQueue.TailPointer += 1
  11. AQueue.QueueArray(AQueue.TailPointer) = TheData
  12. AQueue.TailPointer += 1

Visual Basic (VB.NET)

Function Enqueue(ByRef AQueue As Queue, ByVal TheData As Integer)
                     If AQueue.HeadPointer = -1 Then
                          AQueue.QueueArray(AQueue.TailPointer) = TheData
                          AQueue.HeadPointer = 0
                           AQueue.TailPointer += 1
                          Return 1
                     ElseIf AQueue.TailPointer > 99 Then
                          Return -1
                     Else
                          AQueue.QueueArray(AQueue.TailPointer) = TheData
                          AQueue.TailPointer += 1
                          Return 1
                     End If

                End Function

 University Press & Assessment 2024                       Page 21 of 39

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Python

def Enqueue(AQueue, TheData):

                       if AQueue.HeadPointer == -1:
                           AQueue.HeadPointer = 0
                           AQueue.QueueArray[AQueue.HeadPointer] = TheData
                           AQueue.TailPointer +=1
                           return AQueue, 1
                       elif AQueue.TailPointer > 99:
                           return AQueue, -1
                       else:
                           AQueue.QueueArray[AQueue.TailPointer] = TheData
                           AQueue.TailPointer = AQueue.TailPointer + 1
                           return AQueue, 1

Mark points

  • if AQueue.HeadPointer == -1:
  • AQueue.HeadPointer = 0
  • AQueue.QueueArray[AQueue.HeadPointer] = TheData
  • AQueue.TailPointer +=1
  • AQueue.QueueArray[AQueue.TailPointer] = TheData
  • AQueue.TailPointer = AQueue.TailPointer + 1
  • If AQueue.HeadPointer = -1 Then
  • AQueue.QueueArray(AQueue.TailPointer) = TheData
  • AQueue.HeadPointer = 0
  • AQueue.TailPointer += 1
  • AQueue.QueueArray(AQueue.TailPointer) = TheData
  • AQueue.TailPointer += 1

Part 2(c) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 2(d) — solution

  1. Function header (and end) iterating through each element in the queue
  2. Starting at HeadPointer and incrementing until TailPointer – 1 …
  3. … concatenating and returning all integer values with a space between

Python

def ReturnAllData(TheQueue):
                    Temp = ""

                       for X in range(TheQueue.HeadPointer, TheQueue.TailPointer):
                           Temp = Temp + str(TheQueue.QueueArray[X]) + " "
                       return Temp

 University Press & Assessment 2024                       Page 22 of 39

9618/42                                          Cambridge International AS & A Level – Mark Scheme                      October/November 2024

Mark points

  • Function header (and end) iterating through each element in the queue
  • Starting at HeadPointer and incrementing until TailPointer – 1 …
  • … concatenating and returning all integer values with a space between

Part 2(d) — solution

  1. Dim Temp As String = ""
  2. For X = AQueue.HeadPointer To AQueue.TailPointer - 1
  3. Temp = Temp & AQueue.QueueArray(X).ToString() & " "

Visual Basic (VB.NET)

Function ReturnAllData(AQueue As Queue)
                        Dim Temp As String = ""
                        For X = AQueue.HeadPointer To AQueue.TailPointer - 1
                            Temp = Temp & AQueue.QueueArray(X).ToString() & " "
                        Next X
                        Return Temp
                  End Function

Mark points

  • Dim Temp As String = ""
  • For X = AQueue.HeadPointer To AQueue.TailPointer - 1
  • Temp = Temp & AQueue.QueueArray(X).ToString() & " "

Part 2(e)(i) — solution

  1. Taking only 10 inputs in loop/one at a time
  2. Calling Enqueue() with each input (min) and storing/using return value …
  3. … only calling Enqueue() once when each input is an integer  = 0. Do not award if this validation stops 10 valid
  4. Outputting message if each item is inserted and outputting a message if queue is full
  5. Calling ReturnAllData() and outputting return value at the end

Mark points

  • Taking only 10 inputs in loop/one at a time
  • Calling Enqueue() with each input (min) and storing/using return value …
  • … only calling Enqueue() once when each input is an integer  = 0. Do not award if this validation stops 10 valid
  • Outputting message if each item is inserted and outputting a message if queue is full
  • Calling ReturnAllData() and outputting return value at the end

Part 2(e)(i) — solution

  1. Continue = True
  2. while(Continue == True):
  3. DataInput = int(input("Enter an integer that is 0 or more"))
  4. Continue = False
  5. TheQueue, ReturnValue = Enqueue(TheQueue, DataInput)
  6. if(ReturnValue == -1):
  7. For x = 0 To 9
  8. ContinueLoop = True
  9. While ContinueLoop = True
  10. DataInput = Console.ReadLine
  11. ContinueLoop = False

Visual Basic (VB.NET)

Dim ContinueLoop As Boolean
                Dim DataInput As Integer
                Dim ReturnValue As Integer
                For x = 0 To 9
                    ContinueLoop = True
                    While ContinueLoop = True
                        Console.WriteLine("Enter an integer that is 0 or more")
                        DataInput = Console.ReadLine
                        If DataInput > -1 Then
                            ContinueLoop = False

 University Press & Assessment 2024                       Page 24 of 39

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Python

for x in range(0, 10):
                     Continue = True
                     while(Continue == True):
                         DataInput = int(input("Enter an integer that is 0 or more"))
                         if DataInput > -1:
                             Continue = False

                       TheQueue, ReturnValue = Enqueue(TheQueue, DataInput)

                       if(ReturnValue == -1):
                           print("Queue full")
                       else:
                           print("Item inserted")

                print(ReturnAllData(TheQueue))

Mark points

  • Continue = True
  • while(Continue == True):
  • DataInput = int(input("Enter an integer that is 0 or more"))
  • Continue = False
  • TheQueue, ReturnValue = Enqueue(TheQueue, DataInput)
  • if(ReturnValue == -1):
  • For x = 0 To 9
  • ContinueLoop = True
  • While ContinueLoop = True
  • DataInput = Console.ReadLine
  • ContinueLoop = False

Part 2(e)(i) — solution

  1. ReturnValue = Enqueue(TheQueue, DataInput)
  2. If ReturnValue = 2 Then

Mark points

  • ReturnValue = Enqueue(TheQueue, DataInput)
  • If ReturnValue = 2 Then

Part 2(e)(ii) — solution

  1. All values input and 10 messages ‘Inserted’ (i.e. –1 is not inserted)
  2. Screenshot show 10 9 8 7 6 5 4 3 2 1 on one line with a space between each number

Mark points

  • All values input and 10 messages ‘Inserted’ (i.e. –1 is not inserted)
  • Screenshot show 10 9 8 7 6 5 4 3 2 1 on one line with a space between each number

Part 2(f) — solution

  1. Function Dequeue() (head and close), returning a value in all cases
  2. Checking if empty and returning –1
  3. Returning item at HeadPointer without deleting/changing it
  4. Incrementing HeadPointer

Python

def Dequeue(AQueue):
                     if AQueue.HeadPointer = 100 or AQueue.HeadPointer == -1 or AQueue.HeadPointer ==
                AQueue.TailPointer:
                         return AQueue, -1
                     else:
                         Temp = AQueue.QueueArray[AQueue.HeadPointer]
                         AQueue.HeadPointer = AQueue.HeadPointer + 1
                         return AQueue, Temp

 University Press & Assessment 2024                       Page 26 of 39

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Mark points

  • Function Dequeue() (head and close), returning a value in all cases
  • Checking if empty and returning –1
  • Returning item at HeadPointer without deleting/changing it
  • Incrementing HeadPointer

Part 2(f) — solution

  1. If AQueue.HeadPointer = 100 or AQueue.HeadPointer = -1 or AQueue.HeadPointer =
  2. Dim Temp As Integer = AQueue.QueueArray(AQueue.HeadPointer)
  3. AQueue.HeadPointer += 1

Visual Basic (VB.NET)

Function Dequeue(ByRef AQueue As Queue)
                        If AQueue.HeadPointer = 100 or AQueue.HeadPointer = -1 or AQueue.HeadPointer =
                AQueue.TailPointer Then
                             Return -1
                        Else
                             Dim Temp As Integer = AQueue.QueueArray(AQueue.HeadPointer)
                             AQueue.HeadPointer += 1
                             Return Temp
                        End If
                  End Function

Mark points

  • If AQueue.HeadPointer = 100 or AQueue.HeadPointer = -1 or AQueue.HeadPointer =
  • Dim Temp As Integer = AQueue.QueueArray(AQueue.HeadPointer)
  • AQueue.HeadPointer += 1

Part 2(g)(i) — solution

  1. Calls Dequeue() twice and stores/uses return value
  2. Outputs "Queue empty" when each return values is –1 and outputs return value otherwise
  3. Calls ReturnAllData() at the end

Visual Basic (VB.NET)

ReturnValue = Dequeue(TheQueue)
                If ReturnValue = -1 Then
                     Console.WriteLine("Queue empty")
                Else
                     Console.WriteLine(ReturnValue, " is returned")
                End If

 University Press & Assessment 2024                       Page 28 of 39

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Python

TheQueue, ReturnValue = Dequeue(TheQueue)
                if ReturnValue == -1:
                     print("Queue empty")
                else:
                     print(ReturnValue, " is returned")
                TheQueue, ReturnValue = Dequeue(TheQueue)
                if ReturnValue == -1:
                     print("Queue empty")
                else:
                     print(ReturnValue, " is returned")
                print(ReturnAllData(TheQueue))

Mark points

  • Calls Dequeue() twice and stores/uses return value
  • Outputs "Queue empty" when each return values is –1 and outputs return value otherwise
  • Calls ReturnAllData() at the end

Part 2(g)(i) — solution

  1. ReturnValue = Dequeue(TheQueue)
  2. If ReturnValue = -1 Then

Mark points

  • ReturnValue = Dequeue(TheQueue)
  • If ReturnValue = -1 Then

Part 2(g)(ii) — solution

  1. Screenshot shows the input of 10 9 8 7 6 5 4 3 2 1

Mark points

  • Screenshot shows the input of 10 9 8 7 6 5 4 3 2 1

Question 3

Paper page 12 for Q3
Original paper page 12

Part 3(a) — solution

  1. HighScores created as 2D array, (of strings) with (min) 7  3 elements (local to main) …
  2. … all elements initialised to empty string ("")

Visual Basic (VB.NET)

Dim HighScores(7, 3) As String
                For(X = 0 to 7)
                    For(Y = 0 to 3)
                       HighScores(X, Y) = ""
                  Next Y
                Next X

Python

HighScores = [] #String, 7 x 3
                HighScores = [['' for x in range(3)] for y in range(7)]

Mark points

  • HighScores created as 2D array, (of strings) with (min) 7  3 elements (local to main) …
  • … all elements initialised to empty string ("")

Part 3(b) — solution

  1. Function header (and end where appropriate) that returns populated array
  2. Opening text file to read and closing the file in an appropriate place
  3. Looping through 7 players/to EOF/21 times …
  4. … reading in each group of 3 data items and storing each in separate element in 2D array for each player
  5. Exception handling with all file handling within the try, appropriate catch and an output

Mark points

  • Function header (and end where appropriate) that returns populated array
  • Opening text file to read and closing the file in an appropriate place
  • Looping through 7 players/to EOF/21 times …
  • … reading in each group of 3 data items and storing each in separate element in 2D array for each player
  • Exception handling with all file handling within the try, appropriate catch and an output

Part 3(b) — solution

  1. Temp = []
  2. HighScores = []
  3. File = open("HighScoreTable.txt")
  4. Temp = File.read().split("\n")
  5. NumberRecords = len(Temp)-1
  6. Counter = 0
  7. Counter = Counter + 3
  8. Dim TextFile As String = "HighScoreTable.txt"
  9. Dim Counter As Integer = 0

Visual Basic (VB.NET)

Function ReadData()
                        Dim TextFile As String = "HighScoreTable.txt"

                              Dim HighScores(7, 3) As String
                              Try
                                  Dim FileReader As New System.IO.StreamReader(TextFile)
                                  Dim Counter As Integer = 0

 University Press & Assessment 2024                       Page 32 of 39

9618/42                                            Cambridge International AS & A Level – Mark Scheme   October/November 2024

Python

def ReadData():
                     Temp = []
                     HighScores = []
                     try:
                          File = open("HighScoreTable.txt")
                          Temp = File.read().split("\n")
                          File.close()
                     except:
                          print("No file found")
                     NumberRecords = len(Temp)-1
                     Counter = 0

                       while Counter < NumberRecords:

                              HighScores.append([Temp[Counter], Temp[Counter+1], Temp[Counter+2]])
                              Counter = Counter + 3

                       return HighScores

Mark points

  • Temp = []
  • HighScores = []
  • File = open("HighScoreTable.txt")
  • Temp = File.read().split("\n")
  • NumberRecords = len(Temp)-1
  • Counter = 0
  • Counter = Counter + 3
  • Dim TextFile As String = "HighScoreTable.txt"
  • Dim Counter As Integer = 0

Part 3(b) — solution

  1. HighScores(Counter, 0) = FileReader.ReadLine()
  2. HighScores(Counter, 1) = FileReader.ReadLine()
  3. HighScores(Counter, 2) = FileReader.ReadLine()
  4. Counter = Counter + 1

Mark points

  • HighScores(Counter, 0) = FileReader.ReadLine()
  • HighScores(Counter, 1) = FileReader.ReadLine()
  • HighScores(Counter, 2) = FileReader.ReadLine()
  • Counter = Counter + 1

Part 3(b) — solution

  1. HighScores[X][0] = Reader.readLine();
  2. HighScores[X][1] = Reader.readLine();
  3. HighScores[X][2] = Reader.readLine();

Mark points

  • HighScores[X][0] = Reader.readLine();
  • HighScores[X][1] = Reader.readLine();
  • HighScores[X][2] = Reader.readLine();

Part 3(c) — solution

  1. Procedure (header and end) taking (min) 1 parameter (2D array), looping through each of the first dimension in array
  2. … outputting all data in correct format

Visual Basic (VB.NET)

Sub OutputHighScores(HighScores(,))
                        For x = 0 To 6
                             Console.WriteLine(HighScores(x, 0) & " reached level " & HighScores(x, 1) & "
                with a score of " & HighScores(x, 2))
                        Next
                  End Sub

 University Press & Assessment 2024                         Page 34 of 39

9618/42                                          Cambridge International AS & A Level – Mark Scheme               October/November 2024

Python

def OutputHighScores(HighScores):
                    for x in range(0, len(HighScores)):
                        print(HighScores[x][0], "reached level", HighScores[x][1], "with a score of",
                HighScores[x][2])

Mark points

  • Procedure (header and end) taking (min) 1 parameter (2D array), looping through each of the first dimension in array
  • … outputting all data in correct format

Part 3(c) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 3(d) — solution

  1. Function header (and end taking array as parameter) returning sorted array
  2. Comparing the levels and swapping all dimensions when in incorrect order
  3. Comparing scores when levels are the same and swapping all dimensions when in incorrect order
  4. Correct loops and comparisons to put data in correct order

Visual Basic (VB.NET)

Function SortScores(HighScores)
                        Dim ArrayLength As Integer = 6
                        Dim Temp1 As String

 University Press & Assessment 2024                       Page 35 of 39

9618/42                                            Cambridge International AS & A Level – Mark Scheme      October/November 2024

Python

def SortScores(HighScores):
                     Counter = 0
                     ArrayLength = len(HighScores)

                       for x in range(ArrayLength-1):
                           for y in range(0, ArrayLength-x-1):
                               if int(HighScores[y][1]) < int(HighScores[y + 1][1]):
                                   HighScores[y], HighScores[y + 1] = HighScores[y + 1], HighScores[y]
                               elif int(HighScores[y][1]) == int(HighScores[y+1][1]):
                                   if int(HighScores[y][2]) < int(HighScores[y+1][2]):
                                       HighScores[y], HighScores[y + 1] = HighScores[y + 1], HighScores[y]
                       return HighScores

Mark points

  • Function header (and end taking array as parameter) returning sorted array
  • Comparing the levels and swapping all dimensions when in incorrect order
  • Comparing scores when levels are the same and swapping all dimensions when in incorrect order
  • Correct loops and comparisons to put data in correct order

Part 3(d) — solution

  1. For x = 0 To ArrayLength - 1
  2. For y = 0 To ArrayLength - x - 1
  3. Temp1 = HighScores(y, 0)
  4. Temp2 = HighScores(y, 1)
  5. Temp3 = HighScores(y, 2)
  6. HighScores(y, 0) = HighScores(y + 1, 0)
  7. HighScores(y, 1) = HighScores(y + 1, 1)
  8. HighScores(y, 2) = HighScores(y + 1, 2)
  9. HighScores(y + 1, 0) = Temp1
  10. HighScores(y + 1, 1) = Temp2
  11. HighScores(y + 1, 2) = Temp3
  12. ElseIf Integer.Parse(HighScores(y, 1)) = Integer.Parse(HighScores(y + 1,
  13. Temp1 = HighScores(y, 0)
  14. Temp2 = HighScores(y, 1)
  15. Temp3 = HighScores(y, 2)
  16. HighScores(y, 0) = HighScores(y + 1, 0)
  17. HighScores(y, 1) = HighScores(y + 1, 1)
  18. HighScores(y, 2) = HighScores(y + 1, 2)
  19. HighScores(y + 1, 0) = Temp1
  20. HighScores(y + 1, 1) = Temp2

Mark points

  • For x = 0 To ArrayLength - 1
  • For y = 0 To ArrayLength - x - 1
  • Temp1 = HighScores(y, 0)
  • Temp2 = HighScores(y, 1)
  • Temp3 = HighScores(y, 2)
  • HighScores(y, 0) = HighScores(y + 1, 0)
  • HighScores(y, 1) = HighScores(y + 1, 1)
  • HighScores(y, 2) = HighScores(y + 1, 2)
  • HighScores(y + 1, 0) = Temp1
  • HighScores(y + 1, 1) = Temp2
  • HighScores(y + 1, 2) = Temp3
  • ElseIf Integer.Parse(HighScores(y, 1)) = Integer.Parse(HighScores(y + 1,
  • Temp1 = HighScores(y, 0)
  • Temp2 = HighScores(y, 1)
  • Temp3 = HighScores(y, 2)
  • HighScores(y, 0) = HighScores(y + 1, 0)
  • HighScores(y, 1) = HighScores(y + 1, 1)
  • HighScores(y, 2) = HighScores(y + 1, 2)
  • HighScores(y + 1, 0) = Temp1
  • HighScores(y + 1, 1) = Temp2

Part 3(d) — solution

  1. Integer ArrayLength = 6;
  2. for(Integer x = 0; x < ArrayLength; x++){
  3. for(Integer y = 0; y < ArrayLength - x; y++){
  4. Temp1 = HighScores[y][0];
  5. Temp2 = HighScores[y][1];
  6. Temp3 = HighScores[y][2];
  7. HighScores[y][0] = HighScores[y+1][0];
  8. HighScores[y][1] = HighScores[y+1][1];
  9. HighScores[y][2] = HighScores[y+1][2];
  10. HighScores[y+1][0] = Temp1;
  11. HighScores[y+1][1] = Temp2;
  12. HighScores[y+1][2] = Temp3;
  13. }else if(Integer.parseInt(HighScores[y][1]) ==
  14. Temp1 = HighScores[y][0];
  15. Temp2 = HighScores[y][1];
  16. Temp3 = HighScores[y][2];
  17. HighScores[y][0] = HighScores[y+1][0];
  18. HighScores[y][1] = HighScores[y+1][1];
  19. HighScores[y][2] = HighScores[y+1][2];
  20. HighScores[y+1][0] = Temp1;

Mark points

  • Integer ArrayLength = 6;
  • for(Integer x = 0; x < ArrayLength; x++){
  • for(Integer y = 0; y < ArrayLength - x; y++){
  • Temp1 = HighScores[y][0];
  • Temp2 = HighScores[y][1];
  • Temp3 = HighScores[y][2];
  • HighScores[y][0] = HighScores[y+1][0];
  • HighScores[y][1] = HighScores[y+1][1];
  • HighScores[y][2] = HighScores[y+1][2];
  • HighScores[y+1][0] = Temp1;
  • HighScores[y+1][1] = Temp2;
  • HighScores[y+1][2] = Temp3;
  • }else if(Integer.parseInt(HighScores[y][1]) ==
  • Temp1 = HighScores[y][0];
  • Temp2 = HighScores[y][1];
  • Temp3 = HighScores[y][2];
  • HighScores[y][0] = HighScores[y+1][0];
  • HighScores[y][1] = HighScores[y+1][1];
  • HighScores[y][2] = HighScores[y+1][2];
  • HighScores[y+1][0] = Temp1;

Part 3(d) — solution

} } return HighScores; }

Mark points

  • Include the ideas shown in the solution above.

Part 3(e)(i) — solution

  1. Code statements in order:
  2. Code statements in order:

Visual Basic (VB.NET)

Sub Main(args As String())
                        Dim HighScores(7, 3) As String
                        HighScores = ReadData()
                        Console.WriteLine("Before")
                        OutputHighScores(HighScores)
                        HighScores = SortScores(HighScores)
                        Console.WriteLine("After")
                        OutputHighScores(HighScores)
                  End Sub

 University Press & Assessment 2024                       Page 38 of 39

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Python

HighScores = []
                HighScores = ReadData()
                print("Before")
                OutputHighScores(HighScores)
                HighScores = SortScores(HighScores)
                print("After")
                OutputHighScores(HighScores)

Mark points

  • Code statements in order:
  • Code statements in order:

Part 3(e)(i) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 3(e)(ii) — solution

Output showing ‘Before’ and players and scores in correct format before sorting 2 Output showing ‘After’ players and scores in correct order and format after sorting e.g. University Press & Assessment 2024 Page 39 of 39

Mark points

  • Include the ideas shown in the solution above.