P2 Pseudocode - Topical and Yearly
P2 Pseudocode - Topical and Yearly
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
2018
- 9608/22 – May/June 2018 – Page 187
- 9608/23 – May/June 2018 – Page 202
- 9608/22 – October/November 2018 – Page 217
2019
- 9608/22 – May/June 2019 – Page 243
- 9608/23 – May/June 2019 – Page 258
- 9608/22 – October/November 2019 – Page 275
2021
- 9608/22 – May/June 2021 – Page 652
- 9608/23 – May/June 2021 – Page 669
- 9608/22 – October/November 2021 – Page 690
2022
- 9618/22 – May/June 2022 – Page 441
- 9618/23 – May/June 2022 – Page 459
- 9618/22 – October/November 2022 – Page 476
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:
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
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
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
CALL
CalculatePoints(AmountDue)
PAGE 37
PAGE 38
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
Temp
PAGE 43
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
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
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
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
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 …………………………………………………………
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
TRUE TRUE
TRUE FALSE
FALSE TRUE
FALSE FALSE
PAGE 51
03 08
PAGE 52
INPUT Purchase
CurrentValue
YearCount 1
WHILE AND
IF
THEN
CurrentValue CurrentValue * (1 – 40 / 100)
ELSE
CurrentValue
ENDIF
ENDWHILE
PAGE 55
PAGE 56
BOOLEAN
InitialiseTaskGrid
13 18
03
PAGE 58
17
StaffNum
StaffName
PAGE 59
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
FOR i 1 TO CHARACTERCOUNT(MyString)
NextNum ASC(ONECHAR(MyString, i))
StringTotal StringTotal + NextNum
ENDFOR
StringTotal
MyString.
PAGE 61
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 "3/7+2/9"
ONECHAR(FractionString, )
N1 INTEGER N1Char
N2 INTEGER N2Char
N3 INTEGER N3Char
N4 INTEGER N4Char
TopAnswer INTEGER
BottomAnswer INTEGER
PAGE 63
FractionString
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
DECLARE n : INTEGER
.............................//concatenate to OutString
ENDFOR
.............................................................
ENDFUNCTION
PAGE 71
Lookup
Lookup
Lookup
START
Input
Input
n 0
Loop
Input
Increment
No
Yes
Output message
stating number of
elements changed
STOP
PAGE 73
PAGE 74
PAGE 75
MyMusic
MyMusic
InputData
CDTitle STRING
CDArtist STRING
CDLocation STRING
PAGE 77
InputData
PAGE 78
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
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
y x ThisString
MID("ABCDEFGH", 2, 3) "BCD"
x ThisString
LEFT("ABCDEFGH", 3) "ABC"
x ThisString
RIGHT("ABCDEFGH", 3) "FGH"
ThisChar
ASC( W ) 87
ThisString
LENGTH("Happy Days") 10
&
START
Input
p and
Loop
Produce from
(using built-in function)
End of NO
loop?
YES
STOP
PAGE 88
PAGE 89
E
A F
C
PlayerName STRING
PlayerGameGrade CHAR
PointsTotal INTEGER
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
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
PAGE 109
02.3
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
Answer1
Answer2
Answer3
PAGE 113
Position
ThisString
ThisString
CHARACTERCOUNT("New York") 8
ThisString
Value1
Value2
ThisString
TONUM("502") 502
TONUM("56.36") 56.36
ThisCharacter
ASC('A') 65
PAGE 114
Value
CHR(65) 'A'
RND() 0.67351
ThisNumber
INT(12.79) 12
1 Charge 0
2 INPUT BaggageWeight
4 Is ExcessWeight > 0 ?
5 INPUT TicketType
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
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
Answer2
Word
PAGE 123
PROCEDURE CalculateCustomerID
INPUT Surname
Length
CustomerID 0
FOR i 1 TO Length
NextChar
NextCodeNumber ASC(NextChar)
CustomerID CustomerID +
ENDFOR
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
OPEN
i 1
WHILE
READFILE ("PRODUCTS",
READFILE ("PRODUCTS",
READFILE ("PRODUCTS",
ENDWHILE
CLOSE "PRODUCTS"
PRODUCTS PRODUCTS
0198 Plums(10kg) 11.50
0202 Onions(20kg) 10.00
SearchCode STRING
ThisIndex INTEGER
ThisDescription STRING
ThisRetailPrice REAL
PRODUCTS
PAGE 130
ProductCodeSearch
PCode
ProductCodeSearch
PAGE 131
Base 2.6
Height 10
Radius 1
Height 2
a 13
b 7
c 3
Total 34
Total Total - 2
Answer2 a + c * c
Triangle
Cone
Answer1
Total
Answer2
PAGE 132
Position
ThisString
ThisString
CHARACTERCOUNT("New York") 8
ThisString
Value1
Value2
ThisString
TONUM("502") 502
TONUM("56.36") 56.36
ThisCharacter
ASC('A') 65
PAGE 133
Value
CHR(65) 'A'
RND() 0.67351
ThisNumber
INT(12.79) 12
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.
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.
DC (NH/CT) 150983/3
© UCLES 2018 [Turn over
PAGE 218
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]
Give the most appropriate data type for the variable used in each statement.
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]
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 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.
START
Is YES
Total > 100 ?
OldPoints
NO GetPoints(CardNum)
Is NO
OldPoints > 2000 ?
YES
RETURN NewPoints
END
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[7]
(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.
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.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
ENDFUNCTION
[5]
(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]
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]
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]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[2]
(c) A program needs to search through 1000 elements of an unsorted array to find a given value.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[4]
© UCLES 2018 9608/22/O/N/18
PAGE 224
10
Answer
(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.
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.
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]
...........................................................................................................................................
.......................................................................................................................................[1]
Write program code to declare ResultArray and set all elements to the value "NO DATA".
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[3]
14
For example, when the procedure reads MyFile.txt, the output is:
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.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
© 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.
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.
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
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.
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.
DC (NH/CT) 151783/3
© UCLES 2018 [Turn over
PAGE 231
Repetition
Statement Assignment Selection
(Iteration)
CASE OF TempSensor1
ELSE
REPEAT
ENDFOR
DayNumber DayNumber + 1
Error TRUE
[6]
Give the most appropriate data type for the variable used in each statement.
Complete the table by evaluating each expression using the values from part (b)(i).
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]
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.
START
Points
GetPoints(CardNum)
Spend
GetSpend(CardNum)
Is YES
Points > 2000 ?
NO
Is YES
Spend > 1000 ?
NO
RETURN Bonus
END
Your solution should follow the flowchart for the function as closely as possible.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[5]
(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').
You should refer to the function IS_NUM() in the Appendix on page 16.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
ENDFUNCTION
[6]
© UCLES 2018 9608/23/O/N/18
PAGE 235
(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]
State two different pairs of values for Spend and Points that can be used to test
different paths through the function. Justify your choices.
Justification .......................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
Justification .......................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[4]
(c) Name two types of program maintenance and state the reason why each is needed.
Name ........................................................................................................................................
Reason .....................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Name ........................................................................................................................................
Reason .....................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[4]
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.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[3]
10
…
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.
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.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[8]
© UCLES 2018 9608/23/O/N/18 [Turn over
PAGE 239
12
Describe the mechanism that supports the transfer of values between modules.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[2]
Write program code to change all the numeric characters ('0' to '9') in CharArray
to '*'.
Program code
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[3]
.......................................................................................................................................[1]
14
15
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
....................................................................................................................................................[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.
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
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.
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.
DC (ST/CT) 163546/4
© UCLES 2019 [Turn over
PAGE 244
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
..................................................................................................................
.........................
..................................................................................................................
..................................................................................................................
.........................
..................................................................................................................
..................................................................................................................
Output
..................................................................................................................
[5]
Variable Value
Married 03/04/1982
ID "M1234"
MiddleInitial 'J'
Height 5.6
IsMarried TRUE
Children 2
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]
Give an appropriate data type for the following variables from part (b).
...........................................................................................................................................
..................................................................................................................................... [1]
1 ........................................................................................................................................
...........................................................................................................................................
2 ........................................................................................................................................
...........................................................................................................................................
3 ........................................................................................................................................
...........................................................................................................................................
[3]
Answer 23 + DoSomething("Yellow")
Justification .......................................................................................................................
...........................................................................................................................................
[2]
(b) The program development cycle involves writing, translating and testing a high-level language
program.
• 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.
Identify the type of control structure and describe the function of the code.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[3]
3 The following structure chart shows the relationship between three modules.
TopLevel
B
D
A C
E
SubA SubB
A, D : STRING
C : CHAR
B, E : INTEGER
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [3]
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [3]
(b) Module hierarchy and parameters are two features that may be represented on a structure
chart.
Feature 1 ..................................................................................................................................
Feature 2 ..................................................................................................................................
[2]
For the built-in functions list, refer to the Appendix on page 16.
NewString '0'
Selected 0
ENDFOR
RETURN Selected
ENDFUNCTION
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.
[5]
(ii) State the value returned by the function when it is called as shown in part (a)(i).
....................................... [1]
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.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
11
(b) A procedure, CountLines(), is being written to count the number of lines in a text file. The
procedure will:
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
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 consist of three separate modules. Each module will be implemented using
either a procedure or a function.
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
Nadine has decided that global variables and nested modules must not be used.
13
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.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
© UCLES 2019 9608/22/M/J/19 [Turn over
PAGE 255
14
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.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
© UCLES 2019 9608/22/M/J/19
PAGE 256
15
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [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.
16
Appendix
Operators (pseudocode)
Operator Description
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.
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.
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.
PROCEDURE Search()
ThisChar Message[1]
ThisRun 1
LongRun 1
IF Message[Index] = ThisChar
THEN
ThisRun ThisRun + 1
ELSE
ThisChar Message[Index]
IF ThisRun > LongRun
THEN
LongRun ThisRun
ENDIF
ThisRun 1
ENDIF
ENDFOR
ENDPROCEDURE
[6]
© UCLES 2019 9608/23/M/J/19 [Turn over
PAGE 261
Variable Value
MeltingPoint 180.5
Soluble FALSE
Attempt 3
ProductName "Mushroom Compost"
Version 'A'
ProductID "BZ27-4"
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]
Give an appropriate data type for the following variables from part (b)(i).
Soluble
Attempt
Version
ProductID
[5]
2 (a) A student is learning about arrays. She wants to write a program to:
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
(b) She uses the process of stepwise refinement to develop her algorithm.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
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]
3 The following pseudocode represents three separate modules from an algorithm design. The
module contents are not shown.
ENDFUNCTION
ENDFUNCTION
ENDPROCEDURE
PROCEDURE Setup()
Authorised Allocate()
CALL Enable(ThisValue, 4)
ENDWHILE
ENDPROCEDURE
(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.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
10
4 A program is being written to process student information. One task involves inputting the names
of all students in a class.
(a) Re-write the pseudocode to perform this task in a more efficient way, to allow for the class of
40 students.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
............................................................................................................................................. [1]
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.
NumWords 0
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.
...........................................................................................................................................
..................................................................................................................................... [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]
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.
String .................................................................................................................................
Explanation .......................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[3]
String 1: "Red|and|Yellow"
String 2: "Green||and||Pink|"
Describe the changes that would need to be made to the algorithm to give the correct
output in each case.
String 1 ..............................................................................................................................
Description ........................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
String 2 ..............................................................................................................................
Description ........................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[6]
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:
"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 "".
For each name contained in the ClassList array, the program will:
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)
15
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.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
© UCLES 2019 9608/23/M/J/19 [Turn over
PAGE 272
16
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [9]
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().
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
18
Appendix
Each function returns an error if the function call is not properly formed.
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
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.
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.
DC (ST) 171121/3
© UCLES 2019 [Turn over
PAGE 276
PROCEDURE FillTank()
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.
Feature 1 ...........................................................................................................................
Feature 2 ...........................................................................................................................
Feature 3 ...........................................................................................................................
[3]
(ii) Draw a program flowchart to represent the algorithm implemented in the pseudocode.
Variable declarations are not required in program flowcharts.
[5]
Complete the table by giving a suitable data type for each example value.
43
TRUE
í
í
[4]
,IDQH[SUHVVLRQLVLQYDOLGWKHQZULWH¶(5525·
Refer to the Appendix on page 18 for the list of built-in functions and operators.
Expression Evaluates to
,17
[4]
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]
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.
• 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.
Write pseudocode to declare the array and to initialise all elements to zero.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
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]
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:
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.
(a) Write pseudocode for the procedure Button(). Declare any additional variables you use.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
© UCLES 2019 9608/22/O/N/19 [Turn over
PAGE 284
10
Fill in the gaps below to define three tests that could be carried out.
Parameter value: 10
0D[9RO: ..................
Parameter value: 10
0D[9RO: 34
0D[9RO: 40
[6]
11
(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.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [3]
12
5 The module headers for three modules in a program are defined in pseudocode as follows:
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]
14
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>
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 "".
The program is to be implemented as several modules. The outline description of three of these is
as follows:
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.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
16
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
© 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.
Write a statement in program code that uses CountTimes() to assign the count of unused
elements to the variable Result.
Program code
...................................................................................................................................................
............................................................................................................................................. [3]
18
Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.
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
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.
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.
DC (ST/SG) 171122/4
© UCLES 2019 [Turn over
PAGE 293
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.
Complete the table by naming three different data types together with an example data
value for each.
[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.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
Complete the table below. Write each example statement in program code.
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]
(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.
Feature 1 ..................................................................................................................................
Feature 2 ..................................................................................................................................
Feature 3 ..................................................................................................................................
[3]
Identify the type of testing that includes the use of a trace table.
............................................................................................................................................. [1]
Type ..................................................................................................................................
Explanation .......................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[2]
LOOP
AlarmReset()
Set Status1 to
GetStatus(Sys_A)
Set Status2 to
GetStatus(Sys_B)
Are Status1
NO
and Status2
both TRUE?
YES
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [4]
(b) The following lines of code are taken from a high-level language program.
Study the code. Identify the relevant features in the following table.
Feature Answer
The line numbers for the start and end of a count-controlled loop
Identify one type of translator that can be used to translate the program.
............................................................................................................................................. [1]
3 Three program modules process updating of passwords in a file. A description of the relationship
between the modules is summarised as follows:
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]
4 The following pseudocode algorithm checks whether a string is a valid email address.
NumDots 0
NumAts 0
NumOthers 0
ENDFOR
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]
(b) (i) Complete the trace table by dry running the function when it is called as follows:
Result Check("Jim.99@skail.com")
[5]
(ii) State the value returned when function Check is called as shown in part (b)(i).
..................................................................................................................................... [1]
10
State two different invalid string values that could be used to test the algorithm. Each string
should test a different rule.
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
A function, Abbreviate(), will take a string representing the full name and return a string
containing the abbreviated form.
11
Refer to the Appendix on page 16 for the list of built-in functions and operators.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [8]
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:
102 "978-14-56543-21-8"
103 "BD345"
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.
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [3]
13
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.
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.
Title Location
Learning Python BD345
Arrays are not lists CZ562
Learning Java CZ589
15
Refer to the Appendix on page 16 for the list of built-in functions and operators.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
16
Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.
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
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.
DC (RW/TP) 180777/4
© UCLES 2020 [Turn over
PAGE 309
Name ........................................................................................................................................
Description ................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[3]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
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]
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.
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
(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]
(ii) Complete the structure chart for the six modules described in part (b).
Shop()
[6]
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:
START
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
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.
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]
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>
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]
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.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [4]
12
(ii) A procedure, BubbleSort(), is needed to sort the 1D array Contact into ascending
order of Name using an efficient bubble sort algorithm.
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.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [8]
13
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:
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.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
15
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [8]
...........................................................................................................................................
..................................................................................................................................... [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]
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.
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.
<BoatNumber><Date><AmountPaid>
The total hire amount from each boat is to be stored in a global array, Total. This array is
declared in pseudocode 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
17
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.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
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
Operators (pseudocode)
Operator Description
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.
DC (RW/TP) 180778/4
© UCLES 2020 [Turn over
PAGE 326
State when you would produce an algorithm during program development and state its
purpose.
When ........................................................................................................................................
...................................................................................................................................................
Purpose ....................................................................................................................................
...................................................................................................................................................
[2]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [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]
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.
Feature 1 ..................................................................................................................................
...................................................................................................................................................
Feature 2 ..................................................................................................................................
...................................................................................................................................................
[2]
(b) The following structure chart shows the relationship between three modules.
ModuleA()
ParW
ParX
ParZ
ModuleB() ModuleC()
ParW : REAL
ParX : INTEGER
ParZ : STRING
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [3]
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [3]
(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.
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.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
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.
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
State how the given trace table indicates the existence of each error.
Error 1 ...............................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
Error 2 ...............................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[2]
10
(ii) Give the line number of each error in the pseudocode algorithm and write the modified
pseudocode to correct each error.
...........................................................................................................................................
...........................................................................................................................................
[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>
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.
11
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.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
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.
...................................................................................................................................................
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.
<BoatNumber><Date>
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"
13
Refer to the Appendix on page 19 for a list of built-in pseudocode functions and operators.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
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.
<Date><BoatNumber><HireDuration>
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)
Note:
15
Refer to the Appendix on page 19 for a list of built-in pseudocode functions and
operators.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [8]
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]
Module Description
• Takes an integer as a parameter that represents the maximum
number of hours before a boat must be serviced
• 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
17
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.
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.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(iii) Explain how single stepping may be used to help find a logic error in a program.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
19
Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.
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
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.
DC (CJ) 188580/2
© UCLES 2020 [Turn over
PAGE 343
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]
Complete the table by giving four different data types together with an example data value
for each.
[4]
(d) Draw lines to connect each of the following computing terms with the appropriate description.
Term Description
[3]
FlagA TRUE
FlagB FALSE
FlagC TRUE
Expression Evaluates to
[2]
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
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
© UCLES 2020 9608/22/O/N/20
PAGE 346
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
Use only functions and operators described in the Appendix on pages 18–19.
Expression Evaluates to
.......................... (9, 4) 2
[5]
1 ................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
3 ................................................................................................................................................
...................................................................................................................................................
[3]
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.
• 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.
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.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
(b) Give two sets of test data that could be used to test the function.
[2]
4 (a) The following structured English describes an algorithm used to count the number of odd and
even digits in an input sequence.
[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.
Len1 LENGTH(String1)
RetFlag TRUE
RETURN RetFlag
ENDFUNCTION
11
(i) Complete the trace table below by performing a dry run of the function when it is called
as follows:
[5]
..................................................................................................................................... [1]
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 .............................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
(iv) Describe the modification that needs to be made to the algorithm to correct the error.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [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]
13
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.
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"
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
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
© UCLES 2020 9608/22/O/N/20
PAGE 356
15
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
© UCLES 2020 9608/22/O/N/20 [Turn over
PAGE 357
16
Module Description
• Values from the text file Backup.txt are stored in the
LoadArrays() two arrays
• The number of elements stored is returned
• 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.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
© UCLES 2020 9608/22/O/N/20
PAGE 358
17
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
18
Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.
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
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.
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.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [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.
[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.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
Refer to the Appendix on page 16 for the list of built-in functions and operators.
Statement Error
Hour MID("ALARM:12:02", 7, 6)
Size LENGTH(27.5)
[5]
© UCLES 2020 9608/23/O/N/20 [Turn over
PAGE 364
Set Index to 0
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.
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.
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.
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.
PROCEDURE Search()
DECLARE Index : INTEGER
• either the index value where the search value is first found
• or –1 if the search value is not found.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
(b) A change to the specification in part (a) required a modification of the algorithm.
............................................................................................................................................. [1]
............................................................................................................................................. [1]
Output Explanation
.........................................................................................................
First
value
..................... .........................................................................................................
(line 14)
.........................................................................................................
.........................................................................................................
Second
value
..................... .........................................................................................................
(line 17)
.........................................................................................................
[4]
(e) The procedures ProcA and ProcB in part (d) are examples of program modules.
1 ................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
[2]
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.
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
11
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
12
Module Description
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.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
© UCLES 2020 9608/23/O/N/20
PAGE 373
13
Module Description
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.
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.
You can assume that the arrays contain data for at least one hashtag.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
© UCLES 2020 9608/23/O/N/20
PAGE 375
15
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................ . [8]
16
Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.
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.
2 hours
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.
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.
(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.
X S2
S1
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]
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.
Operation 1 .......................................................................................................................
...........................................................................................................................................
Operation 2 .......................................................................................................................
...........................................................................................................................................
[2]
A B
Dolphin Cat Fish Elk
............................................................................................................................................. [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.
Term ..........................................................................................................................................
Meaning ....................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[2]
(d) Complete the diagram to show the ADT after the data has been sorted in alphabetical order.
[2]
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.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [6]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [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]
Answer
...........................................................................................................................................
..................................................................................................................................... [2]
10
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.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
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.
............................................................................................................................................. [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.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
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.
For example:
• 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.
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
13
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
14
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
© UCLES 2021 9618/22/M/J/21
PAGE 390
2 hours
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.
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.
Example
Explanation Variable name Data type
value
(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
[5]
(c) The following data items need to be stored for each student in a group:
Structure ...................................................................................................................................
Justification ...............................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[3]
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
...................................................................................................................................................
............................................................................................................................................. [2]
[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:
Suggest how data relating to each booking may be stored in a text file.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
10
4 Study the following pseudocode. Line numbers are for reference only.
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.
"|in|a||Cup"
[5]
12
...................................................................................................................................................
Justification ...............................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[2]
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.
...........................................................................................................................................
.......................................................................................................................................[1]
Write the number of the line to be moved and state its new position.
...........................................................................................................................................
[2]
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.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
15
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [8]
16
6 The following diagram represents an Abstract Data Type (ADT) for a linked list.
A C D E Ø
(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]
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.
For example:
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.
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"
19
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
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.
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]
21
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"
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
© UCLES 2021 9618/23/M/J/21
PAGE 408
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.
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]
ThisArray[n] ĸ 42
Complete the following table by writing the answer for each row.
Answer
(c) Complete the pseudocode expressions so that they evaluate to the values shown.
Expression Evaluates to
67
.......................................... ('C')
54
2 * ......................................... ("27")
13
................................ (27 / .................................)
[4]
(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
PumpOn OR PressureOK
[5]
© UCLES 2021 9618/22/O/N/21 [Turn over
PAGE 413
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.
Reason ..............................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[2]
State three activities that will take place during the design stage of the program
development life cycle.
1 ........................................................................................................................................
2 ........................................................................................................................................
3 ........................................................................................................................................
[3]
Data will be stored about each student in the school and each student may join up to three clubs.
The programmer has started to define the fields that will be needed as shown in the following
table.
(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.
...........................................................................................................................................
..................................................................................................................................... [2]
...........................................................................................................................................
..................................................................................................................................... [1]
...........................................................................................................................................
..................................................................................................................................... [1]
© UCLES 2021 9618/22/O/N/21
PAGE 415
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
© UCLES 2021 9618/22/O/N/21 [Turn over
PAGE 416
10
(a) Complete the following table by giving the answers, using the given pseudocode.
Answer
A line number containing a variable being incremented
(b) The pseudocode includes several features that make it easier to read and understand.
1 ................................................................................................................................................
2 ................................................................................................................................................
3 ................................................................................................................................................
[3]
11
(c) (i) The loop structure used in the pseudocode is not the most appropriate.
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]
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:
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
© UCLES 2021 9618/22/O/N/21
PAGE 419
13
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
14
...........................................................................................................................................
..................................................................................................................................... [1]
(ii) State one advantage and one disadvantage of the alternative format.
Advantage .........................................................................................................................
...........................................................................................................................................
Disadvantage ....................................................................................................................
...........................................................................................................................................
[2]
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.
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 programmer has decided to use global values CentreRow and CentreCol as coordinate
values for the centre point.
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
17
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [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]
19
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
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
© UCLES 2021 9618/22/O/N/21
PAGE 425
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.
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.
Description ........................................................................................................................
...........................................................................................................................................
[2]
(b) Complete the following table by giving the appropriate data type in each case.
(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.
(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]
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]
START
Set Count to 1
Is Flag = YES
FALSE AND
Count <= 5 ?
NO
ReBoot()
Is Flag = YES
FALSE ?
NO
Alert(27)
END
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
............................................................................................................................................................ [6]
3 (a) The diagram below represents a queue Abstract Data Type (ADT) that can hold a maximum
of eight items.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [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]
(b) Some operations are carried out on the original queue given in part (a).
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:
0
1
2
3
4
5
6
7
[2]
© UCLES 2021 9618/23/O/N/21 [Turn over
PAGE 433
10
Describe the algorithm that should be used to modify the end of queue pointer when adding
an item to the queue.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
11
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.
Complete the table. The first line has been completed for you.
You can assume that the sensor will generate only integer data values.
(b) A program module controls the heaters. This module operates as follows:
Start
Heaters Heaters
Off On
[3]
12
5 The following data items will be recorded each time a student successfully logs on to the school
network:
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:
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.
............................................................................................................................................. [1]
13
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [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.
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:
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
15
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
16
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
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
© UCLES 2021 9618/23/O/N/21
PAGE 440
17
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
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
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[6]
© UCLES 2021 9618/23/O/N/21
PAGE 441
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.
DC (KN/SW) 303772/3
© UCLES 2022 [Turn over
PAGE 442
Refer to the insert for the list of pseudocode functions and operators.
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.
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
Code LCASE("Electrical")
Result IS_NUM(-27.3)
[4]
START
END
[4]
3 (a) The module headers for five modules in a program are defined in pseudocode as follows:
(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]
(ii) Complete the table using the information in part 3(a) by writing each module name to
replace the labels A to F.
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.
1 ................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
3 ................................................................................................................................................
...................................................................................................................................................
[3]
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.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
(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.
It can be assumed that the file contains at least the number of lines passed.
1 ................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
3 ................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[3]
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
Identify the type of loop and state the condition that ends the loop.
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
0 10 TRUE
[6]
(c) Procedure Encode() is part of a modular program. Integration testing is to be carried out on
the program.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
10
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 ','.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
11
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
ENDPROCEDURE [7]
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.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
(b) The values passed to your MID() function in part (a) need to be validated.
State two checks that could be applied to the values passed to the function.
1 ................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
[2]
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.
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.
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
15
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
16
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
17
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
18
(c) A password has a fixed format, consisting of three groups of four alphanumeric characters,
separated by the hyphen character '-'.
An algorithm is needed for a new function GeneratePassword(), which will generate and
return a password in this format.
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
19
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
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.
DC (PQ/CGW) 303773/3
© UCLES 2022 [Turn over
PAGE 460
Refer to the insert for the list of pseudocode functions and operators.
Complete the table by placing one or more ticks () in each row.
INPUT MyName
IF Mark > 74 THEN
Grade 'A'
ENDIF
[5]
Variable Value
AAA TRUE
BBB FALSE
Count 99
Expression Evaluation
...........................................................................................................................................
..................................................................................................................................... [1]
2 A program has been written to implement a website browser and maintenance is now required.
Name two other types of maintenance that the program may require and give a reason for each.
Type 1 ..............................................................................................................................................
Reason .............................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Type 2 ..............................................................................................................................................
Reason .............................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
[4]
PROCEDURE Section_1()
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(b) Module Section_1() calls one of the other three modules. The module called will be
selected when the program runs.
[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 validation function is to be properly tested. Black-box testing will be used and a test plan
needs to be produced.
[4]
The data will be held in a record structure of type Employee. The fields that will be needed are as
shown:
(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.
...........................................................................................................................................
..................................................................................................................................... [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]
(c) A procedure Absentees() will output the EmployeeNumber and the Name of all employees
who have an Attendance value of 90.00 or less.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
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
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
(b) A procedure FirstTen() will output the factorial of the numbers from 0 to 9. The procedure
will use the function from part (a).
Factorial of 0 is 1
Factorial of 1 is 1
Factorial of 2 is 2
Factorial of 9 is 362880
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.
(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.
...........................................................................................................................................
..................................................................................................................................... [1]
(ii) Describe the error in the algorithm and explain how it may be corrected.
Description ........................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
Explanation .......................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[4]
11
(b) The original algorithm is implemented and sometimes the last three lines of the text file are
output correctly.
...................................................................................................................................................
............................................................................................................................................. [1]
...................................................................................................................................................
............................................................................................................................................. [2]
12
8 The following diagram shows the incomplete waterfall model of the program development life
cycle.
Analysis
Maintenance
[3]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[2]
(c) Identify another type of model for the program development life cycle.
............................................................................................................................................. [1]
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 '-'.
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.
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
15
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
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.
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.
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
17
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
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]
2 hours
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.
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]
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.
Description ................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[4]
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.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [5]
(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]
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.
S1
Input-A
S2
Output-W
Output-W
[4]
3 A stack is used in a program to store string data which needs to be accessed in several modules.
Identify one other example of an ADT and describe its main features.
Example ....................................................................................................................................
Features ...................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[3]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
(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.
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.
957
956
955
954
953 X ĸSP
952 Y
951 Z
950 P
[5]
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
Update(UserID, Total)
END
(a) Write the equivalent pseudocode for the algorithm represented by the flowchart.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
............................................................................................................................................. [1]
10
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
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.
For example:
FindBaseNumber(12)ZLOOUHWXUQíEHFDXVHLVQRWDIDFWRULDO
You may use the rest of this page for rough working.
13
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
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.
......................................................................................................
......................................................................................................
......................................................................................................
......................................................................................................
......................................................................................................
......................................................................................................
......................................................................................................
......................................................................................................
......................................................................................................
......................................................................................................
......................................................................................................
......................................................................................................
[4]
16
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.
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.
Module Description
17
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
18
(b) Write an efficient bubble sort algorithm in pseudocode for module SortArrays().
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
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
...........................................................................................................................................
..................................................................................................................................... [1]
(ii) State two benefits of using the single array of the user-defined data type.
1 ........................................................................................................................................
...........................................................................................................................................
2 ........................................................................................................................................
...........................................................................................................................................
[2]
..................................................................................................................................... [1]
2 hours
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.
DC (NF/CB) 302729/4
© UCLES 2022 [Turn over
PAGE 493
Refer to the insert for the list of pseudocode functions and operators.
(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.
[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]
State one document that may be produced from the analysis stage of the website project.
...........................................................................................................................................
..................................................................................................................................... [1]
(c) The program will be developed using the Rapid Application Development (RAD) 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]
1 ................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
[2]
2 A program is being designed for a smartphone to allow users to send money to the charity of their
choice.
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]
Describe the algorithm needed. Do not include pseudocode statements in your answer.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [5]
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
<StockID><Description><Cost>
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.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [6]
(ii) Explain the term procedure interface with reference to procedure Unpack().
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(b) The design changes and a record structure is defined to store the three data items.
TYPE StockItem
DECLARE StockID : STRING
DECLARE Description : STRING
DECLARE Cost : REAL
ENDTYPE
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]
(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]
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.
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.
(a) Complete the following test plan for five tests that could be performed on function Status().
The tests should address all possible outcomes.
5
[5]
© UCLES 2022 9618/23/O/N/22
PAGE 502
11
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
12
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.
...
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.
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:
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]
16
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.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
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]
2 hours
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.
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:
(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.
1 ................................................................................................................................................
2 ................................................................................................................................................
3 ................................................................................................................................................
[3]
(c) Give the appropriate data types for the following variables:
ValidAddress ........................................................................................................................
ItemPostalCost ...................................................................................................................
ItemStatus ............................................................................................................................
[3]
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.
...................................................................................................................................................
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.
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]
(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
..................................................................................................................................... [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.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
Any comparison between characters needs to be case sensitive. For example, character 'a' and
character 'A' are not identical.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [6]
5 A programmer has produced the following pseudocode to output the square root of the numbers
from 1 to 10.
40 REPEAT
41 CALL DisplaySqrt(Num)
42 Num Num + 1.0
43 UNTIL Num > 10
...
The program code compiles without errors, but the program gives unexpected results. These are
caused by a design error.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
(b) Explain why the compiler does not identify this error.
...................................................................................................................................................
............................................................................................................................................. [1]
(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.
The programmer does not want to delete the complex statement but wants to change the
statement so that it is ignored by the compiler.
...................................................................................................................................................
............................................................................................................................................. [1]
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 (*).
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
11
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
12
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [6]
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]
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.
The table show the inputs, outputs and states for this part of the program:
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>
Format Comment
unique number for each item in the range
ItemNum 4 numeric characters
ƎƎWRƎƎLQFOXVLYH
The file is organised in ascending order of ItemNum and does not contain all possible values in
the range.
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
17
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
18
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
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.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
© 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]
2 hours
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.
DC (PQ/CB) 312089/3
© UCLES 2023 [Turn over
PAGE 526
Refer to the insert for the list of pseudocode functions and operators.
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 ..........................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [1]
(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.
INPUT MyChoice
OUTPUT FirstName & LastName
Result SQRT(NextNum)
[4]
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.
(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.
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.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
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 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
506
504 YYY
503 XXX
502 ZZZ
501 NNN
(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]
Complete the diagram to show the state of the stack and the variables after the given
operations have been performed.
Stack Pointer
506
505
504
503
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.
Step 1 ................................................................................................................................
...........................................................................................................................................
Step 2 ................................................................................................................................
...........................................................................................................................................
Step 3 ................................................................................................................................
...........................................................................................................................................
Step 4 ................................................................................................................................
...........................................................................................................................................
Step 5 ................................................................................................................................
...........................................................................................................................................
[5]
© UCLES 2023 9618/23/M/J/23 [Turn over
PAGE 531
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [6]
5 A program is designed, coded and compiled without errors. The compiled code is sent for testing.
...................................................................................................................................................
Explanation ...............................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[3]
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]
10
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.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [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.
Describe the function interface and two advantages of this modular approach.
Interface ....................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Advantage 1 .............................................................................................................................
...................................................................................................................................................
Advantage 2 .............................................................................................................................
...................................................................................................................................................
[4]
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) 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.
...........................................................................................................................................
..................................................................................................................................... [1]
(ii) Identify one item of information that is required and one item that is not required in the
new module. Justify your choices.
Justification .......................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
Justification .......................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[2]
(iii) Identify two operations that would be required to process data when an overdue book is
returned.
Operation 1 .......................................................................................................................
...........................................................................................................................................
Operation 2 .......................................................................................................................
...........................................................................................................................................
[2]
13
(b) Part of the library program contains program modules with headers as follows:
[3]
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>
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
The file is organised in ascending order of ItemNum and does not contain all possible values in
the range.
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
15
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
16
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:
Item Description
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
17
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
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:
Item Description
(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.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [3]
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.
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
[4]
Complete the table by evaluating each expression using the example values.
Expression Evaluates to
RIGHT(Description, 7)
(LENGTH(Description) - 8) > 16
(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]
2 An algorithm will:
START
END
[5]
Name ........................................................................................................................................
Justification ...............................................................................................................................
...................................................................................................................................................
[2]
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
2 3
4 D40
6 F2 7
8
[5]
(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 Ø
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
Typical test data would consist of odd and even values, for example:
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.
Sequence 1:
...................................................................................................................................................
Sequence 2:
...................................................................................................................................................
Sequence 3:
...................................................................................................................................................
[3]
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.
Index ĸ Start
Count ĸ0
REPEAT
Value ĸMix[Index]
Mix[Index]ĸ Mix[Index] - 1
Index ĸValue
Count ĸCount + 1
UNTIL Count = 5
Complete the trace table on the opposite page by dry running the procedure when it is called as
follows:
CALL Process(3)
11
[6]
12
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:
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]
...........................................................................................................................................
..................................................................................................................................... [1]
..................................................................................................................................... [1]
14
Module-A()
[4]
(b) Explain the meaning of the diamond symbol as used in the diagram in part (a).
...................................................................................................................................................
............................................................................................................................................. [2]
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:
<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.
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.
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
17
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
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [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.
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
19
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
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.
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.
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.
DC (LK/CT) 315870/2
© UCLES 2023 [Turn over
PAGE 562
Refer to the insert for the list of pseudocode functions and operators.
(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.
Variable Value
Active TRUE
Fraction 0.2
Code "Ab12345"
Complete the table by evaluating each expression using the example values.
Expression Evaluates to
STR_TO_NUM(MID(Code, 4, 2)) + 5
(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]
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.
START
END
[5]
(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.
...................................................................................................................................................
............................................................................................................................................. [2]
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.
(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]
(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.
2. Increment ................................... .
4. Increment ................................... .
6. Stop.
[6]
4 A procedure RandList() will output a sequence of 25 random integers, where each integer is
larger than the previous one.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
(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.
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [1]
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.
Index ĸ Start
Total ĸ0
WHILE Total < 20
Value ĸMix[Index]
Total ĸTotal + Value
ENDWHILE
Complete the trace table on the opposite page by dry running the procedure when it is called as
follows:
CALL Process(2)
11
[6]
12
The function will test whether the string meets certain conditions and will return an integer value
as follows:
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.
13
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [6]
14
Module-A()
T1 RA
SA
RB
(a) Explain the meaning of the curved arrow symbol which begins and ends at Module-A().
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
15
A record type MyType will be defined with three fields to store the values passed between the
two modules.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [3]
...........................................................................................................................................
..................................................................................................................................... [2]
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>
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.
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
17
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
18
(b) The use of the string "****" as explained in the module description for ReceiveFile() may
cause a problem.
Problem ....................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Solution .....................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[3]
(c) Two new modules are defined, which will allow two users to exchange messages.
Module Description
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>
19
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [7]
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.
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.
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.
DC (PQ/CGW) 329350/3
© UCLES 2024 [Turn over
PAGE 582
Refer to the insert for the list of pseudocode functions and operators.
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.
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
(c) The variables given in part (b) are chosen during the design stage of the program development
life cycle.
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]
Assume the values are all different and are input in no particular order.
START
No
Yes
END
[5]
(b) A different part of the program contains an algorithm represented by the following program
flowchart:
START
Is Flag = Yes
TRUE ?
No END
Set Port to 1
No
Is Port = 4 ?
CALL Reset(Port)
Yes
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
© UCLES 2024 9618/22/M/J/24
PAGE 587
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.
(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.
...........................................................................................................................................
..................................................................................................................................... [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
B C
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 length of the longest side may not be the first value input.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [5]
10
The program contains a global 1D array Data of type string containing 200 elements.
(a) (i) The pseudocode contains two syntax errors and one other error.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[3]
Statement ..........................................................................................................................
Explanation .......................................................................................................................
...........................................................................................................................................
[2]
11
(b) After correcting all syntax errors, the pseudocode is translated into program code which
compiles without generating any errors.
............................................................................................................................................. [1]
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
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
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.
13
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
14
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:
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]
16
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]
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’.
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]
18
The process is split into a number of stages. Each stage performs a different task and creates a
new file.
For example:
(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:
19
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
ENDFUNCTION [6]
20
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
21
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
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.
DC (KS/CGW) 329352/4
UCLES 2024 [Turn over
PAGE 602
Refer to the insert for the list of pseudocode functions and operators.
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]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [3]
(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.
"and"
........................................ ("Random", 2, 3)
15
5 + ........................................ (10/11/2023)
TRUE
........................................ ("45000")
(20 ........................................ 3) + 1 3
[4]
2 (a) A program uses a global 1D array of type string and a text file.
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.
Step 1 .......................................................................................................................................
...................................................................................................................................................
Step 2 .......................................................................................................................................
...................................................................................................................................................
Step 3 .......................................................................................................................................
...................................................................................................................................................
Step 4 .......................................................................................................................................
...................................................................................................................................................
Step 5 .......................................................................................................................................
...................................................................................................................................................
[5]
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]
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:
Two global variables contain the minimum and maximum acceptable weight for each component.
The values represent an inclusive range and are declared as:
(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.
...........................................................................................................................................
..................................................................................................................................... [1]
Complete the program flowchart to represent the algorithm for module BatchCheck().
START
Is
Index = 1001 ?
Yes
No
END
[5]
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.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
(b) The value zero denotes the split between the two parts of the sequence.
(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]
10
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]
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
13
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
14
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()).
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
...........................................................................................................................................
..................................................................................................................................... [1]
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.
..................................................................................................................................... [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]
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
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
The string stored in column 3 is called the module description. This is the module header without
the keyword.
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
19
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
20
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
x = 1 x = 2 x = 3
ModInfo[10, x] "27" "P" "MyProc(Z : CHAR)"
ModInfo[11, x] "35" "F" "MyFun(Y : CHAR) RETURNS BOOLEAN"
Assume that the array contains enough rows for the number of modules in each project.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
21
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
"#$%&'(!)*!#*&#+,-.,/! !+
] ^ _ _ ` a b c _ d b ]
"012345-")46"4 789:;
< => < ?@ < A 0B*%!;6 !$%!C
DE
F G H
)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
9 @ R R R G R
G Q @
Zo[
Zg[
o
=
Z=[
Q
R @ R G
y
?
Zg[
lNVemA=h=k pqoij==jrj\j=k
PAGE 621
O P !B!* R G
mQ I
0&(&#+E*&( 1'&&!'E*&(
¡¢£¤¥ ¢£¤¥
¡¢£¤¢¡ ¢¡
¡¢£¤¥ ¡ ¡
Zq[
lNVemA=h=k pqoij==jrj\j=k
PAGE 622
Z=[
Zo[
ª «¬v¬ª®¯°±xª²ª³´²¡¥µª¶·ª¬v
RGI
±¸
¶±x
Zo[
t&&u mQ G * R
Z=[
·¹®¶ª¸y¯{®¯°ºy ª²ª¬v|ª¬®¹±ª»¶¶v¬
ª ª ªªª·ªª®¼¬
ª ª ªªªªªª¬®¹ªª½½ªxª°ª¨ ¾ª¿y
ª ª ªªª¬«·
ª ª ªªªª ª®¯°ºy
ª ª ªªª±¸ª ª
ª ª ªªª¶±xª ª¶±xªÀª
ª ª ªªª¬®¹ª®¹¬
ª ª ¬«·¹®¶
Zk[
lNVemA=h=k pqoij==jrj\j=k
PAGE 624
Q P RG G Âww©¾ kh R
¼ w
ª ª «¬v¬ª±¨ª²ª®¬Â¬
ª ª ¶¹®¸¹®ª¼ w
ª ª ±¨ª ª®°x
ª ª ¬¸¬®
ª ª ªªª½½wªw¯°Ã
ª ª ¹®vª®°xªÄª±¨ªÀª¥¥¥¥
ª ª ¶¹®¸¹®ªÂww©¾
> Q P RY kY RG I
ª ª vvª®° ¨{ Ū |
ª ª ¥ª wªwªÃw
lNVemA=h=k pqoij==jrj\j=k
PAGE 625
Zq[
9C
R ¸¨w {| Q RGI
ª ª ªªªwyª ª®{¥¥ª½ªy© ¨|
ª ª ªªª ª ª«´y© ¨µ
ª ª ªªª±¬ª¶·ª{ ªÇ¶«ª|
ª ª ªªªªªª¥ª²ª y¨ºy ª ª®¶È¹¸¸¬{¼®{v© Ūwy||
ª ª ªªªªªªª²ª y¨ºy ª ª
ª ª ªªª¬«±¬
ª ª ªªª¬®¹ª º
ª ª ¬«·¹®¶
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
V
mQ
Z=[
Z=[
9
8 G G É Ê G G
mÉ Ê GRR R
G R
GR oSR
ª ª «¬v¬ª·°°Ãª²ª³ª´² µª¶·ª±®Â
= ¶°w
g ±w
k ¯w˰
Y ¸ yª»y ¨
ª ª «¬v¬ª»¨ ª²ª³ª´²¥µª¶·ª±®Â
= »¨wÍ
g ¸°
±z °{|G @ É Ê G R *}
RR R !
lNVemA=h=k pqoij==jrj\j=k
PAGE 629
9
ª ª ¸¶¬«¹¬ª±z °{|
¬«¸¶¬«¹¬
ZX[
9
t%u G RR G > Q P
@
S G @
Z=[
lNVemA=h=k pqoij==jrj\j=k
PAGE 631
9§
RG R R IJSP P P P
P R P R P R @ R
@
J o
Ð R
J =
Ð R
J g
Ð R
Zg[
Zo[
tBu J R @ R R @ R
G
o
=
g
Zg[
98
Zg[
lNVemA=h=k pqoij==jrj\j=k
PAGE 633
9:
®³¸¬ª¯¨ ¨®¾z
ª ªªª«¬v¬ª¸¾ ¨ª²ª®¬Â¬
ª ªªª«¬v¬ªw ª²ª±®Â
ª ªªª«¬v¬ª ª²ª±®Â
ª ªªª«¬v¬ªv Ë ª²ª®¬Â¬
ª ¬«®³¸¬
¸¾ ¨R G Ko qL R @
hR *
R R P ¸¾ ¨R @ h
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
ZX[
C
R RGI
1'+! !EB&*&
±Ë {| ¦ R R G R
Ò
¦ G R GR
±Ë ·° Î
ª ª ¸¶¬«¹¬ª±Ë {|
¬«¸¶¬«¹¬
ZX[
lNVemA=h=k pqoij==jrj\j=k
PAGE 636
9
ª ª ®³¸¬ª¯¨ ¨®¾z
ª ª ªªª«¬v¬ª¸¾ ¨ª²ª®¬Â¬
ª ª ªªª«¬v¬ªw ª²ª±®Â
ª ª ªªª«¬v¬ª ª²ª±®Â
ª ª ªªª«¬v¬ªv Ë ª²ª®¬Â¬
ª ª ªªª«¬v¬ª±yª²ª»¶¶v¬
ª ª ¬«®³¸¬
S G U R G R R
R Q R
Z=[
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
)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
u
u L M
u L S M
z{|}~} }} {}
}}}~z}~}} |}
}}}}}}z~} }
}}}~z
}~
}{z}
~}| ¡}¢£}z
[h\
sCt kA R A H s%t
4xy!FF& 4 #+#*!F*
§¨©}}{ ~}£}
~}²{}
jOWekB>g>h opnmi>fiqi]i>h
PAGE 639
<
HJ
[Z\
W
O
[>\
} ¸}
} }}}|}¡}¹} |~º
} }}}|}¨¡»}¹}~ º|
} ¸
|}¨ ¡}¹}||¸¹¯}{z}
[n\
[n\
jOWekB>g>h opnmi>fiqi]i>h
PAGE 641
Br
k]T
[h\
sCt ¡S S ¨ ¡ ¡
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
A H > S O
A Q H hZ H
W
}} {
z{|}~}
}}}Ç»}}ºÂ~}È}¯
}}}»}
}}}~z}²»Æ}²»Æ
}}}~z
}~
[h\
)'!x ¤#+!
hg z
hn |
h> |
hf | SW
hh |
hZ |
hp z
jOWekB>g>h opnmi>fiqi]i>h
PAGE 644
[>\
[p\
jOWekB>g>h opnmi>fiqi]i>h !
PAGE 645
9
¼ S H A SH A S S A
A A
µ
T
[f\
jOWekB>g>h opnmi>fiqi]i>h
PAGE 646
99
? R Q SH S H Ë©» A >gJ
[Y\
9
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
B @ n
O
B @ >
O
B @ f
O
B @ h
O
[h\
jOWekB>g>h opnmi>fiqi]i>h
PAGE 648
9D
} ¸}É»ª¡» Ë
} }}}|}Ë»}¹}~ º|
} }}}|}|}¹} |~º
} }}}|}}¹} |~º
} }}}|}ƨ§}¹}~ º|
} ¸
˻S H Ln pMS A
gS *
} |}É»ª¡»}¹}||¸¹®Ä}{z}É»ª¡» Ë
S S Q ˻S g
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
9¼
} } |{|
[Y\
jOWekB>g>h opnmi>fiqi]i>h !
PAGE 650
98
] 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
} } ¸}É»ª¡» Ë
} } }}}|}Ë»}¹}~ º|}}}}}}}z¨}©»}
} } }}}|}|}¹} |~º}}}}}}}}}}z¨}©»}¯
} } }}}|}}¹} |~º}}}}}}}}}}z¨}©»}
} } }}}|}ƨ§}¹}~ º|}}}z¨}©»}®
} } ¸
G ¡»ª¡
jOWekB>g>h opnmi>fiqi]i>h
PAGE 651
9¾
[Y\
sCt S A S S A
[>\
jOWekB>g>h opnmi>fiqi]i>h
PAGE 652
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.
DC (CJ) 205021/2
© UCLES 2021 [Turn over
PAGE 653
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.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [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
Status MID("Computer", 7, 5)
Size LENGTH("Password") * 2
NextChar CHR('A')
PROCEDURE LEM()
Overload FALSE
Landed FALSE
ENDPROCEDURE
Answer
[5]
[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.
Feature 1 ...........................................................................................................................
Feature 2 ...........................................................................................................................
[2]
(ii) The headers for three modules in a program are defined in pseudocode as follows:
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]
(b) Draw a diagram to show the stages of the program development cycle. Use arrows to indicate
how the stages are linked.
[2]
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.
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.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
© UCLES 2021 9608/22/M/J/21 [Turn over
PAGE 660
10
Feature 1 ...........................................................................................................................
...........................................................................................................................................
Feature 2 ...........................................................................................................................
...........................................................................................................................................
[2]
(ii) Name two IDE features that can help with initial error detection.
Feature 1 ...........................................................................................................................
...........................................................................................................................................
Feature 2 ...........................................................................................................................
...........................................................................................................................................
[2]
..............................................
DECLARE Password : STRING
OUTPUT "Please Input your password: "
INPUT Password
Response Validate(UserID, Password) AND Today()
..............................................
ENDFUNCTION
[2]
11
• 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.
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.
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:
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.
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
13
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.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
14
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
15
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
16
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
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.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
17
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
18
Appendix
Each function returns an error if the function call is not properly formed.
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
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.
DC (PQ/FC) 205019/2
© UCLES 2021 [Turn over
PAGE 670
Write each example statement in program code and state the programming language used.
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.
Justification .......................................................................................................................
...........................................................................................................................................
[2]
(ii) Give two possible reasons why the search for the value in part (b)(i) would end.
1 ........................................................................................................................................
...........................................................................................................................................
2 ........................................................................................................................................
...........................................................................................................................................
[2]
(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)
[3]
2 (a) After using a program for some time, a user notices a fault in the program.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(b) Good programming practice may help to avoid faults. The use of sensible identifier names is
one example of good practice.
...........................................................................................................................................
..................................................................................................................................... [1]
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]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
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
Is Online = NO
FALSE ?
YES END
Is Active = NO
TRUE ?
YES
CALL Reset()
CALL Sync()
Is Active = YES
FALSE ?
NO
CALL Error("No
Signal")
CALL ReCheck()
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
Refer to the Appendix on pages 22 and 23 for the list of built-in pseudocode functions and
operators.
Result 0
Count 1
IF Count < 3
THEN
RETURN -1
ELSE
RETURN Result
ENDIF
ENDFUNCTION
(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")
[5]
(ii) State the value returned by the function when it is called as shown in part (a)(i).
................................................ [1]
10
(b) A number group is a string of characters that represents an integer or decimal value. A comma
separates number groups.
The function Check() is intended to analyse 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.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [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.
Description ................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[2]
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.
Different numbers may have different groupings. A template string is used to define the grouping.
For example:
For the first row, template "53" results in a formatted string comprising:
(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
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
16
6 A program stores data about stock items in four global 1D arrays as follows:
• 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.
• 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.
Module Description
17
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [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.
Group: ABLK
Number of items in Group: 11
Total value of items in Group: 387.89
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.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
© UCLES 2021 9608/23/M/J/21
PAGE 685
19
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
20
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
• 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.
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.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
© UCLES 2021 9608/23/M/J/21
PAGE 687
21
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
22
Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.
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
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.
DC (RW) 206327/4
© UCLES 2021 [Turn over
PAGE 691
1 (a) Design and coding are stages of the program development cycle.
Design stage
Activity 1 ...................................................................................................................................
Activity 2 ...................................................................................................................................
Coding stage
Activity 1 ...................................................................................................................................
Activity 2 ...................................................................................................................................
[4]
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]
(ii) Complete the following table by writing an appropriate identifier name for each of these
four lines in the procedure InitVars().
102
103
105
106
[4]
• the identifier should be declared as a fixed value that does not change during
program execution
...........................................................................................................................................
..................................................................................................................................... [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]
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]
(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.
Evaluates to TRUE if
DayOfMonth is within the
first seven days
of the month
[4]
(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.
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
Refer to the Appendix on pages 18–19 for a list of built-in pseudocode functions and
operators.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
(b) Explain the term transferable skills and state how these skills are used in program
development.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
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.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
(b) A procedure called RandomPath() assigns values to the array Flower to store a path
through the flowers in the fields as follows:
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.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
10
(i) State the type of program error that has occurred and identify how this error can be
detected.
...........................................................................................................................................
[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]
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
11
(a) Draw a program flowchart to represent the algorithm for the module.
[5]
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().
Test 1
Year
UseSuffix
Test 2
Year
UseSuffix
Test 3
Year
UseSuffix
[6]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
14
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.
"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".
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
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
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.
"V9PG+3P,ChicagoUSA#12#09/10/2020"
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.
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.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
17
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
© UCLES 2021 9608/22/O/N/21 [Turn over
PAGE 706
18
Appendix
Each function returns an error if the function call is not properly formed.
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
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.
DC (PQ/CGW) 208684/3
© UCLES 2021 [Turn over
PAGE 709
...........................................................................................................................................
.......................................................................................................................................[2]
...........................................................................................................................................
.......................................................................................................................................[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.
[3]
(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
Refer to the Appendix on pages 22–23 for a list of built-in pseudocode functions and
operators.
LENGTH(Description) / NUM_TO_STRING(Limit)
MOD(20, LENGTH(Destination))
[5]
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.
Refer to the Appendix on pages 22–23 for a list of built-in pseudocode functions and operators.
(a) Complete the table by identifying four line numbers that contain errors and give the correct
pseudocode statement.
[4]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
(c) The function PayUsingAccount() is required to process a payment for hiring a car as
follows:
2. If CostOfHire exceeds Balance, the rental is not authorised and FALSE is returned,
otherwise TRUE is returned.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
© UCLES 2021 9608/23/O/N/21 [Turn over
PAGE 713
<user>@<host>•<domain>
Function Description
AddressChecker() will:
(a) Draw a program flowchart to represent the algorithm for the AddressChecker() function.
[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.
Assume that:
Give two reasons why the function may return an unexpected result.
Reason 1 ..................................................................................................................................
...................................................................................................................................................
Reason 2 ...................................................................................................................................
...................................................................................................................................................
[2]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
Program code
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [1]
(d) The following incomplete structure chart shows part of the design of the function
AddressChecker().
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]
10
4 The following pseudocode contains a function that searches a text file for the string contained in
the parameter Match.
(a) Complete the trace table when the function is called using this statement:
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"
11
[5]
• The statement on line 25 is changed to compare the last ten characters of FileData
and the parameter Match.
• 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]
12
(ii) Rewrite the WHILE structure in pseudocode so that it meets the new requirements. The
WHILE structure is given here for reference.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [3]
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 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
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.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
© UCLES 2021 9608/23/O/N/21
PAGE 721
15
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
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"
Array Description
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
Assume that:
The design requirements of the function are shown in the following table:
17
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
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.
Assume that:
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.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
© UCLES 2021 9608/23/O/N/21
PAGE 725
19
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
20
(c) When reviewers write a review for a restaurant, they give the restaurant a score out of 10.
• 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"
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
© UCLES 2021 9608/23/O/N/21
PAGE 727
21
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
22
Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.
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