Cambridge A Level Computer Science 9608 — 2017 May/June Paper 4 · Variant 2

9608/42/M/J/17 · 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.

← All Computer Science papersWhat was in this paper?

Question paper20 pages

Cambridge A Level Computer Science 9608 2017 May/June Paper 4 · Variant 2 question paper, page 1 of 20
Page 1 of 20
Cambridge A Level Computer Science 9608 2017 May/June Paper 4 · Variant 2 question paper, page 2 of 20
Page 2 of 20
Cambridge A Level Computer Science 9608 2017 May/June Paper 4 · Variant 2 question paper, page 3 of 20
Page 3 of 20
Cambridge A Level Computer Science 9608 2017 May/June Paper 4 · Variant 2 question paper, page 4 of 20
Page 4 of 20
Cambridge A Level Computer Science 9608 2017 May/June Paper 4 · Variant 2 question paper, page 5 of 20
Page 5 of 20
Cambridge A Level Computer Science 9608 2017 May/June Paper 4 · Variant 2 question paper, page 6 of 20
Page 6 of 20
Cambridge A Level Computer Science 9608 2017 May/June Paper 4 · Variant 2 question paper, page 7 of 20
Page 7 of 20
Cambridge A Level Computer Science 9608 2017 May/June Paper 4 · Variant 2 question paper, page 8 of 20
Page 8 of 20
Cambridge A Level Computer Science 9608 2017 May/June Paper 4 · Variant 2 question paper, page 9 of 20
Page 9 of 20
Cambridge A Level Computer Science 9608 2017 May/June Paper 4 · Variant 2 question paper, page 10 of 20
Page 10 of 20
Cambridge A Level Computer Science 9608 2017 May/June Paper 4 · Variant 2 question paper, page 11 of 20
Page 11 of 20
Cambridge A Level Computer Science 9608 2017 May/June Paper 4 · Variant 2 question paper, page 12 of 20
Page 12 of 20
Cambridge A Level Computer Science 9608 2017 May/June Paper 4 · Variant 2 question paper, page 13 of 20
Page 13 of 20
Cambridge A Level Computer Science 9608 2017 May/June Paper 4 · Variant 2 question paper, page 14 of 20
Page 14 of 20
Cambridge A Level Computer Science 9608 2017 May/June Paper 4 · Variant 2 question paper, page 15 of 20
Page 15 of 20
Cambridge A Level Computer Science 9608 2017 May/June Paper 4 · Variant 2 question paper, page 16 of 20
Page 16 of 20
Cambridge A Level Computer Science 9608 2017 May/June Paper 4 · Variant 2 question paper, page 17 of 20
Page 17 of 20
Cambridge A Level Computer Science 9608 2017 May/June Paper 4 · Variant 2 question paper, page 18 of 20
Page 18 of 20
Cambridge A Level Computer Science 9608 2017 May/June Paper 4 · Variant 2 question paper, page 19 of 20
Page 19 of 20
Cambridge A Level Computer Science 9608 2017 May/June Paper 4 · Variant 2 question paper, page 20 of 20
Page 20 of 20

Mark scheme19 pages

Answers below. Sit the paper first if you are practising.

Mark scheme, page 1 of 19
Page 1 of 19
Mark scheme, page 2 of 19
Page 2 of 19
Mark scheme, page 3 of 19
Page 3 of 19
Mark scheme, page 4 of 19
Page 4 of 19
Mark scheme, page 5 of 19
Page 5 of 19
Mark scheme, page 6 of 19
Page 6 of 19
Mark scheme, page 7 of 19
Page 7 of 19
Mark scheme, page 8 of 19
Page 8 of 19
Mark scheme, page 9 of 19
Page 9 of 19
Mark scheme, page 10 of 19
Page 10 of 19
Mark scheme, page 11 of 19
Page 11 of 19
Mark scheme, page 12 of 19
Page 12 of 19
Mark scheme, page 13 of 19
Page 13 of 19
Mark scheme, page 14 of 19
Page 14 of 19
Mark scheme, page 15 of 19
Page 15 of 19
Mark scheme, page 16 of 19
Page 16 of 19
Mark scheme, page 17 of 19
Page 17 of 19
Mark scheme, page 18 of 19
Page 18 of 19
Mark scheme, page 19 of 19
Page 19 of 19

Paper as text

Question paper, page 1

* 6 3 6 6 2 6 7 4 2 0 * This document consists of 17 printed pages and 3 blank pages. DC (CW/SW) 129963/3 © UCLES 2017 [Turn over COMPUTER SCIENCE 9608/42 Paper 4 Further Problem-solving and Programming Skills May/June 2017 2 hours Candidates answer on the Question Paper. No Additional Materials are required. No calculators allowed. READ THESE INSTRUCTIONS FIRST Write your Centre number, candidate number and name in the spaces at the top of this page. Write in dark blue or black pen. You may use an HB pencil for any diagrams, graphs or rough working. Do not use staples, paper clips, glue or correction fluid. DO NOT WRITE IN ANY BARCODES. Answer all questions. No marks will be awarded for using brand names of software packages or hardware. At the end of the examination, fasten all your work securely together. The number of marks is given in brackets [ ] at the end of each question or part question. The maximum number of marks is 75. Cambridge International Examinations Cambridge International Advanced Subsidiary and Advanced Level

Question paper, page 2

2 9608/42/M/J/17 © UCLES 2017 1 The following table shows part of the instruction set for a processor which has one general purpose register, the Accumulator (ACC), and an Index Register (IX). Instruction Explanation Op code Operand LDM #n Immediate addressing. Load the number n to ACC. LDD <address> Direct addressing. Load the contents of the location at the given address to ACC. LDI <address> Indirect addressing. The address to be used is at the given address. Load the contents of this second address to ACC. LDX <address> Indexed addressing. Form the address from <address> + the contents of the index register. Copy the contents of this calculated address to ACC. STO <address> Store the contents of ACC at the given address. INC <register> Add 1 to the contents of the register (ACC or IX). CMP <address> Compare the contents of ACC with the contents of <address>. JMP <address> Jump to the given address. JPE <address> Following a compare instruction, jump to <address> if the compare was True. JPN <address> Following a compare instruction, jump to <address> if the compare was False. AND <address> Bitwise AND operation of the contents of ACC with the contents of <address>. XOR <address> Bitwise XOR operation of the contents of ACC with the contents of <address>. OR <address> Bitwise OR operation of the contents of ACC with the contents of <address>. IN Key in a character and store its ASCII value in ACC. OUT Output to the screen the character whose ASCII value is stored in ACC. END Return control to the operating system. (a) A programmer writes a program that: • reads two characters input from the keyboard (you may assume they will be capital letters in ascending alphabetical sequence) • outputs the alphabetical sequence of characters from the first to the second character. For example, if the characters ‘B’ and ‘F’ are input, the output is: BCDEF

Question paper, page 3

3 9608/42/M/J/17 © UCLES 2017 [Turn over The programmer has started to write the program in the following table. The Comment column contains descriptions for the missing program instructions, labels and data. Complete the following program. Use op codes from the given instruction set. Label Op code Operand Comment START: // INPUT character // store in CHAR1 // INPUT character // store in CHAR2 // initialise ACC to ASCII value of CHAR1 // output contents of ACC // compare ACC with CHAR2 // if equal jump to end of FOR loop // increment ACC // jump to LOOP ENDFOR: END CHAR1: CHAR2: [9] (b) The programmer now starts to write a program that: • converts a positive integer, stored at address NUMBER1, into its negative equivalent in two’s complement form • stores the result at address NUMBER2 Complete the following program. Use op codes from the given instruction set. Show the value stored in NUMBER2. Label Op code Operand Comment START: MASK // convert to one's complement // convert to two's complement END MASK: // show value of mask in binary here NUMBER1: B00000101 // positive integer NUMBER2: // negative equivalent [6]

Question paper, page 4

4 9608/42/M/J/17 © UCLES 2017 2 An ordered binary tree Abstract Data Type (ADT) has these associated operations: • create tree • add new item to tree • traverse tree The binary tree ADT is to be implemented as a linked list of nodes. Each node consists of data, a left pointer and a right pointer. (a) A null pointer is shown as O. Explain the meaning of the term null pointer. … …[1] (b) The following diagram shows an ordered binary tree after the following data have been added: Dublin, London, Berlin, Paris, Madrid, Copenhagen Dublin RootPointer Berlin Ø Ø Ø Ø Ø Ø Copenhagen London Paris Madrid Ø Another data item to be added is Athens. Make the required changes to the diagram when this data item is added. [2]

Question paper, page 5

5 9608/42/M/J/17 © UCLES 2017 [Turn over (c) A tree without any nodes Unused nodes are linked together into a free list is represented as: as shown: RootPointer Ø FreePointer Ø Ø Ø Ø Ø The following diagram shows an array of records that stores the tree shown in part (b). (i) Add the relevant pointer values to complete the diagram. RootPointer LeftPointer Tree data RightPointer 0 [0] Dublin [1] London [2] Berlin [3] Paris [4] Madrid FreePointer [5] Copenhagen [6] Athens [7] [8] [9] [5]

Question paper, page 6

6 9608/42/M/J/17 © UCLES 2017 (ii) Give an appropriate numerical value to represent the null pointer for this design. Justify your answer. … … … …[2] (d) A program is to be written to implement the tree ADT. The variables and procedures to be used are listed below: Identifier Data type Description Node RECORD Data structure to store node data and associated pointers. LeftPointer INTEGER Stores index of start of left subtree. RightPointer INTEGER Stores index of start of right subtree. Data STRING Data item stored in node. Tree ARRAY Array to store nodes. NewDataItem STRING Stores data to be added. FreePointer INTEGER Stores index of start of free list. RootPointer INTEGER Stores index of root node. NewNodePointer INTEGER Stores index of node to be added. CreateTree() Procedure initialises the root pointer and free pointer and links all nodes together into the free list. AddToTree() Procedure to add a new data item in the correct position in the binary tree. FindInsertionPoint() Procedure that finds the node where a new node is to be added. Procedure takes the parameter NewDataItem and returns two parameters: • Index, whose value is the index of the node where the new node is to be added • Direction, whose value is the direction of the pointer (“Left” or “Right”).

Question paper, page 7

7 9608/42/M/J/17 © UCLES 2017 [Turn over (i) Complete the pseudocode to create an empty tree. TYPE Node … … … ENDTYPE DECLARE Tree : ARRAY[0 : 9] … DECLARE FreePointer : INTEGER DECLARE RootPointer : INTEGER PROCEDURE CreateTree() DECLARE Index : INTEGER … … FOR Index ← 0 TO 9 // link nodes … … ENDFOR … ENDPROCEDURE [7]

Question paper, page 8

8 9608/42/M/J/17 © UCLES 2017 (ii) Complete the pseudocode to add a data item to the tree. PROCEDURE AddToTree(BYVALUE NewDataItem : STRING) // if no free node report an error IF FreePointer … THEN OUTPUT("No free space left") ELSE // add new data item to first node in the free list NewNodePointer ← FreePointer … // adjust free pointer FreePointer ← … // clear left pointer Tree[NewNodePointer].LeftPointer ← … // is tree currently empty ? IF … THEN // make new node the root node … ELSE // find position where new node is to be added Index ← RootPointer CALL FindInsertionPoint(NewDataItem, Index, Direction) IF Direction = "Left" THEN // add new node on left … ELSE // add new node on right … ENDIF ENDIF ENDIF ENDPROCEDURE [8]

Question paper, page 9

9 9608/42/M/J/17 © UCLES 2017 [Turn over (e) The traverse tree operation outputs the data items in alphabetical order. This can be written as a recursive solution. Complete the pseudocode for the recursive procedure TraverseTree. PROCEDURE TraverseTree(BYVALUE Pointer : INTEGER) … … … … … … … … … … ENDPROCEDURE [5]

Question paper, page 10

10 9608/42/M/J/17 © UCLES 2017 3 A programmer is writing a treasure island game to be played on the computer. The island is a rectangular grid, 30 squares by 10 squares. Each square of the island is represented by an element in a 2D array. The top left square of the island is represented by the array element [0, 0]. There are 30 squares across and 10 squares down. The computer will: • generate three random locations where treasure will be buried • prompt the player for the location of one square where the player chooses to dig • display the contents of the array by outputting for each square: – '.' for only sand in this square – 'T' for treasure still hidden in sand – 'X' for a hole dug where treasure was found – 'O' for a hole dug where no treasure was found. Here is an example display after the player has chosen to dig at location [9, 3]: … … … … … …T… … … …T… ...X… The game is to be implemented using object-oriented programming. The programmer has designed the class IslandClass. The identifier table for this class is: Identifier Data type Description Grid ARRAY[0 : 9, 0 : 29] OF CHAR 2D array to represent the squares of the island Constructor() instantiates an object of class IslandClass and initialises all squares to sand HideTreasure() generates a pair of random numbers used as the grid location of treasure and marks the square with 'T' DigHole(Row, Column) takes as parameters a valid grid location and marks the square with 'X' or 'O' as appropriate GetSquare(Row, Column) CHAR takes as parameter a valid grid location and returns the grid value for that square from the IslandClass object

Question paper, page 11

11 9608/42/M/J/17 © UCLES 2017 [Turn over (a) The programmer designed the pseudocode for the main program as follows: DECLARE Island : IslandClass.Constructor() // instantiate object CALL DisplayGrid() // output island squares FOR Treasure ← 1 TO 3 // hide 3 treasures CALL Island.HideTreasure() ENDFOR CALL StartDig() // user to input location of dig CALL DisplayGrid() // output island squares Write program code to implement this pseudocode. Programming language used … Program code … … … … … … … … … … … … …[3]

Question paper, page 12

12 9608/42/M/J/17 © UCLES 2017 (b) Write program code to declare the IslandClass and write the constructor method. The value to represent sand should be declared as a constant. Programming language used … Program code … … … … … … … … … … … … … … … … … … … … … …[5]

Question paper, page 13

13 9608/42/M/J/17 © UCLES 2017 [Turn over (c) The procedure DisplayGrid shows the current grid data. DisplayGrid makes use of the getter method GetSquare of the Island class. An example output is: … … … … … …T… … … …T… ...X… (i) Write program code for the GetSquare(Row, Column) getter method. … … … … …[2] (ii) Write program code for the DisplayGrid procedure. … … … … … … … … … … …[4]

Question paper, page 14

14 9608/42/M/J/17 © UCLES 2017 (d) Write program code for the HideTreasure method. Your method should check that the random location generated does not already contain treasure. The value to represent treasure should be declared as a constant. Programming language used … Program code … … … … … … … … … … … … … …[5]

Question paper, page 15

15 9608/42/M/J/17 © UCLES 2017 [Turn over (e) (i) The DigHole method takes two integers as parameters. These parameters form a valid grid location. The location is marked with 'X' or 'O' as appropriate. Write program code for the DigHole method. The values to represent treasure, found treasure and hole should be declared as constants. Programming language used … Program code … … … … … … … … … … … … …[3]

Question paper, page 16

16 9608/42/M/J/17 © UCLES 2017 (ii) The StartDig procedure: • prompts the player for a location to dig • validates the user input • calls the DigHole method from part (e)(i). Write program code for the StartDig procedure. Ensure that the user input is fully validated. Programming language used … Program code … … … … … … … … … … … … … … … … … … … … … … … …[5]

Question paper, page 17

17 9608/42/M/J/17 © UCLES 2017 (f) (i) The squares in the IslandClass grid could have been declared as objects of a Square class. State the term used to describe the relationship between IslandClass and Square. … …[1] (ii) Draw the appropriate diagram to represent this relationship. Do not list the attributes and methods of the classes. [2]

Question paper, page 18

18 9608/42/M/J/17 © UCLES 2017 BLANK PAGE

Question paper, page 19

19 9608/42/M/J/17 © UCLES 2017 BLANK PAGE

Question paper, page 20

20 9608/42/M/J/17 © UCLES 2017 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 International Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after the live examination series. Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local Examinations Syndicate (UCLES), which is itself a department of the University of Cambridge. BLANK PAGE

Mark scheme, page 1

® IGCSE is a registered trademark. This document consists of 19 printed pages. © UCLES 2017 [Turn over Cambridge International Examinations Cambridge International Advanced Subsidiary and Advanced Level COMPUTER SCIENCE 9608/42 Paper 4 Written Paper May/June 2017 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 will not enter into discussions about these mark schemes. Cambridge is publishing the mark schemes for the May/June 2017 series for most Cambridge IGCSE®, Cambridge International A and AS Level and Cambridge Pre-U components, and some Cambridge O Level components.

Mark scheme, page 2

9608/42 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 2 of 19 Question Answer Marks 1(a) Label Op code Operand Comment START: IN // INPUT character 1 STO CHAR1 // store in CHAR1 IN // INPUT character 1 STO CHAR2 // store in CHAR2 LDD CHAR1 // initialise ACC to ASCII value of CHAR1 1 LOOP: OUT //output contents of ACC 1+1 CMP CHAR2 // compare ACC with CHAR2 1 JPE ENDFOR // if equal jump to end of FOR loop 1 INC ACC // increment ACC 1 JMP LOOP // jump to LOOP 1 ENDFOR: END CHAR1: CHAR2: 9 1(b) Label Op code Operand Comment START: LDD NUMBER1 1 XOR MASK // convert to one's complement 1 INC ACC // convert to two's complement 1 STO NUMBER2 1 END MASK: B11111111 // show value of mask in binary here 1 NUMBER1: B00000101 // positive integer NUMBER2: B11111011 // show value of negative equivalent 1 6

Mark scheme, page 3

9608/42 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 3 of 19 Question Answer Marks 2(a) • A pointer that doesn’t point to another node/other data/address // indicates the end of the branch 1 2(b) one mark per bullet • node with ‘Athens’ linked to left pointer of Berlin (ignore null pointer) • null pointers in left and right pointers of Athens 2 2(c)(i) RootPointer LeftPointer Tree Data RightPointer 0 [0] 2 Dublin 1 [1] -1/∅ London 3 [2] 6 Berlin 5 [3] 4 Paris -1/∅ [4] -1/∅ Madrid -1/∅ FreePointer [5] -1/∅ Copenhagen -1/∅ 7 [6] -1/∅ Athens -1/∅ 1 mark [7] 8 -1/∅ [8] 9 -1/∅ [9] -1/∅ -1/∅ 5 2(c)(ii) • –1 • It is not the number for any node. 2

Mark scheme, page 4

9608/42 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 4 of 19 Question Answer Marks 2(d)(i) TYPE Node LeftPointer : INTEGER RightPointer : INTEGER 1 Data : STRING ENDTYPE DECLARE Tree : ARRAY[0 : 9] OF Node 1 DECLARE FreePointer : INTEGER DECLARE RootPointer : INTEGER PROCEDURE CreateTree() DECLARE Index : INTEGER RootPointer ← -1 1 FreePointer ← 0 1 FOR Index ← 0 TO 9 // link nodes Tree[Index].LeftPointer ← Index + 1 1 Tree[Index].RightPointer ← -1 1 ENDFOR Tree[9].LeftPointer ← -1 1 ENDPROCEDURE 7

Mark scheme, page 5

9608/42 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 5 of 19 Question Answer Marks 2(d)(ii) PROCEDURE AddToTree(ByVal NewDataItem : STRING) // if no free node report an error IF FreePointer = -1 1 THEN ERROR("No free space left") ELSE // add new data item to first node in the free list NewNodePointer ← FreePointer Tree[NewNodePointer].Data ← NewDataItem 1 // adjust free pointer FreePointer ← Tree[FreePointer].LeftPointer 1 // clear left pointer Tree[NewNodePointer].LeftPointer ← -1 1 // is tree currently empty ? IF RootPointer = -1 1 THEN // make new node the root node RootPointer ← NewNodePointer 1 ELSE // find position where new node is to be added Index ← RootPointer CALL FindInsertionPoint(NewDataItem, Index, Direction) 8

Mark scheme, page 6

9608/42 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 6 of 19 Question Answer Marks IF Direction = "Left" THEN // add new node on left Tree[Index].LeftPointer ← NewNodePointer 1 ELSE // add new node on right Tree[Index].RightPointer ← NewNodePointer 1 ENDIF ENDIF ENDIF ENDPROCEDURE 2(e) 1 mark per bullet • test for base case (null/-1) • recursive call for left pointer • output data • recursive call for right pointer • order, visit left, output, visit right IF Pointer <> NULL 1 THEN TraverseTree(Tree[Pointer].LeftPointer) 1 OUTPUT Tree[Pointer].Data 1 + 1 TraverseTree(Tree[Pointer].RightPointer) 1 ENDIF ENDPROCEDURE 5

Mark scheme, page 7

9608/42 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 7 of 19 Question Answer Marks 3(a) 1 mark per bullet • Instantiation of island object and calling DisplayGrid • Loop 3 times and Island.HideTreasure • Call procedures StartDig and DisplayGrid Example Python Island = IslandClass() 1 DisplayGrid() for Treasure in range(3): Island.HideTreasure() 1 StartDig() DisplayGrid() 1 Example Pascal var Island : IslandClass; var Treasure : integer; begin Island := IslandClass.Create(); 1 DisplayGrid; for Treasure := 1 to 3 do Island.HideTreasure(); 1 StartDig; DisplayGrid; 1 end; 3

Mark scheme, page 8

9608/42 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 8 of 19 Question Answer Marks Example VB.NET Dim Island As New IslandClass() 1 DisplayGrid() For Treasure = 1 To 3 Island.HideTreasure() 1 Next StartDig() DisplayGrid() 1

Mark scheme, page 9

9608/42 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 9 of 19 Question Answer Marks 3(b) 1 mark per bullet to max 5 • Class heading and ending (in appropriate place) • Constructor heading and ending (in appropriate place) • Declaring grid with correct dimensions (as private) • Declaring Sand as a constant • Nested loops covering dimensions (0 – 29 and 0 – 9) • Assigning Sand // ’.’ to each array element Example Python class IslandClass: 1 def __init__(self): 1 Sand = '.' 1 self.__Grid = [[Sand for j in range(30)] 1 + 1 for i in range(10)] 1 Example Pascal type IslandClass = class 1 private Grid : array[0..9, 0..29] of char; 1 public constructor Create(); procedure HideTreasure(); procedure DigHole(x, y : integer); function GetSquare(x, y : integer) : char; end; constructor IslandClass.Create(); 1 const Sand = '.'; 1 var i, j : integer; begin for i := 0 to 9 do for j := 0 to 29 do 1 Grid[i, j] := Sand; 1 end; 5

Mark scheme, page 10

9608/42 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 10 of 19 Question Answer Marks Example VB.NET Class IslandClass 1 Private Grid (9, 29) As Char 1 Public Sub New() 1 Const Sand = "." 1 For i = 0 To 9 For j = 0 To 29 1 Grid(i, j) = Sand 1 Next Next End Sub End Class 3(c)(i) 1 mark per bullet • Method (getter or property) heading, takes two parameters returns char, and ending • Method returns Grid value Example Python def GetSquare(self, Row, Column) : 1 return self.__Grid[Row][Column] 1 Example Pascal function IslandClass.GetSquare( Row, Column : integer) As Char; 1 begin Result := Grid[Row, Column]; end; 1 Example VB.NET Public Function GetSquare(Row As Integer, Column As Integer) As Char 1 Return Grid(Row, Column) 1 end Function 2

Mark scheme, page 11

9608/42 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 11 of 19 Question Answer Marks 3(c)(ii) 1 mark per bullet • DisplayGrid header and ending, with two loops with correct limits • Calling Island.GetSquare with correct parameters inside iteration • Output an entire row in one line • Output a new line at the end of a row Example Python def DisplayGrid() : for i in range (10) : for j in range (30) : 1 print(island.GetSquare(i, j), end='') 1 + 1 print() 1 Example Pascal procedure DisplayGrid(): var i, j : integer; begin for i := 0 to 9 do begin for j := 0 to 29 do 1 write(island.GetSquare(i, j))); 1 + 1 writeLn; 1 end; end; Example VB.NET Sub DisplayGrid() For i = 0 to 9 For j = 0 to 29 1 Console.Write(island.GetSquare(i, j)) 1 + 1 Next Console.WriteLine() 1 Next End Sub 4

Mark scheme, page 12

9608/42 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 12 of 19 Question Answer Marks 3(d) 1 mark per bullet to max 5 • Method header and Declaring Treasure as a constant • Generating a random number for column • Generating a random number for row • Check whether treasure already at generated location • Repeatedly generate new coordinates in a loop • Assign Treasure to location Example Python def HideTreasure(self): 1 Treasure = 'T' x = randint(0,9) 1 y = randint(0,29) 1 while self.__Grid[y][x] == Treasure: 1+1 x = randint(0,9) y = randint(0,29) self.__Grid[y][x] = Treasure 1 Example Pascal procedure IslandClass.HideTreasure(); const Treasure = 'T'; 1 var x, y : integer; begin repeat x := Random(10); 1 y := random(30); 1 until Grid[x, y] <> Treasure; 1+1 Grid[x, y] := Treasure; 1 end; Max 5

Mark scheme, page 13

9608/42 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 13 of 19 Question Answer Marks Example VB.NET Public Sub HideTreasure() Const Treasure = "T" 1 Dim RandomNumber As New Random Dim x, y As Integer Do x = RandomNumber.Next(0, 10) 1 y = RandomNumber.Next(0, 30) 1 Loop Until Grid(x, y) <> Treasure 1+1 Grid(x, y) = Treasure 1 End Sub

Mark scheme, page 14

9608/42 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 14 of 19 Question Answer Marks 3(e)(i) 1 mark per bullet • Method heading, with two parameters & Declaring constants for Treasure, Hole and FoundTreasure • Check if treasure at parameter locations • Set to FoundTreasure (X) and Set to Hole (O) Example Python def DigHole(self, x, y) : Treasure = 'T' Hole = 'O' 1 Foundtreasure = 'X' if self.__Grid[x][y] == Treasure: 1 self.__Grid[x][y] = Foundtreasure else : 1 self.__Grid[x][y] = Hole return Example Pascal procedure IslandClass.DigHole(x, y : integer); const Treasure = 'T'; const Hole = 'O'; const Foundtreasure = 'X'; 1 begin if Grid[x, y] = Treasure 1 then Grid[x, y] := Foundtreasure else Grid[x, y] := Hole; 1 end; 3

Mark scheme, page 15

9608/42 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 15 of 19 Question Answer Marks Example VB.NET Public Sub DigHole(x As Integer, y As Integer) Const Treasure = "T" Const Hole = "O" Const Foundtreasure = "X" 1 If Grid(x, y) = Treasure Then 1 Grid(x, y) = Foundtreasure Else Grid(x, y) = Hole 1 End If End Sub

Mark scheme, page 16

9608/42 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 16 of 19 Question Answer Marks 3(e)(ii) 1 mark per bullet to max 5 • Prompt to user for position down and across, read positions input as an IntegerValidation for position row – between 0 and 9 • Validation for position column- between 0 and 29 • Exception handling/pass for validation • Ask for repeated input until valid (for both row and column) • Call Island.DigHole method with the coordinates Example Python def StartDig() : Valid = False while not Valid : # validate down position 1 try: x = int(input("position down <0 to 9> ? ")) 1 if x >= 0 and x <= 9 : 1 Valid = True except: Valid = False Valid = False while not Valid : # validate across position try : y = int(input("position across <0 to 29> ? ")) 1 if y >= 0 and y <= 29 : 1 Valid = True except : Valid = False island.DigHole(x, y) 1 return Max 5

Mark scheme, page 17

9608/42 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 17 of 19 Question Answer Marks Example Pascal procedure StartDig; var xString, yString : String; x, y : integer; begin Valid := False; repeat Write('position down <0 to 9>? '); ReadLn(xString); 1 try x := StrToInt(xString); if (x >= 0) AND (x <= 9) 1 then Valid := True; except Valid := False; until Valid; Valid := False; repeat Write(position across <0 to 29> ? '); ReadLn(yString); 1 try y := StrToInt(yString); if (y >= 0) AND (y <= 29) 1 then Valid := True; except Valid := False; until Valid; 1 island.DigHole(x,y); 1 end;

Mark scheme, page 18

9608/42 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 18 of 19 Question Answer Marks Example VB.NET Sub StartDig() Dim x, y As Integer Dim Valid = False Do Console.Write("Position down <0 to 9>? ") Try x = CInt(Console.ReadLine()) 1 If (x >= 0) AND (x <= 9) Then 1 Valid = True End If Catch Valid = False 'accept different types of exceptions End Try Loop Until Valid Valid = False Do Console.Write("Position across <0 to 29> ? ") Try y = int(Console.ReadLine()) 1 If (y >= 0) AND (y <= 29) Then 1 Valid = True End IF Catch Valid = False End Try Loop until Valid 1 island.DigHole(x, y) 1 End Sub 3(f)(i) containment/aggregation 1

Mark scheme, page 19

9608/42 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 19 of 19 Question Answer Marks 3(f)(ii) • IslandClass box and Square Box, with correct connection • One at IslandClass and one .. * at Square Max 2

What you needed in this session

Cambridge’s own grade thresholds for 2017 May/June, Paper 4 · Variant 2. A higher threshold means an easier paper — the bar moves with how the cohort did.

A48/75
B37/75
C28/75
D20/75
E11/75