Cambridge International AS & A Level: Computer Science 9608/22 October/November 2021

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

Cambridge International AS & A Level

COMPUTER SCIENCE 9608/22


Paper 2 Fundamental 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.

This document consists of 19 printed pages.

© UCLES 2021 [Turn over


9608/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

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.

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.

© UCLES 2021 Page 2 of 19


9608/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

1(a) One mark per bullet point to Max 4 e.g. 4


Design stage activities:
• create / produce / define identifier table // decide on identifiers
• create / produce / define data structures // data types
• create / produce / define file structures
• create / produce / define test plan / strategy
• create pseudocode
• create flowchart etc.
• identify inputs/outputs/processes
• decomposing the problem into sub-problems
• choose a suitable programming language

Coding stage activities:


• write program code // coding the algorithms (from design) 'write code' on
its own is NE
• define data structures
• use a translator to check and run the code
• initial debugging // testing
• any example of actions performed when programming

1(b)(i) One mark per bullet point to Max 2 2


• names are not meaningful (or equivalent) // name does not reflect the
identifier's use
• makes the program/variables more difficult to understand // difficult for
non-technical/other person to understand the program/variables
• makes the program more difficult to debug / modify / test

1(b)(ii) One mark for each correct row. 4


Line Appropriate identifier name

102 Price / ItemPrice / StockPrice

103 ExpiryDate / ItemExpiryDate / EndDate

105 LowStockValue / LowValue / LowStock

106 IsOutOfStock / IsInStock

1(b)(iii) One mark each 2


• (Constant) declaration with appropriate identifier for program version (as
String)
• Storing correct value in the variable (equals or arrow)
e.g.
CONSTANT ProgramVersion = "ver1.5.8"

1(c) One mark each to Max 2 2


• wider range of character can be represented
• symbols from (more) languages can be represented
• pictograms / emoticons can be represented

© UCLES 2021 Page 3 of 19


9608/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

2(a) One mark each of the following to max 5: 5


• Input the membership number
• Open the file LOYALTY.txt for read and close the file
• Loop until end of file (and membership number not found)
• …read each line from the file
• Extract stored membership number and points
• If number of points is 10 or more, return/output free cake
• If membership number not found, return/output appropriate
value/message
• If number of points is below 10, return / output no free cake
• Subtract 10 points from their points and store

2(b) One mark for each correct row. 4

Description of Evaluates
Pseudocode expression
expression to

Evaluates to TRUE if
STRING_TO_NUM(DayOfMonth)
DayOFMonth is within <= 7 FALSE
the first seven days of // DayOfMonth <= "7"
the month

Concatenates the
MID(Firstname,2,2) &
second and third
RIGHT(Lastname, 3)
letters of Firstname
// MID(Firstname,2,2) & "eason"
and concatenate with MID(Lastname,
the last three letters LENGTH(Lastname)-3, 3)
of Lastname

Evaluates to TRUE if
DOB contains eight LENGTH(DOB) = 8 TRUE
characters

Evaluates to TRUE if
IsMember AND Points >= 10
the customer is a
member and has IsMember = TRUE AND
TRUE
enough points for a Points >= 10
free slice of cake

© UCLES 2021 Page 4 of 19


9608/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

2(c) One mark for each bullet point 4

• CASE statement has correct structure (all key words and format)
• Correct assignment/identification of all 3 file types in case statement
• Assignment/return of "Unknown" as default
• Return FileType instead of FileExt // Correct return value for all file
types and Unknown

FUNCTION GetFileType(Filename : STRING) RETURNS STRING


DECLARE FileExt : STRING
DECLARE FileType: STRING

FileExt ← RIGHT(Filename, 3)

CASE OF FileExt
'rtf' : FileType ← "Rich text format"
'csv' : FileType ← "Comma separated values"
'txt' : FileType ← "Text"
OTHERWISE : FileType ← "Unknown"
ENDCASE

RETURN FileType

ENDFUNCTION

Question Answer Marks

3(a) One mark each to max 3 3


• break the problem/algorithm (not program / code) into smaller steps /
parts/ subproblems
• ... repeatedly only if MP1 given
• … until all subproblems small/detailed enough to solve
• … to identify program modules // to identify repeated elements // for
modular programming
• … to identify subroutines

3(b) 1 mark for definition of term e.g. 2


• apply current knowledge to an unfamiliar scenario

1 mark for how the skills are used in program development e.g.
• use current knowledge of a familiar programming language in a new
language

© UCLES 2021 Page 5 of 19


9608/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

4(a) One mark for each bullet point 4

• Procedure heading and ending


• Loop from 1 to 20 // Loop from 0 to 19 Allow NEXT for ENDFOR
• Assign −1 to array at loop counter
• All logic correct, does not override Flower array, all 20 elements assigned
−1

e.g.
PROCEDURE InitialiseArray()

DECLARE Index : INTEGER

FOR Index ← 1 TO 20
Flower[Index] ← -1
ENDFOR

ENDPROCEDURE

© UCLES 2021 Page 6 of 19


9608/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

4(b) One mark for each bullet point: 7


• Declare variable to store first flower visited and initialise to 10 // Store
flower 10 in first array index
• Loop until all 20 flowers are stored
• Generate random number between 1 and 20 in the loop …
• … Check if array at random number is −1 // Check if random number is
already in flower array
• … If it is not −1 / already in array, generate another random number
• … repeatedly until −1 / not in array
• … otherwise assign Flower at previous flower to random number //
otherwise assign random number to next array element and increment
counter

'Pseudocode' solution included here for development and clarification of mark


scheme. Programming language example solutions appear at the end.
Example 1:
PROCEDURE RandomPath()
DECLARE New : INTEGER
DECLARE Previous : INTEGER
New ← 10
Previous ← 10

FOR X ← 0 TO 19
WHILE NOT(Flower[New] = -1)
New ← INT(RAND(20)+1)
Flower[Previous] ← New
ENDWHILE
ENDFOR
ENDPROCEDURE
Example 2:
PROCEDURE RandomPath()

DECLARE Current : INTEGER


DECLARE Counter: INTEGER
DECLARE Next : INTEGER

Current ← 10
Counter ← 1

WHILE Counter <= 20


Next ← INT(RAND(20)+1)

IF Flower[Next] = -1
THEN
Flower[Current] ← Next
Current ← Next
Counter ← Counter + 1
ENDIF

ENDWHILE

ENDPROCEDURE

© UCLES 2021 Page 7 of 19


9608/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

4(c)(i) 1 mark for error type: 2


• Logic // run-time

1 mark for method of detection e.g.


• Testing the program with a range of data
• Whitebox testing
• Blackbox testing

4(c)(ii) 1 mark each to max 2 e.g. 2


• Program crashes
• Error as number is out of array bounds // number below 1 will produce
error // number above 20 will produce error
• Not all elements will be accessed/used
• Error if decimal generated
• Error if negative number generated
• Infinite loop may be generated

Question Answer Marks

5(a) 1 mark each 5


• Start and end Start/begin End/stop Procedure/end procedure
• For each circled area (Max 4)

© UCLES 2021 Page 8 of 19


9608/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

5(b) 1 mark for values, 1 mark for result from: 6


• Year >= 0 UseSuffix = TRUE
• Matching Year value with "CE"

• Year >= 0 UseSuffix = FALSE


• Matching Year value

• Year < 0 UseSuffix = TRUE


• Matching Year value with "BCE"

• Year < 0 UseSuffix = FALSE


• Matching Year value

5(c)(i) One mark each to max 2. 2


• code is unknown/not considered
• data is chosen to test boundaries // test with normal, extreme and
erroneous
• compare expected output with actual output // testing whether the inputs
produce the correct/expected outputs
• testing if the program meets the requirements

5(c)(ii) One mark each to max 2. 2


• data is chosen to test algorithm/code
• tests every path in the code
• test each line of code/structure
• internal structure is being tested
• tester can view code

© UCLES 2021 Page 9 of 19


9608/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

6(a) One mark each to max 6: 6

• Function declared taking the string to search for as a parameter, string


return (and array)
• (Declare and) initialise a variable (0) to count number times code occurs
• Loop through 20 000 elements … // looping until unused element
• … IF Left 7 from GeoCodeLog[loop counter] = parameter …
• … if true, increment number times occurs
• … if true, RIGHT 10 from GeoCodeLog[loop counter] …
• … if true compare to last date and replace if after // store in variable for
last date
• Return concatenated number times & " " & last date …
• … converting number to string
Example 1:
FUNCTION SearchLog(SearchGeoCode : STRING) RETURNS STRING
DECLARE AccessCount : INTEGER
DECLARE LatestDate : STRING
DECLARE DateAccess : DATE

LatestDate ← "01/01/1500"
FOR Index ← 0 TO 19999
IF LEFT(GeoCodeLog[Index], 7)
THEN
AccessCount ← AccessCount + 1
DateAccess ← (RIGHT(GeoCodeLog[Index],
10)).TODATE
IF DateAccess > LatestDate
THEN
LatestDate ← DateAccess
ENDIF
ENDIF
ENDFOR
RETURN NUM_TO_STRING(AccessCount) & " " &
DATE_TO_STRING(LatestDate)

ENDFUNCTION

© UCLES 2021 Page 10 of 19


9608/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

6(a) Example 2:
FUNCTION SearchLog(SearchGeoCode : STRING) RETURNS STRING

DECLARE Index : INTEGER


DECLARE AccessCount : INTEGER
DECLARE LogGeoCode : STRING
DECLARE LastDate : STRING
DECLARE CountDateLine : STRING

CONSTANT SPACE = ' '

Index ← 1
AccessCount ← 0
LogGeoCode ← ""
LastDate ← ""

WHILE Index <= 20000 AND LogGeoCode <> "AAAA+0A"


LogGeoCode ← LEFT(GeoCodeLog[Index], 7)
IF LogGeoCode = SearchGeoCode
THEN
AccessCount ← AccessCount + 1
LastDate ← RIGHT(GeoCodeLog[Index], 10)
ENDIF
Index ← Index + 1
ENDWHILE

CountDateLine ← NUM_TO_STRING(AccessCount) & SPACE &


LastDate

RETURN CountDateLine

ENDFUNCTION

© UCLES 2021 Page 11 of 19


9608/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

6(b) 1 mark each to max 7 7


• Procedure header
• Open file "Locations.txt" in WRITE mode and close the file
• Loop through 20 000 elements // looping until unused element …
• … if GeoCodeData[loop counter] = "AAAA+0A" loop again/exit
• … if not empty call SearchLog() with
LEFT(GeoCodeData[DataIndex], 7) … FT invalid/missing if
• … use/store returned value
• … replace the space with a #
• … concatenate GeoCodeData[loop counter] & "#" & returned data inside
the loop …
• … writing this value to file inside the loop

'Pseudocode' solution included here for development and clarification of mark


scheme.
Programming language example solutions appear at the end.
Example 1:
PROCEDURE ExtractArrays()

DECLARE DataIndex : INTEGER


DECLARE ShortCode, CountAndDate, LocationLine,
TempCode : STRING

CONSTANT FILENAME = "Locations.txt"

DataIndex ← 1
ShortCode ← ""
TempCode ← ""

OPENFILE FILENAME FOR WRITE

FOR Count ← 0 TO 19999


ShortCode ← LEFT(GeoCodeData[DataIndex], 7)
IF NOT(ShortCode = "AAAA+0A") THEN
CountAndDate ← SearchLog(ShortCode)
FOR Index ← 0 TO LENGTH(CountAndDate)-1
IF NOT(MID(CountAndDate,Index,1) = " ")
THEN
TempCode = TempCode &
MID(CountAndDate,Index,1)
ELSE
TempCode = TempCode & "#"
ENDIF
ENDFOR
LocationLine ← GeoCodeData[DataIndex] & "#" &
TempCode
WRITEFILE(FILENAME, LocationLine)

© UCLES 2021 Page 12 of 19


9608/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

6(b) ENDIF
ENDFOR
CLOSEFILE FILENAME

ENDPROCEDURE

Example 2:

PROCEDURE ExtractArrays()

DECLARE DataIndex : INTEGER


DECLARE ShortCode, CountAndDate, LocationLine : STRING

CONSTANT HASH = '#'


CONSTANT FILENAME = "Locations.txt"

DataIndex ← 1
ShortCode ← ""

OPENFILE FILENAME FOR WRITE

WHILE DataIndex <= 20000 AND ShortCode <> "AAAA+0A"


ShortCode ← LEFT(GeoCodeData[DataIndex], 7)
IF ShortCode <> "AAAA+0A"
THEN
CountAndDate ← SearchLog(ShortCode)
LocationLine ← GeoCodeData[DataIndex] & HASH &
CountAndDate
WRITEFILE (FILENAME, LocationLine)
ENDIF
DataIndex ← DataIndex + 1
ENDWHILE

CLOSEFILE FILENAME

ENDPROCEDURE

© UCLES 2021 Page 13 of 19


9608/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Program Code Example Solutions

Q4 (b): Visual Basic

Sub RandomPath()
' alternative solution
Dim Index, Current, NextFlower As Integer
Dim AllFlowersVisited As Boolean
Dim RandomFlower As New Random

Current = 10
AllFlowersVisited = False

Do While AllFlowersVisited = False


NextFlower = RandomFlower.Next(1, 20)

If Flower(NextFlower) = 0 Then
If Flower(Current) = 0 Then
Flower(Current) = NextFlower
End If
Current = NextFlower
End If
AllFlowersVisited = True
For Index = 1 To 20
If Flower(Index) = 0 Then
AllFlowersVisited = False
End If
Next
Loop
End Sub

© UCLES 2021 Page 14 of 19


9608/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Q4 (b): Pascal

procedure RandomPath();
// alternative solution
var
Index, Current, Next: integer;
AllFlowersVisited : boolean;

begin
Current := 10;
AllFlowersVisited := False;

while (AllFlowersVisited = False) do


begin
Randomize;
Next := RandomRange(1, 21);

if (Flower[Next] = 0) then
begin
if (Flower[Current] = 0) then Flower[Current] := Next;
Current := Next;
end;
AllFlowersVisited := True;
for Index := 1 to 20 do
begin
if Flower[Index] = 0 then
AllFlowersVisited := False;
end;
end;
end;

© UCLES 2021 Page 15 of 19


9608/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Q4 (b): Python

from random import seed


from random import randint

def RandomPath():
# alternative solution
#DECLARE Index : INTEGER
#DECLARE Current : INTEGER
#DECLARE Next : INTEGER
#DECLARE AllFlowersVisited : BOOLEAN

Current = 10 #start at flower 10 in the field


AllFlowersVisited = False

while AllFlowersVisited == False:


#loop until all flowers visited
Next = randint(20)
if Flower[Next] == 0:
if Flower[Current] == 0: #do not revisit a flower
Flower[Current] = Next
Current = Next

AllFlowersVisited = True #assume all visited unless...


for Index in range(1, 20):
if Flower[Index] == 0:
AllFlowersVisited = False #... proved otherwise

© UCLES 2021 Page 16 of 19


9608/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Q6 (b): Visual Basic

Sub ExtractArrays()
Dim DataIndex As Integer
Dim ShortCode, CountAndDate, LocationLine, CountHashDate As String
Dim Sr As StreamWriter = New StreamWriter("Locations")

Const HASH = "#"

DataIndex = 1
ShortCode = ""
CountHashDate = ""

Do While DataIndex <= 20000 And ShortCode <> "AAAA+0A"


CountHashDate = ""
ShortCode = GeoCodeData(DataIndex).SubString(0, 7)
If ShortCode <> "AAAA+0A" Then
CountAndDate = SearchLog(ShortCode)
For Index = 0 To CountAndDate.Length()-1
If (MID(CountAndDate, Index, 1) = " ") Then
CountHashDate = CountHashDate & "#"
Else
CountHashDate = CountHashDate & MID(CountAndDate, Index, 1) = ""
End If
Next Index
LocationLine = GeoCodeData(DataIndex) & HASH & CountHashDate
Sr.WriteLine(LocationLine)
End If
DataIndex = DataIndex + 1
Loop
Sr.Close()
End Sub

© UCLES 2021 Page 17 of 19


9608/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Q6 (b): Pascal

procedure ExtractArrays();
var
DataIndex: integer;
ShortCode, CountAndDate, LocationLine, CountHashDate: string;
Locations: textfile;
const
HASH = '#';
begin
DataIndex := 1;
ShortCode := '';

assign(Locations,'M:\Locations');
rewrite(Locations);

while (DataIndex <= 20000) and (ShortCode <> 'AAAA+0A') do


begin
CountHashDate := "";
ShortCode := LeftStr(GeoCodeData[DataIndex], 7);
if ShortCode <> 'AAAA+0A' then
begin
CountAndDate := SearchLog(ShortCode);
for Index := 0 to Length(CountAndDate)-1 do
begin
if CountAndDate[Index] = " " then
CountHashDate := CountHashDate + "#"
else
CountHashDate := CountHashDate + CountAndDate[Index];
end;

LocationLine := GeoCodeData[DataIndex] + HASH + CountHashDate;


writeln(Locations, LocationLine);
end;
DataIndex := DataIndex + 1;
end;
close(Locations);
end;

© UCLES 2021 Page 18 of 19


9608/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Q6 (b): Python

def ExtractArrays():
#DECLARE DataIndex : INTEGER
#DECLARE ShortCode, CountAndDate, LocationLine, CountHashDate : STRING

HASH = "#"
FILENAME = "Locations"

DataIndex = 1
ShortCode = ""

filehandle = open(FILENAME, 'w')

while dataIndex <= 20000 and ShortCode <> "AAAA+0A":


ShortCode = GeoCodedata[DataIndex][:7]
CountHashDate = ""
if ShortCode <> "AAAA+0A":
CountAndDate = SearchLog(ShortCode)
for Index in range(0, Len(CountAndDate):
if (CountAndDate[Index] == " "):
CountHashDate += "#"
else:
CountHashDate += CountAndDate[Index]
LocationLine = GeoCodeData[DataIndex] + HASH + CountHashDate
filehandle.write(LocationLine)
DataIndex += 1

filehandle.close()

© UCLES 2021 Page 19 of 19

You might also like