Cambridge International Examinations Cambridge International Advanced Subsidiary and Advanced Level

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Cambridge International Examinations

Cambridge International Advanced Subsidiary and Advanced Level

COMPUTER SCIENCE 9608/22


Paper 2 Written Paper May/June 2016
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 2016 series for most Cambridge IGCSE®,
Cambridge International A and AS Level components and some Cambridge O Level components.

® IGCSE is the registered trademark of Cambridge International Examinations.

This document consists of 14 printed pages.

© UCLES 2016 [Turn over


Page 2 Mark Scheme Syllabus Paper
Cambridge International AS/A Level – May/June 2016 9608 22

Question Answer Marks

1 (a) (i) Item Statement Selection Iteration Assignment 6

1 MyScore = 65 
2 FOR IndexVal = 0 TO 99 

3 MyArray[3] = ID(MyString,3,2) 

4 IF MyScore >= 70 THEN 


5 ENDWHILE 
6 ELSE Message = "Error"  

One mark per row


Additional ticks in any row cancels that row

(ii) Item Purpose of statement 6

1 Assign 65 to MyScore
(Start of) loop with loop counter starting from zero & going to 99 /
2
repeating 100 times
3 Assign 2 chars from position 3/4 in MyString to MyArray element 3/4
4 Test if MyScore is greater than or equal to 70
Marks the end of WHILE / precondition loop //Return to top of loop to
5
check condition
6 If a condition is FALSE, variable Message is assigned the value "ERROR"

Exact wording not important


Explanation must refer to variables or values used in code (except for row 5)

(iii) Expression Result 2

"D" & RIGHT(MyString, 4) "Dance"


LEFT(RIGHT(MyString, 7), 3) "ten"

Must have correct case


Quotation marks optional

© Cambridge International Examinations 2016


Page 3 Mark Scheme Syllabus Paper
Cambridge International AS/A Level – May/June 2016 9608 22

Question Answer Marks

2 (a) Identifier Data Type Description 4

AlarmState BOOLEAN Alarm is set to ON or OFF


Value / number from sensor / as
SensorValue INTEGER input by user // used in calculation
of Temperature
REAL / FLOAT /
ThresholdValue
SINGLE / DOUBLE Threshold value for comparison

Temperature
REAL / FLOAT / Temperature value calculated
SINGLE / DOUBLE from sensor value

One mark per row


Data types as shown
Descriptions given above are examples only

© Cambridge International Examinations 2016


Pag
P ge 4 Mar
M k Sch
S hemme
e Sylllab
S bus Pape
P er
C mb
Cambrid
dge Inte
ern
nattional AS/
A /A Le
eve
el – May
M y/Ju
une 201
2 16 9 08
960 2
22

Qu
Q ues
stio
on An
nsw
wer Mar
M rks
s

(b) Max
M x6
A rm
Ala mState ← FA
ALS
SE 1

INPUT ThresholdValue
INPUT SensorV
Value 2

Tem
mperature ← Sen
S nso
orV
Val
lue
e * 1.1
1 135
5 3

IF Temperature > ThresholdValue


HEN
TH N

lar
Al rmS
Sta
ate
e ← T
TRU
UE
5
OU
UTP
PUT
T "Te
" emp
per
rat
tur
re Al
lar
rm"
"
4 LSE
EL E
OU
UTP
PUT
T "Te
" emp
per
rat
tur
re OK
K" 6

Al
lar
rmS
Sta
ate
e ← FA
ALS
SE 7
ENDIF

Mark
k poin
p nts ass ciirclled
d, des
d scriptions as
a below
w:

1. Seettin
ng Al lar State tto FA
rmS F LSE (Co
( ond d. che
c eck
k not essentiaal b
butt mus
m st be
b ccorrrect if
pre
ese entt)
2. puttting S
Inp SennsorrVaal an nd ThhreeshholldVaal
3. Coorreectt va
alue
e ass
a signned
d to
o Tem
T mpeeratur ( ustt be * not x)
re (m
4. IFF...TH HENN..ELS SE...EENDDIF stru
s uctture
e with
w h co ct condition
orrrec n (o
or two
t o se
eparaate
e IF
F
cla
aussess)
5. Coorreectt TH
HENN staatemeentts as
a sho
s ow
wn
6. Coorreectt EL
LSEE stat
s temment as sh howwn
7. Seettin
ng Al lar State tto FA
rmS F LSE wit
w thinn ELS
SE cla
c aus o ly if m
se on maark pooin
nt 1 not
giv
ven n

© Ca
amb
brid
dge
e In
nterrnattion
nal Ex
xam
mina
atio
ons
s 20
016
6
Page 5 Mark Scheme Syllabus Paper
Cambridge International AS/A Level – May/June 2016 9608 22

Question Answer Marks

3 (a) FUNCTION EncryptString (LookUp : ARRAY, PlainText : STRING) 10


RETURNS STRING

DECLARE OldChar, NewChar : CHAR


DECLARE OldCharValue : INTEGER
DECLARE OutString: STRING

//first initialise the return string

OutString ← "" //initialise the return string

//loop through PlainText to produce OutString

FOR n ← 1 to LENGTH(PlainText) //from first to last character


OldChar ← MID(PlainText, n, 1) //get next character
OldCharValue ← ASC(OldChar) //find the ASCII value
NewChar ← Lookup[OldCharValue] //look up substitute character
OutString ← Outstring & NewChar // concatenate to OutString

ENDFOR

RETURN OutString // EncryptString ← OutString

ENDFUNCTION

One mark for each part-statement (shown underlined and bold)

(b) (i) VB: Dim Lookup(0 to 127 / 128) As CHAR 2

Pascal: Var Lookup: Array[0..127 / 1..128] Of CHAR

Python: Lookup = ["" for i in range(128)]

OR

Lookup = []
For i in range(128) :
Lookup.append("")

Mark as follows:
VB / Pascal: one mark per part-statement as underlined and bold
Python:
One mark for Lookup and []
One mark for range(128)

© Cambridge International Examinations 2016


Pag
P ge 6 Mar
M k Sch
S hemme
e Sylllab
S bus Pape
er
C mb
Cambrid
dge Inte
ern
nattional AS/
A /A Le
eve
el – May
M y/Ju
une 201
2 16 9 08
960 2
22

Ques
Qu stio
on An
nsw
wer Mar
M rks
s

(ii) 'P
Pseudocode' ssollutiion
n inclu
ude
ed here forr de
eveelo
opm
mennt and
a d clar
c rificcattion
n of mar
m rk 6
scche
emee.
Prrog
gramm min
ng lan
ngu
uag ge solution
ns app
a pea ar in the
t e App
A penndix
x.

IN
NPU
UT St
tar
rtP
Pos
s 1
IN
NPU
UT Nu
umT
ToC
Cha
ang
ge

FO
OR n ← 0 to
o Num
N mTo
oCh
han
nge
e - 1
OUT
O TPU
UT " In
npu
ut ne
ew va ue fo
alu or po
osi
ition
n " 3
2
INP
I PUT
T New
N wCh
har
r 4
Loo
L oku
up[St
tar
rtP
Pos n] ← Ne
s + n ewC
Cha
ar 5
EN
NDF
FOR
R

UPU
OU UT (N
Num
mTo
oCh
han
nge
e & " ent
e tri
ies c
cha
ang d") 6
ged

AL
LTE
ER
RNA
ATIV
VEE:

IN
NPU
UT St
tar
rtP
Pos
s 1
IN
NPU
UT Nu
umT
ToC
Cha
ang
ge
n ← 0

RE
EPE
EAT
T
OUT
O TPU
UT " In
npu
ut ne
ew va ue fo
alu or po ition
osi n " 3
2 INP
I PUT
T New
N wCh
har
r 4
Loo
L oku
up[St
tar
rtP
Pos
s + nn] ← Ne
ewC ar 5
Cha
n ← n + 1
UN
NTI
IL n = Nu
umT
ToC
Cha
ang
ge

OU
UTP
PUT
T (Nu
umT
ToC
Cha ge & " en
ang ntr es ch
rie han ed") 6
nge

Mark
k poin
p nts ass ciirclled
d, des
d scriptions as
a below
w:

1. Tw
wo INNPUUT staateme entts
2. Woork
king
g lo
oopp (u
usiing
g va
alues off n fro om flo
owcchaart))
3. OU
UTPPUTTpprommppt (exaactt te
ext noot spe
s eciffied
d)
4. IN
NPUUT NeewCChaar
5. As
ssig
gnmmeent of NeewCChaar to co orreect arrrayy elem
e me ent
6. OU
UTPPUTT fina
al mes
m ssa agee affter lo
oopp (eexa
actt te
ext noot specifiied
d bu
ut mu
ust inc
clu
ude
e
Nu
umTToCChaange orr looopp coounnte
er iff va
alue cor
c rrec ct a
at tha
t at poin
p nt)

4 (a)) • Pro
ogramm ccod de is eas
e sie
er to
o im
mpplem meent / ma
m nage Max
M x2
• Moodu
ules m may beb givven
n to
o diffe
erent peop ple to de
evelop
p // giv
ven
n to
o pro
p gra
amm
specialiistss
• ogram
Pro m ccod de is eas
e sie
er to
o te
estt / de
d bug / main ntain
• En
ncoouraage es the
e re-u
usa
ability
y off prrog
gram code

© Ca
amb
brid
dge
e In
nterrnattion
nal Ex
xam
mina
atio
ons
s 20
016
6
Pag
P ge 7 Mar
M k Sch
S hemme
e Sylllab
S bus Pape
er
C mb
Cambrid
dge Inte
ern
nattional AS/
A /A Le
eve
el – May
M y/Ju
une 201
2 16 9 08
960 2
22

Ques
Qu stio
on An
nsw
wer Mar
M rks
s

(b) (i) 3

One mark k per co


orre
ect an
nno
otattion
n as
a sho
s ow wn
Arrrow
ws
s may
m y bee draw
d wn n clockw wise
e or anti
a iclo ock
kwise
Diiam
monnd sy
ymbbol may
m y bee filled
d or
o unf
u fille
ed but
b t mus
m st b
be in pos
p sitiion
n sh
how
wn

(ii) A (orr B)
B – Card
C d deta
d ails s / Ca
ard nu ummbeer / Ca
ardd in
nfo 3
B (orr A)
A – Cos
C st detaails
s / am
amou untt pa
aya
ablee / prrod
duc
ct ccostt / tot
t al billl
C – (F
Fla
ag) ind
dic
catoor ffor su
uccces
ssfu
ul pay
p yme entt /// pa
aym
ment confirmation

ata
Da a ite
em f A an
ms for nd B are
a e interrchange
eab
ble

5 (a)) (i) • So
o th
hat the
e dat
d a / infforrmaatio
on is sav
s vedd afte
a er the prrog gram m is
i rrun
n / wh
whenn th
he Max
M x1
compputter is sw
witc
cheed ooff
• o th
So he dat
d ta / in
nforrmation ca an be accce
esssedd neextt tim
me
e thhe pro
p ogramm is
s ru
un
• So
o th
he dat
d ta infoorm
mation can
c n be "pe
" ermmannenntly
y sttoreed""

© Ca
amb
brid
dge
e In
nterrnattion
nal Ex
xam
mina
atio
ons
s 20
016
6
Page 8 Mark Scheme Syllabus Paper
Cambridge International AS/A Level – May/June 2016 9608 22

Question Answer Marks

(ii) Problem: 4
• When retrieving / searching for / editing (text relating to a particular CD)
• Can’t tell where the artist name stops and the title begins (or any similar
explanation or example)

Solution 1:
• Use of a separator character// or by example
• Where the separator character does not occur in the original strings

Solution 2:
• Use a fixed number of characters for each data item
• Data items are padded with e.g. <Space> character where needed

Solution 3:
• Convert original data items to CamelCase
• …and add a Space separator

Mark as follows:
Two marks for description of problem
Two marks for description of solution

© Cambridge International Examinations 2016


Page 9 Mark Scheme Syllabus Paper
Cambridge International AS/A Level – May/June 2016 9608 22

Question Answer Marks

(b) 'Pseudocode' solution included here for development and clarification of mark Max 8
scheme.
Programming language solutions appear in the Appendix.

PROCEDURE InputData()

DECLARE CDTitle : STRING


DECLARE CDArtist : STRING
DECLARE CDLocation : STRING
DECLARE FileData : STRING

OPENFILE "MyMusic" FOR WRITE

OUTPUT "Input CD Title"


INPUT CDTitle

WHILE CDTitle <> "##"


OUPUT "Input CD Artist"
INPUT CDArtist
OUPUT "Input CD Location"
INPUT CDLocation
FileData = CDTitle & ':' & CDArtist & ':' &
CDLocation
WRITEFILE "MyMusic.txt", FileData
OUTPUT "Input CD Title"
INPUT CDTitle
ENDWHILE

CLOSEFILE("MyMusic.txt ")

ENDPROCEDURE

One mark for each of the following:

• Procedure heading and ending


• Declaration of CDTitle, CDArtist and CDLocation
• Open file for writing (Allow MyMusic or MyMusic.txt)
• Working conditional loop structure including test for rogue value (including initial
input of CDTitle)
• Input of three data values (CDTitle, CDArtist and CDLocation) inside a
loop
• String concatenation of three variables inside a loop
• Write three variables in single line to file inside a loop
• Close file
• Use of string separator

Solutions may repeatedly OPEN – WRITE – CLOSE within the loop.In this case the first
OPEN could be in WRITE or APPEND mode with all others in APPEND.

© Cambridge International Examinations 2016


Pag
ge 10
1 Mar
M k Sch
S hemme
e Sylllab
S bus Pape
P er
C mb
Cambrid
dge Inte
ern
nattional AS/
A /A Le
eve
el – May
M y/Ju
une 201
2 16 9 08
960 2
22

Ques
Qu stio
on An
nsw
wer Marrks
s

6 (a)) n f x y MI
ID(S
Str
rin
ng1
1, x
x, 1) M D(S
MID Str
rin
ng2, y,
y 1)
) 6

0
0 0
1 1 1 'R
R' 'R
R'
2 2 'E
E' 'A
A'
2 2 1 'E
E' 'R
R'
3 3 1 'T
T' 'R
R'
4 4 1 'R
R' 'R
R'
5 2 'A
A' 'A
A'
6 3 'C
C' 'C
C'
4

One mark
k per co
orre
ect co
olum
mn
n

• Minus one
o e mar
m rk iff anytthing els se on
n firrst row
w
• Coolummnn 2 – '4' mu ustt no
ot pre
p eceede
e '4
4' in
n coolu
umnn 1 (a
as sho
s ow
wn b
by arrrow
w)
• Le ers mu
ette ustt all be in uuppperr ca
asee
• Ign
norre quo
q otaatioon sym
s mb bol

(b) (i) • to searc ch forr a strring


gwwith
hin an
nother strin S rin
ng / Str ng2 w hin St
2 with tri ing1 2
• to retturn he po
n th osittion
noof th art of St
he sta ing2 within St
tri S riingg1 // by
b exa
ammple
e

Firstt mark
k poin
p nt: allow
w lo
oca
ate / fiind
d / cal
c culate
e pos
p sitio
on of

(ii) Va
alu
ue: 0 / ze
ero
o 2

Meanin tring2 no
ng: St ot fou
f und
d in ng1
n Strin 1

(iii) Optiion
n1 2

• It is pos
p ssib ble
e to
o “fa
all offf” th
he en o Stri
nd of ing g1 (orr by
y exa
e ampple
e) whi
w le strring
g
ma h (ffor ex
atch xammplle, Sttring1 = "R Retrrac
ce", Strin
ng2
2 = "RRacced
d")
• MIID (S Str ring g1, x, x 1)// de esc
crip
ptio
on of
o 'su
' bscript out of raang
ge''

Optiion
n2

• e herr sttring is em
If eith e ptyy th
henn
• subsc crip
pt ooutt off ra
ang
ge errrorr // de
escripttion
n

Optiion
n3

• If Str
S ing
g1 ffou und
d with
w hin String
g2
• Ann enndllesss loop will
w occcu
ur

© Ca
amb
brid
dge
e In
nterrnattion
nal Ex
xam
mina
atio
ons
s 20
016
6
Page 11 Mark Scheme Syllabus Paper
Cambridge International AS/A Level – May/June 2016 9608 22

Appendix - Program Code Solutions

3 (b) (ii): VB.NET

Console.Write("Enter start position: ")


StartPos = Console.ReadLine()
Console.Write("Enter number to change: ")
NumToChange = Console.ReadLine()
For n = 0 To NumToChange - 1
Console.Write("Enter new value for position: ")
NewChar = Console.ReadLine()
Lookup(StartPos + n) = NewChar
Next
Console.WriteLine(NumToChange & " entries changed")

ALTERNATIVE:

Console.Write("Enter start position: ")


StartPos = Console.ReadLine()
Console.Write("Enter number to change: ")
NumToChange = Console.ReadLine()
n = 0
Do
Console.Write("Enter new value for position: ")
NewChar = Console.ReadLine()
Lookup(StartPos + n) = NewChar
n = n + 1
Loop Until n = NumToChange
Console.WriteLine(NumToChange & " entries changed")

3 (b) (ii): Pascal

write('Enter start position: ');


readln(StartPos);
write('Enter number to change: ');
readln(NumToChange);
for n := 0 to NumToChange - 1 do
begin
write('Input new value for position: ');
readln(NewChar);
LookUp[Startpos + n] := NewChar;
end;
writeln(IntToStr(NumToChange) + ' entries changed');

© Cambridge International Examinations 2016


Page 12 Mark Scheme Syllabus Paper
Cambridge International AS/A Level – May/June 2016 9608 22

ALTERNATIVE:

write('Enter start position: ');


readln(StartPos);
write('Enter number to change: ');
readln(NumToChange);
n := 0;
repeat
write('Input new value for position: ');
readln(NewChar);
LookUp[Startpos + n] := NewChar;
n := n + 1;
until (n = NumToChange);
writeln(IntToStr(NumToChange) + ' entries changed');

3 (b) (ii): Python

StartPos = int(input("Enter start position: "))


NumToChange = int(input("Enter number to change: "))
for n in range(NumToChange) :
NewChar = input("Input new value for position: ")
LookUp[StartPos + n - 1] = NewChar
print(str(NumToChange) + " entries changed")

ALTERNATIVE:

StartPos = int(input("Enter start position: "))


NumToChange = int(input("Enter number to change: "))
n = 0
while n < NumToChange :
NewChar = input("Input new value for position: ")
LookUp[StartPos + n] = NewChar
n = n + 1
print(str(NumToChange) + " entries changed")

© Cambridge International Examinations 2016


Page 13 Mark Scheme Syllabus Paper
Cambridge International AS/A Level – May/June 2016 9608 22

5 (b): VB.NET

A StreamWriter() solution:

Sub InputData()
Dim CDTitle, CDArtist, CDLocation As String
Dim FileHandle As IO.StreamWriter
FileHandle = New IO.StreamWriter("MyMusic.txt") ("MyMusic.txt")
Console.WriteLine("Input CD Title: ")
CDTitle = Console.ReadLine()
Do Until CDTitle = "##"
Console.WriteLine("Input CD Artist: ")
CDArtist = Console.ReadLine()
Console.WriteLine("Input CD Location: ")
CDLocation = Console.ReadLine()
FileHandle.WriteLine(CDTitle & ":" & CDArtist & ":" & CDLocation)
Console.WriteLine("Input CD Title: ")
CDTitle = Console.ReadLine()
Loop
FileHandle.Close()
End Sub

A legacy FileOpen() solution:

Sub InputData()
Dim CDTitle, CDArtist, CDLocation As String
FileOpen(1, "MyMusic", OpenMode.Output)
Console.WriteLine("Input CD Title: ")
CDTitle = Console.ReadLine()
Do Until CDTitle = "##"
Console.WriteLine("Input CD Artist: ")
CDArtist = Console.ReadLine()
Console.WriteLine("Input CD Location: ")
CDLocation = Console.ReadLine()
Print(1, CDTitle & ":" & CDArtist & ":" & CDLocation)
Console.WriteLine("Input CD Title: ")
CDTitle = Console.ReadLine()
Loop
FileClose(1)
End Sub

© Cambridge International Examinations 2016


Page 14 Mark Scheme Syllabus Paper
Cambridge International AS/A Level – May/June 2016 9608 22

5 (b): Pascal

procedure InputData;
var
CDTitle, CDArtist, CDLocation : string;
CDFile : Textfile;
begin
assign(CDFile, 'MyMusic');
rewrite(CDFile);
writeln('Input CD Title: ');
readln(CDTitle);
while (CDTitle <> '##') do
begin
writeln('Input CD Artist: ');
readln(CDArtist);
writeln('Input CD Location: ');
readln(CDLocation);
writeln(CDFile, CDTitle + ':' + CDArtist + ':' + CDLocation);
writeln('Input CD Title: ');
readln(CDTitle);
end;
close(CDFile);
end;

5 (b): Python

def InputData() :
#CDTitle String (or CDTitle = "")
#CDArtist String (or CDArtist = "")
#CDLocation String (or CDLocation = "")

FileHandle = open("MyMusic", "w")


CDTitle = input("Input CD Title: ")
while CDTitle != "##" :
CDArtist = input("Input CD Artist: ")
CDLocation = input("Input CD location: ")
FileHandle.write(CDTitle + ":" + CDArtist + ":" + CDLocation)
CDTitle = input("Input CD Title: ")
FileHandle.close()

© Cambridge International Examinations 2016

You might also like