9618/43 · May/June 2022 · 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) — solution

  1. declaration of at least 1 array with appropriate identifier
  2. … 11 elements (and appropriate data type(s))

Visual Basic (VB.NET)

Dim FileData(0 To 9, 0 To 1) As String

Python

FileData = [[""] *2 for i in range(11)] #string

 2022                                                            Page 4 of 34

9618/43                                          Cambridge International AS & A Level – Mark Scheme   May/June 2022

Mark points

  • declaration of at least 1 array with appropriate identifier
  • … 11 elements (and appropriate data type(s))

Part 1(b) — solution

  1. procedure declaration (and end)
  2. Opening the text file (to read)
  3. Looping 10 times // looping until end of file (e.g. 10 pairs of data)
  4. Reading in each pair of lines …
  5. … storing player name and score in data structure(s)
  6. closing the file
  7. Try and catch on file handling …
  8. … with suitable output

Mark points

  • procedure declaration (and end)
  • Opening the text file (to read)
  • Looping 10 times // looping until end of file (e.g. 10 pairs of data)
  • Reading in each pair of lines …
  • … storing player name and score in data structure(s)
  • closing the file
  • Try and catch on file handling …
  • … with suitable output

Part 1(b) — solution

  1. Filename = "HighScore.txt"
  2. File = open(Filename, 'r')
  3. FileData[x][0] = File.readline()[:3]
  4. FileData[x][1] = File.readline()
  5. Dim Textfile As String = "HighScore.txt"
  6. Dim DataEntered As Integer = 0
  7. FileData(DataEntered, 0) = FileReader.ReadLine()
  8. FileData(DataEntered, 1) = FileReader.ReadLine()
  9. DataEntered = DataEntered + 1

Visual Basic (VB.NET)

Sub ReadHighScores()
                 Dim Textfile As String = "HighScore.txt"
                 Dim FileReader As New System.IO.StreamReader(textfile)
                 Dim DataEntered As Integer = 0
                 While FileReader.Peek <> -1 and DataEntered < 10
                   FileData(DataEntered, 0) = FileReader.ReadLine()
                   FileData(DataEntered, 1) = FileReader.ReadLine()
                   DataEntered = DataEntered + 1
                 End While
                 FileReader.Close()
               End Sub

 2022                                               Page 6 of 34

9618/43                                       Cambridge International AS & A Level – Mark Scheme   May/June 2022

Python

def ReadHighScores():
                 Filename = "HighScore.txt"
                 File = open(Filename, 'r')
                 for x in range(0, 10):
                      FileData[x][0] = File.readline()[:3]
                      FileData[x][1] = File.readline()
                File.close

Mark points

  • Filename = "HighScore.txt"
  • File = open(Filename, 'r')
  • FileData[x][0] = File.readline()[:3]
  • FileData[x][1] = File.readline()
  • Dim Textfile As String = "HighScore.txt"
  • Dim DataEntered As Integer = 0
  • FileData(DataEntered, 0) = FileReader.ReadLine()
  • FileData(DataEntered, 1) = FileReader.ReadLine()
  • DataEntered = DataEntered + 1

Part 1(c) — solution

  1. procedure heading and end
  2. looping through all data structure elements
  3. outputting player name, space, score. Each player must start on a new line

Visual Basic (VB.NET)

Sub OutputHighScores ()
                 For x = 0 To 10
                   Console.WriteLine(FileData(x, 0) & " " & FileData(x,1))
                 Next
               End Sub

 2022                                                        Page 7 of 34

9618/43                                   Cambridge International AS & A Level – Mark Scheme   May/June 2022

Python

def OutputHighScores ():
                  for x in range(0, 11):
                      Output = FileData[x][0] + " " + FileData[x][1]
                      print(Output)

Mark points

  • procedure heading and end
  • looping through all data structure elements
  • outputting player name, space, score. Each player must start on a new line

Part 1(d)(i) — solution

  1. (Main program) calls ReadHighScores()
  2. … then calls OutputHighScores()

Visual Basic (VB.NET)

Sub Main()
                 ReadHighScores()
                 OutputHighScore()
                 Console.ReadLine()
               End Sub

 2022                                                  Page 8 of 34

9618/43                                       Cambridge International AS & A Level – Mark Scheme                                   May/June 2022

Python

ReadHighScores()
               OutputHighScore()

Mark points

  • (Main program) calls ReadHighScores()
  • … then calls OutputHighScores()

Part 1(d)(ii) — solution

1 mark for screenshot showing the 10 names and scores from the file (and one extra blank space may, or may not be 1 included) e.g. 2022 Page 9 of 34 9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2022

Mark points

  • Include the ideas shown in the solution above.

Part 1(e)(i) — solution

  1. Read in a username and score
  2. Validate username input (3-characters, or just selecting the first 3 characters if there are definitely 3 characters)
  3. Validate score input (integer (cast) between 1 and 100 000 inclusive)

Python

Username = "ABCD"
               while len(Username) != 3:
                   Username = input("Enter your Username")

               score = -1
               while Score < 1 or Score > 100000:
                   Score = int(input("Enter score"))

 2022                                                           Page 10 of 34

9618/43                                Cambridge International AS & A Level – Mark Scheme   May/June 2022

Mark points

  • Read in a username and score
  • Validate username input (3-characters, or just selecting the first 3 characters if there are definitely 3 characters)
  • Validate score input (integer (cast) between 1 and 100 000 inclusive)

Part 1(e)(i) — solution

  1. Username = "ABCD"
  2. Username = Console.ReadLine()
  3. Score = -1
  4. Score = Console.ReadLine()

Visual Basic (VB.NET)

Console.WriteLine("Enter Username")
               Username = "ABCD"
               While Username.length <> 3
                 Username = Console.ReadLine()
               End While
               Score = -1
               While Score < 1 Or Score > 100000
                 Console.WriteLine("Enter score")
                 Score = Console.ReadLine()
               End While

 2022                                               Page 11 of 34

9618/43                                       Cambridge International AS & A Level – Mark Scheme               May/June 2022

Mark points

  • Username = "ABCD"
  • Username = Console.ReadLine()
  • Score = -1
  • Score = Console.ReadLine()

Part 1(e)(ii) — solution

  1. procedure declaration (and close where appropriate) taking 1 string and 1 integer parameter
  2. looping through each array element
  3. … finding the position to input the score
  4. storing the array data in the correct position
  5. storing the name and score in the correct position

Mark points

  • procedure declaration (and close where appropriate) taking 1 string and 1 integer parameter
  • looping through each array element
  • … finding the position to input the score
  • storing the array data in the correct position
  • storing the name and score in the correct position

Part 1(e)(ii) — solution

  1. Temp1 = FileData[x][0]
  2. Temp2 = FileData[x][1]
  3. FileData[x][0] = Username
  4. FileData[x][1] = Score
  5. Count = x+1
  6. Second1 = FileData[Count][0]
  7. Second2 = FileData[Count][1]
  8. FileData[Count][0] = Temp1
  9. FileData[Count][1] = Temp2
  10. Temp1 = Second1
  11. Temp2 = Second2
  12. Count = Count + 1

Python

def Arrange(Username, Score):
                   for x in range(0, 10):
                       if Score > FileData[x][1]:
                           Temp1 = FileData[x][0]
                           Temp2 = FileData[x][1]
                           FileData[x][0] = Username
                           FileData[x][1] = Score
                           Count = x+1
                           while(Count < 10):
                               Second1 = FileData[Count][0]
                               Second2 = FileData[Count][1]
                               FileData[Count][0] = Temp1
                               FileData[Count][1] = Temp2

                               Temp1 = Second1
                               Temp2 = Second2
                               Count = Count + 1
                               break;

 2022                                               Page 13 of 34

9618/43                                 Cambridge International AS & A Level – Mark Scheme   May/June 2022

Mark points

  • Temp1 = FileData[x][0]
  • Temp2 = FileData[x][1]
  • FileData[x][0] = Username
  • FileData[x][1] = Score
  • Count = x+1
  • Second1 = FileData[Count][0]
  • Second2 = FileData[Count][1]
  • FileData[Count][0] = Temp1
  • FileData[Count][1] = Temp2
  • Temp1 = Second1
  • Temp2 = Second2
  • Count = Count + 1

Part 1(e)(ii) — solution

  1. For x = 0 To 9
  2. Temp1 = FileData(x, 0)
  3. Temp2 = FileData(x, 1)
  4. FileData(x, 0) = Username
  5. FileData(x, 1) = Score.ToString
  6. For Count = x + 1 To 9
  7. Second1 = FileData(Count, 0)
  8. Second2 = FileData(Count, 1)
  9. FileData(Count, 0) = Temp1
  10. FileData(Count, 1) = Temp2
  11. Temp1 = Second1
  12. Temp2 = Second2
  13. x = 10

Visual Basic (VB.NET)

Sub Arrange(Username, Score)
                 Dim Temp1 As String
                 Dim Temp2 As String
                 Dim Second1 As String
                 Dim Second2 As String
                 For x = 0 To 9
                   If Score > Integer.Parse(FileData(x, 1)) Then
                     Temp1 = FileData(x, 0)
                     Temp2 = FileData(x, 1)

                      FileData(x, 0) = Username
                      FileData(x, 1) = Score.ToString
                      For Count = x + 1 To 9
                        Second1 = FileData(Count, 0)
                        Second2 = FileData(Count, 1)
                        FileData(Count, 0) = Temp1
                        FileData(Count, 1) = Temp2
                        Temp1 = Second1
                        Temp2 = Second2
                        x = 10
                      Next
                   End If
                 Next
               End Sub

 2022                                                Page 14 of 34

9618/43                                       Cambridge International AS & A Level – Mark Scheme   May/June 2022

Mark points

  • For x = 0 To 9
  • Temp1 = FileData(x, 0)
  • Temp2 = FileData(x, 1)
  • FileData(x, 0) = Username
  • FileData(x, 1) = Score.ToString
  • For Count = x + 1 To 9
  • Second1 = FileData(Count, 0)
  • Second2 = FileData(Count, 1)
  • FileData(Count, 0) = Temp1
  • FileData(Count, 1) = Temp2
  • Temp1 = Second1
  • Temp2 = Second2
  • x = 10

Part 1(e)(iii) — solution

  1. Calling sorting procedure with correct parameters
  2. Outputting the array before and after procedure call

Python

ReadHighScores()
               OutputHighScore()
               Username = input("Enter your Username")
               Score = -1
               while Score < 0 or Score > 100000:
                   Score = int(input("Enter score"))
               Arrange(Username, Score)
               OutputHighScore()

 2022                                                        Page 15 of 34

9618/43                                        Cambridge International AS & A Level – Mark Scheme   May/June 2022

Mark points

  • Calling sorting procedure with correct parameters
  • Outputting the array before and after procedure call

Part 1(e)(iii) — solution

  1. Username = Console.ReadLine()
  2. Score = -1
  3. Score = Console.ReadLine()

Visual Basic (VB.NET)

OutputHighScore()
               Username = Console.ReadLine()
               Score = -1
               While(score < 0 or Score > 100000)
                   Score = Console.ReadLine()
               End While
               Arrange(Username, Score)
               OutputHighScore()

Mark points

  • Username = Console.ReadLine()
  • Score = -1
  • Score = Console.ReadLine()

Part 1(e)(iv) — solution

1 mark for screenshot. JKL, 9999 entered. After shows JKL in the second position. 1 e.g. 2022 Page 16 of 34 9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2022

Mark points

  • Include the ideas shown in the solution above.

Part 1(f) — solution

  1. procedure header and end (where appropriate) and opening the file NewHighScore.txt to write
  2. Closing the file
  3. Looping through all 10 array values …
  4. … writing the username, then the score
  5. Exception handling and appropriate output

Python

def WriteTopTen():
                   Filename = " NewHighScore.txt"
                   Filename = open(Filename, 'w')
                   for x in range(0, 10):
                       Filename.write(str(FileData[x][0]) + '\n')
                       Filename.write(str(FileData[x][1]) + '\n')
                       Filename.close

 2022                                                     Page 17 of 34

9618/43                                Cambridge International AS & A Level – Mark Scheme   May/June 2022

Mark points

  • procedure header and end (where appropriate) and opening the file NewHighScore.txt to write
  • Closing the file
  • Looping through all 10 array values …
  • … writing the username, then the score
  • Exception handling and appropriate output

Part 1(f) — solution

  1. Dim Filename As String = " NewHighScore.txt"
  2. For x = 0 To 9

Visual Basic (VB.NET)

Sub WriteTopTen()
                 Dim Filename As String = " NewHighScore.txt"
                 Dim NewFile As New System.IO.StreamWriter(Filename)
                 For x = 0 To 9
                   NewFile.WriteLine(FileData(x, 0))
                   NewFile.WriteLine(FileData(x, 1))
                 Next
                 NewFile.Close()
               End Sub

 2022                                               Page 18 of 34

9618/43                                         Cambridge International AS & A Level – Mark Scheme   May/June 2022

Mark points

  • Dim Filename As String = " NewHighScore.txt"
  • For x = 0 To 9

Part 1 — solution

mark for function heading and end, dealing with ByRef

Mark points

  • Include the ideas shown in the solution above.

Part 1 — solution

  1. IF NumberItems = 10 THEN
  2. IF TailPointer >= 9 THEN

Mark points

  • IF NumberItems = 10 THEN
  • IF TailPointer >= 9 THEN

Question 2

Paper page 5 for Q2
Original paper page 5

Part 2(a) — solution

  1. Class Balloon declaration (and end where appropriate)
  2. declaration of 3 attributes as private with suitable data types
  3. constructor header (and end) with two parameters …
  4. … initialising colour and defence item to parameters
  5. … initialising health to 100

Python

class Balloon:
               #Health as integer
               #Colour as string
               #DefenceItem as string
               def __init__(self, PDefenceItem, PColour):
                   self.__Health = 100
                   self.__Colour = PColour
                   self.__DefenceItem = PDefenceItem

 2022                                                          Page 19 of 34

9618/43                                     Cambridge International AS & A Level – Mark Scheme   May/June 2022

Mark points

  • Class Balloon declaration (and end where appropriate)
  • declaration of 3 attributes as private with suitable data types
  • constructor header (and end) with two parameters …
  • … initialising colour and defence item to parameters
  • … initialising health to 100

Part 2(a) — solution

  1. Health = 100
  2. Colour = PColour
  3. DefenceItem = PDefenceItem

Visual Basic (VB.NET)

Class balloon
                 Private Health As Integer
                 Private Colour As String
                 Private DefenceItem As String

                 Public Sub New(PDefenceItem, PColour)
                   Health = 100
                   Colour = PColour
                   DefenceItem = PDefenceItem
                 End Sub
               End Class

Mark points

  • Health = 100
  • Colour = PColour
  • DefenceItem = PDefenceItem

Part 2(b) — solution

  1. get header and close with no parameter …
  2. … returning defence item attribute

Visual Basic (VB.NET)

Public Function GetDefenceItem()
                 Return DefenceItem
               End Function

 2022                                                    Page 20 of 34

9618/43                                     Cambridge International AS & A Level – Mark Scheme   May/June 2022

Python

def GetDefenceItem(self):
                   return self.__DefenceItem

Mark points

  • get header and close with no parameter …
  • … returning defence item attribute

Part 2(c) — solution

  1. procedure header and close taking 1 parameter …
  2. … adding parameter value to health attribute

Visual Basic (VB.NET)

Public Sub ChangeHealth(Change)
                 Health = Health + Change
               End Sub

 2022                                                       Page 21 of 34

9618/43                                       Cambridge International AS & A Level – Mark Scheme   May/June 2022

Python

def ChangeHealth(self, Change):
                   self.__Health = self.__Health + Change

Mark points

  • procedure header and close taking 1 parameter …
  • … adding parameter value to health attribute

Part 2(d) — solution

  1. method header and close and checking if health attribute is <= 0
  2. Returning TRUE if health attribute <= 0 and returning FALSE otherwise

Visual Basic (VB.NET)

Function CheckHealth()
                 If Health <= 0 Then
                   Return True
                 Else
                   Return False
                 End If
               End Function

 2022                                                       Page 22 of 34

9618/43                                       Cambridge International AS & A Level – Mark Scheme   May/June 2022

Python

def CheckHealth(self):
                   if self.__Health <= 0:
                      return True
                   else:
                      return False

Mark points

  • method header and close and checking if health attribute is <= 0
  • Returning TRUE if health attribute <= 0 and returning FALSE otherwise

Part 2(e) — solution

  1. take as input defence method and colour (2 strings)
  2. instantiating new balloon object with identifier Balloon1 …
  3. … with both input values as parameters

Visual Basic (VB.NET)

Sub Main()
                 Console.WriteLine("Enter balloon defence method")
                 Dim Method As String = Console.ReadLine
                 Console.WriteLine("Enter the balloons colour")
                 Dim Colour As String = Console.ReadLine
                 Dim Balloon1 As Balloon = New Balloon(Method, Colour)
               End Sub

 2022                                                       Page 23 of 34

9618/43                                       Cambridge International AS & A Level – Mark Scheme      May/June 2022

Python

Method = input("Enter balloon defence method ")
               Colour = input("Enter the balloon colour ")
               Balloon1 = Balloon(Method, Colour)

Mark points

  • take as input defence method and colour (2 strings)
  • instantiating new balloon object with identifier Balloon1 …
  • … with both input values as parameters

Part 2(f) — solution

  1. function header (and end where appropriate) and taking balloon object as parameter
  2. Inputting strength
  3. Calling ChangeHealth method for the parameter object …
  4. … with the input as a subtraction
  5. outputting the defence item for the parameter object …
  6. … using GetDefenceItem()
  7. Calling CheckHealth()for the parameter object …
  8. … outputting appropriate message if TRUE is returned (no health remaining)
  9. … outputting appropriate message if FALSE is returned (health remaining)
  10. Returning the updated balloon object

Mark points

  • function header (and end where appropriate) and taking balloon object as parameter
  • Inputting strength
  • Calling ChangeHealth method for the parameter object …
  • … with the input as a subtraction
  • outputting the defence item for the parameter object …
  • … using GetDefenceItem()
  • Calling CheckHealth()for the parameter object …
  • … outputting appropriate message if TRUE is returned (no health remaining)
  • … outputting appropriate message if FALSE is returned (health remaining)
  • Returning the updated balloon object

Part 2(f) — solution

  1. Strength = int(input("Enter the strength of opponent"))
  2. if(MyBalloon.CheckHealth() == True):
  3. Dim Strength As Integer = Console.ReadLine
  4. If (MyBalloon.CheckHealth() = True) Then

Visual Basic (VB.NET)

Function Defend(MyBalloon)
                 Console.WriteLine("Enter the strength of opponent")
                 Dim Strength As Integer = Console.ReadLine
                 MyBalloon.ChangeHealth(-Strength)
                 Console.WriteLine("You defended with " & MyBalloon.GetDefenceItem)
                 If (MyBalloon.CheckHealth() = True) Then
                   Console.WriteLine("Defence failed")
                 Else
                   Console.WriteLine("Defence succeeded")
                 End If
                 Return MyBalloon
               End Function

 2022                                               Page 25 of 34

9618/43                                        Cambridge International AS & A Level – Mark Scheme   May/June 2022

Python

def Defend(MyBalloon):
                   Strength = int(input("Enter the strength of opponent"))
                   MyBalloon.VhangeHealth(-Strength)
                   print("You defended with ", str(MyBalloon.GetDefenceItem()))
                   if(MyBalloon.CheckHealth() == True):
                       print("Defence failed")
                   else:
                       print("Defence succeeded")
                   return MyBalloon

Mark points

  • Strength = int(input("Enter the strength of opponent"))
  • if(MyBalloon.CheckHealth() == True):
  • Dim Strength As Integer = Console.ReadLine
  • If (MyBalloon.CheckHealth() = True) Then

Part 2(g)(i) — solution

  1. calling Defend with balloon object …
  2. … and stores return value over object

Visual Basic (VB.NET)

Balloon1 = Defend(Balloon1)

Python

Balloon1 = Defend(Balloon1)

Mark points

  • calling Defend with balloon object …
  • … and stores return value over object

Part 2(g)(ii) — solution

1 mark for screenshot with: 1 Shield, Red and 50 input Output stating their defence item was Shield Output says health is not 0 (in some manner) e.g. 2022 Page 26 of 34 9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2022

Mark points

  • Include the ideas shown in the solution above.

Question 3

Paper page 8 for Q3
Original paper page 8

Part 3(a) — solution

  1. Declaring variables: head pointer, tail pointer and number of items all initialised as 0 (integer)
  2. QueueArray declared as 1D array as string with 10 elements

Visual Basic (VB.NET)

Sub Main()
                Dim QueueArray(0 To 9) As String
                Dim QueueHeadPointer As Integer = 0
                Dim QueueTailPointer As Integer = 0
                Dim NumberOfItems As Integer = 0
               End Sub

 2022                                                           Page 27 of 34

9618/43                                         Cambridge International AS & A Level – Mark Scheme    May/June 2022

Python

QueueArray = ['','','','','','','','','',''] #string
               QueueHeadPointer = 0 #integer
               QueueTailPointer = 0 #integer
               NumberOfItems = 0 #integer

Mark points

  • Declaring variables: head pointer, tail pointer and number of items all initialised as 0 (integer)
  • QueueArray declared as 1D array as string with 10 elements

Part 3(b) — solution

1 mark per complete statement (5) 7

Mark points

  • Include the ideas shown in the solution above.

Part 3(b) — solution

  1. if NumItems >= 10:
  2. Queue[Tail] = InputData
  3. if Tail >= 9:
  4. Tail = 0
  5. Tail = Tail + 1
  6. NumItems = NumItems + 1
  7. If NumItems = 10 Then
  8. Queue(Tail) = InputData
  9. If Tail >= 9 Then
  10. Tail = 0
  11. Tail = Tail + 1

Visual Basic (VB.NET)

Function Enqueue(ByRef Queue() As String, ByRef Head As Integer, ByRef Tail As Integer,
                        ByRef NumItems As Integer, ByRef InputData As String)
                 If NumItems = 10 Then
                   Return False
                 End If
                 Queue(Tail) = InputData
                 If Tail >= 9 Then
                   Tail = 0
                 Else
                   Tail = Tail + 1

 2022                                               Page 29 of 34

9618/43                                        Cambridge International AS & A Level – Mark Scheme   May/June 2022

Python

def Enqueue(Queue, Head, Tail, NumItems, InputData):
                   if NumItems >= 10:
                       return (False, Queue, Head, Tail, NumItems)
                   Queue[Tail] = InputData
                   if Tail >= 9:
                       Tail = 0
                   else:
                       Tail = Tail + 1
                   NumItems = NumItems + 1
                   return (True, Queue, Head, Tail, NumItems)

Mark points

  • if NumItems >= 10:
  • Queue[Tail] = InputData
  • if Tail >= 9:
  • Tail = 0
  • Tail = Tail + 1
  • NumItems = NumItems + 1
  • If NumItems = 10 Then
  • Queue(Tail) = InputData
  • If Tail >= 9 Then
  • Tail = 0
  • Tail = Tail + 1

Part 3(c) — solution

  1. Function header and end
  2. checking if queue is empty …
  3. … returning False
  4. If not empty accessing and returning item at head pointer
  5. … incrementing head pointer …
  6. … changing head pointer to 0 if it's more than 9 after incrementing
  7. … decrement number of items

Python

def Dequeue(Queue, Head, Tail, NumItems):
                   if NumItems == 0:
                       return (false, Queue, Head, Tail, NumItems)
                   else:
                       ReturnValue = Queue(Head)
                       Head = Head + 1
                       if Head >= 9:
                           Head = 0
                       NumItems = NumItems - 1
                       return(ReturnValue, Queue, Head, Tail, NumItems)

 2022                                                        Page 30 of 34

9618/43                                Cambridge International AS & A Level – Mark Scheme                May/June 2022

Mark points

  • Function header and end
  • checking if queue is empty …
  • … returning False
  • If not empty accessing and returning item at head pointer
  • … incrementing head pointer …
  • … changing head pointer to 0 if it's more than 9 after incrementing
  • … decrement number of items

Part 3(c) — solution

  1. If NumberOfItems = 0 Then
  2. Dim ReturnValue = QueueArray(QueueHeadPointer)
  3. QueueHeadPointer = QueueHeadPointer + 1
  4. If QueueHeadPointer >= 9 Then
  5. QueueHeadPointer = 0
  6. NumberOfItems = NumberOfItems - 1

Visual Basic (VB.NET)

Function Dequeue(ByRef QueueArray() As String, ByRef QueueHeadPointer As Integer, ByRef
               QueueTailpointer As Integer, ByRef NumberOfItems As Integer)

                 If NumberOfItems = 0 Then
                   Return "False"
                 Else
                   Dim ReturnValue = QueueArray(QueueHeadPointer)
                   QueueHeadPointer = QueueHeadPointer + 1
                   If QueueHeadPointer >= 9 Then
                      QueueHeadPointer = 0
                   End If
                   NumberOfItems = NumberOfItems - 1
                   Return ReturnValue
                 End If

               End Function

 2022                                               Page 31 of 34

9618/43                                       Cambridge International AS & A Level – Mark Scheme   May/June 2022

Mark points

  • If NumberOfItems = 0 Then
  • Dim ReturnValue = QueueArray(QueueHeadPointer)
  • QueueHeadPointer = QueueHeadPointer + 1
  • If QueueHeadPointer >= 9 Then
  • QueueHeadPointer = 0
  • NumberOfItems = NumberOfItems - 1

Part 3(d)(i) — solution

  1. Taking 11 inputs…
  2. … calling Enqueue with each of the 11 inputs …
  3. … outputting an appropriate message if added or not added
  4. Calling Dequeue twice …
  5. … outputting return value each time

Mark points

  • Taking 11 inputs…
  • … calling Enqueue with each of the 11 inputs …
  • … outputting an appropriate message if added or not added
  • Calling Dequeue twice …
  • … outputting return value each time

Part 3(d)(i) — solution

  1. InputString = input("Enter a string")
  2. ReturnValue, QueueArray, QueueHeadPointer, QueueTailPointer, NumberOfItems =
  3. if ReturnValue == True:
  4. ReturnValue, QueueArray, QueueHeadPointer, QueueTailPointer, NumberOfItems =
  5. ReturnValue, QueueArray, QueueHeadPointer, QueueTailPointer, NumberOfItems =
  6. For x = 0 To 10
  7. InputString = Console.ReadLine

Visual Basic (VB.NET)

For x = 0 To 10
                Console.WriteLine("Enter a string")
                InputString = Console.ReadLine
                If(Enqueue(QueueArray, QueueHeadPointer, QueueTailPointer, NumberOfItems, InputString))
               Then
                  Console.WriteLine("Successful")
                Else
                  Console.WriteLine("Unsuccessful")
                End If
               Next
               Console.WriteLine(Dequeue)
               Console.WriteLine(Dequeue)

 2022                                               Page 33 of 34

9618/43                                        Cambridge International AS & A Level – Mark Scheme   May/June 2022

Python

for x in range(0, 11):
                    InputString = input("Enter a string")
                    ReturnValue, QueueArray, QueueHeadPointer, QueueTailPointer, NumberOfItems =
                     Enqueue(QueueArray, QueueHeadPointer, QueueTailPointer, NumberOfItems, InputString)
                    if ReturnValue == True:
                        print("Successful")
                    else:
                        print("Unsuccessful")
               ReturnValue, QueueArray, QueueHeadPointer, QueueTailPointer, NumberOfItems =
                 Dequeue(QueueArray, QueueHeadPointer, QueueTailPointer, NumberOfItems)
               print(ReturnValue)
               ReturnValue, QueueArray, QueueHeadPointer, QueueTailPointer, NumberOfItems =
                 Dequeue(QueueArray, QueueHeadPointer, QueueTailPointer, NumberOfItems)
               print(ReturnValue)

Mark points

  • InputString = input("Enter a string")
  • ReturnValue, QueueArray, QueueHeadPointer, QueueTailPointer, NumberOfItems =
  • if ReturnValue == True:
  • ReturnValue, QueueArray, QueueHeadPointer, QueueTailPointer, NumberOfItems =
  • ReturnValue, QueueArray, QueueHeadPointer, QueueTailPointer, NumberOfItems =
  • For x = 0 To 10
  • InputString = Console.ReadLine

Part 3(d)(ii) — solution

1 mark for showing inputs and outputs: 1 A – J input and successful. K input and unsuccessful. Output: A, B e.g. 2022 Page 34 of 34

Mark points

  • Include the ideas shown in the solution above.