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












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


































Questions as text
Q1 · The text file HighScore.txt stores the players who have scored the top ten scores in a…
1 The text file HighScore.txt stores the players who have scored the top ten scores in a game, in descending order of score. The file stores the 3-character name of the player, and their integer score, in the order: player, score. For example, the current top player in the text file: FYI is the player name 10 000 is the score The program: • reads in the data from HighScore.txt • allows the user to enter a new player name and their score • if appropriate, inserts the new player (name and score) into the top ten • writes the top ten players (name and score) into a new text file NewHighScore.txt (a) The program stores the players and their scores in an array of 11 elements (10 elements to be read from the file, 1 element to be inserted by the user). Write a program to declare one or more arrays, as global data structures, to store the player names and their scores. Save your program as Question1_J2022. Copy and paste the program code into part 1(a) in the evidence document. [2] (b) The procedure ReadHighScores() opens the file HighScore.txt and reads the data into the data structure(s) declared in part 1(a). Write program code to declare the procedure ReadHighScores(). Save your program. Copy and paste the program code into part 1(b) in the evidence document. [6] (c) The procedure OutputHighScores() outputs all the values in the data structure(s) in the format: PlayerName Score For example, the first two data items: FYI 10 000 ABC 9 092 Write program code to declare the procedure OutputHighScores(). Save your program. Copy and paste the program code into part 1(c) in the evidence document. [3] (d) The main program should first call ReadHighScores() and then OutputHighScores(). (i) Write the program code for the main program. Save your program. Copy and paste the program code into part 1(d)(i) in the evidence document. [2] (ii) Test your program. Take a screenshot to show the output from part 1(d)(i). Copy and paste the screenshot into part 1(d)(ii) in the evidence document. [1] (e) The main program needs to ask the user to input a new player name and a score. If this score is in the top ten then it will create a new top ten list that includes this score. (i) Amend the main program to ask the user to input a 3-character player name and an integer score that must be between 1 and 100 000 inclusive. Save your program. Copy and paste the program code into part 1(e)(i) in the evidence document. [3] (ii) Write program code to declare a procedure that: • takes the player name and score as parameters • creates a new top ten list that includes the parameter if appropriate. Save your program. Copy and paste the program code into part 1(e)(ii) in the evidence document. [5] (iii) Amend the main program to call the procedure from part 1(e)(ii). Output the contents of the array before inserting the new player name and score, and output the contents of the array after inserting the new player name and score. Save your program. Copy and paste the program code into part 1(e)(iii) in the evidence document. [2] (iv) Test your program by entering the player name "JKL" and the score "9999". Take a screenshot to show the output. Copy and paste the screenshot into part 1(e)(iv) in the evidence document. [1] (f) The procedure WriteTopTen() stores the new top ten player names and scores in a text file called NewHighScore.txt Write program code to declare the procedure WriteTopTen(). Save your program. Copy and paste the program code into part 1(f) in the evidence document. [4]
Mark scheme: 1(a) 1 mark per mark point declaration of at least 1 array with appropriate identifier … 11 elements (and appropriate data type(s)) Example program code: Java Public static String[][] FileData = new String[10][2]; VB.NET Dim FileData(0 To 9, 0 To 1) As String Python FileData = [[""] *2 for i in range(11)] #string Question Answer Marks 1(b) 1 mark per mark point to max 6 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 Example program code: Java public static void ReadHighScores(){ String Filename = "HighScore.txt"; try{ FileReader F = new FileReader(Filename); BufferedReader Reader = new BufferedReader(F); for(Integer x = 0; x < 10; x++){ FileData[x][0] = Reader.readLine(); FileData[x][1] = Reader.readLine(); } Reader.close(); }catch(FileNotFoundException ex){ System.out.println("No file found"); } catch(IOException ex){ System.out.println("No file found"); } } 6 Question Answer Marks 1(b) 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 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 Question Answer Marks 1(c) 1 mark per mark point procedure heading and end looping through all data structure elements outputting player name, space, score. Each player must start on a new line Example program code: Java public static void OutputHighScores(){ for(Integer x = 0; x < 11; x++){ System.out.println(FileData[x][0] + " " + FileData[x][1]); } } Python def OutputHighScores (): for x in range(0, 11): Output = FileData[x][0] + " " + FileData[x][1] print(Output) VB.NET Sub OutputHighScores () For x = 0 To 10 Console.WriteLine(FileData(x, 0) & " " & FileData(x,1)) Next End Sub 3 Question Answer Marks 1(d)(i) 1 mark per mark point (Main program) calls ReadHighScores() … then calls OutputHighScores() Example program code: Java public static void main(String[] args){ ReadHighScores(); OutputHighScores(); } Python ReadHighScores() OutputHighScore() VB.NET Sub Main() ReadHighScores() OutputHighScore() Console.ReadLine() End Sub 2 Question Answer Marks 1(d)(ii) 1 mark for screenshot showing the 10 names and scores from the file (and one extra blank space may, or may not be included) e.g. 1 Question Answer Marks 1(e)(i) 1 mark per mark point 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) Example program code: Java public static void main(String[] args){ Scanner scanner = new Scanner(System.in); ReadHighScores(); OutputHighScores(); String Username = "ABCD" do{ System.out.println("Enter your Username"); Username = scanner.nextLine(); }while(Username.length != 3) String Score = "-1"; do{ System.out.println("Enter your score"); Score = scanner.nextLine(); }while(Integer.parseInt(Score) < 1 || Integer.parseInt(Score) > 100000); } 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")) 3 Question Answer Marks 1(e)(i) 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 Question Answer Marks 1(e)(ii) 1 mark per mark point 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 Example program code: Java public static void Arrange(String Username, String Score){ String Temp1; String Temp2; String Second1; String Second2; for(Integer x = 0; x < 10; x++){ if (Integer.parseInt(Score) > Integer.parseInt(FileData[x][1])){ Temp1 = FileData[x][0]; Temp2 = FileData[x][1]; FileData[x][0] = Username; FileData[x][1] = Score; for(Integer Count = x+1; Count < 10; Count++){ second1 = FileData[count][0]; second2 = FileData[count][1]; FileData[Count][0] = Temp1; FileData[Count][1] = Temp2; Temp1 = Second1; Temp2 = Second2; x = 11; } } } } 5 Question Answer Marks 1(e)(ii) 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; Question Answer Marks 1(e)(ii) 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 Question Answer Marks 1(e)(iii) 1 mark per mark point Calling sorting procedure with correct parameters Outputting the array before and after procedure call Example program code: Java public static void main(String[] args){ Scanner scanner = new Scanner(System.in); ReadHighScores(); OutputHighScores(); System.out.println("Enter your Username"); String Username = scanner.nextLine(); String Score = "-1"; do{ System.out.println("Enter your score"); Score = scanner.nextLine(); }while(Integer.parseInt(Score) < 0 || Integer.parseInt(Score) > 100000); arrange(Username, Score); OutputHighScores(); } 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() 2 Question Answer Marks 1(e)(iii) VB.NET OutputHighScore() Username = Console.ReadLine() Score = -1 While(score < 0 or Score > 100000) Score = Console.ReadLine() End While Arrange(Username, Score) OutputHighScore() 1(e)(iv) 1 mark for screenshot. JKL, 9999 entered. After shows JKL in the second position. e.g. 1 Question Answer Marks 1(f) 1 mark per mark point to max 4 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 Example program code: Java public static void WriteTopTen(){ String Filename = "NewHighScore.txt"; try{ FileWriter F = new FileWriter(Filename); BufferedWriter Out = new BufferedWriter(F); for(Integer x = 0; x < 10; x++){ Out.write(FileData[x][0] + "\n"); Out.write(FileData[x][1] + "\n"); } Out.close(); } catch(Exception e){ System.err.println("No file"); } } 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 4 Question Answer Marks 1(f) 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
Q2 · A computer game is being developed using object-oriented programming
2 A computer game is being developed using object-oriented programming. One element of the game is a balloon. This is designed as the class Balloon. The class has the following attributes and methods. Balloon Health : INTEGER The health of the balloon Colour : STRING The colour of the balloon DefenceItem : STRING The item the balloon uses to defend itself Constructor() Initialises the defence item and colour using the parameters Initialises health to 100 ChangeHealth() Takes the change as a parameter and adds this to the health GetDefenceItem() Returns the defence item of the object CheckHealth() If the health is 0 or less, it returns TRUE, otherwise it returns FALSE (a) The constructor takes the name of the defence item and the balloon’s colour as parameters and sets these to the attributes. The health is initialised to 100. Write program code to declare the class Balloon and its constructor. Do not write any other methods. Use your language appropriate constructor. All attributes should be private. If you are writing in Python include attribute declarations using comments. Save your program as Question2_J2022. Copy and paste the program code into part 2(a) in the evidence document. [5] (b) The get method GetDefenceItem() returns the defence item of the object. Amend your program code to include the get method GetDefenceItem(). Save your program. Copy and paste the program code into part 2(b) in the evidence document. [2] (c) The object’s method ChangeHealth() takes an integer number as a parameter and adds this to the health attribute of the object. Amend your program code to include the method ChangeHealth(). Save your program. Copy and paste the program code into part 2(c) in the evidence document. [2] (d) The object’s method CheckHealth() returns TRUE if the health of the object is 0 or less (no health remaining) and returns FALSE otherwise (health remaining). Amend your program code to include the method CheckHealth(). Save your program. Copy and paste the program code into part 2(d) in the evidence document. [2] (e) Amend the main program to: • take as input a defence item and colour from the user • create a new balloon with the identifier Balloon1 using the data input. Save your program. Copy and paste the program code into part 2(e) in the evidence document. [3] (f) The function Defend(): • takes a balloon object as a parameter • takes as input the strength of an opponent from the user • uses the ChangeHealth() method to subtract the strength input from the object’s health • outputs the defence item of the balloon • checks the health of the object and outputs an appropriate message if it has no health remaining, or if it has health remaining • returns the amended balloon object. Write program code to declare the function Defend(). Save your program. Copy and paste the program code into part 2(f) in the evidence document. [8] (g) (i) Amend the main program to call the function Defend(). Save your program. Copy and paste the program code into part 2(g)(i) in the evidence document. [2] (ii) Test your program using the following inputs: • balloon defence method "Shield" • balloon colour "Red" • strength of opponent 50 Take a screenshot to show the output. Copy and paste the screenshot into part 2(g)(ii) in the evidence document. [1]
Mark scheme: 2(a) 1 mark per mark point 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 Example program code: Java class Balloon{ private Integer Health; private String Colour; private String DefenceItem; public Balloon(String PDefenceItem, String PColour){ Colour = PColour; DefenceItem = PDefenceItem; Health = 100; } public static void main(String[] args){ } } 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 Question Answer Marks 2(a) 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 2(b) 1 mark per mark point get header and close with no parameter … … returning defence item attribute Example program code: Java public String GetDefenceItem(){ return DefenceItem; } Python def GetDefenceItem(self): return self.__DefenceItem VB.NET Public Function GetDefenceItem() Return DefenceItem End Function 2 Question Answer Marks 2(c) 1 mark per mark point procedure header and close taking 1 parameter … … adding parameter value to health attribute Example program code: Java public void ChangeHealth(Integer Change){ Health = Health + Change; } Python def ChangeHealth(self, Change): self.__Health = self.__Health + Change VB.NET Public Sub ChangeHealth(Change) Health = Health + Change End Sub 2 Question Answer Marks 2(d) 1 mark per mark point method header and close and checking if health attribute is <= 0 Returning TRUE if health attribute <= 0 and returning FALSE otherwise Example program code: Java public Boolean CheckHealth(){ if(Health <= 0){ return true; }else{ return false; } } Python def CheckHealth(self): if self.__Health <= 0: return True else: return False VB.NET Function CheckHealth() If Health <= 0 Then Return True Else Return False End If End Function 2 Question Answer Marks 2(e) 1 mark per mark point take as input defence method and colour (2 strings) instantiating new balloon object with identifier Balloon1 … … with both input values as parameters Example program code: Java public static void main(String[] args){ Scanner scanner = new Scanner(System.in); System.out.println("Enter balloon defence method"); String Method = scanner.nextLine(); System.out.println("Enter the balloon colour"); String Colour = scanner.nextLine(); Balloon Balloon1 = new Balloon(Method, Colour); } Python Method = input("Enter balloon defence method ") Colour = input("Enter the balloon colour ") Balloon1 = Balloon(Method, Colour) 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 3 Question Answer Marks 2(f) 1 mark per mark point to max 8 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 Example program code: Java public Balloon Defend(Balloon My Balloon){ System.out.println("Enter the strength of opponent"); Scanner scanner = new Scanner(System.in); Integer Strength = Integer.parseInt(scanner.nextLine()); MyBalloon.ChangeHealth(-Strength); if(MyBalloon.CheckHealth() == true){ System.out.println("Defence failed"); }else { System.out.println("Defence succeeded"); } return MyBalloon; } 8 Question Answer Marks 2(f) 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 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 Question Answer Marks 2(g)(i) 1 mark each calling Defend with balloon object … … and stores return value over object Example program code: Java Balloon1 = Defend(Balloon1); Python Balloon1 = Defend(Balloon1) VB.NET Balloon1 = Defend(Balloon1) 2 2(g)(ii) 1 mark for screenshot with: Shield, Red and 50 input Output stating their defence item was Shield Output says health is not 0 (in some manner) e.g. 1
Q3 · A program uses a circular queue to store strings
3 A program uses a circular queue to store strings. The queue is created as a 1D array, QueueArray, with 10 string items. The following data is stored about the queue: • the head pointer initialised to 0 • the tail pointer initialised to 0 • the number of items in the queue initialised to 0. (a) Declare the array, head pointer, tail pointer and number of items. If you are writing in Python, include attribute declarations using comments. Save your program as Question3_J2022. Copy and paste the program code into part 3(a) in the evidence document. [2] (b) The function Enqueue is written in pseudocode. The function adds DataToAdd to the queue. It returns FALSE if the queue is full and returns TRUE if the item is added. The function is incomplete, there are five incomplete statements. FUNCTION Enqueue(BYREF QueueArray[] : STRING, BYREF HeadPointer : INTEGER, BYREF TailPointer : INTEGER, NumberItems : INTEGER, DataToAdd : STRING) RETURNS BOOLEAN IF NumberItems = …………………………………… THEN RETURN …………………………………… ENDIF QueueArray[……………………………………] DataToAdd ← IF TailPointer >= 9 THEN TailPointer …………………………………… ← ELSE TailPointer TailPointer + 1 ← ENDIF NumberItems NumberItems …………………………………… ← RETURN TRUE ENDFUNCTION Write program code for the function Enqueue(). Save your program. Copy and paste the program code into part 3(b) in the evidence document. [7] (c) The function Dequeue() returns "FALSE" if the queue is empty, or it returns the next data item in the queue. Write program code for the function Dequeue(). Save your program. Copy and paste the program code into part 3(c) in the evidence document. [6] (d) (i) Amend the main program to: • take as input 11 string values from the user • use the Enqueue() function to add each element to the queue • output an appropriate message to state whether each addition was successful, or not • call Dequeue() function twice and output the return value each time. Save your program. Copy and paste the program code into part 3(d)(i) in the evidence document. [5] (ii) Test your program with the input data: "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" Take a screenshot to show the output. Copy and paste the screenshot into part 3(d)(ii) in the evidence document. [1]
Mark scheme: 3(a) 1 mark per mark point 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 Example program code: Java public static void main(String[] args){ String[] QueueArray = new String[10]; Integer QueueHeadPointer = 0; Integer QueueTailPointer = 0; Integer NumberOfItems = 0; } Python QueueArray = ['','','','','','','','','',''] #string QueueHeadPointer = 0 #integer QueueTailPointer = 0 #integer NumberOfItems = 0 #integer 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 Question Answer Marks 3(b) 1 mark per complete statement (5) 1 mark for function heading and end, dealing with ByRef 1 mark for remainder of function correct and following the logic FUNCTION Enqueue(BYREF QueueArray[] : STRING, BYREF HeadPointer : Integer, BYREF TailPointer : Integer, NumberItems : INTEGER, DataToAdd : STRING) RETURNS BOOLEAN IF NumberItems = 10 THEN RETURN FALSE ENDIF QueueArray[TailPointer] DataToAdd IF TailPointer >= 9 THEN TailPointer 0 ELSE TailPointer TailPointer + 1 ENDIF NumberItems NumberItems + 1 RETURN TRUE ENDFUNCTION Example program code: Java public static Boolean Enqueue(String DataToAdd){ if(NumberOfItems == 10){ return false; } QueueArray[QueueTailPointer] = DataToAdd; if(QueueTailPointer >= 9){ QueueTailPointer = 0; }else{ QueueTailPointer = QueueTailPointer + 1; } NumberOfItems = NumberOfItems + 1; return true; } 7 Question Answer Marks 3(b) 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) 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 Question Answer Marks 3(c) 1 mark per mark point to max 6 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 Example program code: Java public static String Dequeue(){ if(NumberOfItems == 0){ return "FALSE"; }else{ String ReturnValue = QueueArray[QueueHeadPointer]; QueueHeadPointer = QueueHeadPointer + 1; if(QueueHeadPointer >= 9){ QueueHeadPointer = 0; } NumberOfItems = NumberOfItems – 1; return ReturnValue; } } 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) 6 Question Answer Marks 3(c) 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 Question Answer Marks 3(d)(i) 1 mark per mark point 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 Example program code: Java public static void main(String args[]){ String InputString; for(Integer x = 0; x < 11; x++){ System.out.println("Enter a string"); Scanner scanner = new Scanner(System.in); InputString = scanner.nextLine(); if(Enqueue(InputString)){ System.out.println("Successful"); }else{ System.out.println("Unsuccessful"); } } System.out.println(Dequeue()); System.out.println(Dequeue()); } 5 Question Answer Marks 3(d)(i) 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) 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) Question Answer Marks 3(d)(ii) 1 mark for showing inputs and outputs: A – J input and successful. K input and unsuccessful. Output: A, B e.g. 1
What was in this paper
The subtopics covered by these 3 questions, and how many questions each got. Open one in a new tab to see every Cambridge question on it.
What you needed in this session
Cambridge’s own grade thresholds for 2022 May/June, Paper 4 · Variant 1. A higher threshold means an easier paper — the bar moves with how the cohort did.