[go: up one dir, main page]

0% found this document useful (0 votes)
28 views733 pages

P2 Pseudocode - Topical and Yearly

The document is a yearly index for A Level Computer Science past papers from 2015 to 2024, detailing the paper codes and corresponding page numbers for each exam session. It also includes a topical index covering various programming topics such as data types, arrays, subroutines, and programming theory. Additionally, the document contains examples of code and programming constructs relevant to the curriculum.

Uploaded by

bintezehra135
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views733 pages

P2 Pseudocode - Topical and Yearly

The document is a yearly index for A Level Computer Science past papers from 2015 to 2024, detailing the paper codes and corresponding page numbers for each exam session. It also includes a topical index covering various programming topics such as data types, arrays, subroutines, and programming theory. Additionally, the document contains examples of code and programming constructs relevant to the curriculum.

Uploaded by

bintezehra135
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 733

P2 YEARLY INDEX

A Level Computer Science

2015
- 9608/22 – May/June 2015 – Page 1
- 9608/23 – May/June 2015 – Page 18
- 9608/22 – October/November 2015 – Page 32
- 9608/23 – October/November 2015 – Page 47

2016
- 9608/22 – May/June 2016 – Page 65
- 9608/23 – May/June 2016 – Page 81
- 9608/22 – October/November 2016 – Page 96
- 9608/23 – October/November 2016 – Page 115

2017
- 9608/22 – May/June 2017 – Page 134
- 9608/23 – May/June 2017 – Page 147
- 9608/22 – October/November 2017 – Page 161

- 9608/23 – October/November 2017 – Page 174

2018
- 9608/22 – May/June 2018 – Page 187
- 9608/23 – May/June 2018 – Page 202
- 9608/22 – October/November 2018 – Page 217

- 9608/23 – October/November 2018 – Page 230

2019
- 9608/22 – May/June 2019 – Page 243
- 9608/23 – May/June 2019 – Page 258
- 9608/22 – October/November 2019 – Page 275

- 9608/23 – October/November 2019 – Page 292


2020
- 9608/22 – May/June 2020 – Page 308
- 9608/23 – May/June 2020 – Page 325

- 9608/22 – October/November 2020 – Page 342

- 9608/23 – October/November 2020 – Page 361

2021
- 9608/22 – May/June 2021 – Page 652
- 9608/23 – May/June 2021 – Page 669
- 9608/22 – October/November 2021 – Page 690

- 9608/23 – October/November 2021 – Page 708

- 9618/22 – May/June 2021 – Page 377


- 9618/23 – May/June 2021 – Page 390
- 9618/22 – October/November 2021 – Page 408
- 9618/23 – October/November 2021 – Page 425

2022
- 9618/22 – May/June 2022 – Page 441
- 9618/23 – May/June 2022 – Page 459
- 9618/22 – October/November 2022 – Page 476

- 9618/23 – October/November 2022 – Page 492

2023
- 9618/22 – May/June 2023 – Page 508
- 9618/23 – May/June 2023 – Page 525
- 9618/22 – October/November 2023 – Page 542
- 9618/23 – October/November 2023 – Page 561

2024
- 9618/22 – May/June 2024 – Page 581
- 9618/23 – May/June 2024 – Page 601
- 9618/22 – October/November 2024 – Page 619
- 9618/23 – October/November 2024 – Page 637
TOPICAL INDEX:

UNIT 1 INFORMATION REPRESENTATION


Programming Topic: Topical past paper reference:

Data Types:
Types & Sizes
Variables & Constants Declarations
Record Data Structure UDT
Identifier Table

String Handling

Arrays:
1D & 2D Arrays
Arrays Operations:
Declarations
Initialisations
Linear Search
Bubble Sort
Tracing

Subroutines:
Variable Scope
Global
Local
Types
Procedure
Functions
Header
Interface
Parameters
Types
Formal (Arguments)
Actual (Parameters)
Passing
ByRef
ByVal
Return Value
Structure Charts
Structure Charts to Pseudocode
Debugging
Stub Testing
White bob
Black Box
Programming Topic: Topical past paper reference:
Filing

Abstract Data Types (ADTs)


Stack
Queue
Linked Lists

Programming Theory
Operators
Abstraction
Algorithm
Programming Constructs
Identifiers
Flowcharts
Flowcharts to Pseudocode
Structure English to Pseudocode
Data Types
Record Structure
State Transition Diagrams
Program Development Life Cycle
Testing & Maintenance
Types
Methods of testing
Test Strategy
PAGE 1
PAGE 2
PAGE 3

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
PAGE 4
PAGE 5
PAGE 6
PAGE 7
PAGE 8
PAGE 9
PAGE 10
PAGE 11
PAGE 12
PAGE 13
PAGE 14
PAGE 15
PAGE 16

o
o
PAGE 17
PAGE 18
PAGE 19
PAGE 20
PAGE 21

o
o
o
PAGE 22
PAGE 23
PAGE 24
PAGE 25
PAGE 26
PAGE 27
PAGE 28
PAGE 29
PAGE 30
PAGE 31
PAGE 32
PAGE 33

DECLARE N1 : INTEGER
DECLARE N2 : INTEGER
DECLARE Answer : REAL
DECLARE Found : BOOLEAN
DECLARE IsValid : BOOLEAN
N1 3
N2 9
Answer (N1 + N2) / 6
Answer 3 * (N1 – 2) + N2 / 2
IsValid (N1 > N2) AND (N2 = 9)
Found FALSE

IsValid (N1 > N2 / 2) OR (Found = FALSE)


Answer "1034" & " + " & "65"

Answer

Answer

IsValid

IsValid

Answer
PAGE 34

P INTEGER
Q INTEGER
X INTEGER

01 INPUT P
02 INPUT Q
03 IF (P = 1 AND Q = 0) OR (P = 0 AND Q = 1) OR (P = 0 AND Q = 0)
04 THEN
05 X 0
06 ELSE
07 X 1
08 ENDIF
09 OUTPUT X

P Q X

1 1
1 0
0 1
0 0

03 08
PAGE 35

CalculatePoints

INPUT AmountDue
NewPoints CalculatePoints(AmountDue)
PointsTotal PointsTotal + NewPoints

IF PointsTotal > 500


THEN
OUTPUT "Exchange points?"
INPUT Response
IF Response = "YES"
THEN
PointsTotal PointsTotal – 500
AmountDue AmountDue – 1
ENDIF
ENDIF

OUTPUT AmountDue, PointsTotal


PAGE 36

CALL
CalculatePoints(AmountDue)
PAGE 37
PAGE 38

01 DECLARE SuitNum : INTEGER


02 DECLARE CardValue : INTEGER
03 DECLARE DealCount : INTEGER
04 DECLARE NewCard : BOOLEAN
05 DECLARE CardPack
06
07 CALL InitialiseCardPack
08 DealCount 0
09 WHILE DealCount <> 52
10 NewCard FALSE
11 WHILE NewCard = FALSE
12 SuitNum RANDOM(1,4) // generates a random number
13 CardValue RANDOM(1,13) // in the range given
14 IF CardPack[SuitNum, CardValue] = FALSE
15 THEN
16 CardPack[SuitNum, CardValue] TRUE
17 NewCard TRUE
18 OUTPUT SuitNum, CardValue
19 ENDIF
20 ENDWHILE
21 DealCount DealCount + 1
22 ENDWHILE
23
24 // end of main program
25
26 PROCEDURE InitialiseCardPack
27 DECLARE i : INTEGER
28 DECLARE j : INTEGER
29 FOR i 1 TO 4
30 FOR j 1 TO 13
31 CardPack[i, j] FALSE
32 ENDFOR
33 ENDFOR
34 ENDPROCEDURE
PAGE 39

14 19

05

05 DECLARE CardPack
PAGE 40

18

CardValue

CardName
PAGE 41

Num N

FOR i 1 TO (N - 1)
j 1
REPEAT
IF Num[j] > Num[j + 1]
THEN
Temp Num[j]
Num[j] Num[j + 1]
Num[j + 1] Temp
ENDIF
j j + 1
UNTIL j = (N – i + 1)
ENDFOR

Num
N i j Temp 1 2 3 4 5
PAGE 42

Num ARRAY[1:100] OF INTEGER

Temp
PAGE 43

ONECHAR(ThisString : STRING, Position : INTEGER) RETURNS CHAR


Position
ThisString
ONECHAR("Barcelona", 3)

CHARACTERCOUNT(ThisString : STRING) RETURNS INTEGER


ThisString
CHARACTERCOUNT("South Africa")

x y

x CHARACTERCOUNT("New Delhi") + 3 x

y ONECHAR("Sri Lanka", 5) y

NewString ""
INPUT InputString

j CHARACTERCOUNT(InputString)
FOR i 1 TO j
NextChar ONECHAR(InputString, i)
IF NextChar <> " "
THEN
// the & character joins together two strings
NewString NewString & NextChar
ENDIF
ENDFOR

OUTPUT NewString

InputString STRING
PAGE 44

MyString
ChangedString

RemoveSpaces

// main program
INPUT MyString
ChangedString RemoveSpaces( )
OUTPUT ChangedString

// function definition

FUNCTION RemoveSpaces( ) RETURNS

j CHARACTERCOUNT(InputString)
FOR i 1 TO j
NextChar ONECHAR(InputString, i)
IF NextChar <> " "
THEN
// the & character joins together two strings
NewString NewString & NextChar
ENDIF
ENDFOR

ENDFUNCTION
PAGE 45

CHARACTERCOUNT(ThisString : STRING) RETURNS INTEGER


ThisString
CHARACTERCOUNT("South Africa")

CHR(ThisInteger : INTEGER) RETURNS CHAR


ThisInteger
CHR(66)

ASC(ThisCharacter : CHAR) RETURNS INTEGER


ThisCharacter
ASC('B')

A B C D

Num1 5
A ASC('F') + Num1 + ASC('Z') A
B CHR(89) & CHR(69) & CHR(83) B
C CHARACTERCOUNT(B & "PLEASE") C
D ASC(ONECHAR("CURRY SAUCE", 7)) D
PAGE 46

OUTPUT "Enter message"


INPUT MyMessage
EncryptString ""

FOR i 1 TO CHARACTERCOUNT(MyMessage)
NextNum ASC(ONECHAR(MyMessage, i) + 3)
EncryptString EncryptString & CHR(NextNum)
ENDFOR

OUTPUT EncryptString
PAGE 47
PAGE 48
PAGE 49

DECLARE h, w, r, Perimeter, Area : REAL


DECLARE A, B, C, D, E : BOOLEAN

h 13.6
w 6.4
Perimeter (h + w) * 2 Perimeter ……………………………………

r 10
Area 3.142 * r^2 Area …………………………………………………

Z 11 + r / 5 + 3 Z …………………………………………………………

A NOT(r > 10) A …………………………………………………………


PAGE 50

InA BOOLEAN
InB BOOLEAN
OutZ BOOLEAN

01 INPUT InA
02 INPUT InB
03 IF (InA = FALSE AND InB = FALSE) OR (InA = FALSE AND InB = TRUE)
OR (InA = TRUE AND InB = FALSE)
04 THEN
05 OutZ TRUE
06 ELSE
07 OutZ FALSE
08 ENDIF
09 OUTPUT OutZ

OutZ

InA InB OutZ

TRUE TRUE
TRUE FALSE
FALSE TRUE
FALSE FALSE
PAGE 51

03 08
PAGE 52

Purchase DiscountRate Paid

INPUT Purchase

IF Purchase > 1000


THEN
DiscountRate 0.10
ELSE
IF Purchase > 500
THEN
DiscountRate 0.05
ELSE
DiscountRate 0
ENDIF
ENDIF

Paid Purchase * (1 - DiscountRate)


OUTPUT Paid
PAGE 53
PAGE 54

OUTPUT "Enter purchase price"


INPUT PurchasePrice

CurrentValue
YearCount 1

WHILE AND

IF
THEN
CurrentValue CurrentValue * (1 – 40 / 100)
ELSE
CurrentValue
ENDIF

OUTPUT YearCount, CurrentValue

ENDWHILE
PAGE 55
PAGE 56

01 DECLARE StaffNum : INTEGER


02 DECLARE TaskNum : INTEGER
03 DECLARE
04 DECLARE NewStaffTask : BOOLEAN
05
06 CALL InitialiseTaskGrid
07 Completed 0
08 WHILE Completed <> 60
09 NewStaffTask FALSE
10 WHILE NewStaffTask = FALSE
11 StaffNum RANDOM(1,5) //generates a random number
12 TaskNum RANDOM(1,12) //in the given range
13 IF TaskGrid[StaffNum, TaskNum] = FALSE
14 THEN
15 TaskGrid[StaffNum, TaskNum] TRUE
16 NewStaffTask TRUE
17 OUTPUT StaffNum, TaskNum
18 ENDIF
19 ENDWHILE
20 Completed Completed + 1
21 ENDWHILE
22 OUTPUT "Staff Task Count", Completed
23
24 // end of main program
25
26 PROCEDURE InitialiseTaskGrid()
27 DECLARE i : INTEGER
28 DECLARE j : INTEGER
29 FOR i 1 TO 5
30 FOR j 1 TO 12
31 TaskGrid[i, j] FALSE
32 ENDFOR
33 ENDFOR
34 ENDPROCEDURE
PAGE 57

BOOLEAN

InitialiseTaskGrid

13 18

03
PAGE 58

17

StaffNum

StaffName
PAGE 59

ONECHAR(ThisString : STRING, Position : INTEGER) RETURNS CHAR


Position
ThisString
ONECHAR("Barcelona", 3)

CHARACTERCOUNT(ThisString : STRING) RETURNS INTEGER


ThisString
CHARACTERCOUNT("BRAZIL")

CHR(ThisInteger : INTEGER) RETURNS CHAR


ThisInteger.
CHR(65)

ASC(ThisCharacter : CHAR) RETURNS INTEGER


ThisCharacter.
ASC('A')

A B C D

Num1 15
A CHR(67) & CHR(65) & CHR(84) A
B ASC('P') - ASC('F') + 3 B
C ASC(ONECHAR("BISCUITS", 3)) C
D CHARACTERCOUNT("New York City") + 2 D
PAGE 60

OUTPUT "Enter string"


INPUT MyString
StringTotal 0

FOR i 1 TO CHARACTERCOUNT(MyString)
NextNum ASC(ONECHAR(MyString, i))
StringTotal StringTotal + NextNum
ENDFOR

OUTPUT MyString, StringTotal

StringTotal
MyString.
PAGE 61

ONECHAR(ThisString : STRING, Position : INTEGER) RETURNS CHAR


Position
ThisString
ONECHAR("Barcelona", 3)

y ONECHAR("San Francisco", 6) y

"3/8+3/5" "5/8-1/4"

FractionString STRING
"5/8-1/4"
N1Char CHAR
N2Char CHAR
N3Char CHAR
N4Char CHAR
Op CHAR
PAGE 62

FractionString "3/7+2/9"
N3Char ONECHAR(FractionString, 5) N3Char
Op ONECHAR(FractionString, 4) Op

' ' FractionString

FractionString "3/7+2/9"

ONECHAR(FractionString, )

N1 INTEGER N1Char
N2 INTEGER N2Char
N3 INTEGER N3Char
N4 INTEGER N4Char
TopAnswer INTEGER
BottomAnswer INTEGER
PAGE 63

TONUM(ThisDigit : CHAR) RETURNS INTEGER


ThisDigit
TONUM('8') 8

TOSTR(ThisNumber : INTEGER) RETURNS STRING


ThisNumber
TOSTR(27) "27"

FractionString

OUTPUT "Enter the expression"


INPUT FractionString

// isolate each number digit and assign its number value


N1Char ONECHAR(FractionString, 1)
N1 TONUM(N1Char)
N2Char ONECHAR(FractionString, 3)
N2 TONUM(N2Char)
N3Char ONECHAR(FractionString, 5)
N3 TONUM(N3Char)
N4Char ONECHAR(FractionString, 7)
N4 TONUM(N4Char)

BottomAnswer N2 * N4

Op ONECHAR(FractionString, 4)
IF Op = '+'
THEN
// add fractions
TopAnswer (BottomAnswer / N2) * N1 + (BottomAnswer / N4) * N3
ELSE
// subtract fractions
TopAnswer (BottomAnswer / N2) * N1 - (BottomAnswer / N4) * N3
ENDIF

IF TopAnswer = BottomAnswer
THEN
OUTPUT '1'
ELSE
IF TopAnswer > BottomAnswer
THEN
TopAnswer TopAnswer MOD BottomAnswer
// the & operator joins strings or character values
OUTPUT "1 " & TOSTR(TopAnswer) & "/" & TOSTR(BottomAnswer)
ELSE
OUTPUT TOSTR(TopAnswer) & "/" & TOSTR(BottomAnswer)
ENDIF
ENDIF
PAGE 64

FractionString "2/5-3/8"

N1 N2 N3 N4 BottomAnswer Op TopAnswer

FractionString "3/4+1/4"

N1 N2 N3 N4 BottomAnswer Op TopAnswer

FractionString "7/9+2/3"

N1 N2 N3 N4 BottomAnswer Op TopAnswer
PAGE 65
PAGE 66

MyScore = 65
FOR IndexVal = 0 TO 99
MyArray[3] = MID(MyString,3,2)
IF MyScore >= 70 THEN
ENDWHILE
ELSE Message = "Error"
PAGE 67

MyString "Adaptive
Maintenance"

D & RIGHT(MyString, 4)

LEFT(RIGHT(MyString, 7), 3)
PAGE 68

SampleTemp

SampleTemp

AlarmState

SensorValue

ThresholdValue

Temperature
PAGE 69
PAGE 70

Lookup
Lookup

EncryptString
PlainText

FUNCTION EncryptString(.............................) RETURNS STRING

DECLARE .................... , ...................... : CHAR

DECLARE OldCharValue : ......................................

DECLARE n : INTEGER

DECLARE OutString : STRING

.............................. //initialise the return string

//loop through PlainText to produce OutString

FOR n 1 TO ................. //from first to last character

OldChar ...................//get next character

OldCharValue ..............//find the ASCII value

NewChar ...................//look up substitute character

.............................//concatenate to OutString

ENDFOR

.............................................................
ENDFUNCTION
PAGE 71

Lookup

Lookup

Lookup

StartPos NumToChange n NewChar


PAGE 72

START

Input

Input

n 0

Loop

Output prompt for new


substitute character

Input

Increment

Assign to current array


element

No

Yes

Output message
stating number of
elements changed

STOP
PAGE 73
PAGE 74
PAGE 75

MyMusic

MyMusic

Kind of GreenMiles ColtraneRack1-5


PAGE 76

InputData

CDTitle STRING
CDArtist STRING
CDLocation STRING
PAGE 77

InputData
PAGE 78

FUNCTION SSM(String1, String2 : STRING) RETURNS INTEGER


DECLARE n, f, x, y : INTEGER

n 0
f 0

REPEAT
n n + 1
x n
y 1
WHILE MID(String1, x, 1) = MID(String2, y, 1)

IF y = LENGTH(String2)
THEN
f n
ELSE
x x + 1
y y + 1
ENDIF

ENDWHILE

UNTIL (n = LENGTH(String1)) OR (f <> 0)

RETURN f

ENDFUNCTION

SSM("RETRACE", "RAC")

n f x y MID(String1, x, 1) MID(String2, y, 1)
0 0
PAGE 79

SSM

SSM
PAGE 80

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING

y x ThisString

MID("ABCDEFGH", 2, 3) "BCD"

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING

x ThisString

LEFT("ABCDEFGH", 3) "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING

x ThisString

RIGHT("ABCDEFGH", 3) "FGH"

ASC(ThisChar : CHAR) RETURNS INTEGER

ThisChar

ASC( W ) 87

LENGTH(ThisString : STRING) RETURNS INTEGER

ThisString

LENGTH("Happy Days") 10

&

"Summer" & " " & "Pudding" "Summer Pudding"


PAGE 81
PAGE 82
PAGE 83
PAGE 84
PAGE 85
PAGE 86
PAGE 87

START

Input
p and

Loop

Produce from
(using built-in function)

Assign current arrayy element to


Increment

Output message line


(see examples on the next page)

End of NO
loop?

YES

STOP
PAGE 88
PAGE 89

Modify Basket Contents

E
A F
C

Input product Remove Change product


data product quantity
PAGE 90
PAGE 91
PAGE 92
PAGE 93
PAGE 94
PAGE 95
PAGE 96
PAGE 97

PlayerName STRING
PlayerGameGrade CHAR
PointsTotal INTEGER

SavePlayerTotal PlayerName PointsTotal

ReadPlayerTotal PlayerName
PAGE 98

Start

Yes

No

Stop
PAGE 99

PointsTotal PlayerGameGrade
PointsTotal

Loop

OUPUT INPUT
"Invalid – Re-enter" PlayerGameGrade

Is
No PlayerGameGrade
= 'A' or 'B' or 'C'
or 'D'?

Yes
PAGE 100

x y z

x ONECHAR("Barcelona", 5) x
y ONECHAR("Cool", 1) & ONECHAR("Ball", 2) & "t-food"

Temp1 "13"
Temp2 ONECHAR("One-2-One", 5)
z TONUM(Temp2 & Temp1) z

InputString

13*156*9*86*1463*18*#
PAGE 101

01 DECLARE Numbers ARRAY [1:100] OF INTEGER


02 DECLARE InputString : STRING
03 DECLARE NextChar : CHAR
04 DECLARE NextNumberString : STRING
05 DECLARE i : INTEGER // Numbers array index
06 DECLARE j : INTEGER // InputString index
07
08 OUTPUT "String ... "
09 INPUT InputString
10 j 1
11 NextChar ONECHAR(InputString, j)
12
13 i 1
14 WHILE NextChar <> '#'
15 NextNumberString = ""
16 WHILE NextChar <> '*'
17 NextNumberString NextNumberString & NextChar
18 j j + 1
19 NextChar ONECHAR(InputString, j)
20 ENDWHILE
21
22 // store the next integer to the array
23 Numbers[i] TONUM(NextNumberString)
24 i i + 1
25 j j + 1
26 NextChar ONECHAR(InputString, j)
27 ENDWHILE
28
29 CALL DisplayArray()
PAGE 102

23*731*5*#

Numbers
i j NextChar NextNumberString
1 2 3
1 1 '2'
""
"2 "
2 '3' "23"
3 '*' 23
PAGE 103

11 settype($TimesTable, Integer);
12 settype($upTo, Integer);
13 settype($Posn, Integer);
14 settype($Product, Integer);
15 $TimesTable = 7;
16 $UpTo = 10;
17
18 $Posn = 1
19 While ($Posn < $UpTo + 1)
20 {
21 $Product = $Posn * $TimesTable;
22 Echo $Posn . ' X' . $TimesTable . ' = ' . $Product . "<br>";
23 $Posn = $Posn + 1;
24 }

settype

19
PAGE 104
PAGE 105

RND()

GenerateNumber
PAGE 106
PAGE 107

12 17 67 31
35 82 44 29
61 39 80 17
81 103 21 11
56 0 98 4

45 6 81 77
12 11 3 6

Vorma
Ravi
Chada
Nigam
Bahri
Smith
Goyal
Lata

01 INPUT GameNumber
02 INPUT PlayerNumber
03 INPUT PlayerGameScore
04 PlayerScore[GameNumber, PlayerNumber] PlayerGameScore
PAGE 108

NAMES.TXT

02

02.1 NAMES.TXT PlayerName


02.2 INPUT ThisPlayerName
02.3 PlayerName ThisPlayerName PlayerNumber

02.1
PAGE 109

02.3

PlayerName ARRAY[1 : 8] OF STRING


ThisPlayerName STRING 02.2
ThisPlayerName
Found BOOLEAN
PlayerName
i INTEGER

02.3
PAGE 110

PlayerScore

01 Total50 0
02 Total100 0
03 FOR PlayerIndex 1 TO 8
04 FOR GameIndex 1 TO 20
05 IF PlayerScore[GameIndex, PlayerIndex] > 100
06 THEN
07 Total100 Total100 + 1
08 ELSE
09 IF PlayerScore[GameIndex, PlayerIndex] > 50
10 THEN
11 Total50 Total50 + GameIndex
12 ENDIF
13 ENDIF
14 ENDFOR
15 ENDFOR
16 OUTPUT Total50
17 OUTPUT Total100

03 04 14 15
PAGE 111
PAGE 112

CONST a = 3.2 : REAL


DECLARE x, y, z, Answer1, Answer2, Answer3 : REAL
DECLARE p, q : BOOLEAN
x 3
x x + 7
y 6
Answer1 2 * (a + y)
z 6
Answer2 y ^ 2 + 5
p TRUE
q NOT(NOT(p))
Answer3 y + a * 2

Answer1

Answer2

Answer3
PAGE 113

ONECHAR(ThisString : STRING, Position : INTEGER) RETURNS CHAR

Position
ThisString

ONECHAR("New York", 5) 'Y'

CHARACTERCOUNT(ThisString : STRING) RETURNS INTEGER

ThisString

CHARACTERCOUNT("New York") 8

SUBSTR(ThisString : STRING, Value1 : INTEGER, Value2 : INTEGER) RETURNS


STRING

ThisString
Value1
Value2

SUBSTR("art nouveau", 5, 11) "nouveau"

TONUM(ThisString : STRING) RETURNS INTEGER or REAL

ThisString

TONUM("502") 502
TONUM("56.36") 56.36

ASC(ThisCharacter : CHAR) RETURNS INTEGER

ThisCharacter

ASC('A') 65
PAGE 114

CHR(Value : INTEGER) RETURNS CHAR

Value

CHR(65) 'A'

RND() RETURNS REAL

RND() 0.67351

INT(ThisNumber : REAL) RETURNS INTEGER

ThisNumber

INT(12.79) 12

& STRING CHAR

"South" & " " & "Pole" "South Pole"


'B' & "000654" "B000654"
PAGE 115
PAGE 116

1 Charge 0

2 INPUT BaggageWeight

3 Charge ExcessWeight * ChargeRate

4 Is ExcessWeight > 0 ?

5 INPUT TicketType

6 ExcessWeight BaggageWeight - BaggageAllowance

7 BaggageAllowance 16

8 ChargeRate 3.5

9 OUTPUT Charge

10 ChargeRate 5.75

11 BaggageAllowance 20

12 Is TicketType = 'E' ?
PAGE 117

Start

Stop
PAGE 118

TicketType BaggageWeight

E 15
PAGE 119

INPUT TicketType

TicketType
E S
PAGE 120

READ(<ChannelNumber>)

BitCount 0
Status2 READ(2)
WHILE Status2 = 1

FOR ReadingCount 1 TO 6
ThisBit READ(1)
IF ThisBit = 1
THEN
BitCount BitCount + 1
ENDIF
IF BitCount = 5
THEN
OUTPUT "Error – Investigate"
BitCount 0
ENDIF
ENDFOR

Status2 READ(2)
ENDWHILE
PAGE 121

1 0 1 1 1 0 1 1 0 0 1 1
1 1 0

Status2 ReadingCount ThisBit BitCount

1 1 1 1

2
PAGE 122

<Space> 32 I 73 R 82
A 65 J 74 S 83
B 66 K 75 T 84
C 67 L 76 U 85
D 68 M 77 V 86
E 69 N 78 W 87
F 70 O 79 X 88
G 71 P 80 Y 89
H 72 Q 81 Z 90

Term CHARACTERCOUNT("TSUNAMI")

Term

Answer1 ASC('G') + ASC(<Space>)

Answer1

Answer2 CHR(CHARACTERCOUNT("HELLO") + 70)

Answer2

Word SUBSTR("Welcome home", 4, 7) )

Word
PAGE 123

PROCEDURE CalculateCustomerID

OUTPUT "Key in surname"

INPUT Surname

Length

CustomerID 0

FOR i 1 TO Length

// NextChar is a single character from Surname

NextChar

NextCodeNumber ASC(NextChar)

CustomerID CustomerID +

ENDFOR

OUTPUT "Customer ID is ", CustomerID


PAGE 124

CalculateCustomerID.
PAGE 125

CalculateCustomerID

ThisID

CalculateUserID
PAGE 126
PAGE 127

PRODUCTS

PRODUCTS
0198
Plums(10kg)
11.50
0202
Onions(20kg)
10.00

0376
Mango chutney(1kg)
02.99

0014
Mango(10kg)
12.75

PRODUCTS TEXT FILE

PCode ARRAY[1:1000] OF STRING


PDescription ARRAY[1:1000] OF STRING
PRetailPrice ARRAY[1:1000] OF REAL
i INTEGER
PAGE 128

PRODUCTS

OPEN

i 1

WHILE

READFILE ("PRODUCTS",

READFILE ("PRODUCTS",

READFILE ("PRODUCTS",

ENDWHILE

CLOSE "PRODUCTS"

OUTPUT "Product file contents written to arrays"

PRODUCTS PRODUCTS
0198 Plums(10kg) 11.50
0202 Onions(20kg) 10.00

0376 Mango chutney(1kg) 02.99

0014 Mango(10kg) 12.75


PAGE 129

SearchCode STRING

ThisIndex INTEGER

ThisDescription STRING
ThisRetailPrice REAL

PRODUCTS
PAGE 130

ProductCodeSearch

PCode

ProductCodeSearch
PAGE 131

CONST Pi = 3.1 : REAL

DECLARE Triangle, Base, Height, Radius, Cone : REAL

DECLARE a, b, c, Answer2 : INTEGER

DECLARE Answer1 : BOOLEAN

Base 2.6

Height 10

Triangle (Base * Height) / 2

Radius 1

Height 2

Cone 2 * Pi * Radius * (Radius + Height)

a 13

b 7

c 3

Answer1 NOT((a + b + c) > 28)

Total 34

Total Total - 2

Answer2 a + c * c

Triangle

Cone

Answer1

Total

Answer2
PAGE 132

ONECHAR(ThisString : STRING, Position : INTEGER) RETURNS CHAR

Position
ThisString

ONECHAR("New York", 5) 'Y'

CHARACTERCOUNT(ThisString : STRING) RETURNS INTEGER

ThisString

CHARACTERCOUNT("New York") 8

SUBSTR(ThisString : STRING, Value1 : INTEGER, Value2 : INTEGER) RETURNS


STRING

ThisString
Value1
Value2

SUBSTR("art nouveau", 5, 11) "nouveau"

TONUM(ThisString : STRING) RETURNS INTEGER or REAL

ThisString

TONUM("502") 502
TONUM("56.36") 56.36

ASC(ThisCharacter : CHAR) RETURNS INTEGER

ThisCharacter

ASC('A') 65
PAGE 133

CHR(Value : INTEGER) RETURNS CHAR

Value

CHR(65) 'A'

RND() RETURNS REAL

RND() 0.67351

INT(ThisNumber : REAL) RETURNS INTEGER

ThisNumber

INT(12.79) 12

& STRING CHAR

"South" & " " & "Pole" "South Pole"


'B' & "000654" "B000654"
PAGE 134
PAGE 135
PAGE 136
PAGE 137
PAGE 138
PAGE 139
PAGE 140
PAGE 141
PAGE 142
PAGE 143
PAGE 144
PAGE 145
PAGE 146
PAGE 147
PAGE 148
PAGE 149
PAGE 150
PAGE 151
PAGE 152
PAGE 153
PAGE 154
PAGE 155
PAGE 156
PAGE 157
PAGE 158
PAGE 159
PAGE 160
PAGE 161
PAGE 162
PAGE 163
PAGE 164
PAGE 165
PAGE 166
PAGE 167
PAGE 168
PAGE 169
PAGE 170
PAGE 171
PAGE 172
PAGE 173
PAGE 174
PAGE 175
PAGE 176
PAGE 177
PAGE 178
PAGE 179
PAGE 180
PAGE 181
PAGE 182
PAGE 183
PAGE 184
PAGE 185
PAGE 186
PAGE 187
PAGE 188
PAGE 189
PAGE 190
PAGE 191
PAGE 192
PAGE 193
PAGE 194
PAGE 195
PAGE 196
PAGE 197
PAGE 198
PAGE 199
PAGE 200
PAGE 201
PAGE 202
PAGE 203
PAGE 204
PAGE 205
PAGE 206
PAGE 207
PAGE 208
PAGE 209
PAGE 210
PAGE 211
PAGE 212
PAGE 213
PAGE 214
PAGE 215
PAGE 216
PAGE 217

Cambridge International Examinations


Cambridge International Advanced Subsidiary and Advanced Level
* 2 7 2 0 5 0 4 7 1 6 *

COMPUTER SCIENCE 9608/22


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2018
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.

This document consists of 16 printed pages.

DC (NH/CT) 150983/3
© UCLES 2018 [Turn over
PAGE 218

1 (a) The following table contains statements written in pseudocode.

Show the type of programming construct each statement represents.

Put a tick () in the appropriate column for each statement.

Repetition
Statement Selection Assignment
(Iteration)
Index Index + 5
FOR Count 1 TO 100
TempValue[Index] ReadValue(SensorID)
IF Index < 30
UNTIL DayNumber > 7
OTHERWISE OUTPUT "ERROR"
[6]

(b) (i) The following table contains statements written in pseudocode.

Give the most appropriate data type for the variable used in each statement.

Statement Data type


Revision 'B'
MaxValue 13.3
ArrayFull TRUE
Activity "Design"
NumberOfEdits 270
[5]

(ii) The following table contains statements written in pseudocode.

Complete the table by evaluating each expression using the values from part (b)(i).
If any expression is invalid, write “ERROR” in the Evaluates to column.

For the built-in functions list, refer to the Appendix on page 16.

Expression Evaluates to
MID(Activity, 3, 4) & "ature"
INT(MaxValue * 2)
ArrayFull AND NumberOfEdits < 300
ASC(Revision + 1)
Activity = "Testing" OR Revision = 'A'
[5]

© UCLES 2018 9608/22/O/N/18 [Turn over


PAGE 219

2 Shop customers have a discount card with a unique card number. Customers collect points each
time they buy items. The number of points they collect depends on:

• the total amount they spend


• the number of points already collected.

The function CalcPoints() takes the card number and the total amount spent as parameters. It
returns the number of new points collected. A flowchart for the function is shown.

The function uses the following variables and functions.

Identifier Data type Description


CardNum STRING A numeric string representing the unique card number
OldPoints INTEGER The number of points already collected
NewPoints INTEGER The number of new points collected
Total REAL The amount spent
Takes the card number as a parameter and returns the
GetPoints() FUNCTION
number of points already collected
INT() FUNCTION Refer to the Appendix on page 16

START

Is YES
Total > 100 ?

OldPoints
NO GetPoints(CardNum)

Is NO
OldPoints > 2000 ?

YES

NewPoints INT(Total * 1.2)

NewPoints 0 NewPoints INT(Total * 1.1)

RETURN NewPoints

END

© UCLES 2018 9608/22/O/N/18


PAGE 220

(a) (i) Write pseudocode for the CalcPoints() function.

Your solution should follow the flowchart as closely as possible.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

.......................................................................................................................................[7]

© UCLES 2018 9608/22/O/N/18 [Turn over


PAGE 221

(ii) The value of the total amount spent is calculated by an Electronic Point Of Sale (EPOS)
system. This system does not have the prices of all items. For these items, a valid total
amount has to be entered manually.

A function, GetTotal(), prompts the user to input this value.

If the user enters a valid value greater than 0 and less than 10 000, the function returns
the value. The function prompts the user to re-enter the value each time the user enters
an invalid value.

Write pseudocode to complete the GetTotal() function.

FUNCTION GetTotal() RETURNS REAL

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
ENDFUNCTION
[5]

© UCLES 2018 9608/22/O/N/18


PAGE 222

(b) The function CalcPoints() is written in a high-level language. It has been checked and it
does not contain any syntax or logic errors.

(i) Name and describe one other type of error that the high-level language code could
contain.

Name .................................................................................................................................

Description ........................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[2]

(ii) The function CalcPoints() is tested using white-box testing.

State two different values of Total that could be used to test different paths through the
algorithm. Justify your choices.

Value .................................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

Value .................................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[4]

© UCLES 2018 9608/22/O/N/18 [Turn over


PAGE 223

3 (a) Programming is sometimes referred to as a transferable skill.

You are asked to work on a program written in a language you are not familiar with.

Explain how transferable skills would help you work on the program.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...............................................................................................................................................[2]

(b) Stepwise refinement is often used in the development of an algorithm.

Describe stepwise refinement.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...............................................................................................................................................[2]

(c) A program needs to search through 1000 elements of an unsorted array to find a given value.

The program will output:

• either the position in the array of the value


• or the message “Not Found”

Outline the steps the program needs to follow.

Do not write pseudocode or program code.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...............................................................................................................................................[4]
© UCLES 2018 9608/22/O/N/18
PAGE 224

10

4 Part of a program written in pseudocode is shown.

010 DECLARE NextArrayElement : INTEGER

100 FUNCTION ScanFile(SearchString: STRING) RETURNS INTEGER


101
102 DECLARE FileData : STRING
103 DECLARE FileLine : INTEGER
104
105 NextArrayElement 1
106 FileLine 1
107 FileData ReadFileLine("DataFile.txt", FileLine)
108
109 WHILE FileData <> ""
110 IF LEFT(FileData, 7) = SearchString
111 THEN
112 ResultArray[NextArrayElement] FileData
113 NextArrayElement NextArrayElement + 1
114 ENDIF
115 FileLine FileLine + 1
116 FileData ReadFileLine("DataFile.txt", FileLine)
117 ENDWHILE
118
119 CALL ScanCompleted()
120 RETURN FileLine
121
122 ENDFUNCTION

(a) (i) Examine the pseudocode. Complete the following table.

Answer

The identifier name of a local variable


The identifier name of a user-defined procedure
The identifier name of a user-defined function
The number of dimensions of ResultArray
The scope of FileData
[5]

(ii) Describe in detail the purpose of lines 109 to 117 in the ScanFile() function. Do not
use pseudocode in your answer.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

.......................................................................................................................................[4]
© UCLES 2018 9608/22/O/N/18
PAGE 225

11

(b) The function ScanFile() is to be amended so that the first 7 characters of FileData are
not written to the array.

Write program code to implement this amended ScanFile() function.

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...............................................................................................................................................[8]
© UCLES 2018 9608/22/O/N/18 [Turn over
PAGE 226

12

(c) (i) State how structured programming languages support the implementation of sub-tasks.

.......................................................................................................................................[1]

(ii) State a benefit of using sub-tasks.

...........................................................................................................................................

.......................................................................................................................................[1]

(d) ResultArray is a 1D array of type STRING. It contains 100 elements.

Write program code to declare ResultArray and set all elements to the value "NO DATA".

Programming language .............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...............................................................................................................................................[3]

© UCLES 2018 9608/22/O/N/18


PAGE 227

14

5 The procedure LineNumber() will:

• read data from a text file


• modify each line by adding a line number, and the string (": ")
• output each modified line.

For example, when the procedure reads MyFile.txt, the output is:

10: <First line of MyFile.txt>


15: <Second line of MyFile.txt>
20: <Third line of MyFile.txt>

350: <Last line of MyFile.txt>

The procedure takes three parameters:

Identifier Data type Description


FileName STRING The name of the text file
StartNumber INTEGER The first line number to be added
StepNumber INTEGER The line number increment

In this example, the procedure call would be:

CALL LineNumber("MyFile.txt", 10, 5)

After every 20 lines, the program outputs a message asking whether the user wants to continue.

The program ends when the user enters an 'N' or the end of file is reached.

Write pseudocode for the LineNumber() procedure.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................
© UCLES 2018 9608/22/O/N/18
PAGE 228

15

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [11]
© UCLES 2018 9608/22/O/N/18 [Turn over
PAGE 229

16

Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString

Example: MID("ABCDEFGH", 2, 3) returns string "BCD"

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString

Example: LEFT("ABCDEFGH", 3) returns string "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString

Example: RIGHT("ABCDEFGH", 3) returns string "FGH"

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.

Example: If x has the value 87.5 then NUM_TO_STRING(x) will return "87.5"
Note: This function will also work if x is of type integer.

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: INT(27.5415) returns 27

ASC(ThisChar : CHAR) RETURNS INTEGER


returns the ASCII value of character ThisChar

Example: ASC('A') returns 65

Operators (pseudocode)

Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE

© UCLES 2018 9608/22/O/N/18


PAGE 230

Cambridge International Examinations


Cambridge International Advanced Subsidiary and Advanced Level
* 4 4 2 0 5 0 2 9 9 4 *

COMPUTER SCIENCE 9608/23


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2018
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.

This document consists of 16 printed pages.

DC (NH/CT) 151783/3
© UCLES 2018 [Turn over
PAGE 231

1 (a) The following table contains statements written in pseudocode.

Show the type of programming construct each statement represents.

Put a tick () in the appropriate column for each statement.

Repetition
Statement Assignment Selection
(Iteration)
CASE OF TempSensor1
ELSE
REPEAT
ENDFOR
DayNumber DayNumber + 1
Error TRUE
[6]

(b) (i) The following table contains statements written in pseudocode.

Give the most appropriate data type for the variable used in each statement.

Statement Data type


Revision 500
FuelType 'P'
MinValue -6.3
ServiceDue FALSE
ModelRef "W212DEC15"
[5]

(ii) The following table contains statements written in pseudocode.

Complete the table by evaluating each expression using the values from part (b)(i).

If any expression is invalid, write “ERROR” in the Evaluates to column.

For the built-in functions list, refer to the Appendix on page 16.

Expression Evaluates to
"Month: " & MID(ModelRef, 5, 3)
INT(MinValue * 2)
ASC(Revision)
Revision > 500
ServiceDue = TRUE OR FuelType = 'P'
[5]

© UCLES 2018 9608/23/O/N/18 [Turn over


PAGE 232

2 Shop customers have a discount card with a unique card number. Customers collect points when
they buy items. At the end of each year, customers are given bonus (extra) points related to the
total amount they have spent during the year, and the number of points they have on their card.

The function CalcBonus() takes the card number as a parameter. It returns the bonus points for
the customer. A flowchart for the function is shown.

The function uses the following variables and functions.

Identifier Data type Description


CardNum STRING A numeric string representing the unique card number
Points INTEGER The number of points collected
Spend REAL The total amount that customer has spent during the year
Bonus INTEGER The number of bonus points
Takes the card number as a parameter and returns the
GetPoints() FUNCTION
number of points already collected
Takes the card number as a parameter and returns the
GetSpend() FUNCTION
total amount that customer has spent during the year

START

Points
GetPoints(CardNum)

Spend
GetSpend(CardNum)

Is YES
Points > 2000 ?

NO

Is YES
Spend > 1000 ?

NO

Bonus 10 Bonus 50 Bonus 100

RETURN Bonus

END

© UCLES 2018 9608/23/O/N/18


PAGE 233

(a) (i) Write pseudocode for the CalcBonus() function.

Your solution should follow the flowchart for the function as closely as possible.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

.......................................................................................................................................[5]

© UCLES 2018 9608/23/O/N/18 [Turn over


PAGE 234

(ii) The function GetCardNumber() prompts the user to input a card number until the
number input is valid.

A valid card number has 16 characters. Each character is a numeric character ('0' to
'9').

Write pseudocode to complete the GetCardNumber() function.

You should refer to the function IS_NUM() in the Appendix on page 16.

FUNCTION GetCardNumber() RETURNS STRING

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

ENDFUNCTION
[6]
© UCLES 2018 9608/23/O/N/18
PAGE 235

(b) The function CalcBonus() is written in a high-level language.

(i) The function is tested using black-box testing and does not contain any syntax errors.

Name and describe one other type of error that black-box testing could find.

Name .................................................................................................................................

Description ........................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[2]

(ii) The function CalcBonus() is tested using white-box testing.

State two different pairs of values for Spend and Points that can be used to test
different paths through the function. Justify your choices.

Spend ........................................ Points ......................................

Justification .......................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

Spend ........................................ Points ......................................

Justification .......................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[4]

(c) Name two types of program maintenance and state the reason why each is needed.

Name ........................................................................................................................................

Reason .....................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Name ........................................................................................................................................

Reason .....................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[4]

© UCLES 2018 9608/23/O/N/18 [Turn over


PAGE 236

3 An array contains 100 integer values. An algorithm will find the maximum and minimum values
stored in the array.

(a) A programmer has started to write this program using a conditional loop.

Name a more appropriate loop structure for this task and justify your choice.

Name ........................................................................................................................................

Justification ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[2]

(b) Outline the steps the program will need to follow to implement the algorithm.

Do not write pseudocode or program code.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...............................................................................................................................................[3]

© UCLES 2018 9608/23/O/N/18


PAGE 237

10

4 Part of a program written in pseudocode is shown.

010 DECLARE ThisArray : ARRAY [1:100, 1:10] OF STRING


011 DECLARE LastElement : INTEGER


100 FUNCTION Update(NewData : STRING) RETURNS INTEGER
101 DECLARE ArrayIndex : INTEGER
102 DECLARE Found : BOOLEAN
103
104 ArrayIndex 1
105 Found FALSE
106
107 WHILE ArrayIndex <= LastElement AND Found = FALSE
108 IF ThisArray[ArrayIndex, 1] > NewData
109 THEN
110 Found TRUE
111 ELSE
112 ArrayIndex ArrayIndex + 1
113 ENDIF
114 ENDWHILE
115
116 IF Found = TRUE
117 THEN
118 CALL Insert(ArrayIndex, NewData)
119 ELSE
120 ArrayIndex 0
121 ENDIF
122
123 RETURN ArrayIndex
124 ENDFUNCTION

(a) (i) Examine the pseudocode and complete the following table.

Answer
The name of a global identifier
The name of a user-defined procedure
The scope of ArrayIndex
The number of dimensions of ThisArray
The scope of NewData
[5]

(ii) Describe in detail, the purpose of lines 107 to 114 in the Update() function.
Do not use pseudocode in your answer.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

.......................................................................................................................................[4]
© UCLES 2018 9608/23/O/N/18
PAGE 238

11

(b) Line 118 of the function Update() calls the subroutine Insert(). A designer decides to
convert Insert() from a procedure to a function. Insert() returns TRUE or FALSE.

A programmer must amend the function Update() as follows:


• If Insert() returns FALSE then the function Update() returns -1
• If Insert() returns TRUE then the function Update() returns the value as before.

Write program code to implement the amended Update() function.

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language .............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...............................................................................................................................................[8]
© UCLES 2018 9608/23/O/N/18 [Turn over
PAGE 239

12

(c) The function Update() is an example of a module within a program.

Describe the mechanism that supports the transfer of values between modules.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...............................................................................................................................................[2]

(d) (i) CharArray is a 1D array of type CHAR. It contains 200 elements.

Write program code to change all the numeric characters ('0' to '9') in CharArray
to '*'.

Programming language .....................................................................................................

Program code

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

.......................................................................................................................................[3]

(ii) A programmer decides to declare LastElement as a constant instead of a variable.

Write a statement in pseudocode to declare LastElement as the value 200.

.......................................................................................................................................[1]

© UCLES 2018 9608/23/O/N/18


PAGE 240

14

5 The function ReadFileLine() returns a specific line from a text file.

The function takes two parameters:

Identifier Data type Description


FileName STRING The name of the text file
FileLine INTEGER The line number that is required

The following pseudocode gives an example of the use of the function.

FileData ReadFileLine(FileName, FileLine)

The function ReadFileLine() will:

• open the file, FileName


• read each line from the file until line FileLine is found or the end of the file is reached
• if the line exists, return the string from this line; otherwise return the string "****"

© UCLES 2018 9608/23/O/N/18


PAGE 241

15

Write pseudocode for the ReadFileLine() function.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

....................................................................................................................................................[10]
© UCLES 2018 9608/23/O/N/18 [Turn over
PAGE 242

16

Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString

Example: MID("ABCDEFGH", 2, 3) returns string "BCD"

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString

Example: LEFT("ABCDEFGH", 3) returns string "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString

Example: RIGHT("ABCDEFGH", 3) returns string "FGH"

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 10

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: INT(27.5415) returns 27

ASC(ThisChar : CHAR) RETURNS INTEGER


returns the ASCII value of ThisChar

Example: ASC('A') returns 65

IS_NUM(ThisString : STRING) RETURNS BOOLEAN


returns the value TRUE if ThisString contains only numeric characters ('0' to '9').

Example: IS_NUM("1234X67") returns FALSE

Operators (pseudocode)

Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE
© UCLES 2018 9608/23/O/N/18
PAGE 243

Cambridge Assessment International Education


Cambridge International Advanced Subsidiary and Advanced Level
* 2 5 4 3 3 5 7 7 0 8 *

COMPUTER SCIENCE 9608/22


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2019
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.

This document consists of 16 printed pages.

DC (ST/CT) 163546/4
© UCLES 2019 [Turn over
PAGE 244

1 (a) Algorithms are used in computer programming.

(i) Explain the term algorithm.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(ii) Algorithms usually consist of three different types of activity.

Complete the table below.

The third activity type is given.

Activity type Pseudocode example

..................................................................................................................
.........................
..................................................................................................................

..................................................................................................................
.........................
..................................................................................................................

..................................................................................................................
Output
..................................................................................................................

[5]

© UCLES 2019 9608/22/M/J/19


PAGE 245

(b) Program variables have values as follows:

Variable Value
Married 03/04/1982
ID "M1234"
MiddleInitial 'J'
Height 5.6
IsMarried TRUE
Children 2

(i) Evaluate each expression in the following table.

If an expression is invalid, write ERROR.

For the built-in functions list, refer to the Appendix on page 16.

Expression Evaluates to
STRING_TO_NUM(RIGHT(ID, 3))
INT(Height * Children)
IsMarried AND Married < 31/12/1999
LENGTH(ID & NUM_TO_STRING(Height))
MID(ID, INT(Height) – Children, 2)
[5]

(ii) Programming languages support different data types.

Give an appropriate data type for the following variables from part (b).

Variable Data type


Married
ID
MiddleInitial
Height
IsMarried
[5]

© UCLES 2019 9608/22/M/J/19 [Turn over


PAGE 246

2 (a) (i) Procedures and functions are examples of subroutines.

State a reason for using subroutines in the construction of an algorithm.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) Give three advantages of using subroutines in a program.

1 ........................................................................................................................................

...........................................................................................................................................

2 ........................................................................................................................................

...........................................................................................................................................

3 ........................................................................................................................................

...........................................................................................................................................
[3]

(iii) The following pseudocode uses the subroutine DoSomething().

Answer 23 + DoSomething("Yellow")

State whether the subroutine is a function or a procedure. Justify your answer.

Type of subroutine .............................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................
[2]

(b) The program development cycle involves writing, translating and testing a high-level language
program.

Describe these activities with reference to each of the following:

• editor
• translator
• debugger

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]
© UCLES 2019 9608/22/M/J/19
PAGE 247

(c) The following lines of code are taken from a high-level language program.

WHEN Result < 20


{
Call ResetSensor(3)
Result := GetSensor(3)
}

Identify the type of control structure and describe the function of the code.

Control structure .......................................................................................................................

Function of code .......................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2019 9608/22/M/J/19 [Turn over


PAGE 248

3 The following structure chart shows the relationship between three modules.

TopLevel

B
D

A C
E

SubA SubB

Parameters A to E have the following data types:

A, D : STRING
C : CHAR
B, E : INTEGER

(a) (i) Write the pseudocode header for module SubA().

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

(ii) Write the pseudocode header for module SubB().

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

(b) Module hierarchy and parameters are two features that may be represented on a structure
chart.

State two other features than can be represented.

Feature 1 ..................................................................................................................................

Feature 2 ..................................................................................................................................
[2]

© UCLES 2019 9608/22/M/J/19


PAGE 249

4 The following is pseudocode for a string handling function.

For the built-in functions list, refer to the Appendix on page 16.

FUNCTION Search(InString : STRING) RETURNS INTEGER

DECLARE NewString : STRING


DECLARE Index : INTEGER
DECLARE NextChar : CHAR
DECLARE Selected : INTEGER
DECLARE NewValue : INTEGER

NewString '0'
Selected 0

FOR Index 1 TO LENGTH(InString)

NextChar MID(InString, Index, 1)


IF NextChar < '0' OR NextChar > '9'
THEN
NewValue STRING_TO_NUM(NewString)
IF NewValue > Selected
THEN
Selected NewValue
ENDIF
NewString '0'
ELSE
NewString NewString & NextChar
ENDIF

ENDFOR

RETURN Selected

ENDFUNCTION

© UCLES 2019 9608/22/M/J/19


PAGE 250

(a) (i) The following assignment calls the Search() function:

Result Search("12|34|5||39")

Complete the following trace table by performing a dry run of this function call.

The symbol '|' represents a space character. Use this symbol to represent a space
character in the trace table.

Index NextChar Selected NewValue NewString

[5]

(ii) State the value returned by the function when it is called as shown in part (a)(i).

....................................... [1]

© UCLES 2019 9608/22/M/J/19 [Turn over


PAGE 251

10

(b) There is an error in the algorithm. When called as shown in part (a)(i), the function did not
return the largest value as expected.

(i) Explain why this error occurred when the program called the function.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(ii) Describe how the algorithm could be amended to correct the error.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

5 A student is learning about text files. She wants to write a program to count the number of lines in
a file.

(a) Use structured English to describe an algorithm she could use.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2019 9608/22/M/J/19


PAGE 252

11

(b) A procedure, CountLines(), is being written to count the number of lines in a text file. The
procedure will:

• take a filename as a string parameter


• count the number of lines in the file
• output a single suitable message that includes the total number of lines.

Write pseudocode for the procedure CountLines().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2019 9608/22/M/J/19 [Turn over


PAGE 253

12

6 Nadine is developing a program to store the ID and preferred name for each student in a school.
For example, student Pradeep uses the preferred name “Prad”.

The program will:

1. prompt and input a valid user ID and a preferred name


2. write the user ID and preferred name to one of two files
3. allow the user to end the program or repeat from step 1.

The program will consist of three separate modules. Each module will be implemented using
either a procedure or a function.

Nadine has defined the modules as follows:

Module Description
TopLevel() • Call GetInfo() to obtain a string containing a valid user ID and a
preferred name
• Call WriteInfo() to write the string to either File1.txt or
File2.txt depending on the first character of the user ID as follows:
ż ¶$·WR¶0·ZULWHVWRFile1.txt
ż ¶1·WR¶=·ZULWHVWRFile2.txt
For example, a string with a user ID of "G1234" writes to File1.txt
• End the program if the file write was unsuccessful
• Input (Y/N) to either repeat for the next user ID or to end the program
GetInfo() • Input a user ID and repeat until the user ID is valid
• Input a preferred name. This will be an empty string if no preferred
name is input.
• Concatenate the user ID and preferred name using a '*' character as
a separator and return this string
WriteInfo() • Open the file
• Append the concatenated string to the file
• Close the file
• Return a Boolean value:
ż TRUE if the file write was successful
ż FALSE if the file write failed, for example, if the disk was full

A valid user ID:

• is five characters in length


• has a single upper case alphabetic character followed by four numeric characters, for
example “G1234”.

Nadine has decided that global variables and nested modules must not be used.

Nadine wants all inputs to have suitable prompts.

© UCLES 2019 9608/22/M/J/19


PAGE 254

13

(a) Write program code for the module GetInfo().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]
© UCLES 2019 9608/22/M/J/19 [Turn over
PAGE 255

14

(b) Write program code for the module TopLevel().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]
© UCLES 2019 9608/22/M/J/19
PAGE 256

15

(c) Write pseudocode for the module declaration of WriteInfo().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

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
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.

Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of
Cambridge Local Examinations Syndicate (UCLES), which itself is a department of the University of Cambridge.

© UCLES 2019 9608/22/M/J/19


PAGE 257

16

Appendix

Built-in functions (pseudocode)


Each function returns an error if the function call is not properly formed.

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString

Example: MID("ABCDEFGH", 2, 3) returns "BCD"

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString

Example: LEFT("ABCDEFGH", 3) returns "ABC"

RIGHT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString

Example: RIGHT("ABCDEFGH", 3) returns "FGH"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: INT(27.5415) returns 27

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.

Example: NUM_TO_STRING(87.5) returns "87.5"


Note: This function will also work if x is of type INTEGER

STRING_TO_NUM(x : STRING) RETURNS REAL


returns a numeric representation of a string.

Example: STRING_TO_NUM("23.45") returns 23.45


Note: This function will also work if x is of type CHAR

Operators (pseudocode)

Operator Description

Concatenates (joins) two strings


&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"

Performs a logical AND on two Boolean values


AND
Example: TRUE AND FALSE produces FALSE

Performs a logical OR on two Boolean values


OR
Example: TRUE OR FALSE produces TRUE

© UCLES 2019 9608/22/M/J/19


PAGE 258

Cambridge Assessment International Education


Cambridge International Advanced Subsidiary and Advanced Level
* 9 9 8 3 8 0 6 9 2 4 *

COMPUTER SCIENCE 9608/23


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2019
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.

This document consists of 18 printed pages and 2 blank pages.

DC (ST) 163547/2
© UCLES 2019 [Turn over
PAGE 259

1 The following pseudocode searches for the longest run of identical characters in the array
Message.

DECLARE Message : ARRAY[1:100] OF CHAR

PROCEDURE Search()

DECLARE Index : INTEGER


DECLARE ThisChar : CHAR
DECLARE ThisRun : INTEGER
DECLARE LongRun : INTEGER

ThisChar Message[1]
ThisRun 1
LongRun 1

FOR Index 2 TO 100

IF Message[Index] = ThisChar
THEN
ThisRun ThisRun + 1
ELSE
ThisChar Message[Index]
IF ThisRun > LongRun
THEN
LongRun ThisRun
ENDIF
ThisRun 1
ENDIF

ENDFOR

OUTPUT "The longest run was " , LongRun

ENDPROCEDURE

© UCLES 2019 9608/23/M/J/19


PAGE 260

(a) Draw a program flowchart to represent the procedure Search().

Variable and array declarations are not required in program flowcharts.

[6]
© UCLES 2019 9608/23/M/J/19 [Turn over
PAGE 261

(b) (i) Program variables have values as follows:

Variable Value
MeltingPoint 180.5
Soluble FALSE
Attempt 3
ProductName "Mushroom Compost"
Version 'A'
ProductID "BZ27-4"

Evaluate each expression in the following table.

If an expression is invalid, write ERROR.

For the built-in functions list, refer to the Appendix on page 18.

Expression Evaluates to
STRING_TO_NUM(MID(ProductID, 3, 2)) + 4
INT(MeltingPoint / 2)
Soluble AND Attempt > 3
LENGTH(ProductID & NUM_TO_STRING(MeltingPoint))
RIGHT(ProductName, 4) & MID(ProductName, 5, 4)
[5]

(ii) Programming languages support different data types.

Give an appropriate data type for the following variables from part (b)(i).

Variable Data type


MeltingPoint

Soluble

Attempt

Version

ProductID
[5]

© UCLES 2019 9608/23/M/J/19


PAGE 262

2 (a) A student is learning about arrays. She wants to write a program to:

• search through a 1D array of 100 elements


• count the number of elements that contain the string “Empty”
• output the number of elements containing “Empty” together with a suitable message.

Use structured English to describe the algorithm she could use.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

(b) She uses the process of stepwise refinement to develop her algorithm.

Explain this process.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2019 9608/23/M/J/19 [Turn over


PAGE 263

(c) The student is learning about file handling.

She has been told that there are different file modes that can be used when opening a text
file. She wants to make sure that the existing contents are not deleted when the file is opened.

Identify two file modes she could use and describe their use.

Mode .........................................

Description ................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Mode .........................................

Description ................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[4]

(d) The student has completed the design of her program and is ready to use an Integrated
Development Environment (IDE).

Describe the features of an IDE that she can use to write, translate and test her program.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2019 9608/23/M/J/19


PAGE 264

Question 3 begins on the next page.

© UCLES 2019 9608/23/M/J/19 [Turn over


PAGE 265

3 The following pseudocode represents three separate modules from an algorithm design. The
module contents are not shown.

FUNCTION Search(AA : INTEGER, BB : STRING) RETURNS INTEGER

ENDFUNCTION

FUNCTION Allocate() RETURNS BOOLEAN

ENDFUNCTION

PROCEDURE Enable(CC : INTEGER, BYREF DD : INTEGER)

ENDPROCEDURE

A fourth module, Setup(), refers to the previous three modules as follows:

PROCEDURE Setup()

WHILE Authorised = TRUE

ThisValue Search(27, "Thursday")

Authorised Allocate()

CALL Enable(ThisValue, 4)

ENDWHILE

ENDPROCEDURE

© UCLES 2019 9608/23/M/J/19


PAGE 266

(a) Draw a structure chart to show the four modules and the parameters that these pass between
them.

[6]

(b) The algorithm is implemented in a high-level language. Changes are required and the
program is given to Albert, who is an experienced programmer. He is not familiar with the
language that has been used.

Explain why Albert would be able to understand the program.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2019 9608/23/M/J/19 [Turn over


PAGE 267

10

4 A program is being written to process student information. One task involves inputting the names
of all students in a class.

A first attempt at the pseudocode for this task is as follows:

DECLARE Name1 : STRING


DECLARE Name2 : STRING
DECLARE Name3 : STRING

DECLARE Name40 : STRING

OUTPUT "Input the name for student 1"


INPUT Name1
OUTPUT "Input the name for student 2"
INPUT Name2
OUTPUT "Input the name for student 3"
INPUT Name3

OUTPUT "Input the name for student 40"


INPUT Name40

(a) Re-write the pseudocode to perform this task in a more efficient way, to allow for the class of
40 students.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]

(b) Give one advantage of your solution.

............................................................................................................................................. [1]

© UCLES 2019 9608/23/M/J/19


PAGE 268

12

5 Nigel is learning about string handling. He wants to write code to count the number of words in a
given string. A word is defined as a sequence of alphabetic characters that is separated by one or
more space characters.

His first attempt at writing an algorithm in pseudocode is as follows:

PROCEDURE CountWords(Message : STRING)

DECLARE NumWords : INTEGER


DECLARE Index : INTEGER
CONSTANT Space = ' '

NumWords 0

FOR Index 1 TO LENGTH(Message)


IF MID(Message, Index, 1) = Space
THEN
NumWords NumWords + 1
ENDIF
ENDFOR

OUTPUT "Number of words : " , NumWords

ENDPROCEDURE

For the built-in functions list, refer to the Appendix on page 18.

His first attempt is incorrect. He will use white-box testing to help him to identify the problem.

(a) (i) State the purpose of white-box testing.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) Dry running the code is often used in white-box testing. In this method, the programmer
records the values of variables as they change.

Identify what the programmer would normally use to record the changes.

..................................................................................................................................... [1]

© UCLES 2019 9608/23/M/J/19


PAGE 269

13

(b) (i) Write a test string containing two words that gives the output:

Number of words : 2

Use the symbol '|' to represent each space character in your test string.

Explain why the algorithm gives the output shown above.

String .................................................................................................................................

Explanation .......................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[3]

(ii) Nigel tested the procedure with the strings:

String 1: "Red|and|Yellow"
String 2: "Green||and||Pink|"

Give the output that is produced for each of the strings.

Describe the changes that would need to be made to the algorithm to give the correct
output in each case.

Do not write pseudocode or program code.

String 1 ..............................................................................................................................

Description ........................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

String 2 ..............................................................................................................................

Description ........................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[6]

© UCLES 2019 9608/23/M/J/19 [Turn over


PAGE 270

14

6 A text file, StudentContact.txt, contains a list of names and telephone numbers of students
in a school. Not all students in the school have provided a contact telephone number. In this case,
their name will not be in the file.

Each line of the file is stored as a string that contains a name and telephone number, separated by
the asterisk character ('*') as follows:

<Name>'*'<TelNumber>, for example:

"Bill Smith*081234567"

A 1D array, ClassList, contains the names of students in a particular class. The array consists
of 40 elements of string data type. You can assume that student names are unique.
Unused elements contain the empty string "".

A program is to be written to produce a new text file, ClassContact.txt, containing student


names and numbers for all students in a particular class.

For each name contained in the ClassList array, the program will:

• search the StudentContact.txt file


• copy the matching string into ClassContact.txt if the name is found
• write the name together with “*No number” into ClassContact.txt if the name is not found.

The program will be implemented as three modules. The description of these is as follows:

Module Description
ProcessArray() • Check each element of the array:
ż Read the student name from the array
ż Ignore unused elements
ż Call SearchFile() with the student name
ż If the student name is found, call AddToFile() to
write the student details to the class file
ż If the student name is not found, call AddToFile()
to write a new string to the class file, formed as
follows:
<Name>“*No number”
• Return the number of students who have not provided a
telephone number
SearchFile() • Search for a given student name at the start of each line
in the file StudentContact.txt:
ż If the search string is found, return the text line from
StudentContact.txt
ż If the search string is not found, return an empty
string
AddToFile() • Append the given string to a specified file, for example,
AddToFile(StringName, FileName)

© UCLES 2019 9608/23/M/J/19


PAGE 271

15

(a) Write program code for the module SearchFile().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]
© UCLES 2019 9608/23/M/J/19 [Turn over
PAGE 272

16

(b) Write pseudocode for the module ProcessArray().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [9]

© UCLES 2019 9608/23/M/J/19


PAGE 273

17

(c) ProcessArray() is modified to make it general purpose. It will now be called with two
parameters as follows:

• an array
• a string representing the name of a class contact file

It will still return the number of students who have not provided a contact telephone number.

Write program code for the header (declaration) of the modified ProcessArray().

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2019 9608/23/M/J/19 [Turn over


PAGE 274

18

Appendix

Built-in functions (pseudocode)

Each function returns an error if the function call is not properly formed.

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString

Example: MID("ABCDEFGH", 2, 3) returns "BCD"

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString

Example: LEFT("ABCDEFGH", 3) returns "ABC"

RIGHT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString

Example: RIGHT("ABCDEFGH", 3) returns "FGH"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: INT(27.5415) returns 27

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.

Example: NUM_TO_STRING(x) returns "87.5" if x has the value 87.5


Note: This function will also work if x is of type INTEGER

STRING_TO_NUM(x : STRING) RETURNS REAL


returns a numeric representation of a string.

Example: STRING_TO_NUM(x) returns 23.45 if x has the value "23.45"


Note: This function will also work if x is of type CHAR

Operators (pseudocode)

Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE
© UCLES 2019 9608/23/M/J/19
PAGE 275

Cambridge Assessment International Education


Cambridge International Advanced Subsidiary and Advanced Level
* 1 2 0 9 8 6 7 3 0 8 *

COMPUTER SCIENCE 9608/22


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2019
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.

This document consists of 18 printed pages and 2 blank pages.

DC (ST) 171121/3
© UCLES 2019 [Turn over
PAGE 276

1 Study the following pseudocode.

PROCEDURE FillTank()

DECLARE Tries : INTEGER


DECLARE Full : BOOLEAN

Tries 1

Full ReadSensor("F1")

IF NOT Full
THEN
WHILE NOT Full AND Tries < 4
CALL TopUp()
Full ReadSensor("F1")
Tries Tries + 1
ENDWHILE
IF Tries > 3
THEN
OUTPUT "Too many attempts"
ELSE
OUTPUT "Tank now full"
ENDIF
ELSE
OUTPUT "Already full"
ENDIF

ENDPROCEDURE

(a) (i) The pseudocode includes features that make it easier to read and understand.

State three such features.

Feature 1 ...........................................................................................................................

Feature 2 ...........................................................................................................................

Feature 3 ...........................................................................................................................
[3]

© UCLES 2019 9608/22/O/N/19


PAGE 277

(ii) Draw a program flowchart to represent the algorithm implemented in the pseudocode.
Variable declarations are not required in program flowcharts.

[5]

© UCLES 2019 9608/22/O/N/19 [Turn over


PAGE 278

(b) (i) Programming languages support different data types.

Complete the table by giving a suitable data type for each example value.

Example value Data type

43

TRUE

í

í

[4]

(ii) Evaluate each expression in the following table.

,IDQH[SUHVVLRQLVLQYDOLGWKHQZULWH¶(5525·

Refer to the Appendix on page 18 for the list of built-in functions and operators.

Expression Evaluates to

5,*+7 6WRS  /()7 LFK

0,' 180B72B675,1*  

,17 180B72B675,1* 

,17  

[4]

© UCLES 2019 9608/22/O/N/19


PAGE 279

2 (a) Describe the program development cycle with reference to the following:

• source code
• object code
• corrective maintenance.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

(b) Give three features of an Integrated Development Environment (IDE) that can help with
initial error detection while writing the program.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................

3 ................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2019 9608/22/O/N/19 [Turn over


PAGE 280

3 A student is developing a program to search through a string of numeric digits to count how many
times each digit occurs. The variable InString will store the string and the 1D array Result will
store the count values.

The program will:

• check each character in the string to count how many times each digit occurs
• record the count for each digit using the array
• output the count for each element of the array together with the corresponding digit.

(a) The array Result is a 1D array of type INTEGER.

Write pseudocode to declare the array and to initialise all elements to zero.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2019 9608/22/O/N/19


PAGE 281

(b) Write the pseudocode for the program.

Declare any variables you use. Do not implement the code as a subroutine.

Refer to the Appendix on page 18 for the list of built-in functions and operators.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2019 9608/22/O/N/19 [Turn over


PAGE 282

4 A program is being written to control the operation of a portable music player. One part of the
program controls the output volume.

The player has two buttons, one to increase the volume and one to decrease it. Whenever a
button is pressed, a procedure Button() is called with a parameter value representing the button
as follows:

Button Parameter value

Volume increase 10

Volume decrease 20

For example, pressing the volume increase button three times followed by pressing the volume
decrease button once would result in the calls:

  &$//%XWWRQ  9RO/HYHOLQFUHDVHGE\
  &$//%XWWRQ  9RO/HYHOLQFUHDVHGE\
  &$//%XWWRQ  9RO/HYHOLQFUHDVHGE\
  &$//%XWWRQ  9RO/HYHOGHFUHDVHGE\

The program makes use of two global variables of type INTEGER as follows:

Variable Description
9RO/HYHO The current volume setting. This must be in the range 0 to 49.
A value that can be set to limit the maximum value of 9RO/HYHO,
LQRUGHUWRSURWHFWWKHXVHU·VKHDULQJ
0D[9RO
A value in the range 1 to 49 indicates the volume limit.
A value of zero indicates that no volume limit has been set.

The procedure Button() will modify the value of 9RO/HYHO depending on which button has
been pressed and whether a maximum value has been set.

© UCLES 2019 9608/22/O/N/19


PAGE 283

(a) Write pseudocode for the procedure Button(). Declare any additional variables you use.

The value of 0D[9RO should not be changed within the procedure.

Parameter validation is not necessary.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]
© UCLES 2019 9608/22/O/N/19 [Turn over
PAGE 284

10

(b) The procedure Button() is to be tested using black-box testing.

Fill in the gaps below to define three tests that could be carried out.

TEST 1 – 9RO/HYHO is changed

Parameter value: 10

0D[9RO: ..................

9RO/HYHO value before call to Button(): 48

9RO/HYHO expected value after call to Button(): ..................

TEST 2 – 9RO/HYHO is not changed

Parameter value: 10

0D[9RO: 34

9RO/HYHO value before call to Button(): ..................

9RO/HYHO expected value after call to Button(): ..................

TEST 3 – 9RO/HYHO is not changed

Parameter value: ..................

0D[9RO: 40

9RO/HYHO value before call to Button(): 0

9RO/HYHO expected value after call to Button(): ..................

[6]

© UCLES 2019 9608/22/O/N/19


PAGE 285

11

(c) The testing stage is part of the program development cycle.

(i) The program for the music player has been completed. The program does not contain
any syntax errors, but testing could reveal further errors.

Identify and describe one different type of error that testing could reveal.

Type ..................................................................................................................................

Description ........................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[2]

(ii) Stub testing is a technique often used in the development of modular programs.

Describe the technique.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

© UCLES 2019 9608/22/O/N/19 [Turn over


PAGE 286

12

5 The module headers for three modules in a program are defined in pseudocode as follows:

Pseudocode module header


PROCEDURE Lookup(P4 : INTEGER, BYREF M4 : STRING)
FUNCTION Update(T4 : INTEGER) RETURNS INTEGER
)81&7,219DOLGDWH 6,17(*(53675,1* 5(78516%22/($1

A fourth module, Renew(), calls the three modules in the following sequence.

 9DOLGDWH
Lookup()
Update()

Draw a structure chart to show the relationship between the four modules and the parameters
passed between them.

[7]

© UCLES 2019 9608/22/O/N/19


PAGE 287

14

6 A text file, 6WXGHQW/LVWW[W, contains a list of information about students in a school.

Each line of the file contains a reference, name and date of birth for one student. All the information
is held as strings and separated by the asterisk character ('*') as follows:

<Reference>'*'<Name>'*'<Date Of Birth>

An example of one line from the file is:

* $OH]D+LOWRQ 

The reference string may be five or eight characters in length and is unique for each student. It is
made up of alphabetic and numeric characters only.

A global 1D array, /HDYHUV, contains the references of all students who have recently left the
school. The array consists of 500 elements of data type STRING. Unused elements contain the
empty string "".

A program is to be written to produce a new text file, 8SGDWHG/LVWW[W, containing information


only for students who are still attending the school.

The program is to be implemented as several modules. The outline description of three of these is
as follows:

Module Outline description


• Read each line from the file 6WXGHQW/LVWW[W
• Check whether the Reference appears in the
array using 6HDUFK/HDYHUV
ProcessStudentList()
• If the Reference does not appear then write the
line to the file 8SGDWHG/LVWW[W
• Return the number of lines not copied.
• Search for a given Reference in the array /HDYHUV
6HDUFK/HDYHUV • If the Reference is found, return TRUE, otherwise
return FALSE
• Take two parameters: the name of an array and a
string.
CountTimes()
• Count the number of elements that are the same as
the string. Return the count value.

© UCLES 2019 9608/22/O/N/19


PAGE 288

15

(a) Write program code for the module 6HDUFK/HDYHUV . Declare any additional variables
you use.

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2019 9608/22/O/N/19 [Turn over


PAGE 289

16

(b) Write pseudocode for the module ProcessStudentList().

The module description is repeated here for reference.

Module Outline description


• Read each line from the file 6WXGHQW/LVWW[W
• Check whether the Reference appears in the
array using 6HDUFK/HDYHUV
ProcessStudentList()
• If the Reference does not appear then write the
line to the file 8SGDWHG/LVWW[W
• Return the number of lines not copied.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2019 9608/22/O/N/19
PAGE 290

17

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [9]

(c) CountTimes() is to be used to count how many unused elements there are in the /HDYHUV
array. An unused element is one that contains an empty string.

The module description is repeated here for reference.

Module Outline description


• Take two parameters: the name of an array and a
string.
CountTimes()
• Count the number of elements that are the same as
the string. Return the count value.

Write a statement in program code that uses CountTimes() to assign the count of unused
elements to the variable Result.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2019 9608/22/O/N/19 [Turn over


PAGE 291

18

Appendix
Built-in functions (pseudocode)

Each function returns an error if the function call is not properly formed.

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString

Example: 0,' $%&'()*+ returns "BCD"

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString

Example: LEFT("ABCDEFGH", 3) returns "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString

Example: RIGHT("ABCDEFGH", 3) returns "FGH"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: ,17  returns 

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.
Note: This function will also work if x is of type INTEGER

Example: 180B72B675,1*  returns 

STRING_TO_NUM(x : STRING) RETURNS REAL


returns a numeric representation of a string.
Note: This function will also work if x is of type CHAR

Example: 675,1*B72B180  returns 

Operators (pseudocode)

Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE

© UCLES 2019 9608/22/O/N/19


PAGE 292

Cambridge Assessment International Education


Cambridge International Advanced Subsidiary and Advanced Level
* 9 5 3 4 4 8 1 8 7 2 *

COMPUTER SCIENCE 9608/23


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2019
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.

This document consists of 16 printed pages.

DC (ST/SG) 171122/4
© UCLES 2019 [Turn over
PAGE 293

Question 1 begins on the next page.

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
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.

Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of
Cambridge Local Examinations Syndicate (UCLES), which itself is a department of the University of Cambridge.

© UCLES 2019 9608/23/O/N/19


PAGE 294

1 (a) (i) Programming languages can support different data types.

Complete the table by naming three different data types together with an example data
value for each.

Data type Example data value

[6]

(ii) Identify the type of programming statement that assigns a data type to a variable.

..................................................................................................................................... [1]

(b) As part of the development of an algorithm, a programmer may construct an identifier table.

Describe what an identifier table contains.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

(c) (i) Simple algorithms usually consist of three different stages.

Complete the table below. Write each example statement in program code.

The second stage has already been given.

Stage Example statement

Process

[5]

(ii) Write a single statement in program code that contains two of the stages. Do not
repeat any of the statements from part (c)(i).

..................................................................................................................................... [1]

© UCLES 2019 9608/23/O/N/19 [Turn over


PAGE 295

(d) A software developer is writing a program and includes several features to make it easier to
read and understand. One of these features is the use of indentation.

State three other features.

Feature 1 ..................................................................................................................................

Feature 2 ..................................................................................................................................

Feature 3 ..................................................................................................................................
[3]

(e) A trace table is often used during program testing.

Identify the type of testing that includes the use of a trace table.

............................................................................................................................................. [1]

© UCLES 2019 9608/23/O/N/19


PAGE 296

2 (a) (i) 7ZRW\SHVRIORRSWKDWPD\EHIRXQGLQDQDOJRULWKP DUHWKH¶SUHFRQGLWLRQ·DQG¶SRVW


FRQGLWLRQ·ORRS

Identify one other type of loop. Explain when it should be used.

Type ..................................................................................................................................

Explanation .......................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[2]

(ii) Part of a program flowchart is shown.

LOOP

AlarmReset()

Set Status1 to
GetStatus(Sys_A)

Set Status2 to
GetStatus(Sys_B)

Are Status1
NO
and Status2
both TRUE?

YES

Implement the flowchart in pseudocode using a post-condition loop.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [4]

© UCLES 2019 9608/23/O/N/19 [Turn over


PAGE 297

(b) The following lines of code are taken from a high-level language program.

100 setvar(Count, Integer)


110 setvar(Gross[0-20], Real)
120 setvar(Posn, Real)
130 setvar(Length, Integer)
140 setvar(Rate, Real)
150 Length := 7
160 Rate := 1.175
170
180 For (Count, 0, 20, 2)
190 {
200 Echo "Input next cost"
210 Posn := Read()
220 Gross[Count] := Mult(Posn, Rate) %Apply current tax rate
230 }

Study the code. Identify the relevant features in the following table.

Feature Answer

The symbol used to indicate an assignment

The line numbers for the start and end of a count-controlled loop

The step value of the count-controlled loop

The character that indicates a comment

The name of a function


[5]

(c) A program written in a high-level language cannot be run directly.

Identify one type of translator that can be used to translate the program.

............................................................................................................................................. [1]

© UCLES 2019 9608/23/O/N/19


PAGE 298

3 Three program modules process updating of passwords in a file. A description of the relationship
between the modules is summarised as follows:

Module name Description

GetPassword()
• Takes two parameters: AccountID and OldPassword
• Returns a string containing the new password
• Takes two parameters: AccountID and NewPassword
UpdateFile() • Returns a Boolean value to indicate whether or not the
update was successful

ChangePassword()
• Calls GetPassword() to obtain the new password then
calls UpdateFile() to write the new password to the file

Draw a structure chart to show the relationship between the three modules and the parameters
passed between them.

[5]

© UCLES 2019 9608/23/O/N/19 [Turn over


PAGE 299

4 The following pseudocode algorithm checks whether a string is a valid email address.

FUNCTION Check(InString : STRING) RETURNS BOOLEAN

DECLARE Index : INTEGER


DECLARE NumDots : INTEGER
DECLARE NumAts : INTEGER
DECLARE NextChar : CHAR
DECLARE NumOthers : INTEGER

NumDots 0
NumAts 0
NumOthers 0

FOR Index 1 TO LENGTH(InString)

NextChar MID(InString, Index, 1)


CASE OF NextChar
'.': NumDots NumDots + 1
'@': NumAts NumAts + 1
OTHERWISE NumOthers NumOthers + 1
ENDCASE

ENDFOR

IF (NumDots >= 1 AND NumAts = 1 AND NumOthers > 5)


THEN
RETURN TRUE
ELSE
RETURN FALSE
ENDIF

ENDFUNCTION

(a) Describe the validation rules that are implemented by this pseudocode. Refer only to the
contents of the string and not to features of the pseudocode.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2019 9608/23/O/N/19


PAGE 300

(b) (i) Complete the trace table by dry running the function when it is called as follows:

Result Check("Jim.99@skail.com")

Index NextChar NumDots NumAts NumOthers

[5]

(ii) State the value returned when function Check is called as shown in part (b)(i).

..................................................................................................................................... [1]

© UCLES 2019 9608/23/O/N/19 [Turn over


PAGE 301

10

(c) The function Check() is to be tested.

State two different invalid string values that could be used to test the algorithm. Each string
should test a different rule.

Justify your choices.

Value .........................................................................................................................................

Justification ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Value .........................................................................................................................................

Justification ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[4]

5 Abbreviations are often used in place of a full name. Concatenating the first letter of each word in
the name makes an abbreviation.

For example:

Name Abbreviation

United Nations UN

World Wide Web WWW

British Computer Society BCS

A function, Abbreviate(), will take a string representing the full name and return a string
containing the abbreviated form.

You should assume that:

• names only contain alphabetic characters and space characters


• names always start with an alphabetic character
• each word in the name always starts with an uppercase character
• only a single space separates words in the name.

© UCLES 2019 9608/23/O/N/19


PAGE 302

11

Write pseudocode to implement the function Abbreviate().

Refer to the Appendix on page 16 for the list of built-in functions and operators.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [8]

© UCLES 2019 9608/23/O/N/19 [Turn over


PAGE 303

12

6 A text file, Library.txt, stores information relating to a book collection. The file stores four
pieces of information about each book on separate lines of the file, as follows:

Line n: <Book Title>


Line n + 1: <Author Name>
Line n + 2: <ISBN>
Line n + 3: <Location>

Information is stored as data strings.

Information relating to two books is shown:

File line Data


100 "Learning Python"

101 "Brian Smith"

102 "978-14-56543-21-8"

103 "BD345"

104 "Surviving in the mountains"

105 "C T Snow"

106 "978-35-17635-43-9"

107 "ZX001"

(a) (i) A function, FindBooksBy(), will search Library.txt for all books by a given author.

The function will store the Book Title and Location in the array Result, and will
return a count of the number of books found.

Array Result is a global 2D array of type STRING. It has 100 rows and 2 columns.

Write pseudocode to declare the array Result.

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

(ii) Function FindBooksBy() will:

• receive the Author Name as a parameter


• search Library.txt for matching entries
• store the Book Title and Location of matching entries in the Result array
• return an integer value giving the number of books by the author that were found.

© UCLES 2019 9608/23/O/N/19


PAGE 304

13

Write program code for the function FindBooksBy().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language .....................................................................................................

Program code

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
© UCLES 2019 9608/23/O/N/19 [Turn over
PAGE 305

14

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [8]

(b) The function FindBooksBy() has already been called and has stored values in the array
Result.

The procedure, DisplayResults(), will output the information from the array.

The procedure receives the following two parameters:

• a string containing the author name


• an integer value representing the number of books found

The output should be formatted as in the following example:

Books written by: Brian Smith

Title Location
Learning Python BD345
Arrays are not lists CZ562
Learning Java CZ589

Number of titles found: 3

If no books by the author are found, the following should be output:

Search found no books by: Brian Smith

© UCLES 2019 9608/23/O/N/19


PAGE 306

15

Write pseudocode for the procedure DisplayResults().

Refer to the Appendix on page 16 for the list of built-in functions and operators.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2019 9608/23/O/N/19 [Turn over


PAGE 307

16

Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString
Example: MID("ABCDEFGH", 2, 3) returns "BCD"

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString
Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString
Example: LEFT("ABCDEFGH", 3) returns "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString
Example: RIGHT("ABCDEFGH", 3) returns "FGH"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x
Example: INT(27.5415) returns 27

ASC(ThisChar : CHAR) RETURNS INTEGER


returns the ASCII value of ThisChar
Example: ASC('A') returns 65

MOD(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the remainder when ThisNum is divided by ThisDiv
Example: MOD(10,3) returns 1

Operators (pseudocode)

Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE
© UCLES 2019 9608/23/O/N/19
PAGE 308

Cambridge International AS & A Level


* 4 8 6 0 2 0 4 7 9 7 *

COMPUTER SCIENCE 9608/22


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2020
2 hours

You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.

This document has 20 pages. Blank pages are indicated.

DC (RW/TP) 180777/4
© UCLES 2020 [Turn over
PAGE 309

1 (a) Selection and repetition are basic constructs of an algorithm.

Name and describe one other construct.

Name ........................................................................................................................................

Description ................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

(b) Program coding is a transferable skill.

Explain the term transferable skill.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

(c) Count-controlled and post-condition are two types of loop.

Describe the characteristics of each of these types of loop.

Count-controlled .......................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Post-condition ...........................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[2]

(d) Name three features provided by an Integrated Development Environment (IDE) that assist
in the coding and initial error detection stages of the program development cycle.

1 ................................................................................................................................................

2 ................................................................................................................................................

3 ................................................................................................................................................
[3]

© UCLES 2020 9608/22/M/J/20 [Turn over


PAGE 310

2 (a) A structure chart is often produced as part of a modular program design. The chart shows the
hierarchy of modules and the sequence of execution.

Give two other features the structure chart can show.

Feature 1 ..................................................................................................................................

...................................................................................................................................................

Feature 2 ..................................................................................................................................

...................................................................................................................................................
[2]

(b) Six program modules implement part of an online shopping program. The following table
gives the modules and a brief description of each module:

Module Description
Allows the user to choose a delivery slot, select items to be added to
Shop()
the basket and finally check out

ChooseSlot() Allows the user to select a delivery time. Returns a delivery slot number

FillBasket() Allows the user to select items and add them to the basket

Completes the order by allowing the user to pay for the items. Returns
Checkout()
a Boolean value to indicate whether or not payment was successful

Search() Allows the user to search for a specific item. Returns an item reference

Adds an item to the basket. Takes an item reference and a quantity as


Add()
parameters

(i) The online shopping program has been split into sub-tasks as part of the design process.

Explain the advantages of decomposing the program into modules. Your explanation
should refer to the scenario and modules described in part (b).

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

© UCLES 2020 9608/22/M/J/20


PAGE 311

(ii) Complete the structure chart for the six modules described in part (b).

Shop()

[6]

© UCLES 2020 9608/22/M/J/20 [Turn over


PAGE 312

3 A navigation program includes a function, CheckCourse(). This function is called with a real
value, Course, and returns an integer value.

The identifier table and the program flowchart for the function are shown as follows:

Identifier Type Description


Course REAL The value passed to CheckCourse()
Adjust INTEGER The value returned by CheckCourse()
Check INTEGER A local variable
A function that is passed a REAL value representing the
Deviate() FUNCTION course and returns a REAL value representing the current
deviation
Alert() PROCEDURE A procedure that generates a warning

START

Set Check to integer


value of
Deviate(Course)

Set Adjust to 255

CASE OF
Check
–20 to –1
OTHERWISE Set Adjust to 10

0
Set Adjust to 0

Alert()

1 to 20
Set Adjust to –10

RETURN Adjust

END

© UCLES 2020 9608/22/M/J/20


PAGE 313

Write pseudocode to implement the function CheckCourse(). The pseudocode must follow the
algorithm represented by the flowchart. Declare any local variables used.

Refer to the Appendix on page 19 for a list of built-in pseudocode functions and operators.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [7]
© UCLES 2020 9608/22/M/J/20 [Turn over
PAGE 314

4 (a) Mustafa has developed the following pseudocode to generate ten random integers in the
range 1 to 100.

DECLARE Random : ARRAY [1:10] OF INTEGER


DECLARE Count, RNum : INTEGER

FOR Count 1 TO 10
Rnum INT(RAND(100)) + 1
Random[Count] RNum
ENDFOR

Refer to the Appendix on page 19 for a list of built-in pseudocode functions and operators.

Rewrite the pseudocode so that there are no duplicated numbers in the list of random
numbers.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

..................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]
© UCLES 2020 9608/22/M/J/20
PAGE 315

(b) The changes made to the pseudocode in part (a) were as a result of changes to the program
requirement.

Give the term used to describe changes made for this reason.

............................................................................................................................................. [1]

© UCLES 2020 9608/22/M/J/20 [Turn over


PAGE 316

10

5 A global 1D array, Contact, of type STRING is used to store a list of names and email addresses.

There are 1000 elements in the array. Each element stores one data item. The format of each
data item is as follows:

<Name>':'<EmailAddress>

Name and EmailAddress are both variable-length strings.

For example:

"Sharma Himal:hsharma99@stlmail.com"

A function, GetName(), is part of the program that processes the array. A data item string will be
passed to the function as a parameter. The function will return the Name part. Validation is not
necessary.

(a) Use structured English to describe the algorithm for the function GetName().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2020 9608/22/M/J/20


PAGE 317

11

(b) (i) The array is to be sorted using an efficient bubble sort algorithm. An efficient bubble sort
reduces the number of unnecessary comparisons between elements.

Describe how this could be achieved.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [4]

© UCLES 2020 9608/22/M/J/20 [Turn over


PAGE 318

12

(ii) A procedure, BubbleSort(), is needed to sort the 1D array Contact into ascending
order of Name using an efficient bubble sort algorithm.

Write program code for the procedure BubbleSort().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language .....................................................................................................

Program code ....................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [8]

© UCLES 2020 9608/22/M/J/20


PAGE 319

13

Question 6 begins on the next page.

© UCLES 2020 9608/22/M/J/20 [Turn over


PAGE 320

14

6 A company hires out rowing boats on a lake. The company has 17 boats numbered from 1 to 17.

Boats may be hired between 9:00 and 18:00, with a maximum hire duration of 90 minutes.

The company is developing a program to help manage and record the boat hire process.

The programmer has decided to store all values relating to hire time as strings. The program will
use a 24-hour clock format. For example:

Time (in words) String value


Nine o’clock in the morning "09:00"
Five minutes past ten o’clock in the morning "10:05"
Ten minutes before three o’clock in the afternoon "14:50"

The programmer has defined the first module as follows:

Module Description
• Takes two parameters:
StartTime: a STRING value representing a time as described
AddTime() Duration: an INTEGER value representing a duration in minutes
• Adds the duration to the time to give a new time
• Returns the new time as a STRING

(a) (i) Write pseudocode for the module AddTime(). Assume both input parameters are valid.

Refer to the Appendix on page 19 for a built-in list of pseudocode functions and
operators.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

© UCLES 2020 9608/22/M/J/20


PAGE 321

15

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [8]

(ii) AddTime() will be tested using white-box testing.

State the reason for using white-box testing.

...........................................................................................................................................

..................................................................................................................................... [1]

(iii) A run-time error is one type of error that black-box testing can reveal.

Describe one other type of error that black-box testing can reveal.

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2020 9608/22/M/J/20 [Turn over


PAGE 322

16

(b) The user will input the desired start time of a hire. A new module will be written to validate the
input string as a valid time in 24-hour clock format.

The string is already confirmed as being in the format "NN:NN", where N is a numeric
character.

Give an example of suitable test data that is in this format but which is invalid. Explain your
answer.

Test data ...................................................................................................................................

Explanation ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[2]

(c) Each time a boat is hired out, details of the hire are added to a text file, Hirelog.txt. Each
line of the text file corresponds to information about one hire session.

The format of each line is as follows:

<BoatNumber><Date><AmountPaid>

• BoatNumber is a two-digit numeric string


• Date is a six-digit numeric string in the format DDMMYY
• AmountPaid is a variable-length string representing a numeric value, for example
"12.75"

The total hire amount from each boat is to be stored in a global array, Total. This array is
declared in pseudocode as follows:

DECLARE Total : ARRAY [1:17] OF REAL

The programmer has defined module GetTotals() as follows:

Module Description
• Search through the file Hirelog.txt
GetTotals() • Extract the AmountPaid each time a boat is hired
• Store the total of AmountPaid for each boat in the array

© UCLES 2020 9608/22/M/J/20


PAGE 323

17

Write program code for the module GetTotals().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2020 9608/22/M/J/20


PAGE 324

19

Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.
LENGTH(ThisString : STRING) RETURNS INTEGER
returns the integer value representing the length of ThisString
Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString
Example: LEFT("ABCDEFGH", 3) returns "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString
Example: RIGHT("ABCDEFGH", 3) returns "FGH"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x
Example: INT(27.5415) returns 27

RAND(x : INTEGER) RETURNS REAL


returns a real number in the range 0 to x (not inclusive of x)
Example: RAND(87) could return 35.43

MOD(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the remainder when ThisNum is divided by ThisDiv
Example: MOD(10,3) returns 1

DIV(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the whole number part of the result when ThisNum is divided
by ThisDiv
Example: DIV(10,3) returns 3

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.
Example: If x has the value 87.5 then NUM_TO_STRING(x) returns "87.5"
Note: This function will also work if x is of type INTEGER

STRING_TO_NUM(x : STRING) RETURNS REAL


returns a numeric representation of a string.
Example: If x has the value "23.45" then STRING_TO_NUM(x) returns 23.45
Note: This function will also work if x is of type CHAR

Operators (pseudocode)
Operator Description

& Concatenates (joins) two strings


Example: "Summer" & " " & "Pudding" produces "Summer Pudding"

AND Performs a logical AND on two Boolean values


Example: TRUE AND FALSE produces FALSE

OR Performs a logical OR on two Boolean values


Example: TRUE OR FALSE produces TRUE

© UCLES 2020 9608/22/M/J/20


PAGE 325

Cambridge International AS & A Level


* 1 7 5 3 4 1 4 9 7 5 *

COMPUTER SCIENCE 9608/23


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2020
2 hours

You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.

This document has 20 pages. Blank pages are indicated.

DC (RW/TP) 180778/4
© UCLES 2020 [Turn over
PAGE 326

1 (a) Algorithms are produced during program development.

State when you would produce an algorithm during program development and state its
purpose.

When ........................................................................................................................................

...................................................................................................................................................

Purpose ....................................................................................................................................

...................................................................................................................................................
[2]

(b) Selection is one of the basic constructs used in algorithms.

Explain the term selection.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

(c) Explain the process of problem decomposition. State one reason it may be used.

Explanation ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Reason .....................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[2]

(d) Name two features provided by a typical Integrated Development Environment (IDE) that
assist in the debugging stage of the program development cycle.

1 ................................................................................................................................................

2 ................................................................................................................................................
[2]

© UCLES 2020 9608/23/M/J/20 [Turn over


PAGE 327

2 (a) A structure chart is often produced as part of a modular program design. The chart shows the
relationship between modules and the parameters that are passed between them.

Give two other features the structure chart can show.

Feature 1 ..................................................................................................................................

...................................................................................................................................................

Feature 2 ..................................................................................................................................

...................................................................................................................................................
[2]

(b) The following structure chart shows the relationship between three modules.

ModuleA()

ParW
ParX

ParZ

ModuleB() ModuleC()

Parameter data types are:

ParW : REAL
ParX : INTEGER
ParZ : STRING

(i) Write the pseudocode header for module ModuleB().

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

(ii) Write the pseudocode header for module ModuleC().

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

© UCLES 2020 9608/23/M/J/20


PAGE 328

(c) A student is developing an algorithm to count the number of times a given string,
SearchString, appears in a 2D array. The array, Item, consists of 100 elements organised
as 50 rows of 2 columns. SearchString could appear in any row or column.

The array is declared in pseudocode as follows:

DECLARE Item : ARRAY [1:50, 1:2] OF STRING

The structured English description of the algorithm is:

1. SET Count to 0.
2. Examine the first row of the array.
3. IF column 1 element value is equal to SearchString, ADD 1 to Count.
4. IF column 2 element value is equal to SearchString, ADD 1 to Count.
5. REPEAT from step 3 for next row, UNTIL row is last row.
6. OUTPUT a suitable message and Count.

Write pseudocode for the algorithm.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

© UCLES 2020 9608/23/M/J/20 [Turn over


PAGE 329

3 (a) Study the following pseudocode.

Error Delta(Plan, Actual)


CASE OF Error
> 10 : Steer 6WHHUí
0 : ZCount ZCount + 1
< -10 : Steer Steer + 10
OTHERWISE OUTPUT "Unexpected Error"
ENDCASE

Draw a program flowchart to represent the pseudocode. Variable declarations are not
required in program flowcharts.

[5]
© UCLES 2020 9608/23/M/J/20 [Turn over
PAGE 330

(b) The following pseudocode algorithm has been developed to check whether a string contains
a valid password.

To be a valid password, a string must:

• be longer than five characters


• contain at least one numeric digit
• contain at least one upper case letter
• contain at least one other character (not a numeric digit or an upper case letter).

10 FUNCTION Check(InString : STRING) RETURNS BOOLEAN


11
12 DECLARE Index : INTEGER
13 DECLARE StrLen : INTEGER
14 DECLARE NumUpper, NumDigit : INTEGER
15 DECLARE NextChar : CHAR
16 DECLARE NumOther : INTEGER
17
18 NumUpper 0
19 NumDigit 0
20
21 StrLen LENGTH(InString)
22 IF StrLen < 6
23 THEN
24 RETURN FALSE
25 ELSE
26 FOR Index 1 TO StrLen - 1
27 // loop for each character
28 NextChar MID(InString, Index, 1)
29 IF NextChar >= '0' AND NextChar <= '9'
30 THEN
31 NumDigit NumDigit + 1 // count digits
32 ELSE
33 IF NextChar >= 'A' AND NextChar <= 'Z'
34 THEN
35 NumUpper NumUpper + 1 // count upper case
36 ENDIF
37 ENDIF
38 ENDFOR
39 ENDIF
40
41 NumOther StrLen – (NumDigit – NumUpper)
42 IF NumDigit >= 1 AND NumUpper >= 1 AND NumOther >= 1
43 THEN
44 RETURN TRUE
45 ELSE
46 RETURN FALSE
47 ENDIF
48
49 ENDFUNCTION

© UCLES 2020 9608/23/M/J/20


PAGE 331

The pseudocode does not work under all circumstances.

The function was dry run with the string "1234AP" and the following trace table was
produced. The string is an invalid password, but the pseudocode returned the value
TRUE.

Trace
StrLen Index NextChar NumUpper NumDigit NumOther
table row
1 6 0 0
2 1 '1'
3 1
4 2 '2'
5 2
6 3 '3'
7 3
8 4 '4'
9 4
10 5 'A'
11 1
12 3

(i) The pseudocode algorithm contains two errors.

State how the given trace table indicates the existence of each error.

Error 1 ...............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

Error 2 ...............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[2]

© UCLES 2020 9608/23/M/J/20 [Turn over


PAGE 332

10

(ii) Give the line number of each error in the pseudocode algorithm and write the modified
pseudocode to correct each error.

Line number for error 1 .....................................................................................................

Correct pseudocode ..........................................................................................................

...........................................................................................................................................

Line number for error 2 .....................................................................................................

Correct pseudocode ..........................................................................................................

...........................................................................................................................................
[2]

(c) The term adaptive maintenance refers to amendments that are made in response to
changes to the program specification. These changes usually affect the program algorithm.

Name one other part of the design that can change as a result of adaptive maintenance.

............................................................................................................................................. [1]

4 A global 1D array, Contact, of type STRING is used to store a list of names and email addresses.
There are 1000 elements in the array. Each element stores one data item. The format of each
data item is as follows:

<Name>':'<EmailAddress>

Name and EmailAddress are both variable-length strings.

For example:

"Wan Zhu:zwan99@mymail.com"

A function, Extract(), is part of the program that processes the array. A string data item is
passed to the function as a parameter. The function will return the Name part. Validation is not
necessary.

© UCLES 2020 9608/23/M/J/20


PAGE 333

11

(a) Write program code for the function Extract().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

© UCLES 2020 9608/23/M/J/20 [Turn over


PAGE 334

12

(b) The original function, Extract(), needs to be modified to separate the name from the email
address. The calling program can then use both of these values.

Write, in pseudocode, the header for the modified subroutine. Explain the changes you have
made.

Subroutine header ....................................................................................................................

...................................................................................................................................................

Explanation ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

5 A company hires out rowing boats on a lake. The company has 20 boats, numbered from 1 to 20.

For safety reasons, the boats have to be serviced (checked and any damage repaired) regularly.

The company is developing a program to help manage the servicing of the boats.

Every time a boat is serviced, details are added at the end of the text file, ServiceLog.txt, as a
single line of information. Each boat is serviced before it is hired out for the first time.

The format of each line is as follows:

<BoatNumber><Date>

BoatNumber and Date are as follows:

• BoatNumber is a two-digit numeric string in the range "01" to "20"


• Date is an 8-digit numeric string in the format YYYYMMDD

The programmer has defined the first module as follows:

Module Description
• Called with a string parameter representing the BoatNumber
GetLastService() • Searches through the file ServiceLog.txt
• Returns the date of the last service in the form "YYYYMMDD"

© UCLES 2020 9608/23/M/J/20


PAGE 335

13

(a) Write pseudocode for the module GetLastService().

Refer to the Appendix on page 19 for a list of built-in pseudocode functions and operators.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2020 9608/23/M/J/20 [Turn over


PAGE 336

14

(b) (i) Every time a boat is hired out, details of the hire are added at the end of a text file,
Hirelog.txt. Each line of the text file corresponds to information about the hire of one
boat.

The format of each line of information is as follows:

<Date><BoatNumber><HireDuration>

• Date is an 8-digit numeric string in the format YYYYMMDD


• BoatNumber is a two-digit numeric string in the range "01" to "20"
• HireDuration is a variable-length string representing a numeric value in hours.
For example, the string "1.5" would represent a hire duration of 1½ hours.

A module GetHours() is defined as follows:

Module Description
• Takes two parameters:
the BoatNumber as a string
the date of the last service for that boat ("YYYYMMDD")
as a string
GetHours()
• Searches through file Hirelog.txt and calculates the sum of
the hire durations for the given boat after the given date (hire
durations on or before the given date are ignored)

• Returns the total of the hire durations as a real

Note:

Standard comparison operators may be used with dates in this format.


For example:

"20200813" > "20200812" would evaluate to TRUE

Parameter validation is not required.

© UCLES 2020 9608/23/M/J/20


PAGE 337

15

Write pseudocode for the module GetHours().

Refer to the Appendix on page 19 for a list of built-in pseudocode functions and
operators.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [8]

© UCLES 2020 9608/23/M/J/20 [Turn over


PAGE 338

16

(ii) An additional module, Validate(), has been written to check that a given string
corresponds to a valid BoatNumber. A valid BoatNumber is a two-digit numeric string in
the range "01" to "20".

Give three test strings that are invalid for different reasons. Explain your choice in each
case.

String 1 ..............................................................................................................................

Reason ..............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

String 2 ..............................................................................................................................

Reason ..............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

String 3 ..............................................................................................................................

Reason ..............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[6]

(c) A new module is described as follows:

Module Description
• Takes an integer as a parameter that represents the maximum
number of hours before a boat must be serviced

• Uses GetLastService() and GetHours()

• Outputs:
a suitable heading
the BoatNumber of each boat hired for more than the
maximum number of hours since its last service
ServiceList() the total hire duration for each of these boats

An example output list is:


Boat Service List
4: 123
17: 117

If no boats are due to be serviced, the output is:


Boat Service List
No boats are due to be serviced

© UCLES 2020 9608/23/M/J/20


PAGE 339

17

Write program code for the module ServiceList().

Python: You should show a comment statement for each variable used with its data type.
Visual Basic and Pascal: You should include the declaration statements for variables.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]
© UCLES 2020 9608/23/M/J/20 [Turn over
PAGE 340

18

(d) (i) A team of programmers will work on the program. Before they begin, the team meet to
discuss ways in which the risk of program faults may be reduced during the design and
coding stages.

State two ways to minimise program faults during the design and coding stages.

1 ........................................................................................................................................

...........................................................................................................................................

2 ........................................................................................................................................

...........................................................................................................................................
[2]

(ii) During development, the team test the program using a process known as stub testing.

Explain this process.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(iii) Explain how single stepping may be used to help find a logic error in a program.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2020 9608/23/M/J/20


PAGE 341

19

Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString

Example: LEFT("ABCDEFGH", 3) returns "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString

Example: RIGHT("ABCDEFGH", 3) returns "FGH"

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString

Example: MID("ABCDEFGH", 2, 3) returns "BCD"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: INT(27.5415) returns 27

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.
Note: This function will also work if x is of type INTEGER

Example: NUM_TO_STRING(87.5) returns "87.5"

STRING_TO_NUM(x : STRING) RETURNS REAL


returns a numeric representation of a string.
Note: This function will also work if x is of type CHAR

Example: STRING_TO_NUM("23.45") returns 23.45

Operators (pseudocode)

Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE

© UCLES 2020 9608/23/M/J/20


PAGE 342

Cambridge International AS & A Level


* 7 1 8 7 0 7 4 0 4 6 *

COMPUTER SCIENCE 9608/22


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2020
2 hours

You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.

This document has 20 pages. Blank pages are indicated.

DC (CJ) 188580/2
© UCLES 2020 [Turn over
PAGE 343

1 (a) Algorithms usually consist of three different stages.

One stage is INPUT.

Name the other stages.

1 ................................................................................................................................................

2 ................................................................................................................................................
[1]

(b) An algorithm may be documented using different methods. These include structured English,
a program flowchart, and pseudocode.

State what a program designer represents using one or more of these methods.

...................................................................................................................................................

............................................................................................................................................. [2]

(c) Programming languages support different data types.

Complete the table by giving four different data types together with an example data value
for each.

Data type Example data value

[4]

© UCLES 2020 9608/22/O/N/20


PAGE 344

(d) Draw lines to connect each of the following computing terms with the appropriate description.

Term Description

A structure for the


Black-box testing
temporary storage of data

A method used when the


File structure of the program is
unknown

A method of setting the


Assignment
value of a variable

A structure for the


Array
permanent storage of data

[3]

(e) A pseudocode algorithm assigns values to three variables as follows:

FlagA TRUE
FlagB FALSE
FlagC TRUE

Evaluate the expressions given in the following table:

Expression Evaluates to

NOT FlagB AND FlagC

NOT (FlagB OR FlagC)

(FlagA AND FlagB) OR FlagC

NOT (FlagA AND FlagB) OR NOT FlagC

[2]

© UCLES 2020 9608/22/O/N/20 [Turn over


PAGE 345

2 (a) The following pseudocode is an attempt to define an algorithm that takes two numbers as
input and outputs the larger of the two numbers.

DECLARE A, B : INTEGER
INPUT A
INPUT B
IF A > B
THEN
OUTPUT A
ELSE
OUTPUT B
ENDIF

The algorithm needs to be amended to include the following changes:

1. Input three values, ensuring that each value input is unique.


2. Output the average.
3. Output the largest value.

Write the pseudocode for the amended algorithm.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2020 9608/22/O/N/20
PAGE 346

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

(b) Complete the pseudocode expressions in the following table.

Use only functions and operators described in the Appendix on pages 18–19.

Expression Evaluates to

"ALARM: " & ...................... ("Time: 1202" , ......................) "ALARM: 1202"

...................... ("Stepwise." , ...................... , ......................) "wise"

1.5 * .......................... ("OnePointFive") 18

...................................... (27.5) "27.5"

.......................... (9, 4) 2
[5]

(c) A problem may be decomposed into sub-tasks when designing an algorithm.

Give three benefits of using sub-tasks.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................

3 ................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2020 9608/22/O/N/20 [Turn over


PAGE 347

3 A car has the ability to detect a skid by monitoring the rate of rotation (the rotational speed) of
each wheel. If the rate of rotation of any wheel is not within 10% of the average of all four wheels,
the car skids.

A function, CheckSkid(), is being developed.

The function will:

• simulate real-time data acquisition, by prompting for the input of four integer values in the
range 0 to 1000 inclusive, representing the rate of rotation of each wheel
• calculate the average value
• check whether any individual value is more than 10% greater than the average or more than
10% less than the average
• return TRUE if any individual value is more than 10% greater than the average or more than
10% less than the average and FALSE otherwise
• output a suitable warning message.

(a) Write program code for the function CheckSkid().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2020 9608/22/O/N/20


PAGE 348

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

(b) Give two sets of test data that could be used to test the function.

Test 1 – No skid detected

Value1 Value2 Value3 Value4

Test 2 – Skid detected

Value1 Value2 Value3 Value4

[2]

© UCLES 2020 9608/22/O/N/20 [Turn over


PAGE 349

4 (a) The following structured English describes an algorithm used to count the number of odd and
even digits in an input sequence.

1. Initialise variables OddCount and EvenCount to zero.


2. Prompt and input an integer.
3. If the integer is not in the range 0 to 9 then go to step 7.
4. If the integer is an even number then add 1 to EvenCount.
5. Otherwise add 1 to OddCount.
6. Repeat from step 2.
7. Output "Same" if there are the same number of odd and even integers.
8. Output "Odd" if there are more odd than even integers.
9. Output "Even" if there are more even than odd integers.

Draw a flowchart on the following page to represent the algorithm.

© UCLES 2020 9608/22/O/N/20


PAGE 350

[7]
© UCLES 2020 9608/22/O/N/20 [Turn over
PAGE 351

10

(b) The following pseudocode is an attempt to check whether two equal-length strings consist of
identical characters.

Refer to the Appendix on pages 18–19 for the list of built-in functions and operators.

FUNCTION Compare(String1, String2 : STRING) RETURNS BOOLEAN


DECLARE x, y, Len1, Len2 : INTEGER
DECLARE RetFlag : BOOLEAN
DECLARE NextChar : CHAR
DECLARE New : STRING

Len1 LENGTH(String1)
RetFlag TRUE

FOR x 1 TO Len1 // for each char in String1


Len2 LENGTH(String2)
NextChar MID(String1, x, 1) // get NextChar from String1
New ""
FOR y 1 TO Len2 // for each char in String2
IF NextChar <> MID(String2, y, 1) // no match
THEN
New New & MID(String2, y, 1) // save this char from String2
ENDIF
ENDFOR
String2 New // replace String2 with New
ENDFOR

IF LENGTH(String2) <> 0 // anything left in String2 ?


THEN
RetFlag FALSE
ENDIF

RETURN RetFlag

ENDFUNCTION

© UCLES 2020 9608/22/O/N/20


PAGE 352

11

(i) Complete the trace table below by performing a dry run of the function when it is called
as follows:

Result Compare("SUB", "BUS")

The first row has been completed for you.

String1 String2 Len1 RetFlag x Len2 NextChar New y


"SUB" "BUS" 3 TRUE 1

[5]

(ii) State the value returned.

..................................................................................................................................... [1]

© UCLES 2020 9608/22/O/N/20 [Turn over


PAGE 353

12

(iii) There is an error in the algorithm, which means that under certain circumstances, the
function will return an incorrect value.

Describe the problem. Give two test strings that would demonstrate it.

Problem .............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

Test String1 .......................................................................................................................

Test String2 .......................................................................................................................


[2]

(iv) Describe the modification that needs to be made to the algorithm to correct the error.

Do not use pseudocode or program code in your answer.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [1]

(v) State the name given to the type of testing that makes use of a trace table.

..................................................................................................................................... [1]

(vi) State two features found in a typical Integrated Development Environment (IDE) that
may be used for debugging a program.

1 ........................................................................................................................................

2 ........................................................................................................................................
[2]

© UCLES 2020 9608/22/O/N/20


PAGE 354

13

Question 5 begins on the next page.

© UCLES 2020 9608/22/O/N/20 [Turn over


PAGE 355

14

5 A hashtag is used on a social media network. A hashtag is a string consisting of a hash character
‘#’ followed by one or more alphanumeric characters.

A program is being developed to monitor the use of hashtags.

The program will include two global arrays each containing 10 000 elements:

• A 1D array, TagString, of type STRING stores each hashtag in a single element. All unused
array elements contain an empty string ("").

• A 1D array, TagCount, of type INTEGER stores a count of the number of times each hashtag
is used. The count value at a given index relates to the element stored at the corresponding
index in the TagString array.

The contents of the two arrays will be stored in a text file Backup.txt. The format of each line of
the file is:

<Hashtag><','><Count>

For example:

"#ComputerScienceClass,978"

A developer has started to define the modules as follows:

Module Description
InitArrays() • Initialise the arrays
• The contents of the two arrays are stored in the text file Backup.txt
Existing file contents will be overwritten
SaveArrays() • Each hashtag and count are stored in one line of the file, as in the example
above
• Unused TagString elements are not added to the file
• Returns the total number of unused TagString elements

LoadArrays()
• Values from the text file Backup.txt are stored in the two arrays
• The number of elements stored is returned

(a) Write pseudocode for the module InitArrays().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]
© UCLES 2020 9608/22/O/N/20
PAGE 356

15

(b) Write pseudocode for the module SaveArrays().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]
© UCLES 2020 9608/22/O/N/20 [Turn over
PAGE 357

16

(c) Write program code for the module LoadArrays().

The module description is repeated here for reference.

Module Description
• Values from the text file Backup.txt are stored in the
LoadArrays() two arrays
• The number of elements stored is returned

You should assume:

• each line of the file contains a string of the correct format and no validation checks are
required
• there are no more than 10 000 lines in the file.

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2020 9608/22/O/N/20
PAGE 358

17

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2020 9608/22/O/N/20 [Turn over


PAGE 359

18

Appendix
Built-in functions (pseudocode)

Each function returns an error if the function call is not properly formed.

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of string ThisString

Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString

Example: LEFT("ABCDEFGH", 3) returns string "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString

Example: RIGHT("ABCDEFGH", 3) returns string "FGH"

MOD(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the remainder when ThisNum is divided by ThisDiv

Example: MOD(10,3) returns 1

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString

Example: MID("ABCDEFGH", 2, 3) returns string "BCD"

DIV(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the whole number part of the result when ThisNum is
divided by ThisDiv
Example: DIV(10,3) returns 3

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.
Note: This function will also work if x is of type INTEGER

Example: NUM_TO_STRING(87.5) returns "87.5"

STRING_TO_NUM(x : STRING) RETURNS REAL


returns a numeric representation of a string.
Note: This function will also work if x is of type CHAR

Example: STRING_TO_NUM("23.45") returns 23.45

© UCLES 2020 9608/22/O/N/20


PAGE 360

19

Operators (pseudocode)

Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE

© UCLES 2020 9608/22/O/N/20


PAGE 361

Cambridge International AS & A Level


* 5 4 7 9 1 0 0 9 4 4 *

COMPUTER SCIENCE 9608/23


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2020
2 hours

You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.

This document has 16 pages. Blank pages are indicated.

DC (JC/CT) 188579/4
© UCLES 2020 [Turn over
PAGE 362

1 (a) A programmer uses the process of stepwise refinement to break down a problem.

Explain the purpose of stepwise refinement.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

(b) Programming languages support different data types. These usually include STRING and
REAL.

Complete the table by giving four other data types and an example data value for each.

Data type Example data value

[4]

(c) An experienced programmer is working on a program that is written in a language she is not
familiar with.

(i) State one feature of the program that she should be able to recognise.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) State the type of skill that would allow her to recognise this feature.

...........................................................................................................................................

..................................................................................................................................... [1]

(d) Give three methods that may be used to identify and locate errors in a program after it has
been written.

You may include one feature found in a typical Integrated Development Environment (IDE).

1 ................................................................................................................................................

2 ................................................................................................................................................

3 ................................................................................................................................................
[3]
© UCLES 2020 9608/23/O/N/20
PAGE 363

2 (a) An algorithm is needed to input a list of numbers representing test marks for a class of
30 students.
The algorithm will output the number of students who have a mark greater than 75. It will also
output the average mark for the class.

Document the algorithm using structured English.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

(b) Each pseudocode statement in the following table contains an error.

State the error in each case.

Refer to the Appendix on page 16 for the list of built-in functions and operators.

Statement Error

Code LEFT(3, "Europe")

Hour MID("ALARM:12:02", 7, 6)

Size LENGTH(27.5)

Num INT(27 / (Count + 3)

Result "Conditional" AND "Loop"

[5]
© UCLES 2020 9608/23/O/N/20 [Turn over
PAGE 364

(c) Part of a program flowchart is shown.

Set Index to 0

Set Status to FALSE

LOOP

Is YES
Status = TRUE
?

NO
NO Is Index > 100
?
Set Status to TopUp()
YES

SetLevel("Super")
Set Index to Index + 1

Write program code to implement the flowchart shown. Variable declarations are not
required.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]
© UCLES 2020 9608/23/O/N/20
PAGE 365

3 A global 1D array, ProdNum, of type INTEGER contains 5 000 elements and is used to store
product numbers.

A procedure is needed to sort ProdNum into ascending order using a bubble sort algorithm.

Write program code for the procedure BubbleSort().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ....................................................................................................................

Program code

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................
© UCLES 2020 9608/23/O/N/20 [Turn over
PAGE 366

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [7]

4 (a) The following pseudocode includes a procedure that searches for a value in a 1D array and
outputs each position in the array where the value is found.

Refer to the Appendix on page 16 for the list of built-in functions and operators.

DECLARE NameList : ARRAY [1:100] OF STRING


DECLARE SearchString : STRING

PROCEDURE Search()
DECLARE Index : INTEGER

FOR Index 1 TO 100


IF NameList[Index] = SearchString
THEN
OUTPUT "Found at " & NUM_TO_STRING(Index)
ENDIF
ENDFOR
ENDPROCEDURE

The specification of module Search() changes. The pseudocode needs to be amended to


meet a new requirement.

The procedure needs to be implemented as a function, Search(), which will:

• take the search value as a parameter


• return an integer which is:

• either the index value where the search value is first found
• or –1 if the search value is not found.

© UCLES 2020 9608/23/O/N/20


PAGE 367

Write the pseudocode for the function Search().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

(b) A change to the specification in part (a) required a modification of the algorithm.

Give the term used for this type of modification.

............................................................................................................................................. [1]

(c) A change to the specification is only one reason to modify an algorithm.

Give another reason for the modification of an algorithm.

............................................................................................................................................. [1]

© UCLES 2020 9608/23/O/N/20 [Turn over


PAGE 368

(d) Consider the following pseudocode:

10 DECLARE VarA : INTEGER


11 VarA 20
12
13 CALL ProcA(VarA)
14 OUTPUT VarA // first value output
15
16 CALL ProcB(VarA)
17 OUTPUT VarA // second value output
18
19
20 PROCEDURE ProcA(BYVALUE ThisValue : INTEGER)
21 ThisValue ThisValue + 5
22 ENDPROCEDURE
23
24 PROCEDURE ProcB(BYREF ThisValue : INTEGER)
25 ThisValue ThisValue + 5
26 ENDPROCEDURE

Procedures ProcA() and ProcB() use two methods of passing parameters.

Complete the following table.

Output Explanation

.........................................................................................................
First
value
..................... .........................................................................................................
(line 14)
.........................................................................................................

.........................................................................................................
Second
value
..................... .........................................................................................................
(line 17)
.........................................................................................................
[4]

© UCLES 2020 9608/23/O/N/20


PAGE 369

(e) The procedures ProcA and ProcB in part (d) are examples of program modules.

Give two advantages of using program modules in program design.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2020 9608/23/O/N/20 [Turn over


PAGE 370

10

5 A hashtag is used on a social media network to make it easier to find messages with a specific
theme or content. A hashtag is a string consisting of a hash character ‘#’ followed by a number of
alphanumeric characters.

A message may contain several hashtag strings. A hashtag may be terminated by a space
character, the start of the next hashtag, or by the end of the message.

For example, the following message contains three hashtags:

"#Alarm34 is the result of #BatteryFailure in the #PowerModule"

The hashtags in this message are "#Alarm34", "#BatteryFailure" and "#PowerModule".

A program is being developed to monitor their use.

The program will include two global arrays each containing 10 000 elements:

• A 1D array, TagString, of type STRING storing each hashtag in a single element of the
array. All unused array elements contain an empty string ("").

• A 1D array, TagCount, of type INTEGER storing a count of the number of times each hashtag
is used. The count value in a given element relates to the hashtag value stored in the element
in the TagString array with the corresponding index value.

A developer has started to define the modules. Module GetStart() has already been written.

Module Description

• Called with two parameters:


• a message of type STRING
• an integer giving the number of the required hashtag;
for example, GetStart(Message, 3) would search
GetStart()
for the third hashtag in the string Message
• Returns an integer value representing the start position of
WKHKDVKWDJLQWKHPHVVDJHRUYDOXHíLIWKDWKDVKWDJ
does not exist
• Called with a hashtag of type STRING
• Copies the hashtag to the next free element of the
TagString array, and sets the corresponding element of
AddHashtag()
the TagCount array to 1
• Returns FALSE if there are no unused elements in the
TagString array, otherwise returns TRUE
• Called with a message of type STRING
CountHashtag()
• Searches the message for hashtags using GetStart()
• Returns a value representing the number of hashtags in the
message
• Called with a hashtag of type STRING
• Increments the value of the appropriate element in the
IncrementHashtag() TagCount array if the hashtag is found
• Returns TRUE if the hashtag is found, or FALSE if the
hashtag is not found

© UCLES 2020 9608/23/O/N/20


PAGE 371

11

(a) Write pseudocode for the module AddHashtag().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2020 9608/23/O/N/20 [Turn over


PAGE 372

12

(b) Write program code for the module CountHashtag().

The module description is repeated here for reference.

Module Description

• Called with a message of type STRING


CountHashtag()
• Searches the message for hashtags using GetStart()
• Returns a value representing the number of hashtags in the
message

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language .............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]
© UCLES 2020 9608/23/O/N/20
PAGE 373

13

(c) Write program code for the module IncrementHashtag().

The module description is repeated here for reference.

Module Description

• Called with a hashtag of type STRING


• Increments the value of the appropriate element in the
IncrementHashtag() TagCount array if the hashtag is found
• Returns TRUE if the hashtag is found, or FALSE if the
hashtag is not found

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language .............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]
© UCLES 2020 9608/23/O/N/20 [Turn over
PAGE 374

14

(d) A procedure, OutputMostPop(), is needed to output the most popular hashtag. The most
popular hashtag is the one with the highest count value stored in the TagCount array.

As a reminder, the program includes two global arrays each containing 10 000 elements:

• A 1D array, TagString, of type STRING storing each hashtag in a single element of the
array. All unused array elements contain an empty string ("").

• A 1D array, TagCount, of type INTEGER storing a count of the number of times each
hashtag is used. The count value in a given element relates to the hashtag value stored
in the element in the TagString array with the corresponding index value.

If the maximum count value occurs once, the procedure will output the corresponding hashtag
and the count value.

It is possible for more than one hashtag to have the same highest count value. In this case,
the procedure will output the maximum count value together with the number of hashtags
with this maximum count value.

In both cases, the procedure must also output a suitable message.

You can assume that the arrays contain data for at least one hashtag.

Write pseudocode for the OutputMostPop() procedure.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2020 9608/23/O/N/20
PAGE 375

15

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................ . [8]

© UCLES 2020 9608/23/O/N/20 [Turn over


PAGE 376

16

Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of string ThisString
Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString
Example: LEFT("ABCDEFGH", 3) returns string "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString
Example: RIGHT("ABCDEFGH", 3) returns string "FGH"

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString
Example: MID("ABCDEFGH", 2, 3) returns string "BCD"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x
Example: INT(27.5415) returns 27

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.
Note: This function will also work if x is of type INTEGER
Example: NUM_TO_STRING(87.5) returns "87.5"

Operators (pseudocode)
Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE

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
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.

Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of
Cambridge Local Examinations Syndicate (UCLES), which itself is a department of the University of Cambridge.

© UCLES 2020 9608/23/O/N/20


PAGE 377

Cambridge International AS & A Level


* 3 0 1 3 8 0 7 6 7 4 *

COMPUTER SCIENCE 9618/22


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2021

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 16 pages. Any blank pages are indicated.

DC (MB/FC) 200588/5
© UCLES 2021 [Turn over
PAGE 378

Refer to the insert for the list of pseudocode functions and operators.

1 (a) (i) Complete the following table by giving the appropriate data type in each case.

Variable Example data value Data type


Name "Catherine"
Index 100
Modified FALSE
Holiday 25/12/2020
[4]

(ii) Evaluate each expression in the following table by using the initial data values shown in
part (a)(i).

Expression Evaluates to
Modified OR Index > 100
LENGTH("Student: " & Name)
INT(Index + 2.9)
MID(Name, 1, 3)
[4]

(b) Each pseudocode statement in the following table contains an example of selection,
assignment or iteration.

Put one tick (‘’) in the appropriate column for each statement.

Statement Selection Assignment Iteration


Index Index + 1
IF Modified = TRUE THEN
ENDWHILE
[3]

© UCLES 2021 9618/22/M/J/21


PAGE 379

2 (a) Examine the following state-transition diagram.

Low level detected | Activate pump

Low level detected

X S2
S1

Normal level detected Normal level detected | Deactivate pump


S3

(i) Complete the table with reference to the diagram.

Answer
The number of transitions that result in a different state
The number of transitions with associated outputs
The label that should replace ‘X’
The final or halting state
[4]

(ii) The current state is S1. The following inputs occur.

1. Low level detected


2. Low level detected
3. Low level detected
4. Low level detected

Give the number of outputs and the current state.

Number of outputs .............................................................................................................

Current state .....................................................................................................................


[2]

© UCLES 2021 9618/22/M/J/21 [Turn over


PAGE 380

(b) A system is being developed to help manage book loans in a library.

Registered users may borrow books from the library for a period of time.

(i) State three items of data that must be stored for each loan.

1 ........................................................................................................................................

2 ........................................................................................................................................

3 ........................................................................................................................................
[2]

(ii) State one item of data that will be required in the library system but does not need to be
stored for each loan.

..................................................................................................................................... [1]

(iii) One operation that manipulates the data stored for each loan, would produce a list of all
overdue books.

Identify two other operations.

Operation 1 .......................................................................................................................

...........................................................................................................................................

Operation 2 .......................................................................................................................

...........................................................................................................................................
[2]

© UCLES 2021 9618/22/M/J/21


PAGE 381

3 The following diagram represents an Abstract Data Type (ADT).

A B
Dolphin Cat Fish Elk

(a) Identify this type of ADT.

............................................................................................................................................. [1]

(b) Give the technical term for the item labelled A in the diagram.

............................................................................................................................................. [1]

(c) Give the technical term for the item labelled B in the diagram.

Explain the meaning of the value given to this item.

Term ..........................................................................................................................................

Meaning ....................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[2]

(d) Complete the diagram to show the ADT after the data has been sorted in alphabetical order.

Dolphin Cat Fish Elk

[2]

© UCLES 2021 9618/22/M/J/21 [Turn over


PAGE 382

4 A teacher uses a paper-based system to store marks for a class test. The teacher requires a
program to assign grades based on these results.

The program will output the grades together with the average mark.

Write a detailed description of the algorithm that will be needed.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [6]

© UCLES 2021 9618/22/M/J/21


PAGE 383

5 (a) A student is learning about arrays.

She wants to write a program to:

• declare a 1D array RNum of 100 elements of type INTEGER


• assign each element a random value in the range 1 to 200 inclusive
• count and output how many numbers generated were between 66 and 173 inclusive.

(i) Write pseudocode to represent the algorithm.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [6]

(ii) The student decides to modify the algorithm so that each element of the array will contain
a unique value.

Describe the changes that the student needs to make to the algorithm.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

© UCLES 2021 9618/22/M/J/21 [Turn over


PAGE 384

(b) The following is a pseudocode function.

Line numbers are given for reference only.

01 FUNCTION StringClean(InString : STRING) RETURNS STRING


02
03 DECLARE NextChar : CHAR
04 DECLARE OutString : STRING
05 DECLARE Counter : INTEGER
06
07 OutString ""
08
09 FOR Counter 1 TO LENGTH(InString)
10 NextChar MID(InString, Counter, 1)
11 NextChar LCASE(NextChar)
12 IF NOT((NextChar < 'a') OR (NextChar > 'z')) THEN
13 OutString OutString & NextChar
14 ENDIF
15 NEXT Counter
16
17 RETURN OutString
18
19 ENDFUNCTION

(i) Examine the pseudocode and complete the following table.

Answer

Give a line number containing an example of an initialisation statement.

Give a line number containing the start of a repeating block of code.

Give a line number containing a logic operation.

Give the number of parameters to the function MID().


[4]

(ii) Write a simplified version of the statement in line 12.

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2021 9618/22/M/J/21


PAGE 385

10

6 A procedure CountVowels() will:

• be called with a string containing alphanumeric characters as its parameter


• count and output the number of occurrences of each vowel (a, e, i, o, u) in the string
• count and output the number of occurrences of the other alphabetic characters (as a single
total).

The string may contain both upper and lower case characters.

Each count value will be stored in a unique element of a global 1D array CharCount of type
INTEGER. The array will contain six elements.

Write pseudocode for the procedure CountVowels().

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

© UCLES 2021 9618/22/M/J/21


PAGE 386

11

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [8]

7 A procedure, FormatName():

• is called with a string containing words and spaces as its parameter. In this context, a word is
any sequence of characters that does not contain a space character.

• creates a new formatted string from this string with the following requirements:
1. Any leading spaces removed (spaces before the first word).
2. Any trailing spaces removed (spaces after the last word).
3. Any multiple spaces between words converted to a single space.
4. All characters converted to lower case.

The FormatName() procedure has been written in a programming language and is to be tested
using the black-box method.

(a) Give a test string that could be used to show that all four formatting requirements have been
applied correctly.

Use the symbol ‘”’ to represent a space character.

............................................................................................................................................. [3]

(b) The FormatName() procedure should assign a value to the global variable FString.

There is a fault in the program, which means that the assignment does not always take place.

Explain two ways of exposing the fault.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2021 9618/22/M/J/21 [Turn over


PAGE 387

12

8 A program is needed to take a string containing a full name and to produce a new string of initials.

Some words in the full name will be ignored. For example, “the”, “and”, “of”, “for” and “to” may all
be ignored.

Each letter of the new string must be upper case.

For example:

Full name Initials


Integrated Development Environment IDE
The American Standard Code for Information Interchange ASCII

The programmer has decided to use the following global variables:

• a ten element 1D array IgnoreList of type STRING to store the ignored words
• a string FNString to store the full name string.

Assume that:

• each alphabetic character in the full name string may be either upper or lower case
• the full name string contains at least one word.

The programmer has started to define program modules as follows:

Module Description
• Called with an INTEGER as its parameter, representing the number of
a word in FNString
GetStart() • Returns the character start position of that word in FNString or
returns -1 if that word does not exist
• For example: GetStart(3) applied to "hot and cold" returns 9
• Called with the position of the first character of a word in FNString
as its parameter
GetWord() • Returns the word from FNString
• For example: if FNString contains the string "hot and cold",
GetWord(9) returns "cold"
• Called with a STRING parameter representing a word
IgnoreWord() • Searches for the word in the IgnoreList array
• Returns TRUE if the word is found, otherwise returns FALSE
• Processes the sequence of words in the full name one word at a time
GetInitials()
• Calls GetStart(), GetWord() and IgnoreWord() to process
each word to form the new string
• Outputs the new string

© UCLES 2021 9618/22/M/J/21


PAGE 388

13

(a) Write pseudocode for the module IgnoreWord().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

© UCLES 2021 9618/22/M/J/21 [Turn over


PAGE 389

14

(b) Write pseudocode for the module GetInitials().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]
© UCLES 2021 9618/22/M/J/21
PAGE 390

Cambridge International AS & A Level


* 7 4 8 3 1 9 9 9 0 1 *

COMPUTER SCIENCE 9618/23


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2021

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 24 pages. Any blank pages are indicated.

DC (PQ/FC) 200587/4
© UCLES 2021 [Turn over
PAGE 391

Refer to the insert for the list of pseudocode functions and operators.

1 (a) A program is being developed to help manage the membership of a football club.

Complete the following identifier table.

Example
Explanation Variable name Data type
value

The preferred name of the member


"Wong"
joining the football club

A value to indicate whether an


FALSE existing member of the club lives at
the same address

When the member joined the football


19/02/1983
club

The number of points a member has


1345 earned. Members of the club earn
points for different activities.
[4]

(b) Each pseudocode statement in the following table may contain an error due to the incorrect
use of the function or operator.

Describe the error in each case, or write ‘NO ERROR’ if the statement contains no error.

You can assume that none of the variables referenced are of an incorrect type.

Statement Error

Result 2 & 4

SubString MID("pseudocode", 4, 1)

IF x = 3 OR 4 THEN

Result Status AND INT(x/2)

Message "Done" + LENGTH(MyString)

[5]

© UCLES 2021 9618/23/M/J/21


PAGE 392

(c) The following data items need to be stored for each student in a group:

• student name (a string)


• test score (an integer).

State a suitable data structure and justify your answer.

Structure ...................................................................................................................................

Justification ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2021 9618/23/M/J/21 [Turn over


PAGE 393

2 (a) Four program modules form part of a program for a library.

A description of the relationship between the modules is summarised as follows:

Module name Description

UpdateLoan() • Calls either LoanExtend() or LoanReturn()


• Called with parameters LoanID and BookID
• Calls CheckReserve() to see whether the book has been
LoanExtend() reserved for another library user
• Returns TRUE if the loan has been extended, otherwise returns
FALSE
• Called with BookID
CheckReserve() • Returns TRUE if the book has been reserved, otherwise returns
FALSE
• Called with parameters LoanID and BookID
LoanReturn() • Returns a REAL (which is the value of the fine to be paid in the
case of an overdue loan)

Draw a structure chart to show the relationship between the four modules and the parameters
passed between them.

[5]
© UCLES 2021 9618/23/M/J/21
PAGE 394

(b) The definition for module LoanReturn() is amended as follows:

Module name Description


Called with parameters LoanID, BookID and Fine
LoanReturn() The module code checks whether the book has been returned on time
and then assigns a new value to Fine

• LoanID and BookID are of type STRING


• Fine is of type REAL

Write the pseudocode header for the amended module LoanReturn().

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2021 9618/23/M/J/21 [Turn over


PAGE 395

(c) A program will:

• input 50 unique integer values


• output the largest value
• output the average of the values excluding the largest value.

Draw a program flowchart to represent the algorithm.

Variable declarations are not required.

It is not necessary to check that each input value is unique.

[6]
© UCLES 2021 9618/23/M/J/21
PAGE 396

3 (a) A concert venue uses a program to calculate admission prices and store information about
ticket sales.

A number of arrays are used to store data. The computer is switched off overnight and data
has to be input again at the start of each day before any tickets can be sold. This process is
very time consuming.

(i) Explain how the program could use text files to speed up the process.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(ii) State the characteristic of text files that allow them to be used as explained in part (a)(i).

...........................................................................................................................................

..................................................................................................................................... [1]

(iii) Information about ticket sales will be stored as a booking. The booking requires the
following data:

• name of person booking


• number of people in the group (for example a family ticket or a school party)
• event type.

Suggest how data relating to each booking may be stored in a text file.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2021 9618/23/M/J/21


PAGE 397

(b) A procedure Preview() will:

• take the name of a text file as a parameter


• output a warning message if the file is empty
• otherwise output the first five lines from the file (or as many lines as there are in the file if
this number is less than five).

Write pseudocode for the procedure Preview().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

© UCLES 2021 9618/23/M/J/21 [Turn over


PAGE 398

10

4 Study the following pseudocode. Line numbers are for reference only.

10 FUNCTION Convert(Name : STRING) RETURNS STRING


11
12 DECLARE Flag: BOOLEAN
13 DECLARE Index : INTEGER
14 DECLARE ThisChar : CHAR
15 DECLARE NewName : STRING
16
17 CONSTANT SPACECHAR = ' '
18
19 Flag TRUE
20 Index 1
21 NewName "" // formatted name string
22
23 WHILE Index <= LENGTH(Name)
24 ThisChar MID(Name, Index, 1)
25 IF Flag = TRUE THEN
26 NewName NewName & UCASE(ThisChar)
27 IF ThisChar <> SPACECHAR THEN
28 Flag FALSE
29 ENDIF
30 ELSE
31 NewName NewName & ThisChar
32 ENDIF
33 IF ThisChar = SPACECHAR THEN
34 Flag TRUE
35 ENDIF
36 Index Index + 1
37 ENDWHILE
38
39 RETURN NewName
40
41 ENDFUNCTION

© UCLES 2021 9618/23/M/J/21


PAGE 399

11

(a) Complete the trace table below by dry running the function when it is called as follows:

Result Convert("|in|a||Cup")

Note: The symbol '|' has been used to represent a space character.
Use this symbol for any space characters in the trace table.

The first row has been completed for you.

Name Flag Index NewName ThisChar

"|in|a||Cup"

[5]

© UCLES 2021 9618/23/M/J/21 [Turn over


PAGE 400

12

(b) The pseudocode for Convert() contains a conditional loop.

State a more appropriate loop structure.

Justify your answer.

Loop structure ...........................................................................................................................

...................................................................................................................................................

Justification ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[2]

(c) Two changes need to be made to the algorithm.

Change 1: Convert to lower case any character that is not the first character after a space.
Change 2: Replace multiple spaces with a single space.

(i) Change 1 may be implemented by modifying one line of the pseudocode.

Write the modified line.

...........................................................................................................................................

.......................................................................................................................................[1]

(ii) Change 2 may be implemented by moving one line of the pseudocode.

Write the number of the line to be moved and state its new position.

Line number ......................................................................................................................

New position ......................................................................................................................

...........................................................................................................................................
[2]

© UCLES 2021 9618/23/M/J/21


PAGE 401

14

5 A global 2D array Result of type INTEGER is used to store a list of exam candidate numbers
together with their marks. The array contains 2000 elements, organised as 1000 rows and
2 columns.

Column 1 contains the candidate number and column 2 contains the mark for the corresponding
candidate. All elements contain valid exam result data.

A procedure Sort() is needed to sort Result into ascending order of mark using an efficient
bubble sort algorithm.

Write pseudocode for the procedure Sort().

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

© UCLES 2021 9618/23/M/J/21


PAGE 402

15

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [8]

© UCLES 2021 9618/23/M/J/21 [Turn over


PAGE 403

16

6 The following diagram represents an Abstract Data Type (ADT) for a linked list.

A C D E Ø

The free list is as follows:

(a) Explain how a node containing data value B is added to the list in alphabetic sequence.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]

(b) Describe how the linked list in part (a) may be implemented using variables and arrays.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2021 9618/23/M/J/21


PAGE 404

18

7 A program is needed to take a string containing a full name and produce a new string of initials.

Some words in the full name will be ignored. For example, "the", "and", "of", "for" and "to" may all
be ignored.

Each letter of the abbreviated string must be upper case.

For example:

Full name Initials

Integrated Development Environment IDE

The American Standard Code for Information Interchange ASCII

The programmer has decided to use a global variable FNString of type STRING to store the full
name.

It is assumed that:

• words in the full name string are separated by a single space character
• space characters will not occur at the beginning or the end of the full name string
• the full name string contains at least one word.

The programmer has started to define program modules as follows:

Module Description
• Called with an INTEGER as a parameter, representing the number of a
word in FNString.
GetStart()
• Returns the character start position of that word in FNString or
returns –1 if that word does not exist
• For example: if FNString contains the string "hot and cold",
GetStart(3) returns 9
• Called with a parameter representing the position of the first character
of a word in FNString
GetWord() • Returns the word from FNString
• For example: if FNString contains the string "hot and cold",
GetWord(9) returns "cold"

© UCLES 2021 9618/23/M/J/21


PAGE 405

19

(a) Write pseudocode for the module GetStart().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2021 9618/23/M/J/21 [Turn over


PAGE 406

20

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

(b) The programmer has decided to use a global ten-element 1D array IgnoreList of type
STRING to store the ignored words. Unused elements contain the empty string ("") and may
occur anywhere in the array.

A new module AddWord() is needed as follows:

Module Description
• Called with a parameter representing a word
• Stores the word in an unused element of the IgnoreList array
AddWord() and returns TRUE
• Returns FALSE if the array was already full or if the word was
already in the array

Write a detailed description of the algorithm for AddWord(). Do not include pseudocode
statements in your answer.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]

© UCLES 2021 9618/23/M/J/21


PAGE 407

21

(c) As a reminder, the module description of GetWord() is repeated:

Module Description
• Called with a parameter representing the position of the first
character of a word in FNString
GetWord() • Returns the word from FNString
• For example: if FNString contains the string "hot and cold",
GetWord(9) returns "cold"

Write pseudocode for the module GetWord().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]
© UCLES 2021 9618/23/M/J/21
PAGE 408

Cambridge International AS & A Level


* 9 6 0 1 3 8 7 0 0 9 *

COMPUTER SCIENCE 9618/22


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2021
2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (LK/CGW) 213669/3
© UCLES 2021 [Turn over
PAGE 409

Refer to the insert for the list of pseudocode functions and operators.

1 (a) A programmer applies decomposition to a problem that she has been asked to solve.

Describe decomposition.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

(b) The following pseudocode assigns a value to an element of an array:

ThisArray[n] ĸ 42
Complete the following table by writing the answer for each row.

Answer

The number of dimensions of ThisArray

The technical terms for minimum and


maximum values that the variable n may take
The technical term for the variable n in the
pseudocode statement
[3]

(c) Complete the pseudocode expressions so that they evaluate to the values shown.

Any functions and operators used must be defined in the insert.

Expression Evaluates to

67
.......................................... ('C')

54
2 * ......................................... ("27")

13
................................ (27 / .................................)

"Sub" & .................... ("Abstraction" , .................... , ....................) "Subtract"

[4]

© UCLES 2021 9618/22/O/N/21


PAGE 410

(d) Evaluate the expressions given in the following table. The variables have been assigned
values as follows:

PumpOn ĸ TRUE
ĸ
PressureOK TRUE
HiFlow ĸ FALSE

Expression Evaluates to

PressureOK AND HiFlow

PumpOn OR PressureOK

NOT PumpOn OR (PressureOK AND NOT HiFlow)

NOT (PumpOn OR PressureOK) AND NOT HiFlow


[2]

© UCLES 2021 9618/22/O/N/21 [Turn over


PAGE 411

2 (a) An algorithm will:

1. input an integer value


2. jump to step 6 if the value is zero
3. sum and count the positive values
4. sum and count the negative values
5. repeat from step 1
6. output the two sum values and the two count values.

Draw a program flowchart on the following page to represent the algorithm.

Note that variable declarations are not required in program flowcharts.

© UCLES 2021 9618/22/O/N/21


PAGE 412

[5]
© UCLES 2021 9618/22/O/N/21 [Turn over
PAGE 413

(b) A software company is working on a project to develop a website for a school.

The school principal has some ideas about the appearance of the website but is unclear
about all the details of the solution. The principal would like to see an initial version of the
website.

(i) Identify a life cycle method that would be appropriate in this case.

Give a reason for your choice.

Life cycle method ..............................................................................................................

Reason ..............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[2]

(ii) The website project has progressed to the design stage.

State three activities that will take place during the design stage of the program
development life cycle.

1 ........................................................................................................................................

2 ........................................................................................................................................

3 ........................................................................................................................................
[3]

© UCLES 2021 9618/22/O/N/21


PAGE 414

3 A programmer is writing a program to help manage clubs in a school.

Data will be stored about each student in the school and each student may join up to three clubs.

The data will be held in a record structure of type Student.

The programmer has started to define the fields that will be needed as shown in the following
table.

Field Typical value Comment


StudentID "CF1234" Unique to each student
Email "Carmen47@xyzmail.com" Contains letters, numbers and certain symbols
Club_1 1 Any value in the range 1 to 99 inclusive
Club_2 14 Any value in the range 1 to 99 inclusive
Club_3 27 Any value in the range 1 to 99 inclusive

(a) (i) Write pseudocode to declare the record structure for type Student.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

(ii) A 1D array Membership containing 3000 elements will be used to store the student
data.

Write pseudocode to declare the Membership array.

...........................................................................................................................................

..................................................................................................................................... [2]

(iii) Some of the elements of the array will be unused.

Give an appropriate way of indicating an unused array element.

...........................................................................................................................................

..................................................................................................................................... [1]

(iv) Some students are members of less than three clubs.

State one way of indicating an unused club field.

...........................................................................................................................................

..................................................................................................................................... [1]
© UCLES 2021 9618/22/O/N/21
PAGE 415

(b) A procedure GetIDs() will:

• prompt and input the number of a club


• output the StudentID of all the students who are members of that club
• output a count of all students in the given club.

Write pseudocode for the procedure GetIDs().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]
© UCLES 2021 9618/22/O/N/21 [Turn over
PAGE 416

10

4 The following is a procedure design in pseudocode.

Line numbers are given for reference only.

10 PROCEDURE Check(InString : STRING)


11 DECLARE Odds, Evens, Index : INTEGER
12
13 Odds ĸ0
14 Evens ĸ0
15 Index ĸ1
16
17 WHILE Index <= LENGTH(InString)
18 IF STR_TO_NUM(MID(InString, Index, 1)) MOD 2 <> 0 THEN
19 Odds ĸ
Odds + 1
20 ELSE
21 Evens ĸ
Evens + 1
22 ENDIF
23 Index ĸ
Index + 1
24 ENDWHILE
25
26 CALL Result(Odds, Evens)
27 ENDPROCEDURE

(a) Complete the following table by giving the answers, using the given pseudocode.

Answer
A line number containing a variable being incremented

The type of loop structure

The number of functions used

The number of parameters passed to STR_TO_NUM()

The name of a procedure other than Check()


[5]

(b) The pseudocode includes several features that make it easier to read and understand.

Identify three of these features.

1 ................................................................................................................................................

2 ................................................................................................................................................

3 ................................................................................................................................................
[3]

© UCLES 2021 9618/22/O/N/21


PAGE 417

11

(c) (i) The loop structure used in the pseudocode is not the most appropriate.

State a more appropriate loop structure and justify your choice.

Loop structure ...................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[2]

(ii) The appropriate loop structure is now used. Two lines of pseudocode are changed and
two lines are removed.

Write the line numbers of the two lines that are removed.

...........................................................................................................................................

..................................................................................................................................... [1]

© UCLES 2021 9618/22/O/N/21 [Turn over


PAGE 418

12

5 A company has several departments. Each department stores the name, email address and the
status of each employee in that department in its own text file. All text files have the same format.

Employee details are stored as three separate data strings on three consecutive lines of the file.
An example of the first six lines of one of the files is as follows:

File line Comment


1 First employee name

2 First email address

3 First employee status

4 Second employee name

5 Second email address

6 Second employee status

A procedure MakeNewFile() will:

• take three parameters as strings:


ż an existing file name
ż a new file name
ż a search status value

• create a new text file using the new file name


• write all employee details to the new file where the employee status is not equal to the search
status value
• count the number of sets of employee details that were in the original file
• count the number of sets of employee details that were written to the new file
• produce a summary output.

An example summary output is as follows:

File Marketing contained 54 employee details


52 employee sets of details were written to file NewMarketingList

(a) Write pseudocode for the procedure MakeNewFile().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2021 9618/22/O/N/21
PAGE 419

13

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2021 9618/22/O/N/21 [Turn over


PAGE 420

14

(b) An alternative format could be used for storing the data.

A text file will still be used.

(i) Describe the alternative format.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) State one advantage and one disadvantage of the alternative format.

Advantage .........................................................................................................................

...........................................................................................................................................

Disadvantage ....................................................................................................................

...........................................................................................................................................
[2]

© UCLES 2021 9618/22/O/N/21


PAGE 421

16

6 A mobile phone has a touchscreen. The screen is represented by a grid, divided into 800 rows
and 1280 columns.

The grid is represented by a 2D array Screen of type INTEGER. An array element will be set to 0
unless the user touches that part of the screen.

Many array elements will set to 1 by a single touch of a finger or a stylus.

The following diagram shows a simplified touchscreen. The dark line represents a touch on the
screen. All grid elements that are wholly or partly inside the outline will be set to 1. These elements
are shaded.
The element shaded in black represents the centre point of the touch.

11

A program is needed to find the coordinates (the row and column) of the centre point. The centre
point on the diagram shown is row 6, column 11.

Assume:

• the user may only touch one area at a time


• screen rotation does not affect the touchscreen.

The programmer has decided to use global values CentreRow and CentreCol as coordinate
values for the centre point.

The programmer has started to define program modules as follows:

Module Description
• Searches for the first row that has an array element set to 1
FirstRowSet() • Returns the index of that row (1 is the first row)
• 5HWXUQVíLIWKHUHDUHQRHOHPHQWVVHWWR
• Searches for the last row that has an array element set to 1
LastRowSet() • Returns the index of that row
• 5HWXUQVíLIWKHUHDUHQRHOHPHQWVVHWWR
• Searches for the first column that has an array element set to 1
FirstColSet() • Returns the index of that column (1 is the first column)
• 5HWXUQVíLIWKHUHDUHQRHOHPHQWVVHWWR
• Searches for the last column that has an array element set to 1
LastColSet() • Returns the index of that column
• 5HWXUQVíLIWKHUHDUHQRHOHPHQWVVHWWR

© UCLES 2021 9618/22/O/N/21


PAGE 422

17

(a) Write efficient pseudocode for the module FirstRowSet().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]
© UCLES 2021 9618/22/O/N/21 [Turn over
PAGE 423

18

(b) Describe a feature of your solution to part (a) that indicates the pseudocode represents an
efficient algorithm.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

(c) The programmer decides to produce a single search module FindSet(), which will be able
to perform each of the individual searches performed by the first four modules in the table.

(i) Outline the changes needed to convert one of the existing modules into this single
module.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(ii) Give one possible advantage and one possible disadvantage of combining the four
searches into a single module.

Advantage .........................................................................................................................

...........................................................................................................................................

Disadvantage ....................................................................................................................

...........................................................................................................................................
[2]

© UCLES 2021 9618/22/O/N/21


PAGE 424

19

(d) An additional module GetCentre() is defined as follows:

Module Description
• Calculates the coordinates of the centre point
• Uses the four modules: FirstRowSet(), LastRowSet(),
GetCentre() FirstColSet(), LastColSet()
• Assigns values to CentreRow and CentreCol
• Sets CentreRowWRíLIQRVFUHHQWRXFKLVGHWHFWHG

Write pseudocode for the module GetCentre().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]
© UCLES 2021 9618/22/O/N/21
PAGE 425

Cambridge International AS & A Level


* 5 4 2 7 3 9 9 5 0 1 *

COMPUTER SCIENCE 9618/23


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2021
2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (CE/CGW) 213696/3
© UCLES 2021 [Turn over
PAGE 426

Refer to the insert for the list of pseudocode functions and operators.

1 Sylvia is testing a program that has been written by her colleague. Her colleague tells her that the
program does not contain any syntax errors.

(a) (i) State what her colleague means by “does not contain any syntax errors”.

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) Identify and describe one other type of error that the program may contain.

Type of error ......................................................................................................................

Description ........................................................................................................................

...........................................................................................................................................
[2]

(b) Complete the following table by giving the appropriate data type in each case.

Use of variable Data type


The average mark in a class of 40 students
An email address
The number of students in the class
To indicate whether an email has been read
[4]

© UCLES 2021 9618/23/O/N/21


PAGE 427

(c) An airline wants to provide passengers with information about individual flights and allow
them to book their flight using an online booking system.

(i) Tick () one box in each row of the table to indicate whether each item of information
would be essential for the customer when making the booking.

Information Essential Not essential


Departure time
Flight number
Departure airport
Aircraft type
Ticket price
Number of seats in aircraft
[3]

(ii) Identify the technique used to filter out information that is not essential when designing
the booking system and state one benefit of this technique.

Technique ..........................................................................................................................

Benefit ...............................................................................................................................

...........................................................................................................................................
[2]

(iii) Identify two additional pieces of essential information that a passenger might need
when booking a flight.

1 ........................................................................................................................................

2 ........................................................................................................................................
[2]

© UCLES 2021 9618/23/O/N/21 [Turn over


PAGE 428

2 (a) An algorithm to sort a 1D array into ascending order is described as follows:

• move the largest value to the end


• keep repeating until the array is sorted.

Apply the process of stepwise refinement to this algorithm in order to produce a more detailed
description.

Write the more detailed description using structured English. Your explanation of the
algorithm should not include pseudocode statements.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2021 9618/23/O/N/21 [Turn over


PAGE 429

(b) The program flowchart shown describes a simple algorithm.

START

Set Count to 1

Set Flag to FALSE

Is Flag = YES
FALSE AND
Count <= 5 ?

NO
ReBoot()

Set Count to Count + 1

Set Flag to Check()

Is Flag = YES
FALSE ?

NO
Alert(27)

END

© UCLES 2021 9618/23/O/N/21


PAGE 430

Write pseudocode for the simple algorithm shown on page 6.

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

............................................................................................................................................................ [6]

© UCLES 2021 9618/23/O/N/21 [Turn over


PAGE 431

3 (a) The diagram below represents a queue Abstract Data Type (ADT) that can hold a maximum
of eight items.

The operation of this queue may be summarised as follows:

• The front of queue pointer points to the next item to be removed.


• The end of queue pointer points to the last item added.
• The queue is circular so that empty storage elements can be reused.

0 Frog Front of queue pointer


1 Cat
2 Fish
3 Elk End of queue pointer
4
5
6
7

(i) Describe how “Octopus” is added to the given queue.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(ii) Describe how the next item in the given queue is removed and stored in the variable
AnimalName.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(iii) Describe the state of the queue when the front of queue and the end of queue pointers
have the same value.

...........................................................................................................................................

..................................................................................................................................... [1]

© UCLES 2021 9618/23/O/N/21


PAGE 432

(b) Some operations are carried out on the original queue given in part (a).

(i) The current state of the queue is:

0 Frog
1 Cat
2 Fish
3 Elk
4
5
6
7

Complete the diagram to show the state of the queue after the following operations:

Add “Wasp”, “Bee” and “Mouse”, and then remove two data items.
[3]

(ii) The state of the queue after other operations are carried out is shown:

0 Frog
1 Cat
2 Fish
3 Elk Front of queue pointer
4 Wasp
5 Bee
6 Mouse End of queue pointer
7 Ant

Complete the following diagram to show the state of the queue after the following
operations:

Remove one item, and then add “Dolphin” and “Shark”.

0
1
2
3
4
5
6
7
[2]
© UCLES 2021 9618/23/O/N/21 [Turn over
PAGE 433

10

(c) The queue is implemented using a 1D array.

Describe the algorithm that should be used to modify the end of queue pointer when adding
an item to the queue.

Your algorithm should detect any potential error conditions.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2021 9618/23/O/N/21


PAGE 434

11

4 A program controls the heating system in a sports hall.

Part of the program involves reading a value from a sensor. The sensor produces a numeric value
that represents the temperature. The value is an integer, which should be in the range 0 to 40
inclusive.

A program function has been written to validate the values from the sensor.

(a) A test plan is needed to test the function.

Complete the table. The first line has been completed for you.

You can assume that the sensor will generate only integer data values.

Test Test data value Explanation Expected outcome


1 23 Normal data Data is accepted
2
3
4
5
[4]

(b) A program module controls the heaters. This module operates as follows:

• If the temperature is below 10, switch the heaters on.


• If the temperature is above 20, switch the heaters off.

Complete the following state-transition diagram for the heating system:

Start
Heaters Heaters
Off On

[3]

© UCLES 2021 9618/23/O/N/21 [Turn over


PAGE 435

12

5 The following data items will be recorded each time a student successfully logs on to the school
network:

Data item Example data


Student ID "CJL404"
Host ID "Lib01"
Time and date "08:30, June 01, 2021"

The Student ID is six characters long. The other two data items are of variable length.

A single string will be formed by concatenating the three data items. A separator character will
need to be inserted between items two and three.

For example:

"CJL404Lib01<separator>08:30, June 01, 2021"

Each string represents one log entry.

A programmer decides to store the concatenated strings in a 1D array LogArray that contains
2000 elements. Unused array elements will contain an empty string.

(a) Suggest a suitable separator character and give a reason for your choice.

Character ..................................................................................................................................

Reason .....................................................................................................................................

...................................................................................................................................................
[2]

(b) The choice of data structure was made during one stage of the program development life
cycle.

Identify this stage.

............................................................................................................................................. [1]

© UCLES 2021 9618/23/O/N/21


PAGE 436

13

(c) A function LogEvents() will:

• take a Student ID as a parameter


• for each element in the array that matches the Student ID parameter:
ƕ add the value of the array element to the existing text file LogFile
ƕ assign an empty string to the array element
• count the number of lines added to the file
• return this count.

Write pseudocode for the function LogEvents().

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [7]
© UCLES 2021 9618/23/O/N/21 [Turn over
PAGE 437

14

6 A mobile phone has a touchscreen. The screen is represented by a grid, divided into 800 rows
and 1280 columns.

The grid is represented by a 2D array Screen of type INTEGER. An array element will be set to 0
unless the user touches that part of the screen.

Many array elements are set to 1 by a single touch of a finger or a stylus.

The following diagram shows a simplified touchscreen. The dark line represents a touch to the
screen. All grid elements that are wholly or partly inside the outline will be set to 1. These elements
are shaded.
The element shaded in black represents the centre point.

11

A program is needed to find the coordinates (the row and column) of the centre point. The centre
point on the diagram above is row 6, column 11.

Assume:

• the user may only touch one area at a time


• screen rotation does not affect the touchscreen.

The programmer has started to define program modules as follows:

Module Description
• Called with three parameters of type INTEGER:
SetRow() ƕa row number
(generates test ƕthe number of pixels to be skipped starting from column 1
data) ƕthe number of pixels that should be set to 1
• Sets the required number of pixels to 1
For example, SetRow(3, 8, 5) will give row 3 as in the diagram shown.
• Takes two parameters of type INTEGER:
ƕa row number
ƕa start column (1 or 1280)
SearchInRow() • Searches the given row from the start column (either left to right or right to left)
for the first column that contains an element set to 1
• Returns the column number of the first element in the given row that is set to 1
• 5HWXUQVíLIQRHOHPHQWLVVHWWR
• Takes two parameters of type INTEGER:
ƕ
a column number
ƕ
a start row (1 or 800)
SearchInCol() • Searches the given column from the start row (either up or down) for the first
row that contains an element set to 1
• Returns the row number of the first element in the given column that is set to 1
• 5HWXUQVíLIQRHOHPHQWLVVHWWR

© UCLES 2021 9618/23/O/N/21


PAGE 438

15

(a) Write pseudocode to implement the module SetRow().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

© UCLES 2021 9618/23/O/N/21 [Turn over


PAGE 439

16

(b) The module description of SearchInRow() is provided here for reference.

Module Description
• Takes two parameters of type INTEGER:
ƕa row number
ƕa start column (1 or 1280)
SearchInRow() • Searches the given row from the start column (either left to right or right to left)
for the first column that contains an element set to 1
• Returns the column number of the first element in the given row that is set to 1
• 5HWXUQVíLIQRHOHPHQWLVVHWWR

Write pseudocode to implement the module SearchInRow().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2021 9618/23/O/N/21
PAGE 440

17

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

(c) The following new module is introduced:

Module Description
• Called with a row number as an INTEGER
• Uses SearchInRow() to find the first and last columns in the given row which
GetCentreCol() have an array element set to 1
• Returns the index of the column midway between the first and last columns
• 5HWXUQVíLIQRHOHPHQWLVVHWWR

Write pseudocode to implement the module GetCentreCol().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...............................................................................................................................................[6]
© UCLES 2021 9618/23/O/N/21
PAGE 441

Cambridge International AS & A Level


* 6 6 4 6 7 4 9 2 2 0 *

COMPUTER SCIENCE 9618/22


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2022
2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (KN/SW) 303772/3
© UCLES 2022 [Turn over
PAGE 442

Refer to the insert for the list of pseudocode functions and operators.

1 (a) A programmer is testing a program using an Integrated Development Environment (IDE).


The programmer wants the program to stop when it reaches a specific instruction or program
statement in order to check the value assigned to a variable.

Give the technical term for the position at which the program stops.

............................................................................................................................................. [1]

(b) The following table lists some activities from the program development life cycle.

Complete the table by writing the life cycle stage for each activity.

Activity Life cycle stage


An identifier table is produced.

Syntax errors can occur.

The developer discusses the program requirements with the customer.

A trace table is produced.


[4]

(c) An identifier table includes the names of identifiers used.

State two other pieces of information that the identifier table should contain.

1 ................................................................................................................................................

2 ................................................................................................................................................
[2]

(d) The pseudocode statements in the following table may contain errors.

State the error in each case or write 'NO ERROR' if the statement contains no error.

You can assume that none of the variables referenced are of an incorrect type.

Statement Error

Status TRUE AND FALSE

IF LENGTH("Password") < "10" THEN

Code LCASE("Electrical")

Result IS_NUM(-27.3)

[4]

© UCLES 2022 9618/22/M/J/22


PAGE 443

2 An algorithm is described as follows:


1. Input an integer value.
2. Jump to step 6 if the value is less than zero.
3. Call the function IsPrime() using the integer value as a parameter.
4. Keep a count of the number of times function IsPrime() returns TRUE.
5. Repeat from step 1.
6. Output the value of the count with a suitable message.

Draw a program flowchart to represent the algorithm.

START

END

[4]

© UCLES 2022 9618/22/M/J/22 [Turn over


PAGE 444

3 (a) The module headers for five modules in a program are defined in pseudocode as follows:

Pseudocode module header


FUNCTION Mod_V(S2 : INTEGER) RETURNS BOOLEAN
PROCEDURE Mod_W(P4 : INTEGER)
PROCEDURE Mod_X(T4 : INTEGER, BYREF P3 : REAL)
PROCEDURE Mod_Y(W3 : REAL, Z8 : INTEGER)
FUNCTION Mod_Z(F3 : REAL) RETURNS INTEGER

An additional module Head() repeatedly calls three of the modules in sequence.

A structure chart has been partially completed.

(i) Complete the structure chart to include the information given about the six modules.

Do not label the parameters and do not write the module names.

B C D

E F

[3]

© UCLES 2022 9618/22/M/J/22


PAGE 445

(ii) Complete the table using the information in part 3(a) by writing each module name to
replace the labels A to F.

Label Module name

F
[3]

(b) The structure chart represents part of a complex problem. The process of decomposition is
used to break down the complex problem into sub-problems.

Describe three benefits of this approach.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................

3 ................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2022 9618/22/M/J/22 [Turn over


PAGE 446

4 (a) A procedure LastLines() will:


• take the name of a text file as a parameter
• output the last three lines from that file, in the same order as they appear in the file.

Note:
• Use local variables LineX, LineY and LineZ to store the three lines from the file.
• You may assume the file exists and contains at least three lines.

Write pseudocode for the procedure LastLines().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2022 9618/22/M/J/22


PAGE 447

(b) The algorithm in part (a) is to be amended. The calling program will pass the number of lines
to be output as well as the name of the text file.

The number of lines could be any value from 1 to 30.

It can be assumed that the file contains at least the number of lines passed.

Outline three changes that would be needed.

1 ................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

3 ................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2022 9618/22/M/J/22 [Turn over


PAGE 448

5 Study the following pseudocode. Line numbers are for reference only.

10 PROCEDURE Encode()
11 DECLARE CountA, CountB, ThisNum : INTEGER
12 DECLARE ThisChar : CHAR
13 DECLARE Flag : BOOLEAN
14 CountA 0
15 CountB 10
16 Flag TRUE
17 INPUT ThisNum
18 WHILE ThisNum <> 0
19 ThisChar LEFT(NUM_TO_STR(ThisNum), 1)
20 IF Flag = TRUE THEN
21 CASE OF ThisChar
22 '1' : CountA CountA + 1
23 '2' : IF CountB < 10 THEN
24 CountA CountA + 1
25 ENDIF
26 '3' : CountB CountB - 1
27 '4' : CountB CountB - 1
28 Flag FALSE
29 OTHERWISE : OUTPUT "Ignored"
30 ENDCASE
31 ELSE
32 IF CountA > 2 THEN
33 Flag NOT Flag
34 OUTPUT "Flip"
35 ELSE
36 CountA 4
37 ENDIF
38 ENDIF
39 INPUT ThisNum
40 ENDWHILE
41 OUTPUT CountA
42 ENDPROCEDURE

(a) Procedure Encode() contains a loop structure.

Identify the type of loop and state the condition that ends the loop.

Do not include pseudocode statements in your answer.

Type ..........................................................................................................................................

Condition ..................................................................................................................................

...................................................................................................................................................
[2]
© UCLES 2022 9618/22/M/J/22
PAGE 449

(b) Complete the trace table below by dry running the procedure Encode() when the following
values are input:

12, 24, 57, 43, 56, 22, 31, 32, 47, 99, 0

The first row is already complete.

ThisNum ThisChar CountA CountB Flag OUTPUT

0 10 TRUE

[6]

(c) Procedure Encode() is part of a modular program. Integration testing is to be carried out on
the program.

Describe integration testing.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2022 9618/22/M/J/22 [Turn over


PAGE 450

10

6 A string represents a series of whole numbers, separated by commas.

For example:
"12,13,451,22"

Assume that:
• the comma character ',' is used as a separator
• the string contains only the characters '0' to '9' and the comma character ','.

A procedure Parse will:


• take the string as a parameter
• extract each number in turn
• calculate the total value and average value of all the numbers
• output the total and average values with a suitable message.

Write pseudocode for the procedure.

PROCEDURE Parse(InString : STRING)

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

© UCLES 2022 9618/22/M/J/22


PAGE 451

11

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

ENDPROCEDURE [7]

© UCLES 2022 9618/22/M/J/22 [Turn over


PAGE 452

12

7 A programming language has string functions equivalent to those given in the insert.

The language includes a LEFT() and a RIGHT() function, but it does not have a MID() function.

(a) Write pseudocode for an algorithm to implement your own version of the MID() function
which will operate in the same way as that shown in the insert.

Do not use the MID() function given in the insert, but you may use any of the other functions.

Assume that the values passed to the function will be correct.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]

(b) The values passed to your MID() function in part (a) need to be validated.

Assume that the values are of the correct data type.

State two checks that could be applied to the values passed to the function.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2022 9618/22/M/J/22


PAGE 453

14

8 A program allows a user to save passwords used to log in to websites. A stored password is then
inserted automatically when the user logs in to the corresponding website.

A global 2D array Secret of type STRING stores the passwords together with the website domain
name where they are used. Secret contains 1000 elements organised as 500 rows by 2 columns.

Unused elements contain the empty string (""). These may occur anywhere in the array.

An example of a part of the array is:

Array element Value


Secret[27, 1] "thiswebsite.com"
Secret[27, 2] "yyyyyyyyyyyy"
Secret[28, 1] "thatwebsite.com"
Secret[28, 2] "yyyyyyyyyyyy"

Note:
• For security, the passwords are stored in an encrypted form, shown as "yyyyyyyyyyyy" in the
example.
• The passwords cannot be used without being decrypted.
• You may assume that the encrypted form of a password will NOT be an empty string.

The programmer has started to define program modules as follows:

Module Description
• Takes two parameters:
  ż DVWULQJ
  ż DFKDUDFWHU
Exists()
• Performs a case-sensitive search for the character in the string
• Returns TRUE if the character occurs in the string, otherwise
returns FALSE
• Takes a password as a parameter of type string
Encrypt()
• Returns the encrypted form of the password as a string
• Takes an encrypted password as a parameter of type string
Decrypt()
• Returns the decrypted form of the password as a string

Note: in a case-sensitive comparison, 'a' is not the same as 'A'.

© UCLES 2022 9618/22/M/J/22


PAGE 454

15

(a) Write pseudocode for the module Exists().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

© UCLES 2022 9618/22/M/J/22 [Turn over


PAGE 455

16

(b) A new module SearchDuplicates() will:


• search for the first password that occurs more than once in the array and output a
message each time a duplicate is found.
For example, if the same password was used for the three websites ThisWebsite.com,
website27.net and websiteZ99.org, then the following messages will be output:

"Password for ThisWebsite.com also used for website27.net"


"Password for ThisWebsite.com also used for websiteZ99.org"

• end once all messages have been output.

The module will output a message if no duplicates are found.


For example:
"No duplicate passwords found"

Write efficient pseudocode for the module SearchDuplicates(). Encrypt() and


Decrypt() functions have been written.

Note: It is necessary to decrypt each password before checking its value.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2022 9618/22/M/J/22


PAGE 456

17

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2022 9618/22/M/J/22 [Turn over


PAGE 457

18

(c) A password has a fixed format, consisting of three groups of four alphanumeric characters,
separated by the hyphen character '-'.

An example of a password is:


"FxAf-3haV-Tq49"

Each password must:


• be 14 characters long
• be organised as three groups of four alphanumeric characters. The groups are separated
by hyphen characters
• not include any duplicated characters, except for the hyphen characters.

An algorithm is needed for a new function GeneratePassword(), which will generate and
return a password in this format.

Assume that the following modules have already been written:

Module Description
• Takes two parameters:
  ż DVWULQJ
  ż DFKDUDFWHU
Exists() • Performs a case-sensitive search for the character in the
string
• Returns TRUE if the character occurs in the string, otherwise
returns FALSE
• Generates a single random character from within one of the
following ranges:
  ż D WR ]
RandomChar()
  ż $ WR =
  ż  WR 
• Returns the character

Note: in a case-sensitive comparison, 'a' is not the same as 'A'.

© UCLES 2022 9618/22/M/J/22


PAGE 458

19

Describe the algorithm for GeneratePassword().

Do not use pseudocode statements in your answer.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2022 9618/22/M/J/22


PAGE 459

Cambridge International AS & A Level


* 0 8 3 2 9 1 8 0 8 6 *

COMPUTER SCIENCE 9618/23


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2022
2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (PQ/CGW) 303773/3
© UCLES 2022 [Turn over
PAGE 460

Refer to the insert for the list of pseudocode functions and operators.

1 (a) The following table contains pseudocode examples.

Each example may include all or part of:


• selection
• iteration (repetition)
• assignment.

Complete the table by placing one or more ticks () in each row.

Pseudocode example Selection Iteration Assignment


FOR Index 1 TO 3
Safe[Index] GetResult()
NEXT Index
OTHERWISE : OUTPUT "ERROR 1202"

REPEAT UNTIL Index = 27

INPUT MyName
IF Mark > 74 THEN
Grade 'A'
ENDIF
[5]

(b) (i) Program variables have values as follows:

Variable Value

AAA TRUE

BBB FALSE

Count 99

Complete the table by evaluating each expression.

Expression Evaluation

AAA AND (Count > 99)

AAA AND (NOT BBB)

(Count <= 99) AND (AAA OR BBB)

(BBB AND Count > 50) OR NOT AAA


[2]

(ii) Give an example of when a variable of type Boolean would be used.

...........................................................................................................................................

..................................................................................................................................... [1]

© UCLES 2022 9618/23/M/J/22


PAGE 461

2 A program has been written to implement a website browser and maintenance is now required.

One type of maintenance is called perfective.

Name two other types of maintenance that the program may require and give a reason for each.

Type 1 ..............................................................................................................................................

Reason .............................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

Type 2 ..............................................................................................................................................

Reason .............................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................
[4]

© UCLES 2022 9618/23/M/J/22 [Turn over


PAGE 462

3 Four program modules are defined as follows:

Pseudocode module header

PROCEDURE Sub1_A(XT : INTEGER, PB : STRING)

FUNCTION Sub1_B(RA : INTEGER) RETURNS BOOLEAN

PROCEDURE Sub1_C(SB : INTEGER, BYREF SA : STRING)

PROCEDURE Section_1()

(a) A structure chart will be produced as part of the development process.

Describe the purpose of a structure chart.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

(b) Module Section_1() calls one of the other three modules. The module called will be
selected when the program runs.

Draw the structure chart.

[5]
© UCLES 2022 9618/23/M/J/22
PAGE 463

4 Items in a factory are weighed automatically. The weight is stored as an integer value representing
the item weight to the nearest gram (g).

A function is written to validate the weight of each item. The function will return "PASS" if the
weight of the item is within the acceptable range, otherwise the function will return "FAIL".

The acceptable weight range for an item is 150 g to 155 g inclusive.

The validation function is to be properly tested. Black-box testing will be used and a test plan
needs to be produced.

Complete the table by writing additional tests to test this function.

Type of Example Expected


Explanation
test data test value return value

Normal 153 "PASS" Value within the acceptable range

[4]

© UCLES 2022 9618/23/M/J/22 [Turn over


PAGE 464

5 A program will store attendance data about each employee of a company.

The data will be held in a record structure of type Employee. The fields that will be needed are as
shown:

Field Typical value Comment

EmployeeNumber 123 A numeric value starting from 1

Name "Smith,Eric" Format: <last name>','<first name>

Department "1B" May contain letters and numbers

Born 13/02/2006 Must not be before 04/02/1957

Attendance 97.40 Represents a percentage

(a) (i) Write pseudocode to declare the record structure for type Employee.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [4]

(ii) A 1D array Staff containing 500 elements will be used to store the employee records.

Write pseudocode to declare the Staff array.

...........................................................................................................................................

..................................................................................................................................... [2]

(b) There may be more records in the array than there are employees in the company. In this
case, some records of the array will be unused.

(i) State why it is good practice to have a standard way to indicate unused array elements.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) Give one way of indicating an unused record in the Staff array.

...........................................................................................................................................

..................................................................................................................................... [1]

© UCLES 2022 9618/23/M/J/22


PAGE 465

(c) A procedure Absentees() will output the EmployeeNumber and the Name of all employees
who have an Attendance value of 90.00 or less.

Write pseudocode for the procedure Absentees().

Assume that the Staff array is global.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]

© UCLES 2022 9618/23/M/J/22 [Turn over


PAGE 466

6 (a) The factorial of a number is the product of all the integers from 1 to that number.

For example:
factorial of 5 is given by 1 ) 2 ) 3 ) 4 ) 5 = 120
factorial of 7 is given by 1 ) 2 ) 3 ) 4 ) 5 ) 6 ) 7 = 5040
factorial of 1 = 1

Note: factorial of 0 = 1

A function Factorial() will:


• be called with an integer number as a parameter
• calculate and return the factorial of the number
• UHWXUQíLIWKHQXPEHULVQHJDWLYH

Write pseudocode for the function Factorial().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2022 9618/23/M/J/22


PAGE 467

(b) A procedure FirstTen() will output the factorial of the numbers from 0 to 9. The procedure
will use the function from part (a).

The required output is:

Factorial of 0 is 1
Factorial of 1 is 1
Factorial of 2 is 2

Factorial of 9 is 362880

The program flowchart represents an algorithm for FirstTen().

START

Set Num to 0

C
A
F
B
D

END

Complete the table by writing the text that should replace each label A to F.

Label Text

F
[4]
© UCLES 2022 9618/23/M/J/22 [Turn over
PAGE 468

10

7 The following pseudocode represents an algorithm intended to output the last three lines as they
appear in a text file. Line numbers are provided for reference only.

10 PROCEDURE LastLines(ThisFile : STRING)


11 DECLARE ThisLine : STRING
12 DECLARE Buffer : ARRAY[1:3] OF STRING
13 DECLARE LineNum : INTEGER
14 LineNum 1
15 OPENFILE ThisFile FOR READ
16
17 WHILE NOT EOF(ThisFile)
18 READFILE Thisfile, ThisLine // read a line
19 Buffer[LineNum] ThisLine
20 LineNum LineNum + 1
21 IF LineNum = 4 THEN
22 LineNum 1
23 ENDIF
24 ENDWHILE
25
26 CLOSEFILE ThisFile
27 FOR LineNum 1 TO 3
28 OUTPUT Buffer[LineNum]
29 NEXT LineNum
30 ENDPROCEDURE

(a) There is an error in the algorithm. In certain cases, a text file will have at least three lines but
the output will be incorrect.

(i) State how the output may be incorrect.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) Describe the error in the algorithm and explain how it may be corrected.

Description ........................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

Explanation .......................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[4]

© UCLES 2022 9618/23/M/J/22


PAGE 469

11

(b) The original algorithm is implemented and sometimes the last three lines of the text file are
output correctly.

State the condition that results in the correct output.

...................................................................................................................................................

............................................................................................................................................. [1]

(c) Lines 20 to 23 inclusive could be replaced with a single pseudocode statement.

Write the pseudocode statement.

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2022 9618/23/M/J/22 [Turn over


PAGE 470

12

8 The following diagram shows the incomplete waterfall model of the program development life
cycle.

(a) Complete the diagram.

Analysis

Maintenance

[3]

(b) Explain the meaning of the downward and upward arrows.

Downward arrows .....................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Upward arrows .........................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[2]

(c) Identify another type of model for the program development life cycle.

............................................................................................................................................. [1]

© UCLES 2022 9618/23/M/J/22


PAGE 471

14

9 A program allows a user to save passwords used to log in to websites. A stored password is then
inserted automatically when the user logs in to the corresponding website.

A student is developing a program to generate a strong password. The password will be of a fixed
format, consisting of three groups of four alphanumeric characters, separated by the hyphen
character '-'.

An example of a password is: "FxAf-3hzV-Aq49"

A valid password:
• must be 14 characters long
• must be organised as three groups of four alphanumeric characters. The groups are
separated by hyphen characters
• may include duplicated characters, provided these appear in different groups.

The programmer has started to define program modules as follows:

Module Description
• Generates a single random character from within one of the following
ranges:
 ż D WR ]
RandomChar()
 ż $ WR =
 ż  WR 
• Returns the character
• Takes two parameters:
 ż DVWULQJ
 ż DFKDUDFWHU
Exists()
• Performs a case-sensitive search for the character in the string
• Returns TRUE if the character occurs in the string, otherwise returns
FALSE
• Generates a valid password
Generate() • Uses RandomChar() and Exists()
• Returns the password

Note: in a case-sensitive comparison, 'a' is not the same as 'A'.

© UCLES 2022 9618/23/M/J/22


PAGE 472

15

(a) Write pseudocode for the module Generate().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2022 9618/23/M/J/22 [Turn over


PAGE 473

16

(b) A global 2D array Secret of type STRING stores the passwords together with the website
domain name where they are used. Secret contains 1000 elements organised as 500 rows
by 2 columns.

Unused elements contain the empty string (""). These may occur anywhere in the array.

An example of part of the array is:

Array element Value

Secret[27, 1] "www.thiswebsite.com"

Secret[27, 2] ƔƔƔƔƔƔƔƔƔƔƔƔ

Secret[28, 1] "www.thatwebsite.com"

Secret[28, 2] ƔƔƔƔƔƔƔƔƔƔƔƔ

Note:
• For security, the passwords are stored in an encrypted form, shown as ƔƔƔƔƔƔƔƔƔƔƔƔ
in the example.
• The passwords cannot be used without being decrypted.
• You may assume that the encrypted form of a password will not be an empty string.

Additional modules are defined as follows:

Module Description
• Takes a password as a string
Encrypt()
• Returns the encrypted form of the password as a string
• Takes an encrypted password as a string
Decrypt()
• Returns the decrypted form of the password as a string
• Takes a website domain name as a string
• Searches for the website domain name in the array Secret
FindPassword() • If the website domain name is found, the decrypted password is
returned
• If the website domain name is not found, an empty string is
returned
• Takes two parameters as strings: a website domain name and a
password
• Searches for the website domain name in the array Secret and
AddPassword() if not found, adds the website domain name and the encrypted
password to the array
• Returns TRUE if the website domain name and encrypted
password are added to the array, otherwise returns FALSE

The first three modules have been written.

© UCLES 2022 9618/23/M/J/22


PAGE 474

17

Write pseudocode for the module AddPassword().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2022 9618/23/M/J/22 [Turn over


PAGE 475

18

(c) The content of the array Secret is to be stored in a text file for backup.

It must be possible to read the data back from the file and extract the website domain name
and the encrypted password.

Both the website domain name and encrypted password are stored in the array as strings of
characters.

The encrypted password may contain any character from the character set used and the
length of both the encrypted password and the website domain name is variable.

Explain how a single line of the text file can be used to store the website domain name and
the encrypted password.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2022 9618/23/M/J/22


PAGE 476

Cambridge International AS & A Level


* 5 9 0 4 1 3 6 4 7 7 *

COMPUTER SCIENCE 9618/22


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2022

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (LK/JG) 302746/2
© UCLES 2022 [Turn over
PAGE 477

Refer to the insert for the list of pseudocode functions and operators.

1 (a) A programmer is developing an algorithm to solve a problem. Part of the algorithm would be
appropriate to implement as a subroutine (a procedure or a function).

(i) State two reasons why the programmer may decide to use a subroutine.

1 ........................................................................................................................................

...........................................................................................................................................

2 ........................................................................................................................................

...........................................................................................................................................
[2]

(ii) A procedure header is shown in pseudocode:

PROCEDURE MyProc(Count : INTEGER, Message : STRING)

Give the correct term for the identifiers Count and Message and explain their use.

Term ..................................................................................................................................

Use ....................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[2]

(b) The algorithm in part (a) is part of a program that will be sold to the public.
All the software errors that were identified during in-house testing have been corrected.

Identify and describe the additional test stage that may be carried out before the program is
sold to the public.

Test stage .................................................................................................................................

Description ................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[4]

© UCLES 2022 9618/22/O/N/22


PAGE 478

(c) Part of an identifier table is shown:

Variable Type Example value


FlagDay DATE 23/04/2004
CharList STRING "ABCDEF"
Count INTEGER 29

Complete the table by evaluating each expression using the example values.

Expression Evaluation
MID(CharList, MONTH(FlagDay), 1)
INT(Count / LENGTH(CharList))
(Count >= 29) AND (DAY(FlagDay) > 23)
[3]

2 (a) An algorithm will process data from a test taken by a group of students. The algorithm will
prompt and input the name and test mark for each of the 35 students.

The algorithm will add the names of all the students with a test mark of less than 20 to an
existing text file Support_List.txt, which already contains data from other group tests.

(i) Describe the steps that the algorithm should perform.

Do not include pseudocode statements in your answer.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [5]

© UCLES 2022 9618/22/O/N/22 [Turn over


PAGE 479

(ii) Explain why it may be better to store the names of the students in a file rather than in an
array.

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [1]

(iii) Explain why WRITE mode cannot be used in the answer to part 2(a)(i).

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [1]

(b) Examine the following state-transition diagram.

Input-A Output-X
Input-B Output-W

Input-B
START
S1 S2
S3

Input-A
Input-A

Input-B
S4 Input-A Output-W

Complete the table to show the inputs, outputs and next states.

Input Output Next state

S1

Input-A

S2

Output-W

Output-W

[4]

© UCLES 2022 9618/22/O/N/22


PAGE 480

3 A stack is used in a program to store string data which needs to be accessed in several modules.

(a) A stack is an example of an Abstract Data Type (ADT).

Identify one other example of an ADT and describe its main features.

Example ....................................................................................................................................

Features ...................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

(b) Explain how the stack can be implemented using an array.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

© UCLES 2022 9618/22/O/N/22 [Turn over


PAGE 481

(c) A second stack is used in the program. The diagram below shows the initial state of this
stack. Value X is at the top of the stack and was the last item added.

Upper-case letters are used to represent different data values.

Stack operations are performed in three groups as follows:

Group 1:
PUSH D
PUSH E

Group 2:
POP
POP
POP

Group 3:
PUSH A
PUSH B
POP
PUSH C

Complete the diagram to show the state of the stack after each group of operations has been
performed.

Include the current stack pointer (SP) after each group.

Memory Initial After After After


location state Group 1 Group 2 Group 3

957

956

955

954

953 X ĸSP
952 Y

951 Z

950 P

[5]

© UCLES 2022 9618/22/O/N/22


PAGE 482

4 The program flowchart represents a simple algorithm.

START

INPUT UserID

Set Average to
GetAverage(UserID)

Set Total to 0

Set Index to 4

Add 1 to Index

YES
Is Index < 7 ?

NO Set Last to
SameMonth[Index]

Is Average NO
> Last ? Add Last to Total

YES

Add Average to Total

Update(UserID, Total)

END

© UCLES 2022 9618/22/O/N/22


PAGE 483

(a) Write the equivalent pseudocode for the algorithm represented by the flowchart.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

(b) Give the name of the iterative construct in the flowchart.

............................................................................................................................................. [1]

© UCLES 2022 9618/22/O/N/22 [Turn over


PAGE 484

10

5 Examine the following pseudocode.

IF A = TRUE THEN
IF B = TRUE THEN
IF C = TRUE THEN
CALL Sub1()
ELSE
CALL Sub2()
ENDIF
ENDIF
ELSE
IF B = TRUE THEN
IF C = TRUE THEN
CALL Sub4()
ELSE
CALL Sub3()
ENDIF
ELSE
IF C = FALSE THEN
CALL Sub3()
ELSE
CALL Sub4()
ENDIF
ENDIF
ENDIF

A programmer wants to re-write the pseudocode as four separate IF...THEN...ENDIF


statements, each containing a single CALL statement. This involves writing a single, simplified
logic expression as the condition in each statement.

Write the amended pseudocode.

1 .......................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

2 .......................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

3 .......................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

4 .......................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................
[4]
© UCLES 2022 9618/22/O/N/22
PAGE 485

12

6 (a) The factorial of an integer number is the product of all the integers from that number down
to 1.

In general, the factorial of n is n ) Qí ) ... ) 2 ) 1

For example, the factorial of 5 is 5 ) 4 ) 3 ) 2 ) 1 = 120

In this question, n will be referred to as the BaseNumber.

A function FindBaseNumber() will:


• be called with a positive, non-zero integer value as a parameter
• return BaseNumber if the parameter value is the factorial of the BaseNumber
• UHWXUQíLIWKHSDUDPHWHUYDOXHis not a factorial.

For example:

Parameter value Value returned


120 5
12 í
6 3
1 1

FindBaseNumber(12)ZLOOUHWXUQíEHFDXVHLVQRWDIDFWRULDO

You may use the rest of this page for rough working.

© UCLES 2022 9618/22/O/N/22


PAGE 486

13

Write pseudocode for the function FindBaseNumber().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2022 9618/22/O/N/22 [Turn over


PAGE 487

14

(b) A program is written to allow a user to input a sequence of values to be checked using the
function FindBaseNumber().

The user will input one value at a time. The variable used to store the user input has to be of
type string because the user will input ‘End’ to end the program.

Valid input will be converted to an integer and passed to FindBaseNumber() and the return
value will be output.

Complete the table by giving four invalid strings that may be used to test distinct aspects of
the required validation. Give the reason for your choice in each case.

Input Reason for choice

......................................................................................................

......................................................................................................

......................................................................................................

......................................................................................................

......................................................................................................

......................................................................................................

......................................................................................................

......................................................................................................

......................................................................................................

......................................................................................................

......................................................................................................

......................................................................................................

[4]

© UCLES 2022 9618/22/O/N/22


PAGE 488

16

7 A teacher is designing a program to perform simple syntax checks on programs written by


students.

Two global 1D arrays are used to store the syntax error data. Both arrays contain 500 elements.
• Array ErrCode contains integer values that represent an error number in the range 1 to 800.
• Array ErrText contains string values that represent an error description.

The following diagram shows an example of the arrays.

Index ErrCode ErrText


1 10 "Invalid identifier name"
2 20 "Bracket mismatch"
3 50 "Undeclared variable"
4 60 "Type mismatch in assignment"

500 999 <Undefined>

Note:
• There may be less than 500 error numbers so corresponding elements in both arrays may be
unused. Unused elements in ErrCode have the value 999. The value of unused elements in
ErrText is undefined.
• Values in the ErrCode array are stored in ascending order but not all values may be present,
for example, there may be no error code 31.

The teacher has defined two program modules as follows:

Module Description

• takes two parameters as integers:


ż a line number in the student’s program
ż an error number
• searches for the error number in the ErrCode array:
OutputError() ż if found, outputs the corresponding error description and the
line number, for example:
"Bracket mismatch on line 34"
ż if not found, outputs the line number and a warning, for
example:
"Unknown error on line 34"

SortArrays() sorts the arrays into ascending order of ErrCode

© UCLES 2022 9618/22/O/N/22


PAGE 489

17

(a) Write efficient pseudocode for module OutputError().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2022 9618/22/O/N/22 [Turn over


PAGE 490

18

(b) Write an efficient bubble sort algorithm in pseudocode for module SortArrays().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2022 9618/22/O/N/22


PAGE 491

19

(c) Two 1D arrays were described at the beginning of the question. Both arrays contain 500
elements.
• Array ErrCode contains integer values that represent an error number in the range
1 to 800.
• Array ErrText contains string values that represent an error description.

The two arrays will be replaced by a single array. A user-defined data type (record structure)
has been declared as follows:
TYPE ErrorRec
DECLARE ErrCode : STRING
DECLARE ErrText : STRING
ENDTYPE

(i) State the error in the record declaration.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) State two benefits of using the single array of the user-defined data type.

1 ........................................................................................................................................

...........................................................................................................................................

2 ........................................................................................................................................

...........................................................................................................................................
[2]

(iii) Write the declaration for the single array in pseudocode.

..................................................................................................................................... [1]

© UCLES 2022 9618/22/O/N/22


PAGE 492

Cambridge International AS & A Level


* 5 3 3 4 5 1 5 3 2 7 *

COMPUTER SCIENCE 9618/23


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2022

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (NF/CB) 302729/4
© UCLES 2022 [Turn over
PAGE 493

Refer to the insert for the list of pseudocode functions and operators.

1 A program is required for a shopping website.

(a) Part of the program requires four variables. The following table describes the use of each
variable.

Complete the table by adding the most appropriate data type for each variable.

Variable use Data type

Store the number of days in the current month

Store the first letter of the customer’s first name

Store an indication of whether a year is a leap year

Store the average amount spent per customer visit

[4]

(b) The designer considers the use of a development life cycle to split the development of the
website into several stages.

(i) State one benefit of a development life cycle when developing the website.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) Analysis is one stage of a development life cycle.

State one document that may be produced from the analysis stage of the website project.

...........................................................................................................................................

..................................................................................................................................... [1]

© UCLES 2022 9618/23/O/N/22


PAGE 494

(c) The program will be developed using the Rapid Application Development (RAD) life cycle.

(i) State one principle of this life cycle.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) Give two benefits and one drawback of its use compared to the waterfall life cycle.

Benefit 1 ............................................................................................................................

...........................................................................................................................................

Benefit 2 ............................................................................................................................

...........................................................................................................................................

Drawback ..........................................................................................................................

...........................................................................................................................................
[3]

(d) Adaptive maintenance needs to be carried out on the website program.

Give two reasons why adaptive maintenance may be required.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2022 9618/23/O/N/22 [Turn over


PAGE 495

2 A program is being designed for a smartphone to allow users to send money to the charity of their
choice.

Decomposition will be used to break the problem down into sub-problems.

Identify three program modules that could be used in the design and describe their use.

Module 1 ..........................................................................................................................................

Use ...................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

Module 2 ..........................................................................................................................................

Use ...................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

Module 3 ..........................................................................................................................................

Use ...................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................
[3]

© UCLES 2022 9618/23/O/N/22


PAGE 496

3 An algorithm is needed to process a sequence of numbers. Numbers may be positive or negative


and may be integer or decimal.

The algorithm will:


• prompt and input one number at a time until the value zero is input
• sum the negative numbers
• sum the positive numbers
• when zero is input, output the two sum values and then end.

Describe the algorithm needed. Do not include pseudocode statements in your answer.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [5]

© UCLES 2022 9618/23/O/N/22 [Turn over


PAGE 497

4 (a) A program contains a 1D array DataItem with 100 elements.

State the one additional piece of information required before the array can be declared.

...................................................................................................................................................

............................................................................................................................................. [1]

(b) A programmer decides to implement a queue Abstract Data Type (ADT) in order to store
characters received from the keyboard. The queue will need to store at least 10 characters
and will be implemented using an array.

(i) Describe two operations that are typically required when implementing a queue.
State the check that must be carried out before each operation can be completed.

Operation 1 .......................................................................................................................

...........................................................................................................................................

Check 1 .............................................................................................................................

...........................................................................................................................................

Operation 2 .......................................................................................................................

...........................................................................................................................................

Check 2 .............................................................................................................................

...........................................................................................................................................
[4]

(ii) Describe the declaration and initialisation of the variables and data structures used to
implement the queue.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [5]
© UCLES 2022 9618/23/O/N/22
PAGE 498

5 (a) A text string contains three data items concatenated as shown:

<StockID><Description><Cost>

Item lengths are:

Item Length
StockID 5
Description 32
Cost the remainder of the string

A procedure Unpack() takes four parameters of type string. One parameter is the original
text string. The other three parameters are used to represent the three data items shown in
the table and are assigned values within the procedure. These values will be used by the
calling program after the procedure ends.

(i) Write pseudocode for the procedure Unpack().

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [6]

(ii) Explain the term procedure interface with reference to procedure Unpack().

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2022 9618/23/O/N/22 [Turn over


PAGE 499

(b) The design changes and a record structure is defined to store the three data items.

A user-defined data type StockItem is created as shown:

TYPE StockItem
DECLARE StockID : STRING
DECLARE Description : STRING
DECLARE Cost : REAL
ENDTYPE

(i) A variable LineData of type StockItem is declared.

Write the pseudocode statement to assign the value 12.99 to the Cost field of
LineData.

..................................................................................................................................... [1]

(ii) Procedure Unpack() is modified and converted to a function which takes the original
text string as the only parameter.

Explain the other changes that need to be made to convert the procedure into a function.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2022 9618/23/O/N/22


PAGE 500

(c) Unpack() is part of a program made up of several modules. During the design stage, it is
important to follow good programming practice. One example of good practice is the use of
meaningful identifier names.

Give the reason why this is good practice. Give two other examples of good practice.

Reason .....................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Example 1 .................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Example 2 .................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

(d) The program that includes Unpack() is tested using the walkthrough method.

Describe this method and explain how it can be used to identify an error.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2022 9618/23/O/N/22 [Turn over


PAGE 501

10

6 Components are weighed during manufacture. Weights are measured to the nearest whole gram.

Components that weigh at least 3 grams more than the maximum weight, or at least 3 grams less
than the minimum weight, are rejected.

A component is rechecked if it weighs within 2 grams of either the maximum or minimum weight.

The final outcome of weighing each component is shown below:

Outcome Weight

Reject

Max + 2
Recheck Max Maximum weight
Max – 2

Accept

Min + 2
Recheck Min Minimum weight
Min – 2

Reject

A function Status() will be called with three parameters. These are integers representing the
weight of an individual component together with the minimum and maximum weights.

The value returned from the function will be as follows:

Outcome Return value


Accept 'A'
Reject 'R'
Recheck 'C'

(a) Complete the following test plan for five tests that could be performed on function Status().
The tests should address all possible outcomes.

Test number Component weight Min Max Expected return value


1 'A'

5
[5]
© UCLES 2022 9618/23/O/N/22
PAGE 502

11

(b) Write pseudocode for Status().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2022 9618/23/O/N/22 [Turn over


PAGE 503

12

7 A teacher is designing a program to perform simple syntax checks on programs written by


students.

Two global 1D arrays are used to store the syntax error data. Both arrays contain 500 elements.

• Array ErrCode contains integer values that represent an error number in the range 1 to 800.
• Array ErrText contains string values that represent an error description.

The following diagram shows an example of the arrays.

Index ErrCode ErrText


1 10 "Invalid identifier name"
2 20 "Bracket mismatch"
3 50 ""
4 60 "Type mismatch in assignment"

...

500 999 <Undefined>

Note:
• There are less than 500 error codes so corresponding elements in both arrays may be
unused. Unused elements in ErrCode have the value 999. These will occur at the end of the
array. The value of unused elements in ErrText is undefined.
• Values in the ErrCode array are stored in ascending order but not all values may be present.
For example, there may be no error code 31.
• Some error numbers are undefined. In these instances, the ErrCode array will contain a
valid error number but the corresponding ErrText element will contain an empty string.

The teacher has defined one program module as follows:

Module Description
• Prompts for input of two error numbers
• Outputs a list of error numbers between the two numbers input
(inclusive) together with the corresponding error description
• Outputs a warning message when the error description is
missing as for error number 50 in the example
• Outputs a suitable header and a final count of error numbers
found
OutputRange()
Output based on the example array data above:

List of error numbers from 1 to 60

10 : Invalid identifier name


20 : Bracket mismatch
50 : Error Text Missing
60 : Type mismatch in assignment

4 error numbers output


© UCLES 2022 9618/23/O/N/22
PAGE 504

13

(a) Write pseudocode for module OutputRange(). Assume that the two numbers input
represent a valid error number range.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2022 9618/23/O/N/22 [Turn over
PAGE 505

14

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2022 9618/23/O/N/22


PAGE 506

16

(b) (i) Two additional modules are defined:

Module Description
SortArrays() • Sorts the arrays into ascending order of ErrCode
• Takes two parameters:
• an error number as an integer
• an error description as a string
• Writes the error number and error description to the first
AddError() unused element of the two arrays. Ensures the ErrCode
array is still in ascending order
• Returns the number of unused elements after the new error
number has been added
• 5HWXUQVíLIWKHQHZHUURUQXPEHUFRXOGQRWEHDGGHG

Write pseudocode for the module AddError(). Assume that the error code is not
already in the ErrCode array.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

© UCLES 2022 9618/23/O/N/22


PAGE 507

17

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [6]

(ii) A new Module RemoveError() will remove a given error number from the array.

Describe the algorithm that would be required. Do not include pseudocode statements in
your answer.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

© UCLES 2022 9618/23/O/N/22


PAGE 508

Cambridge International AS & A Level


* 3 0 3 3 2 5 1 8 2 6 *

COMPUTER SCIENCE 9618/22


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2023

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (EF/SG) 312086/3
© UCLES 2023 [Turn over
PAGE 509

Refer to the insert for the list of pseudocode functions and operators.

1 A program calculates the postal cost based on the weight of the item and its destination.
Calculations occur at various points in the program and these result in the choice of several
possible postal costs. The programmer has built these postal costs into the program.

For example, the postal cost of $3.75 is used in the following lines of pseudocode:

IF Weight < 250 AND ValidAddress = TRUE THEN


ItemPostalCost 3.75 // set postal cost for item to $3.75
ItemStatus "Valid" // item can be sent
ENDIF

(a) (i) Identify a more appropriate way of representing the postal costs.

..................................................................................................................................... [1]

(ii) Describe the advantages of your answer to part (a)(i) with reference to this program.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

(b) The lines of pseudocode contain features that make them easier to understand.

State three of these features.

1 ................................................................................................................................................

2 ................................................................................................................................................

3 ................................................................................................................................................
[3]

(c) Give the appropriate data types for the following variables:

ValidAddress ........................................................................................................................

ItemPostalCost ...................................................................................................................

ItemStatus ............................................................................................................................
[3]

© UCLES 2023 9618/22/M/J/23


PAGE 510

2 A program stores a user’s date of birth using a variable MyDOB of type DATE.

(a) Write a pseudocode statement, using a function from the insert, to assign the value
corresponding to 17/11/2007 to MyDOB.

............................................................................................................................................. [1]

(b) MyDOB has been assigned a valid value representing the user’s date of birth.

Write a pseudocode statement to calculate the number of months from the month of the
user’s birth until the end of the year and to assign this to the variable NumMonths.

For example, if MyDOB contains a value representing 02/07/2008, the value 5 would be
assigned to NumMonths.

............................................................................................................................................. [2]

(c) The program will output the day of the week corresponding to MyDOB.

For example, given the date 22/06/2023, the program will output "Thursday".

An algorithm is required. An array will be used to store the names of the days of the week.

Define the array and describe the algorithm in four steps.

Do not use pseudocode statements in your answer.

Array definition ..........................................................................................................................

...................................................................................................................................................

Step 1 .......................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Step 2 .......................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Step 3 .......................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Step 4 .......................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[6]
© UCLES 2023 9618/22/M/J/23 [Turn over
PAGE 511

3 A program stores data in a text file. When data is read from the file, it is placed in a queue.

(a) The diagram below represents an Abstract Data Type (ADT) implementation of the queue.
Each data item is stored in a separate location in the data structure. During initial design, the
queue is limited to holding a maximum of 10 data items.

The operation of this queue may be summarised as follows:


• The Front of Queue Pointer points to the next data item to be removed.
• The End of Queue Pointer points to the last data item added.
• The queue is circular so that locations can be reused.

0
1
2
3
4
5 Red Front of Queue Pointer
6 Green
7 Blue
8 Pink End of Queue Pointer
9

(i) Describe how the data items Orange and Yellow are added to the queue shown in the
diagram.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [4]

© UCLES 2023 9618/22/M/J/23


PAGE 512

(ii) The following diagram shows the state of the queue after several operations have been
performed. All queue locations have been used at least once.

0 D4
1 D3 End of Queue Pointer
2 D27
3 D8
4 D33
5 D17 Front of Queue Pointer
6 D2
7 D1
8 D45
9 D60

State the number of data items in the queue.

..................................................................................................................................... [1]

(b) The design of the queue is completed and the number of locations is increased.

A function AddToQueue() has been written. It takes a string as a parameter and adds this to
the queue. The function will return TRUE if the string was added successfully.

A procedure FileToQueue() will add each line from the file to the queue. This procedure
will end when all lines have been added or when the queue is full.

Describe the algorithm for procedure FileToQueue().

Do not use pseudocode in your answer.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

© UCLES 2023 9618/22/M/J/23 [Turn over


PAGE 513

4 A function GetNum() will:


1. take two parameters: a string and a character
2. count the number of times that the character occurs in the string
3. return the count.

Any comparison between characters needs to be case sensitive. For example, character 'a' and
character 'A' are not identical.

Write pseudocode for function GetNum().

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [6]

© UCLES 2023 9618/22/M/J/23


PAGE 514

5 A programmer has produced the following pseudocode to output the square root of the numbers
from 1 to 10.

Line numbers are for reference only.

10 DECLARE Num : REAL


11 Num 1.0
...

40 REPEAT
41 CALL DisplaySqrt(Num)
42 Num Num + 1.0
43 UNTIL Num > 10
...

50 PROCEDURE DisplaySqrt(BYREF ThisNum : REAL)


51 OUTPUT ThisNum
52 ThisNum SQRT(ThisNum) // SQRT returns the square root
53 OUTPUT " has a square root of ", ThisNum
54 ENDPROCEDURE

The pseudocode is correctly converted into program code.

Function SQRT() is a library function and contains no errors.

The program code compiles without errors, but the program gives unexpected results. These are
caused by a design error.

(a) Explain why the program gives unexpected results.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

(b) Explain why the compiler does not identify this error.

...................................................................................................................................................

............................................................................................................................................. [1]

© UCLES 2023 9618/22/M/J/23


PAGE 515

(c) Describe how a typical Integrated Development Environment (IDE) could be used to identify
this error.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

(d) The pseudocode is converted into program code as part of a larger program.

During compilation, a complex statement generates an error.

The programmer does not want to delete the complex statement but wants to change the
statement so that it is ignored by the compiler.

State how this may be achieved.

...................................................................................................................................................

............................................................................................................................................. [1]

© UCLES 2023 9618/22/M/J/23 [Turn over


PAGE 516

10

6 A procedure Square() will take an integer value in the range 1 to 9 as a parameter and output a
number square.

The boundary of a number square is made up of the character representing the parameter value.
The inside of the number square is made up of the asterisk character (*).

Parameter value 1 2 3 4 ... 9

1 22 333 4444 ... 99 9 9 99 9 9 9


22 3*3 4**4 9 * * * ** * * 9
333 4**4 9 ** * *** * 9
4444 9 *** **** 9
Output 9 * * * ** * * 9
9 * * * ** * * 9
9 ** * *** * 9
9 ******* 9
999999999

The pseudocode OUTPUT command starts each output on a new line. For example, the following
three OUTPUT statements would result in the outputs as shown:

OUTPUT "Hello"
OUTPUT "ginger"
OUTPUT "cat"

Resulting output:

Hello
ginger
cat

© UCLES 2023 9618/22/M/J/23


PAGE 517

11

Write pseudocode for procedure Square().

Parameter validation is not required.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

© UCLES 2023 9618/22/M/J/23 [Turn over


PAGE 518

12

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [6]

© UCLES 2023 9618/22/M/J/23


PAGE 519

14

7 A computer system for a shop stores information about each customer. The items of information
include name and address (both postal and email) together with payment details and order history.
The system also stores the product categories they are interested in and how they would like to be
contacted.

(a) The shop wants to add a program module that will generate emails to be sent to customers
who may be interested in receiving details of new products.

(i) State three items of information that the new module would need. Justify your choice in
each case.

Information ........................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................

Information ........................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................

Information ........................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................
[3]

(ii) Identify two items of customer information that would not be required by the new module.
Justify your choice in each case.

Information ........................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................

Information ........................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................
[2]

© UCLES 2023 9618/22/M/J/23


PAGE 520

15

(b) The program includes a module to validate a Personal Identification Number (PIN). This is
used when customers pay for goods using a bank card.

A state-transition diagram has been produced for this module.

The table show the inputs, outputs and states for this part of the program:

Current state Input Output Next state


S1 Input PIN S2
S2 Re-input PIN Display error S2
S2 Cancel Re-prompt S1
S2 Valid PIN Enable payment S4
S2 Too many tries Block Account S3

Complete the state-transition diagram to represent the information given in the table.

S2

START
S1

Cancel | Re-prompt

[4]
© UCLES 2023 9618/22/M/J/23 [Turn over
PAGE 521

16

8 A computer shop assembles computers using items bought from several suppliers. A text file
Stock.txt contains information about each item.

Information for each item is stored as a single line in the Stock.txt file in the format:
<ItemNum><SupplierCode><Description>

Valid item information is as follows:

Format Comment
unique number for each item in the range
ItemNum 4 numeric characters
ƎƎWRƎƎLQFOXVLYH

SupplierCode 3 alphabetic characters to identify the supplier of the item

Description a string a minimum of 12 characters

The file is organised in ascending order of ItemNum and does not contain all possible values in
the range.

A programmer has started to define program modules as follows:

Module Description
OnlyAlpha() • called with a parameter of type string
(already written)
• returns TRUE if the string contains only alphabetic characters,
otherwise returns FALSE
CheckInfo() • called with a parameter of type string representing a line of item
information
• checks to see whether the item information in the string is valid
• returns TRUE if the item information is valid, otherwise returns
FALSE

© UCLES 2023 9618/22/M/J/23


PAGE 522

17

(a) Write pseudocode for module CheckInfo().

Module OnlyAlpha() should be used as part of your solution.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2023 9618/22/M/J/23 [Turn over


PAGE 523

18

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

(b) A new module is defined as follows:

Module Description
AddItem() • called with a parameter of type string representing valid information
for a new item that is not currently in the Stock.txt file
• creates a new file NewStock.txt from the contents of the file
Stock.txt and adds the new item information at the appropriate
place in the NewStock.txt file

As a reminder, the file Stock.txt is organised in ascending order of ItemNum and does not
contain all possible values in the range.

Write pseudocode for module AddItem().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2023 9618/22/M/J/23
PAGE 524

19

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

(c) The program contains modules SuppExists() and CheckSupplier(). These have been
written but contain errors. These modules are called from several places in the main program
and testing of the main program (integration testing) has had to stop.

Identify a method that can be used to continue testing the main program before the errors in
these modules have been corrected and describe how this would work.

Method ......................................................................................................................................

Description ................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2023 9618/22/M/J/23


PAGE 525

Cambridge International AS & A Level


* 3 1 4 1 1 6 4 8 5 5 *

COMPUTER SCIENCE 9618/23


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2023

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (PQ/CB) 312089/3
© UCLES 2023 [Turn over
PAGE 526

Refer to the insert for the list of pseudocode functions and operators.

1 The following pseudocode represents part of the algorithm for a program.

Line numbers are for reference only.

10 DECLARE Sheet4 : ARRAY[1:2, 1:50] OF INTEGER

100 FOR PCount 0 TO 49


101 Sheet4[1, PCount] 0
102 Sheet4[2, PCount] 47
103 NEXT PCount

(a) The pseudocode contains references to an array.

Complete the table by writing the answer for each row.

Answer
The dimension of the array
The name of the variable used as an array index
The number of elements in the array
[3]

(b) The pseudocode contains two errors. One error is that variable PCount has not been
declared.

Identify the other error and state the line number where it occurs.

Error ..........................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Line number ..............................................................................................................................


[2]

(c) The pseudocode does not include a declaration for PCount.

State the data type that should be used in the declaration.

............................................................................................................................................. [1]

© UCLES 2023 9618/23/M/J/23


PAGE 527

(d) The pseudocode statements given in the following table are used in other parts of the
algorithm.

Complete the table by placing one or more ticks () in each row.

The first row has already been completed.

Pseudocode statement Input Process Output

INPUT MyChoice 
OUTPUT FirstName & LastName

WRITEFILE YourFile, TextLine

READFILE MyFile, TextLine

Result SQRT(NextNum)
[4]

© UCLES 2023 9618/23/M/J/23 [Turn over


PAGE 528

2 A program stores a date of birth for a student using a variable, MyDOB, of type DATE.

(a) MyDOB has been assigned a valid value corresponding to Kevin’s date of birth.

Complete the pseudocode statement to test whether Kevin was born on a Thursday.

IF ........................................................................................................................ THEN [2]

(b) A function CheckDate()will take three integer parameters representing a day, month and
year of a given date.

The function will validate the date of birth for a student that the parameters passed to it
represent.
For a date to be valid, a student must be at least 18 in year 2020.

(i) Two of the parameter values can be checked without reference to the third parameter.

Describe these two checks.

Check 1 .............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

Check 2 .............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[2]

(ii) Several values of the parameter representing the day can only be checked completely
by referring to the value of one other parameter.

Describe this check.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2023 9618/23/M/J/23


PAGE 529

3 A program processes data using a stack. The data is copied to a text file before the program ends.

(a) The following diagram shows the current state of the stack.

The operation of this stack may be summarised as follows:

• The TopOfStack pointer points to the last item added to the stack.
• The BottomOfStack pointer points to the first item on the stack.
• The stack grows upwards when items are added.

Stack Pointer

Memory location Value

506

505 WWW TopOfStack

504 YYY

503 XXX

502 ZZZ

501 NNN

500 PPP BottomOfStack

(i) An error will be generated if an attempt is made to POP a value when the stack is empty.

State the maximum number of consecutive POP operations that could be performed on
the stack shown above before an error is generated.

..................................................................................................................................... [1]

(ii) The following operations are performed:

1. POP and store value in variable Data1


2. POP and store value in variable Data2
3. PUSH value AAA
4. PUSH value BBB
5. POP and discard value
6. POP and store value in variable Data2

© UCLES 2023 9618/23/M/J/23


PAGE 530

Complete the diagram to show the state of the stack and the variables after the given
operations have been performed.

Stack Pointer

Memory location Value

506

505

504

503

502 Variable Value

501 Data1

500 Data2
[4]
(b) 7KHGDWDLVFRSLHGWRDWH[W¿OHEHIRUHWKHSURJUDPHQGV

(i) State an advantage of writing the data from the stack to a text file before the program
ends.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) A module SaveStack() will write the data from the stack to a text file.

Express an algorithm for SaveStack() as five steps that could be used to produce
pseudocode.

Write the five steps.

Step 1 ................................................................................................................................

...........................................................................................................................................

Step 2 ................................................................................................................................

...........................................................................................................................................

Step 3 ................................................................................................................................

...........................................................................................................................................

Step 4 ................................................................................................................................

...........................................................................................................................................

Step 5 ................................................................................................................................

...........................................................................................................................................
[5]
© UCLES 2023 9618/23/M/J/23 [Turn over
PAGE 531

4 A function MakeString() will:

1. take two parameters:


• a count as an integer
• a character
2. generate a string of length equal to the count, made up of the character
3. return the string generated, or return "ERROR" if the count is less than 1.

For example, the function call:

MakeString(3, 'Z') will return the string "ZZZ"

Write pseudocode for function MakeString().

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [6]

© UCLES 2023 9618/23/M/J/23


PAGE 532

5 A program is designed, coded and compiled without errors. The compiled code is sent for testing.

(a) The program will be tested using the walkthrough method.

Additional information will be needed before this method can be used.

Identify this additional information and explain why it is needed.

Additional information ...............................................................................................................

...................................................................................................................................................

Explanation ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

(b) Testing is completed and the program is made available to users.

Some time later, changes are made to the program to improve the speed of response.

State the type of maintenance that has been applied to the program.

............................................................................................................................................. [1]

© UCLES 2023 9618/23/M/J/23 [Turn over


PAGE 533

10

6 A procedure Select() will:

1. take two integer values as parameters representing start and end values where both values
are greater than 9 and the end value is greater than the start value
2. output each integer value between the start and the end value (not including the start and
end values), where the sum of the last two digits is 6, for example, 142.

(a) Write pseudocode for procedure Select().

Parameter validation is not required.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]
© UCLES 2023 9618/23/M/J/23
PAGE 534

11

(b) The check performed by procedure Select() on the last two digits is needed at several
places in the program and will be implemented using a new function.

The new function CheckNum() will:

• allow the required sum to be specified (not just 6)


• check one number
• return an appropriate value.

Describe the function interface and two advantages of this modular approach.

Interface ....................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Advantage 1 .............................................................................................................................

...................................................................................................................................................

Advantage 2 .............................................................................................................................

...................................................................................................................................................
[4]

© UCLES 2023 9618/23/M/J/23 [Turn over


PAGE 535

12

7 A school has a library system which allows students to borrow books for a length of time.
Information relating to students and books is stored in text files. Student information includes
name, home address, email address, date of birth, tutor and subject choices. Book information
includes author, title, subject category, library location and the date that the book was borrowed.

A program helps the staff to manage the borrowing of books.

(a) A new module needs to be written to generate emails to send to students who have an
overdue book. Students who are sent an email are prevented from borrowing any more books
until the overdue book is returned.

The process of abstraction has been used when designing the new module.

(i) State the purpose of applying abstraction to this problem.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) Identify one item of information that is required and one item that is not required in the
new module. Justify your choices.

Item required .....................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

Item not required ...............................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[2]

(iii) Identify two operations that would be required to process data when an overdue book is
returned.

Operation 1 .......................................................................................................................

...........................................................................................................................................

Operation 2 .......................................................................................................................

...........................................................................................................................................
[2]

© UCLES 2023 9618/23/M/J/23


PAGE 536

13

(b) Part of the library program contains program modules with headers as follows:

Pseudocode module header


PROCEDURE Module-X()
PROCEDURE Module-Y(BYREF RA : INTEGER, SA : REAL)
PROCEDURE Overlay()
FUNCTION Replace(RA : INTEGER, RB : BOOLEAN) RETURNS BOOLEAN
FUNCTION Reset(TA : STRING) RETURNS INTEGER

Module-X() and Module-Y() are both called from module Overlay().

Complete the structure chart.

[3]

© UCLES 2023 9618/23/M/J/23 [Turn over


PAGE 537

14

8 A computer shop assembles desktop computers, using items bought from several suppliers. A text
file Stock.txt contains information about each item.

Information for each item is stored as a single line in the Stock.txt file in the format:

<ItemNum><SupplierCode><Description>

Item information is as follows:

Format Comment
unique number for each item in the range “0001”
ItemNum 4 numeric characters
to “5999” inclusive
SupplierCode 3 alphabetic characters code to identify the supplier of the item

Description a string a minimum of 12 characters

The file is organised in ascending order of ItemNum and does not contain all possible values in
the range.

The programmer has defined the first program module as follows:

Module Description
ChangeSupp() • called with two parameters Code1 and Code2 of type string that represent
valid supplier codes
• creates a new file NewStock.txt from the contents of the
file Stock.txt where any reference to Code1 is replaced by Code2
• returns a count of the number of items that have had their supplier code
changed

© UCLES 2023 9618/23/M/J/23


PAGE 538

15

(a) Write pseudocode for module ChangeSupp().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2023 9618/23/M/J/23 [Turn over


PAGE 539

16

(b) A new module is required:

Module Description
Report_1() • takes a parameter of type string that represents a SupplierCode
• searches the Stock.txt file for each line of item information that
contains the given SupplierCode
• produces a formatted report of items for the given SupplierCode,
for example, for supplier DRG, the output could be:

Report for Supplier: DRG

Item Description

1234 USB Printer Cable 3 m


1273 32GB USB Flash Drive
1350 Mouse Mat 320 x 240 mm

Number of items listed: 3

Write pseudocode for module Report_1().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2023 9618/23/M/J/23


PAGE 540

17

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2023 9618/23/M/J/23 [Turn over


PAGE 541

18

(c) The format of the output from module Report_1() from part (b) is changed. The number of
items listed is moved to the top of the report as shown in the example:

Report for Supplier: DRG


Number of items listed: 3

Item Description

1234 USB Printer Cable 3 m


1273 32GB USB Flash Drive
1350 Mouse Mat 320 x 240 mm

(i) Explain why this new layout would increase the complexity of the algorithm.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(ii) The algorithm will be modified to produce the report in the new format. The modified
algorithm will be implemented so that the file Stock.txt is only read once.

Describe the modified algorithm.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

© UCLES 2023 9618/23/M/J/23


PAGE 542

Cambridge International AS & A Level


* 4 0 2 6 5 6 3 1 4 8 *

COMPUTER SCIENCE 9618/22


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2023
2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (LK/SG) 315868/1
© UCLES 2023 [Turn over
PAGE 543

Refer to the insert for the list of pseudocode functions and operators.

1 A shop sells car accessories. A customer order is created if an item cannot be supplied from
current stock. A program is being developed to create and manage the customer orders.

(a) The following identifier table shows some of the data that will be stored for each order.

Complete the identifier table by adding meaningful variable names and appropriate data
types.

Example
Explanation Variable name Data type
value

"Mr Khan" The name of the customer

3 The number of items in the order

TRUE To indicate whether this is a new customer

15.75 The deposit paid by the customer

[4]

(b) Other variables in the program have example values as shown:

Variable Example value


Total 124.00
DepRate 2.00
Description "AB12345:Cleaning Brush (small)"

Complete the table by evaluating each expression using the example values.

Expression Evaluates to

(Total * DepRate) + 1.5

RIGHT(Description, 7)

(LENGTH(Description) - 8) > 16

NUM_TO_STR(INT(DepRate * 10)) & '%'


[4]

© UCLES 2023 9618/22/O/N/23


PAGE 544

(c) The data that needs to be stored for each customer order in part (a) is not all of the same
type.

Describe an effective way of storing this data for many customer orders while the program is
running.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2023 9618/22/O/N/23 [Turn over


PAGE 545

2 An algorithm will:

1. input a sequence of integer values, one at a time


2. ignore all values until the value 27 is input, then sum the remaining values in the sequence
3. stop summing values when the value 0 is input and then output the sum of the values.

(a) Draw a program flowchart to represent the algorithm.

START

END

[5]

© UCLES 2023 9618/22/O/N/23


PAGE 546

(b) The solution to the algorithm includes iteration.

Give the name of a suitable loop structure that could be used.

Justify your answer.

Name ........................................................................................................................................

Justification ...............................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2023 9618/22/O/N/23 [Turn over


PAGE 547

3 The diagram represents a linked list Abstract Data Type (ADT).

• Ptr1 is the start pointer. Ptr2 is the free list pointer.


• Labels D40, D32, D11 and D100 represent the data items of nodes in the list.
• Labels F1, F2, F3 and F4 represent the data items of nodes in the free list.
• The symbol Ø represents a null pointer.

Ptr1
D40 D32 D11 D100 Ø

Ptr2
F1 F2 F3 F4 Ø

(a) The linked list is implemented using two variables and two 1D arrays as shown.

The pointer variables and the elements of the Pointer array store the indices (index numbers)
of elements in the Data array.

Complete the diagram to show how the linked list as shown above may be represented using
the variables and arrays.

Variable Value
Start_Pointer

Free_List_Pointer 5

Index Data array Pointer array


1 D32 2

2 3

4 D40

6 F2 7

8
[5]

© UCLES 2023 9618/22/O/N/23


PAGE 548

(b) The original linked list is to be modified. A new node D6 is inserted between nodes D32 and
D11.

Ptr1
D40 D32 D11 D100 Ø

Ptr2
F1 F2 F3 F4 Ø

The algorithm required is expressed in four steps as shown.

Complete the steps.

1. Assign the data item .................................. to .................................. .

2. Set the .................................. of this node to point to .................................. .

3. Set Ptr2 to point to .................................. .

4. Set pointer of .................................. to point to .................................. .


[4]

© UCLES 2023 9618/22/O/N/23 [Turn over


PAGE 549

4 A procedure Count() will:

1. input a value (all values will be positive integers)


2. count the number of odd values and count the number of even values
3. repeat from step 1 until the value input is 99
4. output the two count values, with a suitable message.

The value 99 must not be counted.

(a) Write pseudocode for the procedure Count().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2023 9618/22/O/N/23


PAGE 550

(b) The procedure Count() is to be tested.

Typical test data would consist of odd and even values, for example:

23, 5, 64, 100, 2002, 1, 8, 900, 99

The purpose of this test would be to test a typical mix of even and odd values and check the
totals.

Give three test data sequences that may be used to test different aspects of the procedure.

Do not include invalid data.

Sequence 1:

Test data ...................................................................................................................................

Purpose of test. ........................................................................................................................

...................................................................................................................................................

Sequence 2:

Test data ...................................................................................................................................

Purpose of test. ........................................................................................................................

...................................................................................................................................................

Sequence 3:

Test data ...................................................................................................................................

Purpose of test. ........................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2023 9618/22/O/N/23 [Turn over


PAGE 551

10

5 A global 1D array of integers contains four elements, which are assigned values as shown:

Mix[1] ĸ1
Mix[2] ĸ3
Mix[3] ĸ4
Mix[4] ĸ2
A procedure Process() manipulates the values in the array.

The procedure is written in pseudocode:

PROCEDURE Process(Start : INTEGER)


DECLARE Value, Index, Count : INTEGER

Index ĸ Start
Count ĸ0
REPEAT
Value ĸMix[Index]
Mix[Index]ĸ Mix[Index] - 1
Index ĸValue
Count ĸCount + 1
UNTIL Count = 5

Mix[4] ĸ Count * Index


ENDPROCEDURE

Complete the trace table on the opposite page by dry running the procedure when it is called as
follows:

CALL Process(3)

© UCLES 2023 9618/22/O/N/23


PAGE 552

11

Index Value Count Mix[1] Mix[2] Mix[3] Mix[4]

[6]

© UCLES 2023 9618/22/O/N/23 [Turn over


PAGE 553

12

6 (a) A procedure CreateFiles() will take two parameters:

• a string representing a file name


• an integer representing the number of files to be created.

The procedure will create the number of text files specified.

Each file is given a different name. Each file name is formed by concatenating the file name
with a suffix based on the file number. The suffix is always three characters.

For example, the call CreateFiles("TestData", 3) would result in the creation of the
three files, TestData.001, TestData.002 and TestData.003.

Each file will contain a single line. For example, file TestData.002 would contain the string:

This is File TestData.002

Write pseudocode for CreateFiles().

Assume both parameters are valid and that the integer value is between 1 and 999, inclusive.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]
© UCLES 2023 9618/22/O/N/23
PAGE 554

13

(b) A module CheckFiles() will count the number of files produced by CreateFiles() in
part (a).

CheckFiles() will take a string representing a file name and return the number of files
found.

(i) Identify the type of module that should be used for CheckFiles().

..................................................................................................................................... [1]

(ii) Write the module header for CheckFiles().

...........................................................................................................................................

..................................................................................................................................... [1]

(iii) State the file mode that should be used in CheckFiles().

..................................................................................................................................... [1]

© UCLES 2023 9618/22/O/N/23 [Turn over


PAGE 555

14

7 A program contains six modules:

Pseudocode module header


PROCEDURE Module-A()
PROCEDURE Module-X(T1 : INTEGER, S2 : REAL)
PROCEDURE Reset(BYREF Code : INTEGER)
FUNCTION Restore(OldCode : INTEGER) RETURNS BOOLEAN
FUNCTION Module-Y(RA : INTEGER, RB : BOOLEAN) RETURNS BOOLEAN
FUNCTION Module-Z(SA : INTEGER) RETURNS INTEGER

Module-X() calls Reset()


Module-Y() calls Restore()

(a) Complete the structure chart for these modules.

Module-A()

[4]

(b) Explain the meaning of the diamond symbol as used in the diagram in part (a).

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2023 9618/22/O/N/23


PAGE 556

16

8 A class of students are developing a program to send data between computers. Many computers
are connected together to form a wired network. Serial ports are used to connect one computer to
another.

Each computer:

• is assigned a unique three-digit ID


• has three ports, each identified by an integer value
• is connected to between one and three other computers.

Data is sent as individual message strings.


Each string contains the destination ID (the ID of the computer that is to receive the message)
followed by the data:

<DestinationID><Data>

Messages may pass through several computers on the way to their destination.
When a message arrives at a computer, that is not the destination, the program needs to forward
it on to another computer using one of its serial ports.

The port to use is obtained from information that is stored in an array RouteTable.

RouteTable is a global 2D array of integers. It is declared in pseudocode as follows:

DECLARE RouteTable : ARRAY[1:6,1:3] OF INTEGER

The values in the first two columns of RouteTable define a range of ID values.
Column 3 gives the corresponding port number to use when forwarding the message to a computer
with an ID within this range.

For example, the contents of RouteTable could be:

Column 1 Column 2 Column 3


Row 1 100 199 1
Row 2 200 259 2
Row 3 í <undefined> <undefined>
Row 4 260 399 2
Row 5 400 599 3
Row 6 600 999 1

In this example, a message that arrives with a DestinationID of "283" will be forwarded using
port 2.

Row 3 in the example shows an unused row. These may occur anywhere. Unused rows have the
FROXPQHOHPHQWVHWWRí7KHYDOXHRIXQXVHGHOHPHQWVLQWKHRWKHUWZRFROXPQVLVXQGHILQHG

© UCLES 2023 9618/22/O/N/23


PAGE 557

17

The programmer has defined the first program module as follows:

Module Description
• takes a DestinationID as a parameter of type string
• searches for the range corresponding to the DestinationID
GetPort() in the array
• UHWXUQVWKHSRUWQXPEHURUUHWXUQVíLIQRFRUUHVSRQGLQJ
range is found

(a) Write pseudocode for module GetPort().

Assume DestinationID contains a valid three-digit string.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]
© UCLES 2023 9618/22/O/N/23 [Turn over
PAGE 558

18

(b) Copies of the same program will run on each computer. The program contains a global
variable MyID of type string, which contains the unique ID of the computer in which the
program is running.

When messages are received, they are placed on one of two stacks. Stack 1 is used for
messages that have reached their destination and stack 2 is used for messages that will be
forwarded on to another computer.

Additional modules are defined:

Module Description
• takes two parameters:
ż a string representing a message
StackMsg() ż an integer representing the stack number
(already written) • adds the message to the required stack
• returns TRUE if the message is added to the required stack,
otherwise returns FALSE
• takes a message as a parameter of type string
• ignores any message with a zero-length data field
• extract the DestinationID from the message
• checks whether the DestinationID is this computer or
ProcessMsg() whether the message is to be forwarded
• uses StackMsg() to add the message to the appropriate
stack
• outputs an error if the message could not be added to the
stack

© UCLES 2023 9618/22/O/N/23


PAGE 559

19

Write pseudocode for module ProcessMsg().

Module StackMsg() must be used.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2023 9618/22/O/N/23 [Turn over


PAGE 560

20

(c) The program contains a module GetFile() which receives text files sent from another
computer.

Lines from the file are sent one at a time. Each message contains one line and ProcessMsg()
from part (b) adds each message as it is received onto stack 1.

Module GetFile() removes messages from stack 1 and writes the data to a text file.

There is a problem. Under certain circumstances, the received file does not appear as
expected.

Assume that while a file is being received ProcessMsg() receives only messages containing
lines from the file.

(i) Describe the circumstances and explain the problem.

Circumstances ..................................................................................................................

...........................................................................................................................................

Explanation .......................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[3]

(ii) Suggest a more appropriate Abstract Data Type that could be used to store the messages
that would not have the same problem.

..................................................................................................................................... [1]

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
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.

Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge
Local Examinations Syndicate (UCLES), which is a department of the University of Cambridge.

© UCLES 2023 9618/22/O/N/23


PAGE 561

Cambridge International AS & A Level


* 1 7 9 0 6 9 5 1 7 2 *

COMPUTER SCIENCE 9618/23


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2023
2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages.

DC (LK/CT) 315870/2
© UCLES 2023 [Turn over
PAGE 562

Refer to the insert for the list of pseudocode functions and operators.

1 A program is being developed in pseudocode before being converted into a programming


language.

(a) The following table shows four valid pseudocode assignment statements.

Complete the table by giving the data type that should be used to declare the variable
underlined in each assignment statement.

Assignment statement Data type

MyVar1 ĸ Total1 / Total2


MyVar2 ĸ 27/10/2023

MyVar3 ĸ "Sum1 / Sum2"

MyVar4 ĸ Result1 AND Result2


[4]

(b) Other variables in the program have example values as shown:

Variable Value
Active TRUE
Fraction 0.2
Code "Ab12345"

Complete the table by evaluating each expression using the example values.

Expression Evaluates to

Fraction >= 0.2 AND NOT Active

INT((Fraction * 100) + 13.3)

STR_TO_NUM(MID(Code, 4, 2)) + 5

LENGTH("TRUE" & Code)


[4]

© UCLES 2023 9618/23/O/N/23


PAGE 563

(c) The program makes use of complex statistical functions. The required functions are not
built-in to the programming language and are too complicated for the programmer to write.

One solution would be to employ another programmer who has experience of writing these
functions, as there is no time to train the existing programmer.

State one other way that these functions may be provided for inclusion in the program.

...................................................................................................................................................

............................................................................................................................................. [1]

(d) The hardware that runs the program is changed and the program needs to be modified so
that it works with the new hardware.

Identify the type of maintenance that this represents and give one other reason why this type
of maintenance may be needed.

Type ..........................................................................................................................................

Reason .....................................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2023 9618/23/O/N/23 [Turn over


PAGE 564

2 Data is a 1D array of integers, containing 30 elements. All element values are unique.

(a) An algorithm will output the index of the element with the smallest value.

Draw a program flowchart to represent the algorithm.

START

END

[5]

© UCLES 2023 9618/23/O/N/23


PAGE 565

(b) The 30 data values could have been stored in separate variables rather than in an array.

Explain the benefits of using an array when designing a solution to part (a).

...................................................................................................................................................

............................................................................................................................................. [2]

(c) The requirement changes. Array Data needs to hold 120 elements and each value may
include a decimal place.

Write a pseudocode statement to declare the modified array.

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2023 9618/23/O/N/23 [Turn over


PAGE 566

3 The diagram represents a queue Abstract Data Type (ADT).

The organisation of this queue may be summarised as follows:

• The FrontOfQueue pointer points to the next data item to be removed.


• The EndOfQueue pointer points to the last data item added.

Queue

D3 ĸ FrontOfQueue
D4

D1

D2

D5 ĸ EndOfQueue

The queue is implemented using three variables and a 1D array of eight elements as shown. The
variable NumItems stores the number of items in the queue.

The pointer variables store indices (index numbers) of the array.

(a) Complete the diagram to represent the state of the queue as shown above.

Index Array

4 Variable

5 FrontOfQueue

6 EndOfQueue

7 NumItems 5

8
[3]

© UCLES 2023 9618/23/O/N/23


PAGE 567

(b) A module AddTo() will add a value to the queue by manipulating the array and variables in
part (a).

The queue implementation is circular. When pointers reach the end of the queue, they will
‘wrap around’ to the beginning.

Before a value can be added to the queue, it is necessary to check the queue is not full.

The algorithm to add a value to the queue is expressed in six steps.

Complete the steps.

1. If NumItems .............................. then jump to step 6.

2. Increment ................................... .

3. If ................................................. then set EndOfQueue to .............................. .

4. Increment ................................... .

5. Set the ............................ at the index stored in ........................... to the ............................


being added.

6. Stop.

[6]

© UCLES 2023 9618/23/O/N/23 [Turn over


PAGE 568

4 A procedure RandList() will output a sequence of 25 random integers, where each integer is
larger than the previous one.

(a) Write pseudocode for procedure RandList().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2023 9618/23/O/N/23


PAGE 569

(b) Procedure RandList() is modified so that the random numbers are also written into a
1D array Result.

A new module is written to confirm that the numbers in the array are in ascending order.

This module contains an IF statement that performs a comparison between elements:

IF (Result[x + 1] = Result[x]) OR (Result[x] > Result[x + 1]) THEN


Sequence FALSE ĸ
ENDIF

Write a simplified version of the conditional clause.

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [1]

© UCLES 2023 9618/23/O/N/23 [Turn over


PAGE 570

10

5 A global 1D array of integers contains four elements, which are assigned values as shown:

Mix[1] ĸ4
Mix[2] ĸ2
Mix[3] ĸ3
Mix[4] ĸ5
A procedure Process() manipulates the values in the array.

The procedure is written in pseudocode as follows:

PROCEDURE Process(Start : INTEGER)


DECLARE Value, Index, Total : INTEGER

Index ĸ Start
Total ĸ0
WHILE Total < 20
Value ĸMix[Index]
Total ĸTotal + Value

IF Index < 4 THEN


Mix[Index] ĸ
Mix[Index] + Mix[Index+1]
ELSE
Mix[Index] ĸ
Mix[Index] + Mix[1]
ENDIF
Index ĸ
(Value MOD 4) + 1

ENDWHILE

Mix[1] ĸ Total * Index


ENDPROCEDURE

Complete the trace table on the opposite page by dry running the procedure when it is called as
follows:

CALL Process(2)

© UCLES 2023 9618/23/O/N/23


PAGE 571

11

Index Value Total Mix[1] Mix[2] Mix[3] Mix[4]

[6]

© UCLES 2023 9618/23/O/N/23 [Turn over


PAGE 572

12

6 A function TestNum() will take a six-digit string as a parameter.

The function will test whether the string meets certain conditions and will return an integer value
as follows:

Return value Condition Example


1 The last three digits are the same but non-zero. "253444"
2 The last three digits are zero. "253000"
3 The first three and last three digits are the same. "410410"

The function will return the highest possible value for the given string.

If the string does not meet any of the conditions, zero is returned.

© UCLES 2023 9618/23/O/N/23


PAGE 573

13

Write pseudocode for function TestNum().

Assume that the parameter is valid.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [6]

© UCLES 2023 9618/23/O/N/23 [Turn over


PAGE 574

14

7 A structure chart shows the modular structure of a program:

Module-A()

T1 RA
SA

RB

Sub-Y1() Sub-Y2() Sub-9()

(a) Explain the meaning of the curved arrow symbol which begins and ends at Module-A().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2023 9618/23/O/N/23


PAGE 575

15

(b) The structure chart shows that Sub-9() is a function.

A Boolean value is returned by Sub-9() for processing by Module-A().

The original parameter RA is of type integer and RB is of type string.

A record type MyType will be defined with three fields to store the values passed between the
two modules.

(i) Write pseudocode to define MyType.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

(ii) The design is modified and Sub-9() is changed to a procedure.

The procedure will be called with a single parameter of type MyType.

Write the pseudocode header for procedure Sub-9().

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2023 9618/23/O/N/23 [Turn over


PAGE 576

16

8 A class of students are developing a program to send data between computers. Many computers
are connected together to form a wired network. Serial ports are used to connect one computer to
another.

Each computer:
• is assigned a unique three-digit ID
• has three ports, each identified by an integer value
• is connected to between one and three other computers.

Messages are sent between computers as a string of characters organised into fields as shown:

<STX><DestinationID><SourceID><Data><ETX>

Field name Description

a single character marking the start of the message


STX
(ASCII value 02)

DestinationID three numeric characters identifying the destination computer

SourceID three numeric characters identifying the source computer

a variable length string containing the data being sent


Data
(Minimum length is 1 character)
a single character marking the end of the message
ETX
(ASCII value 03)

For example, the following message contains the data "Hello Jack" being sent from computer
"202" to computer "454":

<STX>"454202Hello Jack"<ETX>

Each computer will run a copy of the same program. Each program will contain a global variable
MyID of type string which contains the unique ID of the computer in which the program is running.

The first two program modules are defined as follows:

Module Description

GetData()
• returns the data field from a message that has been received
(already written)
• If no message is available, the module waits until one has been
received.
• takes a file name as a parameter of type string
• creates a text file with the given file name (no checking required)
ReceiveFile()
• writes the data field returned by GetData() to the file
• repeats until the data field is "****", which is not written to the file
• outputs a final message giving the total number of characters
written to the file, for example:
132456 characters were written to newfile.txt

© UCLES 2023 9618/23/O/N/23


PAGE 577

17

(a) Write pseudocode for module ReceiveFile().

Module GetData() has already been written and must be used.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2023 9618/23/O/N/23 [Turn over


PAGE 578

18

(b) The use of the string "****" as explained in the module description for ReceiveFile() may
cause a problem.

Explain the problem and suggest a solution.

Problem ....................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Solution .....................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

(c) Two new modules are defined, which will allow two users to exchange messages.

Module Description

• takes two parameters:


Transmit() ż a string representing a message
(already written) ż an integer representing a port number
• transmits the message using the given port
• takes two parameters:
ż a string representing a Destination ID
ż an integer representing a port number
Chat()
• extracts data from a received message using GetData() and
outputs it
• forms a message using data input by the user and sends it
using Transmit()
• repeats until either the output string or the sent string is "Bye"

Reminders:

• Each program contains a global variable MyID of type string which contains the unique ID of
the computer in which the program is running.
• Messages are sent between computers as a string of characters organised into fields as
shown:

<STX><DestinationID><SourceID><Data><ETX>

© UCLES 2023 9618/23/O/N/23


PAGE 579

19

Write pseudocode for module Chat().

Modules GetData() and Transmit() must be used.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [7]

© UCLES 2023 9618/23/O/N/23 [Turn over


PAGE 580

20

(d) Module GetData() returns the data field from a message that has been received. If no
message is available, the module waits until one has been received.

Explain the limitation of this on module Chat() from part (c).

Describe a modification to GetData() to address this limitation.

Limitation ..................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Modification ..............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

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
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.

Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge
Local Examinations Syndicate (UCLES), which is a department of the University of Cambridge.

© UCLES 2023 9618/23/O/N/23


PAGE 581

Cambridge International AS & A Level


* 2 3 2 3 4 6 9 7 5 8 *

COMPUTER SCIENCE 9618/22


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2024
2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 24 pages. Any blank pages are indicated.

DC (PQ/CGW) 329350/3
© UCLES 2024 [Turn over
PAGE 582

Refer to the insert for the list of pseudocode functions and operators.

1 (a) The following table contains pseudocode examples.

Each example may contain statements that relate to one or more of the following:
• selection
• iteration (repetition)
• input/output.

Complete the table by placing one or more ticks () in each row.

Pseudocode example Selection Iteration Input/Output


FOR Index 1 TO 10
Data[Index] 0
NEXT Index
WRITEFILE ThisFile, "****"

UNTIL Level > 25


IF Mark > 74 THEN
READFILE OldFile, Data
ENDIF
[4]

(b) Program variables have data types as follows:

Variable Data type

MyChar CHAR

MyString STRING

MyInt INTEGER

Complete the table by filling in each gap with a function (from the insert) so that each expression
is valid.

Expression

MyInt .......................................... (3.1415926)

MyChar .......................................... ("Elwood", 3, 1)

MyString .......................................... ( .......................................... (27.509))

MyInt .......................................... ( .......................................... ("ABC123", 3))


[4]

© UCLES 2024 9618/22/M/J/24


PAGE 583

(c) The variables given in part (b) are chosen during the design stage of the program development
life cycle.

The choices are to be documented to simplify program maintenance.

State a suitable way of documenting the variables and give one piece of information that
should be recorded, in addition to the data type.

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2024 9618/22/M/J/24 [Turn over


PAGE 584

2 A program is being developed.

(a) An algorithm for part of the program will:


• input three numeric values and assign them to identifiers Num1, Num2 and Num3
• assign the largest value to variable Ans
• output a message giving the largest value and the average of the three numeric values.

Assume the values are all different and are input in no particular order.

Complete the program flowchart on page 5 to represent the algorithm.

© UCLES 2024 9618/22/M/J/24


PAGE 585

START

INPUT Numl, Num2, Num3

No

Yes

END

[5]

© UCLES 2024 9618/22/M/J/24 [Turn over


PAGE 586

(b) A different part of the program contains an algorithm represented by the following program
flowchart:

START

Set Flag to GetStat()

Is Flag = Yes
TRUE ?

No END

Set Port to 1

No
Is Port = 4 ?

CALL Reset(Port)
Yes

Set Port to Port + 1

Write pseudocode for the algorithm.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]
© UCLES 2024 9618/22/M/J/24
PAGE 587

3 A factory needs a program to help manage its production of items.

Data will be stored about each item.

The data for each item will be held in a record structure of type Component.

The programmer has started to define the fields that will be needed as shown in the table.

Field Example value Comment


Item_Num 123478 a numeric value used as an array index
Reject FALSE TRUE if this item has been rejected
Stage 'B' a letter to indicate the stage of production
Limit_1 13.5 any value in the range 0 to 100 inclusive
Limit_2 26.4 any value in the range 0 to 100 inclusive

(a) (i) Write pseudocode to declare the record structure for type Component.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [4]

(ii) A 1D array Item of 2000 elements will store the data for all items.

Write pseudocode to declare the Item array.

...........................................................................................................................................

..................................................................................................................................... [2]

(b) State three benefits of using an array of records to store the data for all items.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................

3 ................................................................................................................................................

...................................................................................................................................................
[3]
© UCLES 2024 9618/22/M/J/24 [Turn over
PAGE 588

4 A triangle has sides of length A, B and C.

B C

In this example, A is the length of the longest side.

This triangle is said to be right-angled if the following equation is true:

A ) A = (B ) B) + (C ) C)

A procedure will be written to check whether three lengths represent a right-angled triangle.
The lengths will be input in any sequence.

The procedure IsRA() will:


• prompt and input three integer values representing the three lengths
• test whether the three lengths correspond to the sides of a right-angled triangle
• output a suitable message.

The length of the longest side may not be the first value input.

© UCLES 2024 9618/22/M/J/24


PAGE 589

Write pseudocode for the procedure IsRA().

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [5]

© UCLES 2024 9618/22/M/J/24 [Turn over


PAGE 590

10

5 A program is being designed in pseudocode.

The program contains a global 1D array Data of type string containing 200 elements.

The first element has the index value 1.

A procedure Process() is written to initialise the values in the array:

PROCEDURE Process(Label : STRING)


DECLARE Index : INTEGER
Index 0
INPUT Data[Index]
WHILE Index < 200
Index Index + 1
CASE OF (Index MOD 2)
0 : Data[Index] TO_UPPER(Label)
1 : Data[Index] TO_LOWER(Label)
OTHERWISE : OUTPUT "Alarm 1201"
ENDCASE
NEXT Index
OUTPUT "Completed " & Index & " times"
ENDPROCEDURE

(a) (i) The pseudocode contains two syntax errors and one other error.

Identify the errors.

Syntax error 1 ....................................................................................................................

...........................................................................................................................................

Syntax error 2 ....................................................................................................................

...........................................................................................................................................

Other error .........................................................................................................................

...........................................................................................................................................
[3]

(ii) The procedure contains a statement that is not needed.

Identify the pseudocode statement and explain why it is not needed.

Statement ..........................................................................................................................

Explanation .......................................................................................................................

...........................................................................................................................................
[2]

© UCLES 2024 9618/22/M/J/24


PAGE 591

11

(b) After correcting all syntax errors, the pseudocode is translated into program code which
compiles without generating any errors.

When the program is executed it unexpectedly stops responding.

Identify the type of error that has occurred.

............................................................................................................................................. [1]

© UCLES 2024 9618/22/M/J/24 [Turn over


PAGE 592

12

6 A music player stores music in a digital form and has a display which shows the track being
played.

(a) Up to 16 characters can be displayed. Track titles longer than 16 characters will need to be
trimmed as follows:
• Words must be removed from the end of the track title until the resulting title is less than
14 characters.
• When a word is removed, the space in front of that word is also removed.
• Three dots are added to the end of the last word displayed when one or more words
have been removed.

The table below shows some examples:

Original title Display string

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Bat out of Hull B a t o u t o f H u l l

Bohemian Symphony B o h e m i a n . . .

Paperbook Writer P a p e r b o o k W r i t e r

Chris Sings the Blues C h r i s S i n g s . . .

Green Home Alabama G r e e n H o m e . . .

A function Trim() will:


• take a string representing the original title
• return the string to be displayed.

Assume:
• Words in the original title are separated by a single space character.
• There are no spaces before the first word or after the last word of the original title.
• The first word of the original title is less than 14 characters.

© UCLES 2024 9618/22/M/J/24


PAGE 593

13

Write pseudocode for the function Trim().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2024 9618/22/M/J/24 [Turn over


PAGE 594

14

(b) Music is stored as a sequence of digital samples.

Each digital sample is a denary value in the range 0 to 99999999 (8 digits).

The samples are to be stored in a text file. Each sample is converted to a numeric string and
32 samples are concatenated (joined) to form a single line of the text file.

Each numeric string is 8 characters in length; leading ‘0’ characters are added as required.

Example:

Sample Denary value String


1 456 "00000456"
2 48 "00000048"
3 37652 "00037652"

32 673 "00000673"

The example samples will be stored in the text file as a single line:

"000004560000004800037652...00000673"

(i) Identify one drawback of adding leading ‘0’ characters to each numeric string.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) Suggest an alternative method of storing the samples which does not involve adding
leading ‘0’ characters but which would still allow each individual sample to be extracted.

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [1]

(iii) State one drawback of the alternative method given in part (b)(ii).

...........................................................................................................................................

..................................................................................................................................... [1]

© UCLES 2024 9618/22/M/J/24


PAGE 595

16

7 A fitness club has a computerised membership system.

The system stores information for each club member: name, home address, email address, mobile
phone number, date of birth and exercise preferences.

Many classes are full, and the club creates a waiting list for each class. The club adds details of
members who want to join a class that is full to the waiting list for that class.

When the system identifies that a space is available in one of the classes, a new module will send
a text message to each member who is on the waiting list.

(a) Decomposition will be used to break the new module into sub-modules (sub-problems).

Identify three sub-modules that could be used in the design and describe their use.

Sub-module 1 ...........................................................................................................................

Use ...........................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Sub-module 2 ...........................................................................................................................

Use ...........................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Sub-module 3 ...........................................................................................................................

Use ...........................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2024 9618/22/M/J/24


PAGE 596

17

(b) A different part of the program is represented by the following state-transition diagram.

Input-B | Output-W
Input-B
Input-B
START
S1 S3 S2 S5

Input-A
Input-A Input-A | Output-W

Input-B | Output-Y
Input-A | Output-X
S4

(i) Complete the table to show the inputs, outputs and next states.

Assume that the current state for each row is given by the ‘Next state’ on the previous
row. For example, the first Input-A is made when in state S1.

If there is no output for a given transition, then the output cell should contain ‘none’.

The first two rows have been completed.

Input Output Next state

S1

Input-A none S3

Output-W

none

Input-B

Input-A

S4
[5]

(ii) Identify the input sequence that will cause the minimum number of state changes in the
transition from S1 to S4.

..................................................................................................................................... [1]

© UCLES 2024 9618/22/M/J/24 [Turn over


PAGE 597

18

8 A teacher is designing a program to process pseudocode projects written by her students.

Each student project is stored in a text file.

The process is split into a number of stages. Each stage performs a different task and creates a
new file.

For example:

File name Comment

MichaelAday_src.txt Student project file produced by student Michael Aday

MichaelAday_S1.txt File produced by stage 1

MichaelAday_S2.txt File produced by stage 2

(a) Suggest a reason why the teacher’s program has been split into a number of stages and give
the benefit of producing a different file from each stage.

Reason .....................................................................................................................................

...................................................................................................................................................

Benefit ......................................................................................................................................

...................................................................................................................................................
[2]

(b) The teacher has defined the first program module as follows:

Module Description
DeleteSpaces() • called with a parameter of type string representing a line of
pseudocode from a student’s project file
• returns the line after removing any leading space characters

The following example shows a string before and after the leading
spaces have been removed:

Before: " IF X2 > 13 THEN"


After: "IF X2 > 13 THEN"

© UCLES 2024 9618/22/M/J/24


PAGE 598

19

Complete the pseudocode for module DeleteSpaces().

FUNCTION DeleteSpaces(Line : STRING) RETURNS STRING

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

ENDFUNCTION [6]

© UCLES 2024 9618/22/M/J/24 [Turn over


PAGE 599

20

(c) Two modules are defined:

Module Description
DeleteComment() • called with a parameter of type string representing a line of
(already written) pseudocode from a student’s project file
• returns the line after removing any comment
Stage_2() • called with two parameters:
ż a string representing an input file name
ż a string representing an output file name
• copies each line from the input file to the existing output file having
first removed all leading spaces and comments from that line
• does not write blank lines to the output file
• outputs a final message giving the number of blank lines removed

© UCLES 2024 9618/22/M/J/24


PAGE 600

21

Write pseudocode for module Stage_2().

Modules DeleteComment() and DeleteSpaces() must be used in your solution.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2024 9618/22/M/J/24


PAGE 601

Cambridge International AS & A Level


* 6 8 0 6 8 0 7 8 2 2 *

COMPUTER SCIENCE 9618/23


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2024
2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
 Answer all questions.
 Use a black or dark blue pen.
 Write your name, centre number and candidate number in the boxes at the top of the page.
 Write your answer to each question in the space provided.
 Do not use an erasable pen or correction fluid.
 Do not write on any bar codes.
 You may use an HB pencil for any diagrams, graphs or rough working.
 Calculators must not be used in this paper.

INFORMATION
 The total mark for this paper is 75.
 The number of marks for each question or part question is shown in brackets [ ].
 No marks will be awarded for using brand names of software packages or hardware.
 The insert contains all the resources referred to in the questions.

This document has 24 pages. Any blank pages are indicated.

DC (KS/CGW) 329352/4
 UCLES 2024 [Turn over
PAGE 602

Refer to the insert for the list of pseudocode functions and operators.

1 A program uses many complex algorithms.

One algorithm is repeated in several places. The code for the algorithm is the same wherever it is
used, but the calculations within the algorithm may operate on different data.

The result of each calculation is used by the code that follows it.

It is decided to modify the program and implement the algorithm as a separate module.

(a) (i) State two benefits of this modification to the existing program.

1 ........................................................................................................................................

...........................................................................................................................................

2 ........................................................................................................................................

...........................................................................................................................................
[2]

(ii) Describe how the modification would be implemented.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

 UCLES 2024 9618/23/M/J/24


PAGE 603

(b) Four of the expressions used in the program are represented by pseudocode in the table.

Complete each pseudocode expression with a function or operator so that it evaluates to the
value shown.

Any functions and operators used must be defined in the insert.

Pseudocode expression Evaluates to

"and"
........................................ ("Random", 2, 3)

15
5 + ........................................ (10/11/2023)

TRUE
........................................ ("45000")

(20 ........................................ 3) + 1 3

[4]

 UCLES 2024 9618/23/M/J/24 [Turn over


PAGE 604

2 (a) A program uses a global 1D array of type string and a text file.

An algorithm that forms part of the program is expressed as follows:


• copy the first line from the file into the first element of the array
• copy the second line from the file into the second element of the array
• continue until all lines in the file have been copied into the array.

Stepwise refinement is applied to the algorithm.

Outline five steps for this algorithm that could be used to produce pseudocode.

Assume there are more elements in the array than lines in the file.

Do not use pseudocode statements in your answer.

Step 1 .......................................................................................................................................

...................................................................................................................................................

Step 2 .......................................................................................................................................

...................................................................................................................................................

Step 3 .......................................................................................................................................

...................................................................................................................................................

Step 4 .......................................................................................................................................

...................................................................................................................................................

Step 5 .......................................................................................................................................

...................................................................................................................................................
[5]

(b) Sequence is one programming construct.

Identify one other programming construct that will be required when the algorithm from
part (a) is converted into pseudocode and explain its use.

Construct ..................................................................................................................................

...................................................................................................................................................

Use ...........................................................................................................................................

...................................................................................................................................................
[2]

 UCLES 2024 9618/23/M/J/24


PAGE 605

3 A record structure is declared to hold data relating to components being produced in a factory:

TYPE Component
DECLARE Item_ID : STRING
DECLARE Reject : BOOLEAN
DECLARE Weight : REAL
ENDTYPE

The factory normally produces a batch (or set) of 1000 components at a time. A global array is
declared to store 1000 records for a batch:

DECLARE Batch : ARRAY [1:1000] OF Component

Two global variables contain the minimum and maximum acceptable weight for each component.
The values represent an inclusive range and are declared as:

DECLARE Min, Max : REAL

(a) (i) A program uses a variable ThisIndex as the array index to access a record.

Write a pseudocode clause to check whether or not the weight of an individual component
is within the acceptable range.

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

(ii) When batches of less than 1000 components are processed, it is necessary to indicate
that certain elements in the array are unused.

Suggest how an unused array element could be indicated.

...........................................................................................................................................

..................................................................................................................................... [1]

(b) A module InRange() will:


• be called with an integer parameter representing an index value of a record in the Batch
array
• check if the weight of the indexed component is within the acceptable range
• return TRUE if the weight is in the range and FALSE if it is not.

A module BatchCheck() will:


• iterate through a batch of 1000 component records
• call module InRange() to check each individual component record
• keep a count of the number of components that fail
• output a suitable warning message and immediately stop if the number of failed
components exceeds 5.

 UCLES 2024 9618/23/M/J/24


PAGE 606

Complete the program flowchart to represent the algorithm for module BatchCheck().

START

Is
Index = 1001 ?

Yes

No

END

[5]

 UCLES 2024 9618/23/M/J/24 [Turn over


PAGE 607

4 A procedure TwoParts() will input a sequence of real values, one at a time.

The procedure will:


• process the sequence in two parts
• form a first total by adding the values until the first zero
• form a second total by adding the values after the first zero until the second zero
• output the average of the two totals, together with a suitable message.

Values input in the first part are totalled using global variable TotalA and those input in the
second part are totalled using global variable TotalB.

(a) Write pseudocode for the procedure TwoParts().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

 UCLES 2024 9618/23/M/J/24


PAGE 608

(b) The value zero denotes the split between the two parts of the sequence.

The requirement changes and now there may be up to 20 parts.

(i) Identify a suitable data structure that could be used to store the different total values.

..................................................................................................................................... [2]

(ii) Describe three benefits of using the data structure given in part (b)(i).

1 ........................................................................................................................................

...........................................................................................................................................

2 ........................................................................................................................................

...........................................................................................................................................

3 ........................................................................................................................................

...........................................................................................................................................
[3]

 UCLES 2024 9618/23/M/J/24 [Turn over


PAGE 609

10

5 A program is being designed in pseudocode.

The program contains the following declaration:

DECLARE Data : ARRAY[1:1000] OF STRING

A procedure ArrayInitialise() is written to initialise the values in the array:

PROCEDURE ArrayInitialise(Label : STRING)


DECLARE Index : INTEGER
Index 1
WHILE Index <= 1000
CASE OF (Index MOD 2)
0 : Data[Index] FormatA(Label)
Index Index + 1
1 : Data[Index] FormatB(Label)
Index Index + 1
ENDCASE
ENDWHILE
ENDPROCEDURE

Functions FormatA() and FormatB() apply fixed format case changes to the parameter string.

(a) The design of the procedure does not use the most appropriate loop construct.

Suggest a more appropriate construct that could be used and explain your choice.

Construct ..................................................................................................................................

Explanation ...............................................................................................................................

...................................................................................................................................................
[2]

(b) The algorithm calls one of the functions FormatA() and FormatB() each time within the
loop.

Explain why this is not efficient and suggest a more efficient solution.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]

 UCLES 2024 9618/23/M/J/24


PAGE 610

12

6 A program displays a progress bar to inform the user of the progress of tasks that take a significant
time to complete, such as those involving file transfer operations.

Task progress is divided into 11 steps. Each step represents the amount of progress as a
percentage. An image is associated with each step and each image is stored in a different file.

Different progress bar images may be selected. For a given image, files all have the same filename
root, with a different suffix.

The table illustrates the process for using the image with filename root BargraphA

Percentage
Step Image filename Image
progress
1 < 10 BargraphA-1.bmp
2 >= 10 and < 20 BargraphA-2.bmp
3 >= 20 and < 30 BargraphA-3.bmp

9 >= 80 and < 90 BargraphA-9.bmp


10 >= 90 and < 100 BargraphA-10.bmp
11 100 BargraphA-11.bmp

A procedure Progress() will:


• be called with two parameters:
 an integer representing the percentage progress (0 to 100 inclusive)
 a string representing the image filename root
• generate the full image filename
• call a procedure Display() using the full image filename as the parameter.

 UCLES 2024 9618/23/M/J/24


PAGE 611

13

(a) Write pseudocode for procedure Progress().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

 UCLES 2024 9618/23/M/J/24 [Turn over


PAGE 612

14

(b) The definition of procedure Progress() is provided here for reference:

A procedure Progress() will:


• be called with two parameters:
 an integer representing the percentage progress (0 to 100 inclusive)
 a string representing the image filename root
• generate the full image filename
• call a procedure Display() using the full image filename as the parameter.

Progress() will be rewritten and a new module Progress2() produced with these
requirements:
• an additional parameter of type integer will specify the total number of steps
• the image filename will be returned (procedure Display() will not be called from within
Progress2()).

(i) Write pseudocode for the new module header.

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(ii) State one benefit of increasing the number of steps.

...........................................................................................................................................

..................................................................................................................................... [1]

 UCLES 2024 9618/23/M/J/24


PAGE 613

16

7 Seven program modules form part of a program. A description of the relationship between the
modules is summarised below. Any return values are stated in the description.

Module name Description

Mod-A calls Mod-B followed by Mod-C

• called with parameters Par1 and Par2


Mod-B • calls either Mod-D or Mod-E, determined when the program runs
• returns a Boolean value
• called with parameters Par1 and Par3
Mod-C • Par3 is passed by reference
• repeatedly calls Mod-F followed by Mod-G

Mod-D called with parameter Par2

• called with parameter Par3


Mod-E
• returns an integer value

Mod-F called with parameter Par3

• called with parameter Par3


Mod-G
• Par3 is passed by reference

Parameters in the table are as follows:


• Par1 and Par3 are of type string.
• Par2 is of type integer.

(a) (i) Identify the modules that would be implemented as functions.

..................................................................................................................................... [1]

(ii) Modules Mod-F and Mod-G are both called with Par3 as a parameter.
In the case of Mod-F, the parameter is passed by value.
In the case of Mod-G, the parameter is passed by reference.

Explain the effect of the two different ways of passing the parameter Par3.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

 UCLES 2024 9618/23/M/J/24


PAGE 614

17

(b) Draw a structure chart to show the relationship between the seven modules and the
parameters passed between them.

[6]
 UCLES 2024 9618/23/M/J/24 [Turn over
PAGE 615

18

8 A teacher is designing a program to process pseudocode projects written by her students.

The program analyses a student project and extracts information about each module that is
defined (each procedure or function). This information is stored in a global 2D array ModInfo of
type string.

A module header is the first line of a module definition and starts with either of the keywords
PROCEDURE or FUNCTION.

An example of part of the array is given below. Row 10 of the array shows that a procedure header
occurs on line 27 and row 11 shows that a function header occurs on line 35. "P" represents a
procedure and "F" represents a function:

x = 1 x = 2 x = 3

ModInfo[10, x] "27" "P" "MyProc(Z : CHAR)"

ModInfo[11, x] "35" "F" "MyFun(Y : CHAR) RETURNS BOOLEAN"

The string stored in column 3 is called the module description. This is the module header without
the keyword.

A valid module header will:


• be at least 13 characters long
• start with the keyword PROCEDURE or FUNCTION. The keyword may appear in either upper or
lower case (or a mix of both) and must be followed by a space character.

The teacher has defined the first program module as follows:

Module Description
Header() • called with a parameter of type string representing a line of
pseudocode
• if the line is a valid procedure header, returns a string:
"P<Module description>"
• if the line is a valid function header, returns a string:
"F<Module description>"
• otherwise, returns an empty string

For example, given the string:

"FUNCTION Zap(X : INTEGER) RETURNS CHAR"

Header()returns the string:

"FZap(X : INTEGER) RETURNS CHAR"

 UCLES 2024 9618/23/M/J/24


PAGE 616

19

(a) Write pseudocode for module Header().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

 UCLES 2024 9618/23/M/J/24 [Turn over


PAGE 617

20

(b) A new module is required:

Module Description
FindModules() • called with a parameter of type string representing a student
project file name
• uses module Header() to check each line of the project
• assigns values to the ModInfo array for each module
declaration in the student project

As a reminder, the previous example of part of the array is repeated below:

x = 1 x = 2 x = 3
ModInfo[10, x] "27" "P" "MyProc(Z : CHAR)"
ModInfo[11, x] "35" "F" "MyFun(Y : CHAR) RETURNS BOOLEAN"

Write pseudocode for module FindModules().

Assume that the array contains enough rows for the number of modules in each project.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

 UCLES 2024 9618/23/M/J/24


PAGE 618

21

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

 UCLES 2024 9618/23/M/J/24


PAGE 619

"#$%&'(!)*!#*&#+,-.,/! !+
] ^ _ _ ` a b c _ d b ]

"012345-")46"4 789:;
< =>  < ?@  <  A 0B*%!;6 !$%!C
 DE

F    G    H    

F G I J   K  L

)6-53")06-
M  G #++H   
M N   
M O    P            Q     R   
M O   G   H       @ 
M S*         R 
M S*G    
M F     TU R  P G 
M V    *      

)6W051,)06
M     R  XY
M    R R H    H   G   Z [
M \ G G R     RR G  G 
M             R      H   

        

SVKefLggXhhijk
lNVemA=h=k   !
PAGE 620

s R    &E!*R   R  R      

9    @      R   R R G  R    
  G                Q  @ 

 t#u            

  J R    R    @  R           

  Zo[

 t%u         R    vwwxyz{|R   @    P    R       


R             @ 

   J  S @  m @ KJSmL        

   JSmR   RG G GP       G   

  mQ     R                G              


vwwxyz{|











  Zg[

 tBu @           G   

     R   G               

  J R*}R   R JSm  G      R  G   

o

=
 Z=[

 t'u   G    R     tBu   *D!! G@ 

  V    RG   @       R 

~#&#%+!#$! 3E!'*E*! #*#*€!

‚ƒ„      

†‡ˆ ‰    Q
    R  @ R  G
Š ‹yŒ
 ?Ž   
Zg[
lNVemA=h=k pqoij==jrj\j=k
PAGE 621

     @      R   

 O    P   !•B!*   R    G   
  –—–

 V            G oh =h    

   R    ˜w‡™ ƒŒ{| G                      R 


  

 mQ    I

0&(&#+E*&( 1'&š&!'E*&(
›œžŸ ¡¢£¤¥› ›——————¢£¤¥›
›œžŸ ¡¢£¤¢¡ › ›—————————¢¡ ›
›œžŸ ¡¢£¤¥œžŸ ¡› ›————————————žŸ ¡›

 t#u  R   ˜w‡™ ƒŒ{|GI

¦              


¦      G       Q     R  
R     

  O   R  R   ˜w‡™ ƒŒ{|





























  Zq[
lNVemA=h=k pqoij==jrj\j=k
PAGE 622

 t%u   H  @    ˜w‡™ ƒŒ{|G G G    G


G ohh       

     G    =S˜ƒ¨ˆ‚y„© ¨    G   


       R      G

  t&u O        



  Z=[

  t&&u   G     ˜w‡™ ƒŒ{| G G    R           


    G

    ˜ƒ¨ˆ‚y„© ¨      G   ˜w‡™ ƒŒ{|

   J RG     R     G     



  Zo[

lNVemA=h=k pqoij==jrj\j=k  !


PAGE 623

‘        qh @ 


        G  @  oS

       G I

ª «¬˜v­Š¬ª®¯°‹±ƒ™xª²ª­ŠŠ­³´œ²¡¥µª¶·ªŠ¬­v

     RGI

¦ @ ±¸          Q @     


@ R±¸      Q
¦ @ ¶‡±ƒ™x       R@       
¦   G GR     Qo

 t#u t&u @     @         *}@ 

±¸

¶‡±ƒ™x
 Zo[

  t&&u mQ G *           R      







  Z=[

 t%u R    @  ®¯°‹±ƒ™x Q     G 


   R   G  @    G       G  R   

  V      R    

  ·¹‚˜®†¶‚ª¸y‹¯{®¯°‹ºƒŒy ª²ªŠ¬­v|ªŠ¬®¹Š‚±ª»¶¶v¬­‚

ª ª ªªª«¬˜v­Š¬ªŠ y¨‡ºƒŒy ª²ª»¶¶v¬­‚

ª ª ªªª†·ªª®¼¬‚

ª ª ªªªªªªŠ¬®¹Š‚ªª½½ª‹ƒ™xª°‹ªƒŒ¨ ƒˆ¾ª¿yŒŒ

ª ª ªªª¬‚«†·

ª ª ªªªª ª®¯°‹ºƒŒy

ª ª ªªª±¸ª ª

ª ª ªªª¶‡±ƒ™xª ª¶‡±ƒ™xªÀªœ

ª ª ªªªŠ¬®¹Š‚ª®Š¹¬

ª ª ¬‚«·¹‚˜®†¶‚
 Zk[
lNVemA=h=k pqoij==jrj\j=k
PAGE 624

   @ ®°™xG   @    Kohhh     L


  R       

  @ R®°™x        @       

      @ R®°™x   @ RG

   Q  P  RG     G   ›Âwwˆ©¾ ›kh  R 
   ›¼ ŒŒw›

ª ª «¬˜v­Š¬ª±ƒ¨ª²ª†‚®¬Â¬Š

ª ª ¶¹®¸¹®ª›¼ ŒŒw›
ª ª ±ƒ¨ª ª®°™x

ª ª Ь¸¬­®
ª ª ªªª½½ˆwª‡w¯°‡Ã
ª ª ¹‚®†vª®°™xªÄª±ƒ¨ªÀªŸ¥¥¥¥

ª ª ¶¹®¸¹®ª›Âwwˆ©¾ ›

             @     

      R   @  G       

        ®°„ ¨{|GGI

¦   G  @                


¦    @ R@ ®°™x        
¦   G    gh   R        
¦   R   G         

 > Q  P    RY   kY         RG I

ª ª ˜­vvª®°„ ¨{ ۟ |

 O Y   oY  @   P   G  I

ª ª ›ž¥ª‹ ™w‡ˆ‹ªwªÃw›

 O Y   kY  @   P   G  I

ª ª ›®¯ ª°„ ª°‹ªyzƛ

lNVemA=h=k pqoij==jrj\j=k
PAGE 625

 O   R     ®°„ ¨{|



































  Zq[

lNVemA=h=k pqoij==jrj\j=k  !


PAGE 626

9C

§    oS«ƒƒG ohh  R  †‚®¬Â¬Š

     R   ¸¨w™ ‹‹{| Q     RGI

ª ª ·¹‚˜®†¶‚ª¸¨w™ ‹‹{‚y„© ¨ª²ª†‚®¬Â¬ŠÅªvƒ© Œª²ª±®Š†‚Â|ªŠ¬®¹Š‚±ª±®Š†‚Â


ª ª ªªª«¬˜v­Š¬ª†‡ˆ ‰Åª˜wy‡ª²ª†‚®¬Â¬Š
ª ª ªªª«¬˜v­Š¬ªŠ y¨‡ºƒŒy ª²ª±®Š†‚Â

ª ª ªªª˜wy‡ª ª†‚®{œ¥¥ª½ª‚y„© ¨|
ª ª ªªª†‡ˆ ‰ª ª«ƒƒ´‚y„© ¨µ

ª ª ªªª˜­±¬ª¶·ª{†‡ˆ ‰ªÇ¶«ª|
ª ª ªªªªªª¥ª²ªŠ y¨‡ºƒŒy ª ª®¶È¹¸¸¬Š{Š†Â¼®{vƒ© ŒÅª˜wy‡||
ª ª ªªªªªªœª²ªŠ y¨‡ºƒŒy ª ª›————›
ª ª ªªª¬‚«˜­±¬

ª ª ªªªŠ¬®¹Š‚ªŠ ºƒŒ
ª ª ¬‚«·¹‚˜®†¶‚

 t#u s ?             RR   G > Q  P   ?   G  


  RR    G  @ 

                 ?  

  O   *D!!  #' Q G     ?  

A o

mQ   



A =

mQ   



A g

mQ   


 Zg[

lNVemA=h=k pqoij==jrj\j=k
PAGE 627

99

 t%u r   R ?           KÉR Ž ÊL

  J R    R              R #'


Q G  

V    

mQ   




 Z=[

 tBu  R   ¸¨w™ ‹‹{|            ˜­±¬    

  O                     G     R     }&*D*


 ˜­±¬    









  Z=[

lNVemA=h=k pqoij==jrj\j=k  !


PAGE 628

9

8      G        G     É  Ê  G G 
      mÉ Ê GRR  R    
G    R 

  G G        É Ê G

              GR  oSR    

       RGI

ª ª «¬˜v­Š¬ª·°ŒŒ°‡Ãª²ª­ŠŠ­³ª´œ²ž µª¶·ª±®Š†‚Â

 m        R R 

   Q  R  R R@   RGI

)'!• 4+!$!* #+!


o ›˜¯ ‹ ›

= ›¶‡°w‡›

g ›±ƒŒ„w‡›

k ›­‡™¯w˰ ‹›

Y ›¸ ƒ‡yª»y ¨›

   oS        I

ª ª «¬˜v­Š¬ª»¨ ƒˆª²ª­ŠŠ­³ª´œ²œ¥µª¶·ª±®Š†‚Â

 m        R   R 

   Q  R  R     RGI

)'!• 4+!$!* #+!


o ›Ì¯° ›

= ›»¨w͇›

g ›¸°ƒ›

 U         @ R   G         


  G    

    ±z ™°ƒŒ{|G    @   É Ê G  R *}
     RR  R  !      

 N      *   G      É Ê G

 N   @  Q  P      I

ª ª ›®¯ ªˆƒ°Œ¾ª‹z ™°ƒŒª°‹ª˜¯ ‹ ªƒ‡ˆª¶‡°w‡ªw‡ª»¨w͇ª©¨ ƒˆÎ›

lNVemA=h=k pqoij==jrj\j=k
PAGE 629

 t#u V      R     ±z ™°ƒŒ{|

       

ª ª ¸Š¶˜¬«¹Š¬ª±z ™°ƒŒ{|













































  ¬‚«¸Š¶˜¬«¹Š¬
 ZX[

lNVemA=h=k pqoij==jrj\j=k  !


PAGE 630

9

 t%u  G          RR   G    > Q  P
 @     

  S  G          @             















  Z=[

lNVemA=h=k pqoij==jrj\j=k
PAGE 631

Á RR       

 V    G  G        G  H    JS

 e                  

  RG  R     R    IJSP  P  P  P
     P   R  P   R  P   R   @       R  
   @ 

  G   G              G


 @   RR            G    H @  
 G        R         G     Q 
GG 

 t#u J R*D!! R    R     G      G   #'Ï  R


  

J o

Ð  R  



J =

Ð  R  



J g

Ð  R  


 Zg[

 t%u J R                   G  t#u

  Zo[

 tBu J     R   @  R    R   @  R
  G   

    R   G        Ï   @         


S                 G  R 

  A  *D!!*D!   G  R R   G           

o

=

g
 Zg[

lNVemA=h=k pqoij==jrj\j=k  !


PAGE 632

98

 t'u < R  RR          RGI

¦   †‡°{|     U  


¦   Š ‹ {|         J  
¦   ˜¯ ™x{|   †‡°{|RG Š ‹ {|

  SG               G   *D!!   P   


    @ 

 Zg[

lNVemA=h=k pqoij==jrj\j=k
PAGE 633

9:

:     @      R  Q 

 S     P      R      R       


kY @ 

 m R   PRGI

,**&%*! 4•#$+!E "$$!*

<  hPoPg        

 Ï     G R    


s U  P  PS 
 
   R   A @  
\ UPe P>P  R     P   G 
@  H   
  @ R         
e @  okP=gPXq
  h ohh  @ 

    R      R   

      R   G    RGI

 ®³¸¬ª˜¯ƒ¨ƒ™ ¨®¾z
ª ªªª«¬˜v­Š¬ª¸Œƒ¾ ¨ª²ª†‚®¬Â¬Š
ª ªªª«¬˜v­Š¬ªŠwŒ ª²ª±®Š†‚Â
ª ªªª«¬˜v­Š¬ª‚ƒ„ ª²ª±®Š†‚Â
ª ªªª«¬˜v­Š¬ªv Ë Œª²ª†‚®¬Â¬Š
ª ¬‚«®³¸¬

  ¸Œƒ¾ ¨R       G    Ko qL R @ 
hR   *    

    R        RGI

ª «¬˜v­Š¬ª˜¯ƒ¨ƒ™ ¨ª²ª­ŠŠ­³´œ²Ÿ µª¶·ª˜¯ƒ¨ƒ™ ¨®¾z

      R    R     P ¸Œƒ¾ ¨R @    h

    R     RGI

1'+! !EB&*&
­‹‹°Ã‡{| ¦  G  G I
Ñ         
Ñ        
¦     ˜¯ƒ¨ƒ™ ¨  R       G   
 H  
¦ JRR P       @      R   
 PR Q  I
 ›»°ŒŒª¯ ª»y°Œˆ ¨ª¯ƒ‹ª© ‡ªƒ‹‹°Ã‡ ˆªwªzŒƒ¾ ¨ªž›
¦ JR    G    H   R P     
 

lNVemA=h=k pqoij==jrj\j=k
PAGE 634

97

 t#u O   R   ­‹‹°Ã‡{|





















































  ZX[

lNVemA=h=k pqoij==jrj\j=k  !


PAGE 635

C

 t%u  G   G     R  ˜¯ƒ¨ƒ™ ¨  Q R 

       R RGI

1'+! !EB&*&
±ƒË {| ¦ R   R   G R     
 –Ò–
¦ G        R   GR   
±ƒË ·°Œ ΍‰

  V      R   ±ƒË {|

ª ª ¸Š¶˜¬«¹Š¬ª±ƒË {|









































 ¬‚«¸Š¶˜¬«¹Š¬
ZX[
lNVemA=h=k pqoij==jrj\j=k
PAGE 636

9

 tBu            R    R RGI

ª ª ®³¸¬ª˜¯ƒ¨ƒ™ ¨®¾z
ª ª ªªª«¬˜v­Š¬ª¸Œƒ¾ ¨ª²ª†‚®¬Â¬Š
ª ª ªªª«¬˜v­Š¬ªŠwŒ ª²ª±®Š†‚Â
ª ª ªªª«¬˜v­Š¬ª‚ƒ„ ª²ª±®Š†‚Â
ª ª ªªª«¬˜v­Š¬ªv Ë Œª²ª†‚®¬Â¬Š
ª ª ªªª«¬˜v­Š¬ª±ƒy‹ª²ª»¶¶v¬­‚
ª ª ¬‚«®³¸¬

  S  G    U  R     G     R  R    
R Q R 







  Z=[

 t'u   @          Q         R     @      


  GG           R  @    R  
  R     H   G  R  @ 

  S     G G   R   @ #'@   Q  R*}
   @ R  

 



mQ  


 Z=[

lNVemA=h=k pqoij==jrj\j=k
PAGE 637

"#$%&'(!)*!#*&#+,-.,/! !+
^ _ _ ` a b ` _ c d b ^

"012345-")46"4 789:;<
= >?  = @A  =  B 0C*%!;6 !$%!D
 EF

G    H    I    

G H J K   L  M

)6-53")06-
N  H #++I   
N O   
N P    Q            R     S   
N P   H   I       A 
N T*         S 
N T*H    
N G     UV S  Q H 
N W    *      

)6X051,)06
N     S  YZ
N    S S I    I   H   [ \
N ] H H S     SS H  H 
N             S      I   

        

TWLBeMffYg>hif
jOWekB>g>h   !
PAGE 638

r S    &F!*S   S  S      

9 s#t  SH        R  

  k R               S  SH J

u    
u    L    M
u    L   S   M

  W       !$! LvwvM  H

2F!'C'!!x#$y+! -!+!C*& )*!#*& -%*&!

ƒ
z{|}~€‚} }„} {}†
}}}~z}‡ˆ‰Š~€‚‹}Œ} |Ž} Ž
}}}}}}z‘ˆ’Š~€‚‹} }“ ƒ
}}}ސ”~z
Ž• }~€‚
–—‡Ž}{z}–˜™’˜š€›†œ

|ŽŽ— } ~ž}—‘‘”˜›œ}Œ} |Ž

Ÿ~žŽ}| š‘¡Š†‹}¢£}z—ž‡Ž
 [h\

 s%t W      A          

¤#&#%+! 4x#$y+!'#*# #+! ¥#*#*¦y!


—§ˆ¨‘ˆ©‘ |Ž
|ª¨§€ «„¬­“®­¯“¯„«
~€‚ „““
 [f\

 sCt kA    R            A H   s%t

  P °krrqr±S   R      

4xy!FF& 4 #+#*!F*

—§ˆ¨‘ˆ©‘}—”}{ ›~€‚}£}„““œ

~€‚}²{”}†“

²³ {³‡ |›~€‚}´}«††«œ


 [f\

jOWekB>g>h opnmi>fiqi]i>h
PAGE 639

<

    HJ

 n       I  Sngg  A Q   


 >     A   
 f        S   

 s#t P   S    

     A ·     A    A 

  G     A        

























  [Z\

 s%t     I      S    q S    I  

  K S!*E!     I      #'  H   

W    

O 


  [>\

jOWekB>g>h opnmi>fiqi]i>h  !


PAGE 640

<      S        A  nTž¨ ¡S  ˜€

 r   ˜€     SHJ

} ¸Ž}˜€
} }}}”Ž–ž—|Ž}”ˆ¡ˆ}¹}‡ |~º
} }}}”Ž–ž—|Ž}˜¨¡»}¹}~ ŽºŽ|
} ސ” ¸Ž

  ž¨ ¡     SHJ

 ”Ž–ž—|Ž}ž¨ ¡}¹}—||—¸Š„¹¯““‹}{z}˜€

     H  SHJ

u K  A ˆ€˜¨¡»H      RS  S         


u   ˜¨¡» S  S           R A  S   R    L   R 
 M      
u  A g    

 s#t s&t B  H  A g        



 [n\

  s&&t ¶A     SAA       A ˆ€˜¨¡»

 [n\

jOWekB>g>h opnmi>fiqi]i>h
PAGE 641

 s%t  ž¨ ¡H             SH   


      H    

  W     SH         S    

Br

k]T

 [h\

jOWekB>g>h opnmi>fiqi]i>h  !


PAGE 642

 sCt        ”ˆ¡ˆS S      ž¨ ¡    ”ˆ¡ˆ
                 

  T       ½ 

  T*         H 

B n





B >





B f





B h




 [h\

jOWekB>g>h opnmi>fiqi]i>h
PAGE 643

D   R      R SYZ q SSA  L kM Q
          H   SA   H     

    H    R     

  SA        nTºÂS  ~ ŽºŽ|QS R  J

)'!x ¤#+! "$$!*


n ÃÄ      S  
> ÄÅ      SV 
f ®†      SW 
h †Ä      ST 
Z ¯Å      S k 

      A  H  > S       O   
A   Q H hZ H      

 s#t              H               H 


  S      A ²ˆ»Æ¶A ²ˆ»ÆQ~€‚Q’’» 
ž˜Ç»     

  W      

  ƒ}„} {
z{|}~€‚}

  }}}ž˜Ç»}ƒ}ºÂŠ~€‚‹}È}¯

  }}}’’»}ƒ

  }}}~z}²ˆ»Æ—”}²ˆ»Æ Ž

  }}}}}}{  }«–ɁªÆ}¡É¨ }’ˆ’»«

  }}}ސ”~z

  Ž• }~€‚
 [h\

 s%t     A       S        nT


–ɁªÆQ   Yp  S  Â{{žŽ—   S   S g YZ
L  A MQ        S  

     A  –ɁªÆ |ŽS    RH  > S  ?


R  Q    H    W  hf      S  –ɁªÆ
H  SHJ

)'!x ¤#+!
hg z—ž‡Ž
hn |Ž
h> |Ž
hf |Ž ƒ   SW
hh |Ž
hZ |Ž
hp z—ž‡Ž
jOWekB>g>h opnmi>fiqi]i>h
PAGE 644

  s&t   SA     A ²ˆ»Æ

   T  H   H     –ɁªÆ    H    


    







 [>\

  s&&t    ºÂ~¨¡¨ˆ‘¨ ›œH     –ɁªÆ  A S   ºÂ




   ]              R      A  S  Yg    


  A SknZ

   P   S     



































 [p\
jOWekB>g>h opnmi>fiqi]i>h  !
PAGE 645

9

¼  S H   A   SH     A   S      S    A   
 A    A   

 s#t  SH      A   A  

  W      H      S  S    S  A 

,C*& &*¦ 6#$!½+&½!C¦C+!F*#(!


    
       S    S 
     
       S 
 [h\

 s%t  S H   A    H      ¡³—›œ    ¡³Â›œ    A   


H            S  A        
    S     L      M  

  K S                  %!½!    


     A    #'  H H H

µ 

T   






 [f\

jOWekB>g>h opnmi>fiqi]i>h
PAGE 646

99

8 K    Q    B  µQ A     H  A 


SH  

    —€Êš ¡–‘˜ªÆ›œH               H


     A         S   µ H   A 
SH

 ? R  Q  SH  S  H  ”ˆËš™©»  A >gJ

 ”ˆËš™©» ƒ—€Êš ¡–‘˜ªÆ›¯“¯¯œ


 P   S  S   —€Êš ¡–‘˜ªÆ›œ

 T S   S   &F!*        





































  [Y\

jOWekB>g>h opnmi>fiqi]i>h  !


PAGE 647

9

¾ SS H H          

       S   H   H 

 s#t K S      S      A   S             S #'
A    H        

B  

T 


 [>\

 s%t    H A               I      KT  
    H                 
 H    Q   Q         ±  P 
      R               Q   H A       
R   S 

              A  H        H    T    


H            S       H    H     @ 
L @   M

  K S½ @              S   H   #'  


   

B @   n

O 



B @   >

O 



B @   f

O 



B @   h

O 


 [h\

jOWekB>g>h opnmi>fiqi]i>h
PAGE 648

9D

:     A      S  R 

 T     Q      S      S       


hZ A 

 k S   QSHJ

,**&%*! 4x#$y+!F "$$!*


=  gQnQf        
 Ì     H S    
r V  Q  QT 
 
   S   B A  
] VQe Q?Qµ  S     Q   H 
A  I   
B A  nhQ>fQYp         g nggQ  A 

    S      S        S   


H    SHJ

} ¸Ž}–Ɉ»ˆª¡» ˒
} }}}”Ž–ž—|Ž}‘ˆË»}¹}~ ŽºŽ|
} }}}”Ž–ž—|Ž}|˜‘}¹}‡ |~º
} }}}”Ž–ž—|Ž}ˆ™}¹}‡ |~º
} }}}”Ž–ž—|Ž}‡Æ¨‘‘ž§‘}¹}~ ŽºŽ|
} ސ” ¸Ž

  ‘ˆË»S       H    Ln pMS A 
gS   *    

    S        QSHJ

} ”Ž–ž—|Ž}–Ɉ»ˆª¡»}¹}—||—¸Š„¹®Ä‹}{z}–Ɉ»ˆª¡» ˒

      S    S     Q ‘ˆË»S    g

    S     SHJ

1'+! ¥!FC&y*&
–˜š¡›œ u  H  H J
Í         
Í        
u     –Ɉ»ˆª¡»S H   A     
    A  
u      S         A 
u        S   S H   A   S Q
S R  J
 «‘ˆË»}†}Ɉ }®}ªÉˆ»ˆª¡» }Ǩ¡É}¡É}»˜‘}˜‰} ˆªÉ»}
ˆ€}¡É}¡˜¡ˆ‘} ƨ‘‘}‘§‘}¨ }ÃÄ«
u S  H   A   S Q  J
 «˜}ªÉˆ»ˆª¡» }Ǩ¡É}¡Éˆ¡}»˜‘}ˆ»}ˆ ¨Î€}¡˜}¡É¨ }
’‘ˆË»«

jOWekB>g>h opnmi>fiqi]i>h
PAGE 649

 s#t W      S   –˜š¡›œ

  |{–Ž”|Ž}–˜š¡› ɨ ‘ˆË»}¹}~ ŽºŽ|Ï} ɨ |˜‘}¹}‡ |~ºœ



















































} } ސ”|{–Ž”|Ž
 [Y\
jOWekB>g>h opnmi>fiqi]i>h  !
PAGE 650

98

 s%t  –Ɉ»ˆª¡»  A     R S ‡ˆ§z¨‘Ð¡‚¡


  k S  S      S  L  M

  ] H     S J

1'+! ¥!FC&y*&
Ž‚¡»ˆª¡›œ u  H  H J
L H M Í          S    R S
Í        S   L      HM
u            I  S 
| ¡˜»›œ u     R S ‡ˆ§z¨‘Ð¡‚¡
u   S   S   A       
–Ɉ»ˆª¡»   S   S  S

     Q            J

} } ¸Ž}–Ɉ»ˆª¡» ˒
} } }}}”Ž–ž—|Ž}‘ˆË»}¹}~ ŽºŽ|}}}}}}}­­z¨‘€}𙩁»}„
} } }}}”Ž–ž—|Ž}|˜‘}¹}‡ |~º}}}}}}}}}}­­z¨‘€}𙩁»}¯
} } }}}”Ž–ž—|Ž}ˆ™}¹}‡ |~º}}}}}}}}}}­­z¨‘€}𙩁»}†
} } }}}”Ž–ž—|Ž}‡Æ¨‘‘ž§‘}¹}~ ŽºŽ|}}}­­z¨‘€}𙩁»}®
} } ސ” ¸Ž

  P   S   | ¡˜»›œ

  G          Ž‚¡»ˆª¡›œ




























jOWekB>g>h opnmi>fiqi]i>h
PAGE 651









  [Y\

 sCt     S A    S S     A       
            

  T     S S    S ‡ˆ§z¨‘Ð¡‚¡    s%t







  [>\

jOWekB>g>h opnmi>fiqi]i>h
PAGE 652

Cambridge International AS & A Level


* 8 3 0 3 8 3 5 5 8 0 *

COMPUTER SCIENCE 9608/22


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2021
2 hours

You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.

This document has 20 pages. Any blank pages are indicated.

DC (CJ) 205021/2
© UCLES 2021 [Turn over
PAGE 653

1 (a) Maintenance of programs may be needed for a number of different reasons.

State two types of maintenance and give a reason why each may be needed.

Type ..........................................................................................................................................

Reason .....................................................................................................................................

...................................................................................................................................................

Type ..........................................................................................................................................

Reason .....................................................................................................................................

...................................................................................................................................................
[4]

(b) State why characters need to be represented in ASCII or Unicode before they can be
processed.

...................................................................................................................................................

............................................................................................................................................. [1]

(c) Each line of a text file contains several data items. A special character is inserted between
data items before the line is written to the file.

Explain why a special character is used in this way.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

(d) Each pseudocode statement in the following table may contain an error due to the incorrect
use of the function or operator.

Describe the error in each case, or write ‘NO ERROR’ if the statement contains no error.

Refer to the Appendix on page 18 for the list of built-in pseudocode functions and operators.

Statement Error

Code RIGHT("Cap" & "art", 4)

Status MID("Computer", 7, 5)

Size LENGTH("Password") * 2

NextChar CHR('A')

Index Index & 3


[5]

© UCLES 2021 9608/22/M/J/21 [Turn over


PAGE 654

2 Study the following pseudocode.

DECLARE Overload : BOOLEAN

PROCEDURE LEM()

DECLARE Status : BOOLEAN


DECLARE Landed : INTEGER

Overload FALSE
Landed FALSE

WHILE Landed = FALSE


Status Sample()
IF Status = TRUE
THEN
Landed SubA(42)
ELSE
Overload SubB(37)
IF Overload = TRUE
THEN
CALL Display("Alarm 1202")
ENDIF
ENDIF
ENDWHILE

ENDPROCEDURE

(a) Examine the pseudocode and complete the following table:

Answer

The identifier name of a global variable

The name of the loop structure

The identifier involved in a data type mismatch

The name of a procedure that takes a parameter

The name of a function

[5]

© UCLES 2021 9608/22/M/J/21


PAGE 655

(b) Draw a program flowchart to represent the pseudocode algorithm.

Variable declarations are not required in program flowcharts.

[5]
© UCLES 2021 9608/22/M/J/21 [Turn over
PAGE 656

3 (a) (i) Module names and parameters are features that may be represented on a structure
chart.

State two other features than can be represented on a structure chart.

Feature 1 ...........................................................................................................................

Feature 2 ...........................................................................................................................
[2]

(ii) The headers for three modules in a program are defined in pseudocode as follows:

Pseudocode module header


PROCEDURE Create(S2 : INTEGER, P3 : STRING)
PROCEDURE Modify(S2 : INTEGER, BYREF P4 : STRING)
FUNCTION Delete(P4 : INTEGER, M4 : STRING) RETURNS INTEGER

A fourth module, Membership(), may call any one of the three modules.

Draw a structure chart to represent the information given about the four modules.

[5]

© UCLES 2021 9608/22/M/J/21


PAGE 657

(b) Draw a diagram to show the stages of the program development cycle. Use arrows to indicate
how the stages are linked.

[2]

© UCLES 2021 9608/22/M/J/21 [Turn over


PAGE 658

4 (a) Using pseudocode, write a post-condition loop to output every odd number between 100
and 200.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]

(b) A program contains a global 2D array XRef. The array consists of 100 rows and 3 columns.
The array is of data type STRING.

A function, Search(), takes two parameters Par1 and Par2 as string values and returns an
integer value.

The function returns:

• the index number of the first row where:

• the element in column 1 of that row matches Par1 and


• either of the other two elements in that row match Par2

• –1 if no match found in any row.

© UCLES 2021 9608/22/M/J/21


PAGE 659

Write program code for the function Search().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language .............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]
© UCLES 2021 9608/22/M/J/21 [Turn over
PAGE 660

10

5 (a) An Integrated Development Environment (IDE) will be used to develop a program.

(i) An IDE includes features for program presentation.

State two of these presentation features.

Feature 1 ...........................................................................................................................

...........................................................................................................................................

Feature 2 ...........................................................................................................................

...........................................................................................................................................
[2]

(ii) Name two IDE features that can help with initial error detection.

Feature 1 ...........................................................................................................................

...........................................................................................................................................

Feature 2 ...........................................................................................................................

...........................................................................................................................................
[2]

(b) (i) A function, Verify(), is written in pseudocode.

Write the two missing lines to complete the pseudocode.

FUNCTION Verify(UserID : STRING) RETURNS BOOLEAN

..............................................
DECLARE Password : STRING
OUTPUT "Please Input your password: "
INPUT Password
Response Validate(UserID, Password) AND Today()

..............................................

ENDFUNCTION
[2]

© UCLES 2021 9608/22/M/J/21


PAGE 661

11

(ii) The function, Verify(), is to be amended as follows:

• if the UserID is "Guest", a password is not required and TRUE should be returned
• output a message to try again if the password entered is not valid
• return FALSE if the number of attempts to enter a valid password exceeds three.

Write program code for the amended function Verify().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ......................................................................................................

Program code

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [6]
© UCLES 2021 9608/22/M/J/21 [Turn over
PAGE 662

12

6 A program stores data about stock items in four global 1D arrays as follows:

Example Initial data


Array Data type Description
data value value
the stock item ID
StockID STRING "JBCD0002" ""
(eight alpha-numeric characters)
a description of the item
Description STRING "soap" ""
(alphabetic characters only)
Quantity INTEGER the number in stock 9 0
Cost REAL the cost of the item 1.45 0.0

• Each array contains 10 000 elements.


• Elements with the same index relate to the same stock item. For example, StockID[3]
contains the ID for the product whose description is in Description[3].
• The StockID array is not sorted.

The program will be modified so that the data from the arrays can be stored in a text file for
backup. You may assume that a backup file contains only valid stock data.

The programmer has started to define program modules as follows:

Module Description
• called with two parameters:
• an array index
Unpack()
• a string value read from one line of the backup file
• extracts the four data values from the string and assigns each
to the appropriate array
• called with a string representing the name of a backup file
• returns FALSE if the file is empty
• sets all elements of each array to the initial data value as given
in the table
Restore() • reads the backup file line by line
calls Unpack() to extract data from each line and assign
values to the corresponding arrays
• returns FALSE if the arrays are full but there are still lines in the
file, otherwise returns TRUE
For all items where StockID does not contain the initial value:
• counts the number of stock entries in the StockID array
StockSummary() • outputs the overall value of all items in stock (cost multiplied by
the quantity)
• outputs the number of stock entries

© UCLES 2021 9608/22/M/J/21


PAGE 663

13

(a) Write program code for the module StockSummary().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language .............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

© UCLES 2021 9608/22/M/J/21 [Turn over


PAGE 664

14

(b) Write pseudocode for the module Restore().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2021 9608/22/M/J/21


PAGE 665

15

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2021 9608/22/M/J/21 [Turn over


PAGE 666

16

(c) The module description of GetValidFilename() is as follows:

Module Description
• prompts and inputs a filename
• validates the filename by checking that it:
• is between 4 and 10 characters in length (inclusive)
GetValidFilename() • contains only alphanumeric characters
• if the filename is invalid, outputs a warning message and
asks the user to try again
• otherwise returns the valid filename

Write program code for the module GetValidFilename().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language .............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2021 9608/22/M/J/21


PAGE 667

17

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2021 9608/22/M/J/21


PAGE 668

18

Appendix

Built-in functions (pseudocode)

Each function returns an error if the function call is not properly formed.

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString
Example: MID("ABCDEFGH", 2, 3) returns "BCD"

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString
Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString
Example: LEFT("ABCDEFGH", 3) returns "ABC"

RIGHT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString
Example: RIGHT("ABCDEFGH", 3) returns "FGH"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x
Example: INT(27.5415) returns 27

LCASE(ThisChar : CHAR) RETURNS CHAR


returns the character value representing the lower case equivalent of ThisChar
If ThisChar is not an upper case alphabetic character, it is returned unchanged.
Example: LCASE('W') returns 'w'

ASC(ThisChar : CHAR) RETURNS INTEGER


returns the ASCII value of character ThisChar
Example: ASC('A') returns 65

CHR(x : INTEGER) RETURNS CHAR


returns the character whose ASCII value is x
Example: CHR(87) returns 'W'

Operators (pseudocode)

Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE

© UCLES 2021 9608/22/M/J/21


PAGE 669

Cambridge International AS & A Level


* 3 6 5 9 0 7 9 7 1 3 *

COMPUTER SCIENCE 9608/23


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2021
2 hours

You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.

This document has 24 pages. Any blank pages are indicated.

DC (PQ/FC) 205019/2
© UCLES 2021 [Turn over
PAGE 670

1 (a) Algorithms usually consist of three different types of activity.

Complete the following table.

Write each example statement in program code and state the programming language used.

The third activity has already been given.

Programming
Activity Example statement in program code
language

OUTPUT

[5]

(b) An algorithm searches a 1D array to find the first index of an element that contains a given
value. If the value is found, the index of that element is returned.

(i) State an appropriate loop structure for this algorithm. Justify your choice.

Loop structure ...................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................
[2]

(ii) Give two possible reasons why the search for the value in part (b)(i) would end.

You should assume there is no error.

1 ........................................................................................................................................

...........................................................................................................................................

2 ........................................................................................................................................

...........................................................................................................................................
[2]

© UCLES 2021 9608/23/M/J/21


PAGE 671

(c) Each pseudocode statement in the following table may contain an error due to the incorrect
use of the function or operator.

Describe the error in each case, or write 'NO ERROR' if the statement contains no error.

Refer to the Appendix on pages 22 and 23 for the list of built-in pseudocode functions and
operators.

Statement Error

Code RIGHT("Cap" * 3, 2)

Valid IS_NUM(3.14159)

NextChar MID(ThisString, Index), 1

[3]

© UCLES 2021 9608/23/M/J/21 [Turn over


PAGE 672

2 (a) After using a program for some time, a user notices a fault in the program.

Describe the term program fault.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

(b) Good programming practice may help to avoid faults. The use of sensible identifier names is
one example of good practice.

(i) Explain the reason for using sensible identifier names.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) State three other examples of good programming practice.

1 ........................................................................................................................................

2 ........................................................................................................................................

3 ........................................................................................................................................
[3]

(c) A programmer chooses data to test each path through her program.

Identify the type of testing that the programmer has decided to perform.

............................................................................................................................................. [1]

© UCLES 2021 9608/23/M/J/21


PAGE 673

3 (a) The process of decomposition is often applied to a programming problem.

Describe the process of decomposition.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

(b) Result is a 1D array of type STRING. It contains 100 elements.

Draw a program flowchart for an algorithm that will output each element in the array.

[4]
© UCLES 2021 9608/23/M/J/21 [Turn over
PAGE 674

(c) The program flowchart for part of an algorithm from a mobile phone program is shown.
Identifier Active is a global variable of type BOOLEAN.

START

Set Online to FALSE

Is Online = NO
FALSE ?

YES END

Is Active = NO
TRUE ?

YES
CALL Reset()
CALL Sync()

Is Active = YES
FALSE ?

NO
CALL Error("No
Signal")

Set Online to TRUE

CALL ReCheck()

© UCLES 2021 9608/23/M/J/21


PAGE 675

Write pseudocode to implement the algorithm represented by the flowchart.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2021 9608/23/M/J/21 [Turn over


PAGE 676

4 Study the following pseudocode for a string handling function Check().

Refer to the Appendix on pages 22 and 23 for the list of built-in pseudocode functions and
operators.

FUNCTION Check(InString : STRING) RETURNS INTEGER

DECLARE Index, Result, Count : INTEGER


DECLARE NextChar : CHAR

Result 0
Count 1

FOR Index 1 TO LENGTH(InString)

NextChar MID(InString, Index, 1)


IF (NextChar >= '0' AND NextChar <= '9') OR NextChar = '.'
THEN
Result Result + 1
ELSE
IF NextChar = ','
THEN
Count Count + 1
ELSE
Result -1
ENDIF
ENDIF
ENDFOR

IF Count < 3
THEN
RETURN -1
ELSE
RETURN Result
ENDIF

ENDFUNCTION

© UCLES 2021 9608/23/M/J/21


PAGE 677

(a) (i) Complete the trace table by performing a dry run of the function when it is called as
follows:

Answer Check("74.0,4.6,3x2")

Note, there are no space characters in the string shown.

Result Count Index NextChar

[5]

(ii) State the value returned by the function when it is called as shown in part (a)(i).

................................................ [1]

© UCLES 2021 9608/23/M/J/21 [Turn over


PAGE 678

10

(b) A number group is a string of characters that represents an integer or decimal value. A comma
separates number groups.

For example, "74.0" is a number group in the string "74.0,4.6,3x2".

The function Check() is intended to analyse the number groups in the parameter passed.

The function returns:

• a count of the number groups in the parameter passed

or

• í LI WKHUH DUH OHVV WKDQ WKUHH QXPEHU JURXSV LQ WKH VWULQJ or if any non-numeric
characters occur in the string (other than decimal point and comma).

There is an error in the algorithm causing an incorrect value to be returned by the function.

(i) Explain why this error can occur.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(ii) Describe how the algorithm could be amended to correct the error.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [1]

(c) A dry run of a pseudocode algorithm may help to locate logic errors.

Give another type of program error and describe how it can occur.

Type of error .............................................................................................................................

Description ................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2021 9608/23/M/J/21


PAGE 679

12

5 A program stores a contact list of telephone numbers. Each telephone number is stored as a
string of six or more numeric characters.

Before they are displayed, number strings are formatted to make them easier to read. This involves
forming the characters into groups, separated by the space character.

The maximum length of a number group is five characters.

Different numbers may have different groupings. A template string is used to define the grouping.

For example:

Number string Template string Formatted string

"01223553998" "53" "01223 553 998"

"509700101" "222" "50 97 00 101"

"4044496128" "33" "404 449 6128"

For the first row, template "53" results in a formatted string comprising:

• the first five characters in the first group


• a space character
• the next three characters in the second group
• a space character
• the remaining characters from the number string.

(a) Write pseudocode for a function GroupNum(), which takes a telephone number and a
template as parameter strings and returns a formatted string.

You may assume that the template and telephone number are valid.

Refer to the Appendix on pages 22 and 23 for the list of built-in pseudocode functions and
operators.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2021 9608/23/M/J/21
PAGE 680

13

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]
© UCLES 2021 9608/23/M/J/21 [Turn over
PAGE 681

14

(b) The function GroupNum() is to be extended to include parameter checking.

State one check that could be applied to each parameter.


Give an example of test data that could be used to demonstrate that each check identifies
invalid data.

The type of check must be different for each parameter.

Telephone number check .........................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Test data ...................................................................................................................................

Template check .........................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Test data ...................................................................................................................................


[4]

© UCLES 2021 9608/23/M/J/21


PAGE 682

16

6 A program stores data about stock items in four global 1D arrays as follows:

Example Initial data


Array Data type Description
data value value
the stock item ID
StockID STRING (eight alpha-numeric "ABLK0001" ""
characters)
a description of the item
Description STRING "torch" ""
(alphabetic characters only)
Quantity INTEGER the number in stock 6 0

Cost REAL the cost of the item 4.80 0.0

• Each array contains 10 000 elements.

• Elements with the same index relate to the same stock item. For example, StockID[5]
contains the ID for the product whose description is in Description[5].

• The StockID array is not sorted and unused elements may occur at any index position.

• Unused elements are assigned the initial data value shown in the table above.

• The first four characters of the StockID represent a product group. The last four characters
represent the item within the group.

The program is to be modified so that:

• data from the arrays are stored in a text file for backup purposes. Data from unused elements
are not stored in the file.

• a Summary array is added. This will be a global 1D array of 500 elements of type STRING.
Each product group will occur once in the array, for example "ABLK" for the item in the table
above.

The programmer has started to define program modules as follows:

Module Description

• prompts and inputs a filename


GetValidFilename()
• returns a valid filename as a STRING
• calls GetValidFilename() for a filename
• checks if the file is empty
CheckBackupFile() • If the file is not empty ask the user to confirm that overwrite
is intended. If not intended allow the user to re-input a
different filename.
• returns the filename.

© UCLES 2021 9608/23/M/J/21


PAGE 683

17

(a) Write pseudocode for the module CheckBackupFile().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]
© UCLES 2021 9608/23/M/J/21 [Turn over
PAGE 684

18

(b) Write program code for a module GroupReport(), which will summarise the stock data for
a given product group.

The product group will be passed to the module as a string. The total value of items is
calculated by multiplying the cost by the quantity.

An example of the output for group ABLK is as follows:

Group: ABLK
Number of items in Group: 11
Total value of items in Group: 387.89

If no items are found for group ABLK, the output is as follows:

There are no items in Group: ABLK

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2021 9608/23/M/J/21
PAGE 685

19

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2021 9608/23/M/J/21 [Turn over


PAGE 686

20

(c) Two additional modules are required:

Module Description
• called with a STRING representing a product group
(for example, "ABLK")
Lookup()
• searches the Summary array for the group
• UHWXUQVWKHLQGH[SRVLWLRQRUUHWXUQVíLIQRWIRXQG
• stores each product group name (found in the
StockID array) into the Summary array, if not there
already
GroupSummary() • calls Lookup() to check whether the name is
already in the Summary array
• returns the number of product groups added to the
Summary array

You can assume:

• all elements of the Summary array have been initialised to the value "" before
GroupSummary() is called
• there will be no more than 500 product groups.

Write program code for the module GroupSummary().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2021 9608/23/M/J/21
PAGE 687

21

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2021 9608/23/M/J/21


PAGE 688

22

Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString

Example: MID("ABCDEFGH", 2, 3) returns "BCD"

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString

Example: LEFT("ABCDEFGH", 3) returns "ABC"

RIGHT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString

Example: RIGHT("ABCDEFGH", 3) returns "FGH"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: INT(27.5415) returns 27

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.
Note: This function will also work if x is of type INTEGER

Example: NUM_TO_STRING(87.5) returns "87.5"

STRING_TO_NUM(x : STRING) RETURNS REAL


returns a numeric representation of a string.
Note: This function will also work if x is of type CHAR

Example: STRING_TO_NUM("23.45") returns 23.45

IS_NUM(ThisString : STRING) RETURNS BOOLEAN


returns the value TRUE if ThisString contains only numeric characters ('0' to '9').

Example: IS_NUM("123a") returns FALSE

© UCLES 2021 9608/23/M/J/21


PAGE 689

23

Operators (pseudocode)

Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE

© UCLES 2021 9608/23/M/J/21


PAGE 690

Cambridge International AS & A Level


* 8 4 9 4 3 7 7 8 0 0 *

COMPUTER SCIENCE 9608/22


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2021
2 hours

You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.

This document has 20 pages. Any blank pages are indicated.

DC (RW) 206327/4
© UCLES 2021 [Turn over
PAGE 691

1 (a) Design and coding are stages of the program development cycle.

State two activities from each of these stages.

Design stage

Activity 1 ...................................................................................................................................

Activity 2 ...................................................................................................................................

Coding stage

Activity 1 ...................................................................................................................................

Activity 2 ...................................................................................................................................
[4]

(b) The following is part of a procedure to manage the stock in a shop:

100 PROCEDURE InitVars()


101 DECLARE Vs : STRING // program version
102 DECLARE Pe : REAL // stock item purchase price
103 DECLARE Exp : STRING // date when item expires
104 DECLARE S_lr: STRING // supplier ID
105 DECLARE Rp : REAL // low stock value
106 DECLARE OUT : BOOLEAN // any items in stock ?

180 ENDPROCEDURE

(i) Give two reasons why the identifier names used in the procedure InitVars() are not
examples of good practice.

Reason 1 ...........................................................................................................................

...........................................................................................................................................

Reason 2 ...........................................................................................................................

...........................................................................................................................................
[2]

© UCLES 2021 9608/22/O/N/21


PAGE 692

(ii) Complete the following table by writing an appropriate identifier name for each of these
four lines in the procedure InitVars().

Line Appropriate identifier name

102

103

105

106

[4]

(iii) Line 101 of the procedure needs to be changed because:

• the identifier should be declared as a fixed value that does not change during
program execution

• the identifier name is not appropriate

• the program version should be ver1.5.8

Write the new correct statement for line 101.

...........................................................................................................................................

..................................................................................................................................... [2]

(c) A program can store characters using either the ASCII or the Unicode character set.

Give two reasons why Unicode is preferred to the ASCII character set for storing characters.

Reason 1 ..................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Reason 2 ..................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2021 9608/22/O/N/21 [Turn over


PAGE 693

2 A café manager needs a program for a loyalty scheme. A customer is awarded one loyalty point
for each purchase.

When a customer has ten or more points, the customer is offered a free slice of cake.

(a) During the program design, a decision is made to store the loyalty data in a text file called
LOYALTY.txt. This file holds the membership number and total number of points for each
customer on a single line.

Part of the program will check whether a particular customer has enough points for a free
slice of cake.

Describe the algorithm for this part of the program using structured English.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

© UCLES 2021 9608/22/O/N/21


PAGE 694

(b) In another part of the program, the following statements assign values to variables.

DayOfMonth "15"
IsMember TRUE
DOB "22042001"
Firstname "Seanna"
Lastname "Adamson"
Points 12

Complete the table by writing the pseudocode expression that matches the description given
and the value that each expression evaluates to.

Refer to the Appendix on pages 18–19 for a list of built-in pseudocode functions and
operators.

Description of expression Pseudocode expression Evaluates to

Evaluates to TRUE if
DayOfMonth is within the
first seven days
of the month

Concatenates the second


and third letters of
Firstname with the last
three letters of Lastname

Evaluates to TRUE if DOB


contains eight characters

Evaluates to TRUE if the


customer is a member and
has enough points for a free
slice of cake

[4]

© UCLES 2021 9608/22/O/N/21 [Turn over


PAGE 695

(c) Another part of the loyalty scheme program will need to access additional files. A filename
contains a three-letter extension that represents its file type.

For example, the filename "thisfile.txt" has the extension "txt" and file type "Text".
The filename will always be in lower case.

A function GetFileType() returns a string containing the description of the file type.

The function uses selection constructs as follows:

FUNCTION GetFileType(Filename : STRING) RETURNS STRING


DECLARE FileExt : STRING
DECLARE FileType : STRING

FileExt RIGHT(Filename, 3)

IF FileExt = "rtf"
THEN
FileType "Rich text format"
ENDIF

IF FileExt = "csv"
THEN
FileType "Comma separated values"
ENDIF

IF FileExt = "txt"
THEN
FileType "Text"
ELSE
FileType "Unknown"
ENDIF

RETURN FileExt
ENDFUNCTION

Rewrite the function as follows:


• Replace the IF structures with a CASE structure.
• Correct the logic error in the function.

Refer to the Appendix on pages 18–19 for a list of built-in pseudocode functions and
operators.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2021 9608/22/O/N/21


PAGE 696

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]

3 (a) Describe the term decomposition when used to develop algorithms.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

(b) Explain the term transferable skills and state how these skills are used in program
development.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2021 9608/22/O/N/21 [Turn over


PAGE 697

4 A global 1D array Flower represents the flowers in a field and is defined as follows:
• The array contains 20 elements of type integer.
• Each element of the array contains a number associated with each flower.

(a) A procedure, InitialiseArray(), initialises the array Flower by setting the value of each
element to –1.

Write pseudocode for the procedure InitialiseArray().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]

© UCLES 2021 9608/22/O/N/21


PAGE 698

(b) A procedure called RandomPath() assigns values to the array Flower to store a path
through the flowers in the fields as follows:

• the first flower to be visited is flower number 10


• randomly select the next flower to be visited between 1 and 20
• store the index of the next flower to be visited in the current element of the array Flower
if the flower has not been visited
• visit each flower only once
• repeat until the path has been completed through all flowers.

An element of –1 indicates that a flower has not been visited.

Write program code for the procedure RandomPath().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2021 9608/22/O/N/21 [Turn over


PAGE 699

10

(c) The procedure RandomPath() executes but gives an unexpected result.

(i) State the type of program error that has occurred and identify how this error can be
detected.

Type of program error .......................................................................................................

Method of detection ...........................................................................................................

...........................................................................................................................................
[2]

(ii) Assume that the random number has been incorrectly generated in the procedure
RandomPath().

State two possible consequences of the incorrect use of the random number function.

1 ........................................................................................................................................

...........................................................................................................................................

2 ........................................................................................................................................

...........................................................................................................................................
[2]

5 The pseudocode for a procedure FormatYear() is written as follows:

PROCEDURE FormatYear(Year : INTEGER, UseSuffix : BOOLEAN)

DECLARE OutYear : STRING


CONSTANT SUFFIX1 = "BCE"
CONSTANT SUFFIX2 = "CE"

OutYear NUM_TO_STRING(Year)

IF UseSuffix = TRUE
THEN
IF Year < 0
THEN
OutYear OutYear & SUFFIX1
ELSE
OutYear OutYear & SUFFIX2
ENDIF
ENDIF
OUTPUT OutYear
ENDPROCEDURE

© UCLES 2021 9608/22/O/N/21


PAGE 700

11

(a) Draw a program flowchart to represent the algorithm for the module.

Variable and constant declarations are not required in program flowcharts.

[5]

© UCLES 2021 9608/22/O/N/21 [Turn over


PAGE 701

12

(b) For each of the following tests, choose three values of the parameters Year and UseSuffix
that test three different aspects of the procedure FormatYear().

State the expected output in each case.

Test 1

Parameter Value Expected output

Year

UseSuffix

Test 2

Parameter Value Expected output

Year

UseSuffix

Test 3

Parameter Value Expected output

Year

UseSuffix

[6]

(c) (i) Describe two features of black-box testing.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(ii) Describe two features of white-box testing.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2021 9608/22/O/N/21


PAGE 702

14

6 A geocode string consists of four characters that are followed by:


• the character '+'
• two more characters
• a comma
• a description of the location.

For example:
• The geocode string for Cambridge, UK is "646A+6R,CambridgeUK".
• The geocode string for Chicago, USA is "V9PG+3P,ChicagoUSA".

A program uses two 1D arrays to store data about the locations in which photographs were taken.

• An array GeoCodeData contains a geocode string for each location. A geocode string is
added to this array if it does not exist in the array.

• An array GeoCodeLog contains the first seven characters of the geocode string for each
photograph, followed by a space and the date when the photograph was taken. The date
format is DD/MM/YYYY.

For example, a photograph taken in Cambridge, UK on 21/12/2020 is represented as:

"646A+6R 21/12/2020"

Assume that:
• both arrays contain 20 000 elements
• new data is added to the next unused element
• unused array elements are indicated by the string "AAAA+0A".

(a) A programmer has started to define the program module SearchLog().

Module Description
• takes the first seven characters of a geocode as a parameter
• counts the number of times this parameter occurs in the array
GeoCodeLog
SearchLog()
• extracts the date the last photograph was taken at the geocode location
• returns a string formed by concatenating the count, a single space and
the date

Write pseudocode for the module SearchLog().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2021 9608/22/O/N/21


PAGE 703

15

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]
© UCLES 2021 9608/22/O/N/21 [Turn over
PAGE 704

16

(b) A text file, Locations.txt, stores data from the array GeoCodeData combined with data
extracted from the array GeoCodeLog. Each line of the text file contains three items of data in
the following format:

• The geocode stored in each element of the array GeoCodeData followed by a hash
symbol (#).
• The number of times each geocode is found in the array GeoCodeLog followed by the
hash symbol.
• The date of the last photograph taken at that location.

For example, twelve photographs were taken at geocode V9PG+3P,ChicagoUSA.


The last photograph was taken on 09/10/2020.

The corresponding entry in the file Locations.txt is:

"V9PG+3P,ChicagoUSA#12#09/10/2020"

The program module ExtractArrays() is defined as follows:

Module Description
• creates the text file Locations.txt

ExtractArrays()
• uses SearchLog() to obtain the string of the count and the date of the
last photograph for each geocode location
• writes the entry in the text file Locations.txt

You may assume that unused elements of GeoCodeData array are not added to the file
Locations.txt.

Write program code for the module ExtractArrays().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2021 9608/22/O/N/21


PAGE 705

17

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]
© UCLES 2021 9608/22/O/N/21 [Turn over
PAGE 706

18

Appendix

Built-in functions (pseudocode)

Each function returns an error if the function call is not properly formed.

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString

Example: MID("ABCDEFGH", 2, 3) returns "BCD"

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString.

Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString

Example: LEFT("ABCDEFGH", 3) returns "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString

Example: RIGHT("ABCDEFGH", 3) returns "FGH"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: INT(27.5415) returns 27

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value
Note: This function will also work if x is of type INTEGER

Example: NUM_TO_STRING(87.5) returns "87.5"

STRING_TO_NUM(x : STRING) RETURNS REAL


returns a numeric representation of a string
Note: This function will also work if x is of type CHAR

Example: STRING_TO_NUM("23.45") returns 23.45

RAND(x : INTEGER) RETURNS REAL


returns a real number in the range 0 to x (not inclusive of x)

Example: RAND(87) could return 35.43

© UCLES 2021 9608/22/O/N/21


PAGE 707

19

Operators (pseudocode)

Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE

© UCLES 2021 9608/22/O/N/21


PAGE 708

Cambridge International AS & A Level


* 3 2 6 3 2 2 9 2 3 5 *

COMPUTER SCIENCE 9608/23


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2021
2 hours

You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.

This document has 24 pages. Any blank pages are indicated.

DC (PQ/CGW) 208684/3
© UCLES 2021 [Turn over
PAGE 709

1 (a) An algorithm contains the following steps:

1. prompt and input a product number


2. validate the product number
3. save the validated product number to FILE_A.txt

(i) Write the pseudocode statement for step 1.

...........................................................................................................................................

.......................................................................................................................................[2]

(ii) State the purpose of FILE_A.txt.

...........................................................................................................................................

.......................................................................................................................................[1]

(b) State two benefits of creating program flowcharts when documenting a program.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................
[2]

(c) Draw one line from each technical term to its appropriate description.

Technical term Description

Stores data of the same data type


Corrective maintenance
in memory

Amends an algorithm following


Array
identification of errors

Amends an algorithm in response


Adaptive maintenance
to specification changes

Shows parameters passed between


Structure chart
program modules

[3]

© UCLES 2021 9608/23/O/N/21


PAGE 710

(d) The following pseudocode procedure, SetupVars(), initialises the variables used to check
the status of a product.

PROCEDURE SetupVars()
Description "CONCRETE-SLAB"
Destination "ELY"
Mileage 200
EndOfYear 1
Limit 20000
Overdue FALSE
ENDPROCEDURE

Complete the table by evaluating each pseudocode expression.

If the expression is invalid, write “ERROR” in the Evaluates to column.

Refer to the Appendix on pages 22–23 for a list of built-in pseudocode functions and
operators.

Pseudocode expression Evaluates to

EndOfYear * Limit / Mileage

LENGTH(Description) / NUM_TO_STRING(Limit)

MOD(20, LENGTH(Destination))

(EndOfYear < 2) AND (Limit = 20000) AND NOT(Overdue)

MID(Description, 1, 5) & LEFT(Destination, 2)


& NUM_TO_STRING(Limit / 1000)

[5]

© UCLES 2021 9608/23/O/N/21 [Turn over


PAGE 711

2 A company owns 50 cars that are available for hire. The cars are numbered from 1 to 50. The size
of a car can be small, medium, or large.

The following pseudocode procedure, SetOut(), takes as input the size of the car the customer
has requested for hire and outputs details of the cars that are available for hire for that size of car.

Line numbers are given for reference only.

Refer to the Appendix on pages 22–23 for a list of built-in pseudocode functions and operators.

01 DECLARE Available : ARRAY[1:50] OF BOOLEAN


02 DECLARE CarSize : ARRAY[1:50] OF STRING
03
04 PROCEDURE SetOut(Size: STRING)
05 DECLARE Index : REAL
06
07 FOR Index 0 TO 50
08 IF Size = CarSize[Index] AND Available[Index] = "TRUE"
09 THEN
10 OUTPUT NUM_TO_STRING(Index) & ": " & Size & " Available"
11 ENDIF
12 ENDFOR
13
14 ENDPROCEDURE

(a) Complete the table by identifying four line numbers that contain errors and give the correct
pseudocode statement.

Line number Correct pseudocode statement

[4]

© UCLES 2021 9608/23/O/N/21


PAGE 712

(b) Study the pseudocode algorithm on page 4.

Describe the algorithm using structured English.

Do not use pseudocode or program code in your answer.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]

(c) The function PayUsingAccount() is required to process a payment for hiring a car as
follows:

1. The function takes two parameters with REAL data type:

• Balance is the amount of money in the account


• CostOfHire is the cost of hiring the car.

2. If CostOfHire exceeds Balance, the rental is not authorised and FALSE is returned,
otherwise TRUE is returned.

Write pseudocode for the function PayUsingAccount().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]
© UCLES 2021 9608/23/O/N/21 [Turn over
PAGE 713

3 The function AddressChecker() checks if an email address is in the format:

<user>@<host>•<domain>

The design requirements of the function are:

• The <user> contains only lower-case characters.


• The <domain> contains exactly three alphabetic characters.

AddressChecker() will use three functions as described in the following table.

Function Description

Split() • Takes two parameters:


• a STRING value containing the email address
• a BOOLEAN value representing the required return value

• Returns two different values:


• a STRING containing <user> if the BOOLEAN parameter
value is TRUE
• a STRING containing <domain> if the BOOLEAN
parameter value is FALSE
IsLowerCase() • Takes an element of the email address as a STRING
parameter

• Returns a BOOLEAN value of TRUE if the string contains only


lower-case characters, otherwise returns FALSE
IsThreeLetter() • Takes the domain as a STRING parameter

• Returns a BOOLEAN value of TRUE if the string consists of


exactly three alphabetic characters, otherwise returns FALSE

AddressChecker() will:

• prompt and input an email address


• check that the email address is valid
• return the string "Invalid" if the email address does not meet the design requirements,
otherwise return the email address.

© UCLES 2021 9608/23/O/N/21


PAGE 714

(a) Draw a program flowchart to represent the algorithm for the AddressChecker() function.

Variable declarations are not required in program flowcharts.

[6]
© UCLES 2021 9608/23/O/N/21 [Turn over
PAGE 715

(b) The function AddressChecker() is changed to check a list of email addresses stored in a
text file.

The function’s header is changed as follows:

FUNCTION AddressChecker(Filename : STRING, StartLine : INTEGER,


LastLine : INTEGER) RETURNS BOOLEAN

Assume that:

• The function is called with a valid filename of the text file.


• The text file exists and contains at least one email address.
• Each email address is stored in a separate line in the text file.
• The function does not contain logical errors.

Give two reasons why the function may return an unexpected result.

Reason 1 ..................................................................................................................................

...................................................................................................................................................

Reason 2 ...................................................................................................................................

...................................................................................................................................................
[2]

(c) (i) Explain what is meant by the term syntax error.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(ii) Give an example of a syntax error in program code.

Programming language .....................................................................................................

Program code

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [1]

© UCLES 2021 9608/23/O/N/21


PAGE 716

(d) The following incomplete structure chart shows part of the design of the function
AddressChecker().

Complete the structure chart.

AddressChecker()

IsThreeLetter()

[3]

(e) State and describe two features of an Integrated Development Environment (IDE) that aid
debugging.

Feature 1 ..................................................................................................................................

...................................................................................................................................................

Description ................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Feature 2 ..................................................................................................................................

...................................................................................................................................................

Description ................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[4]

© UCLES 2021 9608/23/O/N/21 [Turn over


PAGE 717

10

4 The following pseudocode contains a function that searches a text file for the string contained in
the parameter Match.

01 DECLARE MatchItems : ARRAY[1:100] OF STRING

10 FUNCTION Extract(FileName : STRING, Match : STRING,


Signal : INTEGER) RETURNS BOOLEAN
11
12 DECLARE FileLine : INTEGER
13 DECLARE Counter : INTEGER
14 DECLARE FileData, SubMatch : STRING
15 DECLARE Result : BOOLEAN
16
17 Counter 0
18 FileLine 1
19 Result FALSE
20
21 OPENFILE FileName FOR READ
22
23 WHILE NOT EOF(FileName) AND FileLine <= 100
24 READFILE FileName, FileData
25 SubMatch LEFT(FileData, LENGTH(Match))
26 IF SubMatch = Match
27 THEN
28 MatchItems[Counter] FileData
29 Counter Counter + 1
30 ENDIF
31 FileLine FileLine + 1
32 ENDWHILE
33
34 CLOSEFILE FileName
35 IF Counter >= Signal
36 THEN
37 Result TRUE
38 ENDIF
39 RETURN Result
40
41 ENDFUNCTION

(a) Complete the trace table when the function is called using this statement:

Present Extract("DATA.txt", "TG12367", 1)

You may assume that the text file DATA.txt contains the following lines:

"XD43668#23/11/19#DSCP"
"TG12367#24/01/19#MAHA"
"HD44356#24/11/19#MAHA"
"TG12367#24/11/19#GHFI"

© UCLES 2021 9608/23/O/N/21


PAGE 718

11

FileLine Counter LEFT(FileData, SubMatch = Match Result


LENGTH(Match))

[5]

(b) The function is changed as follows:

• The statement on line 25 is changed to compare the last ten characters of FileData
and the parameter Match.

If the comparison is successful:

• store the first seven characters of FileData in a global 1D array called Original
• store the last four characters of FileData in a global 1D array called Backup

• The count of the number of items stored in the array Backup is returned.

(i) Rewrite the function header in pseudocode so that it meets the new requirements.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2021 9608/23/O/N/21 [Turn over


PAGE 719

12

(ii) Rewrite the WHILE structure in pseudocode so that it meets the new requirements. The
WHILE structure is given here for reference.

23 WHILE NOT EOF(FileName) AND FileLine <= 100


24 READFILE FileName, FileData
25 SubMatch LEFT(FileData, LENGTH(Match))
26 IF SubMatch = Match
27 THEN
28 MatchItems[Counter] FileData
29 Counter Counter + 1
30 ENDIF
31 FileLine FileLine + 1
32 ENDWHILE

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

© UCLES 2021 9608/23/O/N/21


PAGE 720

14

(c) A procedure, Encrypt(), is required to encrypt the data stored in each line of the text file
DATA.txt.

You may assume that the text file DATA.txt contains the following lines:

"XD43668#23/11/19#DSCP"
"TG12367#24/01/19#MAHA"
"HD44356#24/11/19#MAHA"
"TG12367#24/11/19#GHFI"

The requirements of the procedure are:

• the day of the month from the line of data is extracted as the encryption key
• the encryption key is added to the ASCII value of each character of the line to form the
encrypted data
• the encrypted data are appended to the text file DATA-EN.txt until there are no more
lines in the text file DATA.txt

Write program code for the procedure Encrypt().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2021 9608/23/O/N/21
PAGE 721

15

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2021 9608/23/O/N/21 [Turn over


PAGE 722

16

5 A geocode string contains four alphanumeric characters, followed by the character '+' and then
two alphanumeric characters.

For example, the geocode string for the Avocado Restaurant in Cambridge UK is:

"1DFG+9N"

A website allows a user to upload a review of a restaurant.

A programmer has defined the following two arrays:

Array Description

GeoData • a global 1D array of data type STRING


• stores the geocode for each restaurant

Example:
GeoData[1] "1DFG+9N"
Review • a global 1D array of data type STRING
• stores the following data items as a single element in the array:
• the four-character user ID of the reviewer
• the geocode of the restaurant
• the text of the review
• the hash symbol (#) separates the data items in each single element

Example of a review for the Avocado restaurant submitted by user ID JH76:


Review[1000] "JH76#1DFG+9N#Good restaurant"

Assume that:

• both arrays are initialised with an empty string


• both arrays can store up to 20 000 elements
• new reviews are added in the next unused element of the Review array.

(a) The programmer writes a function CheckReview().

The design requirements of the function are shown in the following table:

Description Parameter Returns

• searches the • a STRING value • the comment from the review


GeoData array to containing the if the geocode exists in the
determine if the user’s user ID of the GeoData array
latest review contains reviewer
a listed geocode • a STRING value of "LOCATION
NOT FOUND" if the geocode of
the user’s review does not exist
in the GeoData array

• a STRING value of "NO


REVIEW" if no review exists for
the user ID

© UCLES 2021 9608/23/O/N/21


PAGE 723

17

Write pseudocode to complete the function CheckReview().

DECLARE GeoData : ARRAY[1:20000] OF STRING


DECLARE Review : ARRAY[1:20000] OF STRING
FUNCTION CheckReview(UserID : STRING) RETURNS STRING

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

ENDFUNCTION
[8]
© UCLES 2021 9608/23/O/N/21 [Turn over
PAGE 724

18

(b) Before a review is published on the website, it is checked to find out whether the review
contains a valid geocode.

The function AddReview() has the following requirements:

Description Parameters Returns

• calls CheckReview() • a STRING value • a BOOLEAN value of FALSE


containing the if the text of the review is not
• if the text of the review user ID of the added in the array Accepted,
is returned from reviewer otherwise returns a BOOLEAN
CheckReview(), value of TRUE
store the text in
the global 1D array
Accepted

Assume that:

• the 1D array Accepted is initialised with empty strings


• the array contains up to 20 000 elements.

Write program code for the function AddReview().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2021 9608/23/O/N/21
PAGE 725

19

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]

© UCLES 2021 9608/23/O/N/21 [Turn over


PAGE 726

20

(c) When reviewers write a review for a restaurant, they give the restaurant a score out of 10.

The 2D global array ReviewScores stores the review data as follows:

• The first column element stores the seven-character alphanumeric geocode string of the
restaurant with its average score, separated by the hash symbol (#).
• The second column element stores the comment from the review that has the highest
score.
The array has dimensions of 20 000 rows and 2 columns.

For example, the contents of the 2D array ReviewScores for review 20 are:

ReviewScores[20, 1] "1DFG+9N#8.3"
ReviewScores[20, 2] "Food was good but I waited too long"

The procedure BestRestaurants()is required as follows:

Description Parameter Output

• searches the array • a STRING value • if the parameter matches


ReviewScores for consisting of the a geocode in the array
restaurants with an geocode of the ReviewScores and the
average score that restaurant average score exceeds
exceeds 8.0 8.0, output the geocode
concatenated with the review
comment

Write pseudocode for the procedure BestRestaurants().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2021 9608/23/O/N/21
PAGE 727

21

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

© UCLES 2021 9608/23/O/N/21 [Turn over


PAGE 728

22

Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.

ASC(ThisChar : CHAR) RETURNS INTEGER


returns the ASCII value of ThisChar
Example: ASC('A') returns 65

CHR(x : INTEGER) RETURNS CHAR


returns the character whose ASCII value is x
Example: CHR(87) returns 'W'

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of string ThisString
Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString
Example: LEFT("ABCDEFGH", 3) returns "ABC"

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString
Example: MID("ABCDEFGH", 2, 3) returns "BCD"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString
Example: RIGHT("ABCDEFGH", 3) returns "FGH"

MOD(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the remainder when ThisNum is divided by ThisDiv
Example: MOD(10,3) returns 1

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value
Note: This function will also work if x is of type INTEGER
Example: NUM_TO_STRING(87.5) returns "87.5"

STRING_TO_NUM(x : STRING) RETURNS REAL


returns a numeric representation of a string
Note: This function will also work if x is of type CHAR
Example: STR_TO_NUM("23.45") returns 23.45

© UCLES 2021 9608/23/O/N/21


PAGE 729

23

Operators (pseudocode)
Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE

© UCLES 2021 9608/23/O/N/21

You might also like