Computer Science (9608) · May/June 2017 · Mark scheme 42

Cambridge Computer Science (9608) mark scheme for paper 42, May/June 2017 — 9608/42/M/J/17, file 9608_s17_ms_42.pdf.

Advertisement
Loading the paper…
Text of this paper

www.dynamicpapers.com

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.

® IGCSE is a registered trademark.

This document consists of 19 printed pages.
© UCLES 2017

[Turn over

9608/42

Cambridge International AS/A Level – Mark Scheme
PUBLISHED

Question
1(a)

May/June 2017
www.dynamicpapers.com

Answer
Label
START:

Op
code

Operand

IN
STO

ENDFOR:

9

Comment
// INPUT character

CHAR1

IN

LOOP:

Marks

1

// store in CHAR1
// INPUT character

1

STO

CHAR2

// store in CHAR2

LDD

CHAR1

// initialise ACC to ASCII value of CHAR1

OUT

//output contents of ACC

1
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

END

CHAR1:
CHAR2:

1(b)

6

Label

Op
code

START:

LDD

NUMBER1

XOR

MASK

// convert to one's complement

1

INC

ACC

// convert to two's complement

1

STO

NUMBER2

Operand

Comment
1

1

END

© UCLES 2017

MASK:

B11111111

// show value of mask in binary here

NUMBER1:

B00000101

// positive integer

NUMBER2:

B11111011

// show value of negative equivalent

Page 2 of 19

1
1

9608/42

Question
2(a)
2(b)

May/June 2017
www.dynamicpapers.com

Cambridge International AS/A Level – Mark Scheme
PUBLISHED
Answer
•

Marks

A pointer that doesn’t point to another node/other data/address // indicates the end of the branch

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

1
2

•
•

2(c)(i)

5
RootPointer

LeftPointer

Tree Data

RightPointer

[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/∅

0

2(c)(ii)

© UCLES 2017

•
•

–1
It is not the number for any node.

2

Page 3 of 19

9608/42

Cambridge International AS/A Level – Mark Scheme
PUBLISHED

Question
2(d)(i)

May/June 2017
www.dynamicpapers.com

Answer

Marks

TYPE Node

7

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

© UCLES 2017

Page 4 of 19

9608/42

Cambridge International AS/A Level – Mark Scheme
PUBLISHED

Question
2(d)(ii)

May/June 2017
www.dynamicpapers.com

Answer

Marks

PROCEDURE AddToTree(ByVal NewDataItem : STRING)

8

// 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
THEN

// make new node the root node

RootPointer
ELSE

1

←

NewNodePointer

// find position where new node is to be added

Index ← RootPointer
CALL FindInsertionPoint(NewDataItem, Index, Direction)

© UCLES 2017

Page 5 of 19

1

9608/42

Cambridge International AS/A Level – Mark Scheme
PUBLISHED

Question

May/June 2017
www.dynamicpapers.com

Answer

Marks

IF Direction = "Left"
THEN

// add new node on left

Tree[Index].LeftPointer
ELSE

←

NewNodePointer

1

// add new node on right

Tree[Index].RightPointer

←

NewNodePointer

1

ENDIF
ENDIF
ENDIF
ENDPROCEDURE

2(e)

5

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
1

IF Pointer <> NULL
THEN
TraverseTree(Tree[Pointer].LeftPointer)

1+1

OUTPUT Tree[Pointer].Data
TraverseTree(Tree[Pointer].RightPointer)
ENDIF
ENDPROCEDURE

© UCLES 2017

1

Page 6 of 19

1

9608/42

Cambridge International AS/A Level – Mark Scheme
PUBLISHED

Question
3(a)

May/June 2017
www.dynamicpapers.com

Answer

Marks
3

1 mark per bullet
• Instantiation of island object and calling DisplayGrid
• Loop 3 times and Island.HideTreasure
• Call procedures StartDig and DisplayGrid
Example Python
1

Island = IslandClass()
DisplayGrid()
for Treasure in range(3):

1

Island.HideTreasure()
StartDig()

1

DisplayGrid()

Example Pascal
var Island : IslandClass;
var Treasure : integer;
begin
1

Island := IslandClass.Create();
DisplayGrid;
for Treasure := 1 to 3 do

1

Island.HideTreasure();
StartDig;

1

DisplayGrid;
end;

© UCLES 2017

Page 7 of 19

9608/42

Cambridge International AS/A Level – Mark Scheme
PUBLISHED

Question

May/June 2017
www.dynamicpapers.com

Answer

Marks

Example VB.NET
1

Dim Island As New IslandClass()
DisplayGrid()
For Treasure = 1 To 3

1

Island.HideTreasure()
Next
StartDig()

1

DisplayGrid()

© UCLES 2017

Page 8 of 19

9608/42

Cambridge International AS/A Level – Mark Scheme
PUBLISHED

Question
3(b)

May/June 2017
www.dynamicpapers.com

Answer

Marks
5

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:
def __init__(self):
Sand = '.'
self.__Grid = [[Sand for j in range(30)]
for i in range(10)]

1
1
1
1+1
1

Example Pascal
type
IslandClass = class
private
Grid : array[0..9, 0..29] of char;
public
constructor Create();
procedure HideTreasure();
procedure DigHole(x, y : integer);
function GetSquare(x, y : integer) : char;
end;
constructor IslandClass.Create();
const Sand = '.';
var i, j : integer;
begin
for i := 0 to 9 do
for j := 0 to 29 do
Grid[i, j] := Sand;
end;
© UCLES 2017

Page 9 of 19

1
1

1
1

1
1

9608/42

Cambridge International AS/A Level – Mark Scheme
PUBLISHED

Question

May/June 2017
www.dynamicpapers.com

Answer

Marks

Example VB.NET
1
1
1
1

Class IslandClass
Private Grid (9, 29) As Char
Public Sub New()
Const Sand = "."
For i = 0 To 9
For j = 0 To 29
Grid(i, j) = Sand
Next
Next
End Sub
End Class

3(c)(i)

1
1

2

1 mark per bullet
•
•

Method (getter or property) heading, takes two parameters returns char, and ending
Method returns Grid value

Example Python
1
1

def GetSquare(self, Row, Column) :
return self.__Grid[Row][Column]

Example Pascal
function IslandClass.GetSquare( Row, Column : integer) As Char;
begin
Result := Grid[Row, Column];
end;

1

1

Example VB.NET
Public Function GetSquare(Row As Integer, Column As Integer) As Char
Return Grid(Row, Column)

end Function

© UCLES 2017

Page 10 of 19

1
1

9608/42

Cambridge International AS/A Level – Mark Scheme
PUBLISHED

Question
3(c)(ii)

May/June 2017
www.dynamicpapers.com

Answer

Marks

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

4

Example Python
def DisplayGrid() :
for i in range (10) :
for j in range (30) :
print(island.GetSquare(i, j), end='')
print()

1
1+1
1

Example Pascal
procedure DisplayGrid():
var i, j : integer;
begin
for i := 0 to 9 do
begin
for j := 0 to 29 do
write(island.GetSquare(i, j)));
writeLn;
end;
end;

1
1+1
1

Example VB.NET
Sub DisplayGrid()
For i = 0 to 9
For j = 0 to 29
Console.Write(island.GetSquare(i, j))
Next
Console.WriteLine()
Next
End Sub
© UCLES 2017

Page 11 of 19

1
1+1
1

9608/42

Cambridge International AS/A Level – Mark Scheme
PUBLISHED

Question
3(d)

May/June 2017
www.dynamicpapers.com

Answer

Marks
Max 5

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
1

def HideTreasure(self):
Treasure = 'T'
x = randint(0,9)
y = randint(0,29)
while self.__Grid[y][x] == Treasure:
x = randint(0,9)
y = randint(0,29)
self.__Grid[y][x] = Treasure

1
1
1+1

1

Example Pascal
procedure IslandClass.HideTreasure();
const Treasure = 'T';
var x, y : integer;
begin
repeat
x := Random(10);
y := random(30);
until Grid[x, y] <> Treasure;
Grid[x, y] := Treasure;
end;

© UCLES 2017

1

1
1
1+1
1

Page 12 of 19

9608/42

Cambridge International AS/A Level – Mark Scheme
PUBLISHED

Question

May/June 2017
www.dynamicpapers.com

Answer

Marks

Example VB.NET
Public Sub HideTreasure()
Const Treasure = "T"
Dim RandomNumber As New Random
Dim x, y As Integer
Do
x = RandomNumber.Next(0, 10)
y = RandomNumber.Next(0, 30)
Loop Until Grid(x, y) <> Treasure
Grid(x, y) = Treasure
End Sub

© UCLES 2017

1

1
1
1+1
1

Page 13 of 19

9608/42

Cambridge International AS/A Level – Mark Scheme
PUBLISHED

Question
3(e)(i)

May/June 2017
www.dynamicpapers.com

Answer

Marks
3

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'
Foundtreasure = 'X'
if self.__Grid[x][y]
self.__Grid[x][y]
else :
self.__Grid[x][y]
return

:
1
1

== Treasure:
= Foundtreasure

1
= Hole

Example Pascal
procedure IslandClass.DigHole(x, y : integer);
const Treasure = 'T';
const Hole = 'O';
const Foundtreasure = 'X';
begin
if Grid[x, y] = Treasure
then
Grid[x, y] := Foundtreasure
else
Grid[x, y] := Hole;
end;

© UCLES 2017

Page 14 of 19

1
1

1

9608/42

Cambridge International AS/A Level – Mark Scheme
PUBLISHED

Question

May/June 2017
www.dynamicpapers.com

Answer

Marks

Example VB.NET
Public Sub DigHole(x As Integer, y As Integer)
Const Treasure = "T"
Const Hole = "O"
Const Foundtreasure = "X"
If Grid(x, y) = Treasure Then
Grid(x, y) = Foundtreasure
Else
Grid(x, y) = Hole
End If
End Sub

© UCLES 2017

Page 15 of 19

1
1

1

9608/42

Cambridge International AS/A Level – Mark Scheme
PUBLISHED

Question
3(e)(ii)

May/June 2017
www.dynamicpapers.com

Answer

Marks
Max 5

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
try:
x = int(input("position down <0 to 9> ? "))
if x >= 0 and x <= 9 :
Valid = True
except:
Valid = False
Valid = False
while not Valid :
# validate across position
try :
y = int(input("position across <0 to 29> ? "))
if y >= 0 and y <= 29 :
Valid = True
except :
Valid = False
island.DigHole(x, y)

return

© UCLES 2017

Page 16 of 19

1
1
1

1
1

1

9608/42

Cambridge International AS/A Level – Mark Scheme
PUBLISHED

Question

May/June 2017
www.dynamicpapers.com

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);
try
x := StrToInt(xString);
if (x >= 0) AND (x <= 9)
then
Valid := True;
except
Valid := False;
until Valid;
Valid := False;
repeat
Write(position across <0 to 29> ? '); ReadLn(yString);
try
y := StrToInt(yString);
if (y >= 0) AND (y <= 29)
then
Valid := True;
except
Valid := False;
until Valid;
island.DigHole(x,y);
end;

© UCLES 2017

Page 17 of 19

1

1

1

1

1
1

9608/42

Cambridge International AS/A Level – Mark Scheme
PUBLISHED

Question

May/June 2017
www.dynamicpapers.com

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())
If (x >= 0) AND (x <= 9) Then
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())
If (y >= 0) AND (y <= 29) Then
Valid = True
End IF
Catch
Valid = False
End Try
Loop until Valid
island.DigHole(x, y)
End Sub

3(f)(i)

© UCLES 2017

containment/aggregation

1
1

1
1

1
1

1

Page 18 of 19

9608/42

Cambridge International AS/A Level – Mark Scheme
PUBLISHED

Question
3(f)(ii)

© UCLES 2017

Answer
•
•

IslandClass box and Square Box, with correct connection
One at IslandClass and one .. * at Square

Page 19 of 19

May/June 2017
www.dynamicpapers.com

Marks
Max 2

Advertisement