Cambridge A Level Computer Science 9608 — 2021 Oct/Nov Paper 4 · Variant 2
9608/42/O/N/21 · 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 paper20 pages




















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





















Paper as text
Question paper, page 1
This document has 20 pages. Any blank pages are indicated. Cambridge International AS & A Level DC (PQ/CT) 212836/4 © UCLES 2021 [Turn over * 5 6 6 4 8 3 3 1 1 2 * COMPUTER SCIENCE 9608/42 Paper 4 Further Problem-solving and Programming Skills October/November 2021 2 hours You must answer on the question paper. No additional materials are needed. INSTRUCTIONS ● Answer all questions. ● Use a black or dark blue pen. ● Write your name, centre number and candidate number in the boxes at the top of the page. ● Write your answer to each question in the space provided. ● Do not use an erasable pen or correction fluid. ● Do not write on any bar codes. ● You may use an HB pencil for any diagrams, graphs or rough working. ● Calculators must not be used in this paper. INFORMATION ● The total mark for this paper is 75. ● The number of marks for each question or part question is shown in brackets [ ]. ● No marks will be awarded for using brand names of software packages or hardware.
Question paper, page 2
2 9608/42/O/N/21 © UCLES 2021 1 An array, NumberArray, stores 100 integer values. The array needs to be sorted into ascending numerical order. (a) Describe how an insertion sort will sort the data in NumberArray. … … … … … … … … … … [4]
Question paper, page 3
3 9608/42/O/N/21 © UCLES 2021 [Turn over (b) Another type of sorting algorithm is a bubble sort. The procedure Bubble() takes an array as a parameter. It performs a bubble sort on the array. The sorting algorithm stops as soon as all the elements are in ascending order. Complete the procedure Bubble(). PROCEDURE Bubble(BYREF NumberArray : ARRAY[0 : 99] OF INTEGER) DECLARE Outer : INTEGER DECLARE Swap : BOOLEAN DECLARE Inner : INTEGER DECLARE Temp : INTEGER Outer LENGTH(NumberArray) - 1 REPEAT Inner … Swap FALSE REPEAT IF NumberArray[Inner] > NumberArray[Inner + 1] THEN Temp NumberArray[Inner] NumberArray[Inner] NumberArray[Inner + 1] NumberArray[Inner + 1] Temp Swap … ENDIF Inner Inner + 1 UNTIL Inner = … Outer Outer - 1 UNTIL Swap = … OR Outer = … ENDPROCEDURE [5]
Question paper, page 4
4 9608/42/O/N/21 © UCLES 2021 2 Complete the JSP structure diagram for the following pseudocode procedure. PROCEDURE Calculate() INPUT Number1 INPUT Number2 INPUT Command IF Command = 1 THEN Value Function1(Number1, Number2) ELSE IF Command = 2 THEN Value Function2(Number1, Number2) ELSE Value Function3(Number1, Number2) ENDIF ENDIF OUTPUT Value ENDPROCEDURE JSP structure diagram Calculate [4]
Question paper, page 5
5 9608/42/O/N/21 © UCLES 2021 [Turn over 3 A user has to choose a new password to create an account. It is recommended that the password has at least two of the following elements: • upper-case letter • numeric character • symbol. The system outputs: • "Strong" if there are at least two of the elements • "Medium" if there is only one of the elements • "Weak" if there are none of the elements. Complete the following decision table for the password system described. Rules Conditions One or more upper-case letters N Y N Y N Y N Y One or more numeric characters N N Y Y N N Y Y One or more symbols N N N N Y Y Y Y Actions Strong Medium Weak [3]
Question paper, page 6
6 9608/42/O/N/21 © UCLES 2021 4 Each node of a binary tree is a record. Each record has a left pointer, an integer data value between 0 and 100 inclusive, and a right pointer. For example: Item Example data LeftPointer 2 Data 34 RightPointer 3 (a) Write pseudocode to declare the record with the identifier Node. … … … … … … … [2] (b) Write pseudocode to declare a new node, Node100, and assign 100 to its data value, 1 to the left pointer and 4 to the right pointer. … … … … … … … [3]
Question paper, page 7
7 9608/42/O/N/21 © UCLES 2021 [Turn over (c) The ordered binary tree is stored as a 1D global array named BinaryTree of type Node. RootNode and FreePointer are declared as global variables. A null pointer is represented by –1. The current state of the binary tree is shown in the following table: RootNode 0 Index LeftPointer Data RightPointer [0] 1 23 3 FreePointer 6 [1] -1 5 2 [2] -1 8 4 [3] 5 100 -1 [4] -1 9 -1 [5] -1 88 -1 [6] -1 null -1 [7] -1 null -1 (i) State the purpose of the free pointer. … … [1] (ii) Identify an appropriate integer value to represent null data. … [1] (iii) Draw the current state of the binary tree. [2]
Question paper, page 8
8 9608/42/O/N/21 © UCLES 2021 (iv) The procedure AddData(): • takes the node to be added to the tree as a parameter • finds the location for the node to be stored • stores the node in the next free array index • stores –1 in the new node’s LeftPointer and RightPointer • updates the pointers in the other nodes • updates FreePointer. Complete the pseudocode for the procedure AddData(). PROCEDURE AddData(NewNode) BinaryTree[FreePointer] … BinaryTree[FreePointer].LeftPointer -1 BinaryTree[FreePointer].RightPointer -1 DECLARE PositionFound : BOOLEAN DECLARE PointerCounter : INTEGER PositionFound … PointerCounter RootNode WHILE NOT … IF … < BinaryTree[PointerCounter].Data THEN IF BinaryTree[PointerCounter].LeftPointer = −1 THEN BinaryTree[PointerCounter].LeftPointer FreePointer PositionFound TRUE ELSE PointerCounter BinaryTree[PointerCounter].LeftPointer ENDIF ELSE IF BinaryTree[PointerCounter].RightPointer = -1 THEN BinaryTree[PointerCounter].RightPointer FreePointer PositionFound TRUE ELSE PointerCounter BinaryTree[PointerCounter].RightPointer ENDIF ENDIF ENDWHILE FreePointer FreePointer … ENDPROCEDURE [5]
Question paper, page 9
9 9608/42/O/N/21 © UCLES 2021 [Turn over 5 Study the following recursive pseudocode algorithm. FUNCTION Recursive(Num1, Num2 : INTEGER) RETURNS INTEGER IF Num1 > Num2 THEN RETURN 10 ELSE IF Num1 = Num2 THEN RETURN Num1 ELSE RETURN Num1 + Recursive(Num1 * 2, Num2) ENDIF ENDIF ENDFUNCTION (a) The function is called as follows: Recursive(1, 15) Dry run the function and complete the trace table. Give the final return value. Trace table: Function call Num1 Num2 Return value Final return value … Working … … … … … [4]
Question paper, page 10
10 9608/42/O/N/21 © UCLES 2021 (b) Rewrite the function Recursive() in pseudocode, using an iterative algorithm. … … … … … … … … … … … … … … … … … … [7]
Question paper, page 11
11 9608/42/O/N/21 © UCLES 2021 [Turn over 6 Details of errors generated in a program are stored in a stack. Details of each error are stored in a record structure, Error. (a) State which error will be the first retrieved from the stack. … … [1] (b) The stack is implemented as a 1D array with the identifier ErrorArray. The pointer LastItem stores the position of the last error in the array. (i) The function, AddItemToStack, takes the next error, the array, and pointer as parameters. If the stack is full, the function returns FALSE; otherwise it adds the error to the stack, changes the pointer’s value and returns TRUE. Complete the following pseudocode for the function AddItemToStack. FUNCTION AddItemToStack(BYREF ErrorArray : ARRAY[0 : 99] OF Error, BYREF LastItem : INTEGER, BYVALUE Error1 : Error) RETURNS BOOLEAN IF LastItem = … THEN RETURN … ELSE ErrorArray[LastItem + 1] … LastItem … RETURN … ENDIF ENDFUNCTION [4] (ii) Explain the reasons why ErrorArray and LastItem are passed by reference, but Error1 is passed by value. … … … … … … [3]
Question paper, page 12
12 9608/42/O/N/21 © UCLES 2021 (iii) The function RemoveItem takes the next error from the stack and returns it. If there are no errors in the stack, it returns the global record NullError. Complete the pseudocode algorithm RemoveItem. FUNCTION RemoveItem(BYREF ErrorArray : ARRAY[0 : 99] OF Error, BYREF LastItem : INTEGER) RETURNS Error DECLARE ItemToRemove : Error IF … THEN RETURN … ELSE ItemToRemove ErrorArray[…] LastItem LastItem - 1 RETURN … ENDFUNCTION [3]
Question paper, page 13
13 9608/42/O/N/21 © UCLES 2021 [Turn over (iv) The errors that have been processed are stored in a global queue, ErrorComplete. The function Enqueue adds a record to ErrorComplete: Enqueue(ErrorToAdd) Enqueue() returns TRUE if the record is successfully added to the queue, and returns FALSE if the queue is full. The procedure RunError() should: • remove a record from the stack using the function RemoveItem() • output an appropriate message if there were no records in the stack • if an error record is returned, add the record to the queue using the function Enqueue() • if the record is added to the queue, output an appropriate message • if the record is not added to the queue, output an appropriate message. Complete the pseudocode procedure RunError(). PROCEDURE RunError(BYREF ErrorComplete : ARRAY[0 : 99] OF Error, BYREF ErrorArray : ARRAY[0 : 99] OF Error) … … … … … … … … … … … … … … … ENDPROCEDURE [5]
Question paper, page 14
14 9608/42/O/N/21 © UCLES 2021 7 A treasure box is hidden within a computer game. The box has a code that needs to be entered to allow the user into the box. The box contains up to 10 objects that are defined as being of the class FieldObject. The definition for the class Box is: Box Size : STRING Contents : ARRAY[0 : 9] OF FieldObject Lock : STRING Strength : INTEGER // small, medium or large // the 10 items the box holds // the code to unlock the box // the strength of the box // decreases by 1 each time an // incorrect code is entered Constructor() Unlock() GetContents() SetSize() SetContents() SetLock() SetStrength() // instantiates an object of the Box // class and assigns initial values // to the attributes // checks if the code is correct to // unlock the box // returns the array // sets the size of the box // sets the contents of the box // sets the lock code // sets the strength
Question paper, page 15
15 9608/42/O/N/21 © UCLES 2021 [Turn over (a) The constructor creates a new instance of a box. It takes the size of the box, one item of content and the lock code as parameters. The strength is initialised to 100. Write program code to create the class and constructor for Box. Do not write the code for Unlock() or any of the set or get methods. Use the constructor for your chosen language. Programming language … Program code … … … … … … … … … … … … … … … … [5]
Question paper, page 16
16 9608/42/O/N/21 © UCLES 2021 (b) The player inputs the code to unlock the box. Each time they enter an incorrect code, the strength of the box decreases by 1. If the strength of the box becomes 0, the box automatically unlocks. The class Box has a method Unlock() that: • takes the code entered as a parameter and checks if it matches the code to unlock the box • returns TRUE if the parameter matches the unlock code • subtracts 1 from Strength if the parameter does not match the unlock code • checks if the new value of Strength is less than 1 • returns TRUE if the new value of Strength is less than 1, otherwise it returns FALSE. Write program code for the method Unlock(). Programming language … Program code … … … … … … … … … … … … … … [5]
Question paper, page 17
17 9608/42/O/N/21 © UCLES 2021 [Turn over (c) The text file, Progress.txt, stores data about the player’s previous progress. The procedure LoadGame(): • opens the text file in read mode • takes the data from the file and stores the data in the variable GameData • raises an exception with an appropriate message output if it cannot find the file. Write program code for the procedure LoadGame(). Programming language … Program code … … … … … … … … … … … … … … [6]
Question paper, page 18
18 9608/42/O/N/21 © UCLES 2021 8 A game stores details about characters. A declarative programming language is used to represent the following knowledge base: 01 hair(blonde). 02 hair(black). 03 hair(red). 04 face(glasses). 05 face(moustache). 06 face(beard). 07 person(ismail). 08 person(anisha). 09 person(kim). 10 person(kyle). 11 has(kyle, glasses). 12 has(kyle, beard). 13 has(anisha, red). 14 has(kyle, black). These clauses have the following meaning: Clause Explanation 01 Hair can be blonde 04 Glasses can be on the face 08 Anisha is a person 12 Kyle has a beard 13 Anisha has red hair
Question paper, page 19
19 9608/42/O/N/21 © UCLES 2021 A person, X, is a selected person if they have black hair and either a moustache or a beard. Write a rule to represent this condition. SelectedPerson(X) IF … … … … [2]
Question paper, page 20
20 9608/42/O/N/21 © UCLES 2021 Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the publisher will be pleased to make amends at the earliest possible opportunity. To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cambridgeinternational.org after the live examination series. Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of Cambridge Local Examinations Syndicate (UCLES), which itself is a department of the University of Cambridge. BLANK PAGE
Mark scheme, page 1
This document consists of 21 printed pages. © UCLES 2021 [Turn over Cambridge International AS & A Level COMPUTER SCIENCE 9608/42 Paper 4 Further Problem-solving and Programming Skills October/November 2021 MARK SCHEME Maximum Mark: 75 Published This mark scheme is published as an aid to teachers and candidates, to indicate the requirements of the examination. It shows the basis on which Examiners were instructed to award marks. It does not indicate the details of the discussions that took place at an Examiners’ meeting before marking began, which would have considered the acceptability of alternative answers. Mark schemes should be read in conjunction with the question paper and the Principal Examiner Report for teachers. Cambridge International will not enter into discussions about these mark schemes. Cambridge International is publishing the mark schemes for the October/November 2021 series for most Cambridge IGCSE™, Cambridge International A and AS Level components and some Cambridge O Level components.
Mark scheme, page 2
9608/42 Cambridge International AS & A Level – Mark Scheme PUBLISHED OCTOBER/NOVEMBER 2021 © UCLES 2021 Page 2 of 21 Generic Marking Principles These general marking principles must be applied by all examiners when marking candidate answers. They should be applied alongside the specific content of the mark scheme or generic level descriptors for a question. Each question paper and mark scheme will also comply with these marking principles. GENERIC MARKING PRINCIPLE 1: Marks must be awarded in line with: • the specific content of the mark scheme or the generic level descriptors for the question • the specific skills defined in the mark scheme or in the generic level descriptors for the question • the standard of response required by a candidate as exemplified by the standardisation scripts. GENERIC MARKING PRINCIPLE 2: Marks awarded are always whole marks (not half marks, or other fractions). GENERIC MARKING PRINCIPLE 3: Marks must be awarded positively: • marks are awarded for correct/valid answers, as defined in the mark scheme. However, credit is given for valid answers which go beyond the scope of the syllabus and mark scheme, referring to your Team Leader as appropriate • marks are awarded when candidates clearly demonstrate what they know and can do • marks are not deducted for errors • marks are not deducted for omissions • answers should only be judged on the quality of spelling, punctuation and grammar when these features are specifically assessed by the question as indicated by the mark scheme. The meaning, however, should be unambiguous. GENERIC MARKING PRINCIPLE 4: Rules must be applied consistently, e.g. in situations where candidates have not followed instructions or in the application of generic level descriptors.
Mark scheme, page 3
9608/42 Cambridge International AS & A Level – Mark Scheme PUBLISHED OCTOBER/NOVEMBER 2021 © UCLES 2021 Page 3 of 21 GENERIC MARKING PRINCIPLE 5: Marks should be awarded using the full range of marks defined in the mark scheme for the question (however; the use of the full mark range may be limited according to the quality of the candidate responses seen). GENERIC MARKING PRINCIPLE 6: Marks awarded are based solely on the requirements as defined in the mark scheme. Marks should not be awarded with grade thresholds or grade descriptors in mind.
Mark scheme, page 4
9608/42 Cambridge International AS & A Level – Mark Scheme PUBLISHED OCTOBER/NOVEMBER 2021 © UCLES 2021 Page 4 of 21 Question Answer Marks 1(a) 1 mark per bullet point to max 4 • Set the first element to be the sorted list • Store the next element in a temporary variable // store the value to be sorted in a temporary variable • … compare this next element to each element in the sorted list • Move the elements that are greater than it one space to the right and insert the temporary variable // swap the element down until in the correct positions • Loop through all items from 2nd to end of array/100 4 1(b) 1 mark for each completed statement PROCEDURE Bubble(ByRef NumberArray : ARRAY[0:99] OF INTEGER) DECLARE Outer : INTEGER DECLARE Swap : BOOLEAN DECLARE Inner : INTEGER DECLARE Temp : INTEGER Outer ← LENGTH(NumberArray)-1 REPEAT Inner ← 0 Swap ← FALSE REPEAT IF NumberArray[Inner] > NumberArray[Inner + 1] THEN Temp ← NumberArray[Inner] NumberArray[Inner] ← NumberArray[Inner + 1] NumberArray[Inner + 1] ← Temp Swap ← TRUE ENDIF Inner ← Inner + 1 UNTIL Inner = Outer Outer ← Outer - 1 UNTIL Swap = FALSE OR Outer = 0 ENDPROCEDURE 5
Mark scheme, page 5
9608/42 Cambridge International AS & A Level – Mark Scheme PUBLISHED OCTOBER/NOVEMBER 2021 © UCLES 2021 Page 5 of 21 Question Answer Marks 2 1 mark per bullet point: • input of Number1 Number2 Command on same level under an input box • three functions (1, 2, 3) below e.g. decision box … • …with selection on each • output value at end in box below calculate 4 calculate INPUT Decision OUTPUT Value Number1 Number2 Command Function1 (Number1, Number2) Function2 (Number1, Number2) Function3 (Number1, Number2)
Mark scheme, page 6
9608/42 Cambridge International AS & A Level – Mark Scheme PUBLISHED OCTOBER/NOVEMBER 2021 © UCLES 2021 Page 6 of 21 Question Answer Marks 3 1 mark for each row Rules Conditions One or more upper-case letters N Y N Y N Y N Y One or more numeric characters N N Y Y N N Y Y One or more symbols N N N N Y Y Y Y Actions Strong Y Y Y Y Medium Y Y Y Weak Y 3 Question Answer Marks 4(a) 1 mark per bullet point • Record declaration with identifier Node … • … all three fields declared with type integer Example: TYPE Node DECLARE LeftPointer : INTEGER DECLARE Data : INTEGER DECLARE RightPointer : INTEGER ENDTYPE 2
Mark scheme, page 7
9608/42 Cambridge International AS & A Level – Mark Scheme PUBLISHED OCTOBER/NOVEMBER 2021 © UCLES 2021 Page 7 of 21 Question Answer Marks 4(b) 1 mark per bullet point: • Declaration with correct identifier (Node100) of type Node • Assigning LeftPointer to 1 and RightPointer to 4 • Assigning 100 to the Data Example pseudocode DECLARE Node100 : Node Node100.LeftPointer ← 1 Node100.Data ← 100 Node100.RightPointer ← 4 3 4(c)(i) To point to the start/first of the empty node/nodes 1 4(c)(ii) –1 or below // 101 or above 1
Mark scheme, page 8
9608/42 Cambridge International AS & A Level – Mark Scheme PUBLISHED OCTOBER/NOVEMBER 2021 © UCLES 2021 Page 8 of 21 Question Answer Marks 4(c)(iii) 1 mark for 23 at top, with 5 below left, 100 below right 1 mark for remaining in correct places below 5 and 100 2 23 5 8 9 100 88
Mark scheme, page 9
9608/42 Cambridge International AS & A Level – Mark Scheme PUBLISHED OCTOBER/NOVEMBER 2021 © UCLES 2021 Page 9 of 21 Question Answer Marks 4(c)(iv) 1 mark for each completed statement PROCEDURE AddData(NewNode) BinaryTree[FreePointer] ← NewNode BinaryTree[FreePointer].LeftPointer ← -1 BinaryTree[FreePointer].RightPointer ← -1 DECLARE PositionFound : BOOLEAN DECLARE PointerCounter : INTEGER PositionFound ← FALSE PointerCounter ← RootNode WHILE NOT PositionFound IF NewNode.Data < BinaryTree[PointerCounter].Data THEN IF BinaryTree[PointerCounter].LeftPointer = -1 THEN BinaryTree[PointerCounter].LeftPointer ← FreePointer PositionFound ← TRUE ELSE PointerCounter ← BinaryTree[PointerCounter].LeftPointer ENDIF ELSE IF BinaryTree[PointerCounter].RightPointer = -1 THEN BinaryTree[PointerCounter].RightPointer ← FreePointer PostionFound ← True ELSE PointerCounter ← BinaryTree[PointerCounter].RightPointer ENDIF ENDIF ENDWHILE FreePointer ← FreePointer + 1 ENDPROCEDURE 5
Mark scheme, page 10
9608/42 Cambridge International AS & A Level – Mark Scheme PUBLISHED OCTOBER/NOVEMBER 2021 © UCLES 2021 Page 10 of 21 Question Answer Marks 5(a) 1 mark per bullet point • Return value of 25 (in space or if space left empty look at tracing) • Calling with 1 and 15, then 2 and 15 • Calling with 4, then 8, then 16 • Showing the unwinding of the return values Function Call Num1 Num2 Return value Recursive(1, 15) 1 15 1 + Recursive(2, 15) 1 + 24 = 25 Recursive(2, 15) 2 15 2 + Recursive(4, 15) 2 + 22 = 24 Recursive(4, 15) 4 15 4 + Recursive(8, 15) 4 + 18 = 22 Recursive(8, 15) 8 15 8 + Recursive(16, 15) 8 + 10 = 18 Recursive(16, 15) 16 15 10 4
Mark scheme, page 11
9608/42 Cambridge International AS & A Level – Mark Scheme PUBLISHED OCTOBER/NOVEMBER 2021 © UCLES 2021 Page 11 of 21 Question Answer Marks 5(b) 1 mark per bullet point to max 7 • function declaration (and end) taking two parameters and the function returns the final totalling value outside of loop and in all cases • Initialising totalling value to 0 outside of loop • Loop until Num1 >= Num2 // loop while Num1 < Num2 … • … adding Num1 to totalling value inside the loop • … and multiplying Num1 by 2 inside a loop and storing back in Num1 After loop • Checking if Num1 > Num2 … • … adding 10 to totalling value when true • check Num1 = Num2 … • … adding Num1 to totalling value when true Example pseudocode: FUNCTION NonRecursive(Num1, Num2 : INTEGER) RETURNS INTEGER Value ← 0 WHILE Num1 < Num2 Value ← Value + Num1 Num1 ← Num1 * 2 ENDWHILE IF Num1 > Num2 THEN Value ← Value + 10 ELSE Value ← Value + Num1 ENDIF RETURN Value ENDFUNCTION 7
Mark scheme, page 12
9608/42 Cambridge International AS & A Level – Mark Scheme PUBLISHED OCTOBER/NOVEMBER 2021 © UCLES 2021 Page 12 of 21 Question Answer Marks 6(a) The last one in // most recent 1 6(b)(i) 1 mark for True and False in the correct place 1 for each other completed statement FUNCTION AddItemToStack(BYREF ErrorArray : ARRAY[0:99] OF Error, BYREF LastItem : INTEGER, BYVALUE Error1 : Error) RETURNS BOOLEAN IF LastItem = 99 // ErrorArray.Length - 1 THEN RETURN FALSE ELSE ErrorArray(LastItem + 1) ← Error1 LastItem ← LastItem + 1 RETURN TRUE ENDIF ENDFUNCTION 4 6(b)(ii) 1 mark per bullet point to max 3 • The function needs to change the values in ErrorArray and/or LastItem in main/where called • … otherwise they would not be changed outside of the function // otherwise changes would only stay in the function • Error1's value does not change in the function // no changes to Error1's value need reflecting where it was called / to the original • BYVALUE stops the value being changed outside the function but BYREF changes the value where called from 3
Mark scheme, page 13
9608/42 Cambridge International AS & A Level – Mark Scheme PUBLISHED OCTOBER/NOVEMBER 2021 © UCLES 2021 Page 13 of 21 Question Answer Marks 6(b)(iii) 1 mark for both return statements 1 mark for each other completed statement FUNCTION RemoveItem(ByRef ErrorArray : ARRAY[0:99] OF Error, ByRef LastItem : INTEGER) RETURNS Error DECLARE ItemToRemove : Error IF LastItem < 0 / = -1 THEN RETURN NullError ELSE ItemToRemove ← ErrorArray[LastItem] LastItem ← LastItem - 1 RETURN ItemToRemove ENDFUNCTION 3
Mark scheme, page 14
9608/42 Cambridge International AS & A Level – Mark Scheme PUBLISHED OCTOBER/NOVEMBER 2021 © UCLES 2021 Page 14 of 21 Question Answer Marks 6(b)(iv) 1 mark per bullet point to max 5 • Using RemoveItem(ErrorArray, LastItem) and storing return value … • …checking if return value is NullError and outputting "stack empty" message if it is null • … (if not NullError), calling Enqueue with return value … • … if return value is TRUE, output "added to queue" message … • … if return value is FALSE output "not added to queue" message PROCEDURE RunError(BYREF ErrorComplete : ARRAY[0:99] OF Error, BYREF ErrorArray : ARRAY[0:99] OF Error) DECLARE DataItem : error DataItem ← RemoveItem(ErrorArray, LastItem) IF DataItem = NullError THEN OUTPUT "Stack empty" ELSE IF Enqueue(DataItem) = True THEN OUTPUT "Item added to queue" ELSE OUTPUT "Item not added to queue" ENDIF ENDPROCEDURE 5
Mark scheme, page 15
9608/42 Cambridge International AS & A Level – Mark Scheme PUBLISHED OCTOBER/NOVEMBER 2021 © UCLES 2021 Page 15 of 21 Question Answer Marks 7(a) 1 mark per bullet point to max 5 • class header (and end where appropriate) • contents array declared of type FieldObject with 10 elements • size, lock and strength all private (size & lock – string, strength – integer) • constructor taking 3 parameters … • … setting Size, Lock and Contents at index 0/1 to parameters • … setting strength to 100 Example program code VB.NET Public Class Box Private Size As String Private Contents(9) As FieldObject Private Lock As String Private Strength As Integer Sub New(sizep, firstContent, lockNumber) Size = sizep Lock = lockNumber Strength = 100 Contents(0) = firstContent End Sub End Class Python class Box: def __init__(self, Sizep, FirstContent, LockNumber): self.__Size = Sizep #string self.__Lock = LockNumber #string self.__Strength = 100 #integer self.__Contents[0] = FirstContent #array 10 elements of FieldObject 5
Mark scheme, page 16
9608/42 Cambridge International AS & A Level – Mark Scheme PUBLISHED OCTOBER/NOVEMBER 2021 © UCLES 2021 Page 16 of 21 Question Answer Marks 7(a) Pascal type Box = class private Size : String; Contents : array[0 .. 9] of String; Lock : String; Strength : integer; public constructor create(Sizep : String; FirstContent : String; LockNumber : string); end; constructor Box.create(Sizep : String; FirstContent : String; LockNumber : string); begin Size := Sizep; Lock := LockNumber; Strength := 100; Contents[0] := FirstContent; end;
Mark scheme, page 17
9608/42 Cambridge International AS & A Level – Mark Scheme PUBLISHED OCTOBER/NOVEMBER 2021 © UCLES 2021 Page 17 of 21 Question Answer Marks 7(b) 1 mark per bullet point to max 5 • Function declaration (and end) taking (string) parameter (and return Boolean) • Check if parameter matches Lock and returning true if it does • (otherwise) decrementing Strength … • … If Strength is < 1 / = 0, return true • … otherwise if Strength is >= 1, return false Example program code: V.B.NET Function Unlock(Key) If Lock = Key Then Return True Else Strength = Strength - 1 If Strength <= 0 Then Return True Else Return False End If End If End Function Python def Unlock(self, Key): if self.__Lock == Key: return True else: self.__Strength = self.__Strength - 1 if self.__Strength <= 0: return True else: return False 5
Mark scheme, page 18
9608/42 Cambridge International AS & A Level – Mark Scheme PUBLISHED OCTOBER/NOVEMBER 2021 © UCLES 2021 Page 18 of 21 Question Answer Marks 7(b) Pascal function Box.Unlock(Key : String) : Boolean; begin if Lock = Key then begin Unlock := true; end else begin Strength := Strength - 1; if Strength <= 0 then begin Unlock := true; end else begin Unlock := false; end; end; end;
Mark scheme, page 19
9608/42 Cambridge International AS & A Level – Mark Scheme PUBLISHED OCTOBER/NOVEMBER 2021 © UCLES 2021 Page 19 of 21 Question Answer Marks 7(c) 1 mark per bullet point to max 6 • procedure heading (and end where applicable) • opening progress.txt to read • read all data from file into GameData • closing file • Exception check when trying to open the file … • … appropriate message/other Example program code VB.NET Sub LoadGame() Dim Filename As String = "progress.txt" Dim GameData As String Try Dim ObjRead As New System.IO.StreamReader(Filename) GameData = ObjRead.ReadToEnd Console.WriteLine(GameData) ObjRead.Close() Catch Console.WriteLine("File not found") End Try End Sub 6
Mark scheme, page 20
9608/42 Cambridge International AS & A Level – Mark Scheme PUBLISHED OCTOBER/NOVEMBER 2021 © UCLES 2021 Page 20 of 21 Question Answer Marks 7(c) Python def LoadGame(): Filename = "progress.txt" try: F = open(Filename, "r") GameData = F.read() F.close() except: print("File not found") Pascal procedure LoadGame(); var Myfile : Text; GameData : String; begin try assign(Myfile, 'progress.txt'); reset(Myfile); read(Myfile, GameData); close(Myfile); except writeln('File not found'); end; end;
Mark scheme, page 21
9608/42 Cambridge International AS & A Level – Mark Scheme PUBLISHED OCTOBER/NOVEMBER 2021 © UCLES 2021 Page 21 of 21 Question Answer Marks 8 1 mark per bullet point • person(X) AND has(X, black) • AND (has(X, moustache) OR has(X, beard)) Example: person(X) AND has(X, black) AND (has(X, moustache) OR has(X, beard)) 2
What you needed in this session
Cambridge’s own grade thresholds for 2021 Oct/Nov, Paper 4 · Variant 2. A higher threshold means an easier paper — the bar moves with how the cohort did.