Cambridge International Examinations: Computer Science 9608/42 May/June 2017
Cambridge International Examinations: Computer Science 9608/42 May/June 2017
Cambridge International Examinations: Computer Science 9608/42 May/June 2017
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.
1(b) Op 6
Label Operand Comment
code
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
2(c)(ii) • –1 2
• It is not the number for any node.
Data : STRING
ENDTYPE
DECLARE Tree : ARRAY[0 : 9] OF Node 1
PROCEDURE CreateTree()
DECLARE Index : INTEGER
RootPointer ← -1 1
FreePointer ← 0 1
Tree[Index].LeftPointer ← Index + 1 1
Tree[Index].RightPointer ← -1 1
ENDFOR
Tree[9].LeftPointer ← -1 1
ENDPROCEDURE
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
FreePointer ← Tree[FreePointer].LeftPointer 1
Tree[NewNodePointer].LeftPointer ← -1 1
IF RootPointer = -1 1
Tree[Index].LeftPointer ← NewNodePointer 1
ENDIF
ENDIF
ENDIF
ENDPROCEDURE
THEN
TraverseTree(Tree[Pointer].LeftPointer) 1
TraverseTree(Tree[Pointer].RightPointer) 1
ENDIF
ENDPROCEDURE
Example Python
Island = IslandClass() 1
DisplayGrid()
for Treasure in range(3):
Island.HideTreasure() 1
StartDig()
DisplayGrid() 1
Example Pascal
Island.HideTreasure() 1
Next
StartDig()
DisplayGrid() 1
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;
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
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
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;
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;
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
3(f)(i) containment/aggregation 1