A1 CS P2 2015-2022 Part II
A1 CS P2 2015-2022 Part II
1. BASIC DATA TYPES 2 | 32 | 61 | 64 | 67 | 84 | 97 | 110 | 120 | 122| 135 | 149 | 161 | 186 | 215
AND BUILT IN
FUNCTIONS | 256 | 278 | 287 | 320 | 336 |362 | 382 | 408 | 416 | 433 | 457 | 465 | 481
| 507 | 536 | 562 | 585 | 609 | 633 | 656 | 686 | 714 | 744 | 771 | 1005 |
2. ENGLISH STRUCTURED 3 | 62 | 168 | 199 | 223 | 339 | 365 | 385 | 435 | 517 | 590 | 620 | 636 |
TO PSEUDO CODE 663 | 687 |696 | 718 | 836 | 861 | 892 | 1044 | 1063 | 1251 | 1298 |
1309 |
3. THEORY 4 | 262 | 443 | 465 | 567 | 658 | 721 | 745 | 797 | 806 | 829 | 859 | 890 |
926 | 965 | 1010 | 1061 | 1139 | 1170 | 1194 | 1224 | 1231 | 1257 |
1284 | 1289 |
4. PSEUDO CODES
5 | 35 | 88 | 111| 166 | 257 | 319 | 344 | 370 | 390 | 492 | 515 | 548 | 573
| 588 | 596 | 612 | 616 | 637 | 640 | 659 | 692 | 719 | 746 | 748 | 778 | 840
| 865 | 894 | 897 | 928 | 930 | 969 | 973 | 1011 | 1018 | 1045 | 1047 |
1049 | 1094 | 1121 | 1124 | 1147 | 1179 | 1204 | 1230 | 1232 | 1254 |
1259 | 1288 | 1290 | 1312 | 1317 | 1319 | 1338 | 1345 | 1372 | 1376 |
5. STRUCTURE CHARTS
8 | 38 | 65 | 168 | 193 | 222 | 254 | 318 | 341 | 369 | 387 |486 | 513 | 541
660 | 690 | 752 | 775 | 798 | 830 | 860 | 1007 | 1141 | 1235 | 1293 | 1344|
1374 |
6. TRACE TABLE 11 | 42 | 85 | | 99 | 150 | 173 | 198 | 226 | 245 | 277 | 309 | 410 | 459 |
638 | 644 | 661 | 720 | 776 | 799 | 863 | 934 | 971 | 1012 | 1145 | 1177|
1340 | 1370 |
7. TEXT FILES 14 | 45 | 170 | 195 | 223 | 252 | 282 | 342 | 368 | 370 | 388 | 390 | 414 |
417 | 443 | 466 | 488 | 516 | 544 | 571 | 594 | 618 | 643 | 665 | 695 | 722
754 | 780 | 809 | 842 | 867 | 938 | 1070 | 1143 | 1181 | 1234 | 1236 |
1263 | 1294 | 1342 |
8. 2D ARRAY
71 | 344 | 490 | 518 | 546 | 570 | 804 | 1072 | 1097 | 1151 |
1176 | 1209 | 1313
9. FLOWCHARTS 87 | 112 | 138 | 221 | 241 | 272 | 305 | 411 | 436 | 460 | 484 | 511 | 542
| 563 | 586 | 610 | 684 | 712 | 742 | 773 | 802 | 832 | 862 | 932 | 967 |
11. UNDERSTANDING 92 | 115 | 142 | 275 | 311 | 482| 509 | 538 | 568 | 591 | 615 | 641 | 693
PSEUDO CODES
| 716 | 774 | 893 | 1046 | 1092 | 1229 | 1250 | 1256 | 1282 | 1308 | 1314 |
12. CASE OF
93 | 117 | 120 | 144 | 409 | 458 | 540 |
13. BUBBLE SORT 118 | 439 | 461 | 412 | 438 | 807 | 838 | 968 | 1015 |
15. ADTs 1017 | 1043 | 1066 | 1116 | 1172 |1174 | 1197 | 1252 | 1286
| 1310 | 1336 | 1366 |
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) 171120/3
© UCLES 2019 [Turn over
PAGE 712
(a) (i) This pseudocode lacks features that would 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.
"NOT TRUE"
í
NOT FALSE
132
[4]
,IDQH[SUHVVLRQLVLQYDOLGWKHQZULWH¶(5525·
Refer to the Appendix on page 16–17 for the list of built-in functions and operators.
Expression Evaluates to
0,' VDPSOH
NUM_TO_STRING(12.3 * 2)
[4]
2 (a) A structure chart is often used in modular program design. One feature shown is the sequence
of module execution.
Feature 1 ..................................................................................................................................
...................................................................................................................................................
Feature 2 ..................................................................................................................................
...................................................................................................................................................
Feature 3 ..................................................................................................................................
...................................................................................................................................................
Feature 4 ..................................................................................................................................
...................................................................................................................................................
[4]
(b) Identify and describe one feature of an Integrated Development Environment (IDE) that can
help with program presentation.
Feature .....................................................................................................................................
Description ................................................................................................................................
...................................................................................................................................................
[2]
Method ......................................................................................................................................
Description ................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[2]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
© UCLES 2019 9608/21/O/N/19 [Turn over
PAGE 716
Study the pseudocode. Identify the relevant features in the following table.
Refer to the Appendix on pages 16–17 for the list of built-in functions and operators.
Feature Answer
[7]
4 A student is developing a program to count how many times each character of the alphabet (A to Z)
occurs in a given string. Upper case and lower case characters will be counted as the same. The
string may contain non-alphabetic characters, which should be ignored.
• check each character in the string to count how many times each alphabetic character occurs
• store the count for each alphabetic character in a 1D array
• output each count together with the corresponding character.
(a) The student has written a structured English description of the algorithm:
The student decides to apply a process to increase the level of detail given in step 4.
State the name of the process and use this process to write step 4 in more detail. Use
structured English for your answer.
Process .....................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[4]
You should assume the following lines of pseudocode have been written:
Declare any further variables you use. Do not implement the code as a subroutine.
Refer to the Appendix on pages 16–17 for the list of built-in functions and operators.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
10
Upper 0
Lower 0
Digit 0
Other 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]
© UCLES 2019 9608/21/O/N/19
MUHAMMAD ALI KHAN
PAGE 721
11
(b) (i) Complete the trace table by dry running the function when it is called as follows:
Result CheckPassword("Jim+Smith*99")
[5]
(ii) State the value returned when the function is called using the expression shown. Justify
your answer.
Value .................................................................................................................................
Justification .......................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[2]
12
6 Account information for users of a library is held in one of two text files; UserListAtoM.txt and
UserListNtoZ.txt
The format of the data held in the two files is identical. Each line of the file is stored as a string that
contains an account number, name and telephone number separated by the asterisk character
('*') as follows:
The account number string may be six or nine characters in length and is unique for each
person. It is made up of alphabetic and numeric characters only.
An error has occurred and the same account number has been given to different users in the two
files. There is no duplication of account numbers within each individual file.
A program is to be written to search the two files and to identify duplicate entries. The account
number of any duplicate found is to be written to an array, Duplicates, which is a 1D array of
100 elements of data type STRING.
The program is to be implemented as several modules. The outline description of three of these is
as follows:
ClearArray()
• Initialise the global array Duplicates. Set all elements to the
empty string.
• Read each line from the file UserListAtoM.txt
• Check whether the account number appears in file
UserListNtoZ.txt using SearchFileNtoZ()
FindDuplicates() • If the account number does appear then add the account
number to the array.
• Output an error message and exit the module if there are more
duplicates than can be written to the array.
• Search for a given account number in file UserListNtoZ.txt
SearchFileNtoZ()
• If found, return TRUE, otherwise return FALSE
(a) State one reason for storing data in a file rather than in an array.
...................................................................................................................................................
............................................................................................................................................. [1]
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
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
© UCLES 2019 9608/21/O/N/19 [Turn over
PAGE 724
14
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
15
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
(d) ClearArray() is to be modified to make it general purpose. It will be used to initialise any
1D array of data type STRING to any value.
1. The array
2. The number of elements
3. The initialisation string
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [3]
(ii) Write program code for a statement that calls the modified ClearArray() procedure
to clear the array Duplicates to "Empty".
Program code
...........................................................................................................................................
...........................................................................................................................................
[2]
16
Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.
17
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
4.5 REAL
132 INTEGER
Expression Evaluates to
MID("sample", 3, 5) ERROR
NUM_TO_STRING(12.3 * 2) "24.6"
INT(STRING_TO_NUM("53.4")) + 7 60
1. Module hierarchy
2. The parameters that are passed (between modules) // the module interface
3. Selection / Decisions (which modules are executed)
4. Iteration / Repetition
2(b) One mark for name and one mark for explanation. 2
Example:
• Auto(matic) indentation
• Allows the programmer to clearly see the different code sections / easier to
see the code structure
• By reference / ref
• The address of / pointer to the parameter is passed to the subroutine // if the
parameter value is changed in the subroutine this changes the original value
3 7
One mark per row: Answer
4(a) One mark for process name, max 3 for structured English. 4
Process:
• Stepwise Refinement / Top-down design
Structured English:
• Check that character is between 'A' and 'Z'
• Produce unique array index for this character
• Increment this array element
FOR Index m 1 TO 26
0 0 0 0
1 'J' 1
2 'i' 1
3 'm' 2
4 '+' 1
5 'S' 2
6 'm' 3
7 'i' 4
8 't' 5
9 'h' 6
10 '*' 2
11 '9' 1
12 '9' 2
6(a) To retain data when the computer is shut down / turned off // after the program 1
ends
6(b) 'Pseudocode' solution included here for development and clarification of mark 7
scheme.
Programming language example solutions appear in the Appendix.
ENDWHILE
CLOSEFILE SearchFile
RETURN Found
ENDFUNCTION
IF SearchFileNtoZ(AccNum) = TRUE
THEN
IF Index = 101 // is the array already full?
THEN
OUTPUT "Error – Array Full"
Continue m FALSE
ELSE
Duplicates[Index] m AccNum
Index m Index + 1
ENDIF
ENDIF
ENDWHILE
CLOSEFILE "UserListAtoM.txt"
ENDPROCEDURE
ENDPROCEDURE
Mark as follows:
• Procedure header
• Loop
• Assignment within loop
6(d)(ii) 'Pseudocode' solution included here for development and clarification of mark 2
scheme.
Programming language example solutions appear in the Appendix.
Mark as follows:
• Procedure call
• Parameter list (in brackets)
Found = FALSE
Filedata = LineInput(1)
If SearchString & '*' = Left(FileData, Len(SearchString)+1) Then
Found = TRUE
End If
End While
FileClose(1)
Return Found
End Function
begin
Found := FALSE;
assign(MyFile, "UserListNtoZ.txt");
reset (Myfile);
end;
close(MyFile);
end;
def SearchFileNtoZ(SearchString):
## FileData : String
## Found : Boolean
## MyFile : Text
Found = False
FileData = MyFile.readline()
MyFile.close
return(Found)
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 742
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 750
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]
13
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
MUHAMMAD ALI KHAN
PAGE 757
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
1. Indentation
2. Blank lines / white space
3. Sensible identifier names / use of Camel Case for identifier names
4. Capitalised keywords
1(a)(ii) START 5
YES Is Full =
TRUE? Loop must be included for
this area mark
NO
Is NOT Full NO
AND Tries < 4
YES
Call TopUp() Is NO
Tries > 3?
YES
Full ĸ
ReadSensor("F1")
Output
Tries ĸ Tries + 1 "Too many attempts"
Output
"Tank now full"
Output
"Already Full"
END
43 INTEGER
TRUE BOOLEAN
273.16 REAL
"273.16" STRING
Expression Evaluates to
MID(NUM_TO_STRING(2019), 3, 1) "1"
INT(NUM_TO_STRING(-273.16)) ERROR
INT(13/2) 6
FOR Index m 0 TO 9
Result[Index] m 0
ENDFOR
FOR Index m 0 TO 9
OUTPUT "Count of digit " & NUM_TO_STRING(Index) & " : "
& NUM_TO_STRING(Result[Index])
ENDFOR
Mark as follows:
5. Increment VolLevel
6. Ensure VolLevel still in range: for both cases. i.e:
VolLevel <= 49 (for MaxVol = 0)
VolLevel <= MaxVol (for MaxVol <> 0)
Test 1
MaxVol: 0/49
VolLevel expected: 49
Test 2
VolLevel before: 34
VolLevel expected: 34
Test 3
Parameter: 20
VolLevel expected: 0
• Tests carried out before all the modules / subroutines have been written
• Simple / dummy module written to simulate / model / replace the actual
module / subroutine / object
• Contains an output statement // returns a fixed value to indicate that the call
has been made
5 7
6(a) 'Pseudocode' solution included here for development and clarification of mark 6
scheme.
Programming language example solutions appear in the Appendix.
Found m FALSE
Index m 0
IF Reference = Leavers[Index]
THEN
Found m TRUE
ENDIF
Index m Index + 1
ENDWHILE
RETURN Found
ENDFUNCTION
NotCopied m 0
IF MID(FileData, 6, 1) = '*'
THEN
Reference m MID(FileData, 1, 5) // five char
reference
ELSE
Reference m MID(FileData, 1, 8) // eight char
reference
ENDIF
IF SearchLeavers(Reference) = FALSE
THEN
WriteFile "UpdatedList.txt", FileData
ELSE
NotCopied m NotCopied + 1
ENDIF
ENDWHILE
CLOSEFILE "StudentList.txt"
CLOSEFILE "UpdatedList.txt"
RETURN NotCopied
ENDFUNCTION
6(c) 'Pseudocode' solution included here for development and clarification of mark 3
scheme.
Programming language example solutions appear in the Appendix.
Found = FALSE
Index = 0
Index = Index + 1
Loop
Return Found
End Function
Q6 (a): Pascal
function SearchLeavers(Reference : String) : boolean;
begin
Found := FALSE;
Index := 0;
Index := Index + 1;
end;
end;
Q6 (a): Python
def SearchLeavers(Reference):
## Index : Integer
## Found : Boolean
Found = False
Index = 0
Index = Index + 1
return Found
Q6 (c): Pascal
Result := CountTimes(Leavers, "");
Q6 (c): Python
Result = CountTimes(Leavers, "")
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
MUHAMMAD ALI KHAN
PAGE 771
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("[email protected]")
[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 782
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
MUHAMMAD ALI KHAN
PAGE 785
9608/23 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019
1(a)(ii) Declaration 1
Process x = INT(y/3)
Output Console.Writeline("Goodbye")
1(c)(ii) One mark for statement in program code that includes (at least) two 'stages' 1
• Next = LEN(Console.Input())
• Console.writeline(Name & Address)
• Console.WriteLine(Console.Readline() & " is what you
entered")
• Blank lines
• Capitalisation of Keywords
• Sensible variable names
• Use of (library/built-in) functions
• Comments
• PrettyPrint / keywords coloured
1(e) White-box 1
2(a)(ii) REPEAT 4
CALL AlarmReset()
Status1 m GetStatus(Sys_A)
Status2 m GetStatus(Sys_B)
UNTIL (Status1 = TRUE AND Status2 = TRUE)
2(b) 5
Feature Answer
The line numbers for the start and end of a count- 180/190 and 230
controlled loop
3 5
0 0 0
1 'J' 1
2 'i' 2
3 'm' 3
4 '.' 1
5 '9' 4
6 '9' 5
7 '@' 1
8 's' 6
9 'k' 7
10 'a' 8
11 'i' 9
12 'l' 10
13 '.' 2
14 'c' 11
15 'o' 12
16 'm' 13
4(b)(ii) TRUE 1
4(c) One mark for string and one mark for correct explanation. 4
Same for second answer providing it results in a different path through the
algorithm.
Space m TRUE
NewString m ""
RETURN NewString
ENDFUNCTION
Count m 0
IF SearchAuthor = ThisAuthor
THEN
Result[Count, 0] m Title
Result[Count, 1] m Location
Count m Count + 1
ENDIF
ENDWHILE
CLOSEFILE("Library.txt")
RETURN Count
ENDFUNCTION
IF Count = 0
THEN
OUTPUT "Search found no books by: " & Author
ELSE
OUTPUT "Books written by: " & Author
OUTPUT "Title" & LEFT(Gap, 20) & "Location"
FOR Index m 1 TO Count
GLen m 25 – LENGTH(Result[Index, 0])
OUTPUT Result[Index, 0] & LEFT(Gap, GLen) &
Result[Index, 1]
ENDFOR
OUTPUT "Number of titles found: " &
NUM_TO_STRING(Count)
ENDIF
ENDPROCEDURE
Count = 0
FileClose(1)
Return Count
END FUNCTION
var
Title : string;
Author : string;
Isbn : string;
Location : string;
Count : integer;
MyFile : text;
begin
Count := 0;
assign(MyFile, 'Library.txt');
reset(MyFile);
end;
close(MyFile);
FindBooksBy := Count;
end;
def FindBooksBy(SearchAuthor):
## Title : STRING
## Author : STRING
## Isbn : STRING
## Location : STRING
## Count : INTEGER
Count = 0
MyFile = open("Library.txt", 'r')
Title = MyFile.readline()
MyFile.close()
return(Count)
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 (CE/CB) 180782/4
© UCLES 2020 [Turn over
MUHAMMAD ALI KHAN
PAGE 797
...................................................................................................................................................
............................................................................................................................................. [2]
(b) A program design includes the use of subroutines (functions and procedures).
1 ................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
3 ................................................................................................................................................
...................................................................................................................................................
[3]
(c) Draw lines on the following diagram to connect each computing term with the appropriate
description.
Term Description
[3]
2 (a) Three modules form part of a program for a car rental company. A description of the
relationship between the modules is summarised as follows:
Draw a structure chart to show the relationship between the three modules and the
parameters passed between them.
[5]
© UCLES 2020 9608/21/M/J/20 [Turn over
MUHAMMAD ALI KHAN
PAGE 799
(b) The following pseudocode algorithm has been developed to check whether a string contains
a valid password.
Refer to the Appendix on page 21 for a list of built-in pseudocode functions and operators.
A dry run performed on the function Check(), with the string "crAsh99", produced the
following trace table.
The string is a valid password, but the pseudocode would return the value FALSE.
Trace
StrLen Index NextChar NumUpper NumLower NumNonAlpha
table row
1 7 0 0 0
2 1 'c'
3 1
4 2 'r'
5 2
6 3 'A'
7 1
8 4 's'
9 3
10 5 'h'
11 4
12 6 '9'
13 2
14 7 '9'
15 3
(i) Describe how the completed trace table may be used to identify the error in the
pseudocode. In your answer, refer to the trace table row number(s).
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(ii) State the pseudocode line number that has to be changed to correct the error and write
the correct pseudocode for the complete line.
...........................................................................................................................................
[2]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [4]
3 (a) A mobile phone provider has developed an account management program. The program
includes a procedure, AddCredit(). The procedure is called with two parameters, TopUp
and PhoneNum.
The relevant part of the identifier table and the program flowchart for the procedure are as
shown:
START
Set Multiple
to 1
Set Balance to
GetBalance(PhoneNum)
NO
NO
Set TopUp to
TopUp * Multiple
END
Write pseudocode to implement the procedure AddCredit(). The pseudocode must follow
the algorithm represented by the flowchart. Declare any local variables used.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
10
(b) The following pseudocode searches for a string "Chris" in a 1D array and outputs the index
positions where the string is found.
FOR n 1 TO 100
IF NameList[n] = "Chris"
THEN
OUTPUT "Found at: " & NUM_TO_STRING(n)
ENDIF
ENDFOR
• Write the search as a procedure, Search(), that takes the search string as a parameter.
• Change the array to a 2D array. The first dimension contains names and the second
dimension contains the corresponding status.
For example:
NameList[23, 1] "Chris" // name
NameList[23, 2] "On Holiday" // status
• Detect a match only when the name contains the search string and the status contains
"Active".
• If a match has been detected, the procedure will output a single message giving all of
the index positions where a match occurred. For example, "Found at: 3 6 22".
• If no match has been detected, the procedure will output a suitable message.
Refer to the Appendix on page 21 for a list of built-in pseudocode functions and operators.
11
Write the pseudocode for the procedure Search(). Assume the array has been declared
globally.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
12
4 (a) An inexperienced user buys a games program. A program fault occurs while the user is
playing the game.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(b) Give three ways to minimise the risk of faults when writing programs.
1 ................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
3 ................................................................................................................................................
............................................................................................................................................. [3]
(c) Three types of program error are syntax, logic and run-time.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[3]
14
5 (a) A 1D array, Directory, of type STRING is used to store a list of school internal telephone
numbers. There are 1000 elements in the array. Each element stores a single data item. The
format of each data item is as follows:
<Number><Name>
For example:
"1024Collins Robbie"
Refer to the Appendix on page 21 for a list of built-in pseudocode functions and operators.
PROCEDURE SortContacts ()
DECLARE Temp : STRING
DECLARE FirstName, SecondName : STRING
DECLARE NoSwaps : ……………………………………
DECLARE Boundary, J : INTEGER
Boundary ……………………
REPEAT
NoSwaps TRUE
FOR J 1 TO Boundary
FirstName …………………………(Directory[J], LENGTH(Directory[J]) – …………… )
SecondName RIGHT(Directory[J + 1], LENGTH(Directory[J + 1]) – 4)
IF FirstName ………………………………
THEN
Temp Directory[J]
Directory[J] Directory ……………………………
Directory[J + 1] Temp
NoSwaps ……………………………
ENDIF
ENDFOR
Boundary ……………………………
UNTIL NoSwaps = TRUE
ENDPROCEDURE
[8]
15
(b) The pseudocode contains a mechanism designed to make this an efficient bubble sort.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
16
6 A company hires out rowing boats on a lake. The company has ten boats, numbered from 1 to 10.
The company is developing a program to help manage and record the hiring out process.
Hire information is stored in three global 1D arrays when a boat is hired out. Each array contains
10 elements representing each of the ten boats.
If an individual boat is not currently on hire, the corresponding element of the HireTime array will
be set to "Available".
Module Description
• Called with two parameters:
o a STRING value representing a time
AddTime() o 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
• Called with a STRING value representing the time the
hire will start
• Outputs the boat numbers that will be available for hire at
the given start time. A boat will be available for hire if it is
either:
ListAvailable()
o currently not on hire, or
o due back before the given hire start time
• Outputs the number of each boat available
• Outputs the total number of boats available or a suitable
message if there are none
• Called with four parameters:
o an INTEGER value representing the boat number
o a STRING value representing the hire start time
o an INTEGER value representing the hire duration in
minutes
o a REAL value representing the cost of hire
RecordHire()
• Updates the appropriate element in each array
• Adds the cost of hire to the global variable DailyTakings
• Converts the four input parameters to strings,
concatenated using commas as separators, and writes
the resulting string to the end of the existing text file
HireLog.txt
17
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
18
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
19
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 2020 9608/21/M/J/20 [Turn over
MUHAMMAD ALI KHAN
PAGE 813
20
Module Description
• Called with two parameters:
o a STRING value representing a time
AddTime() o 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
(i) Write program code for a statement that uses the AddTime() function to add a duration
of 60 minutes to a start time contained in variable BeginTime and to assign the new
time to variable EndTime.
Program code
...........................................................................................................................................
..................................................................................................................................... [2]
Complete the following two tests that can be performed to check the operation of the
function. Note that test 1 and test 2 are different.
Test 2 – Boat is returned during the hour after the rental starts
21
Appendix
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
Max 3
1(c) 3
2(a) 5
Mark as follows:
1 One mark for all three boxes correctly labelled
2 One mark for selection diamond
3 One mark for passing value and return Boolean from PayByCard()
4 One mark for passing Value, AccountNUmber and AccountLimit to
PayByAccount()
5 One mark for passing CurrentBalance ByRef
Max 2
• Line number: 33
• Correction: IF NextChar >= 'A' AND NextChar <= 'Z'
ENDCASE
Multiple ← 1
Balance ← GetBalance(PhoneNum)
IF Balance > 10
THEN
Multiple ← 1.125
ELSE
IF Balance > 5
THEN
Multiple ← 1.1
ENDIF
ENDIF
ENDPROCEDURE
Note:
MP6 could be included in MP7 statement
Note:
Credit alternative solutions for forming and checking a single output string
4(a) A program fault is something that makes the program not do what it is 2
supposed to do under certain circumstances
Max 3
Logic Error:
An error in the algorithm that causes the program not to behave as intended
Run-time:
A program performs an invalid operation / tries to divide by zero // enters an
infinite loop / stops unexpectedly
5(b) Description: 4
• uses a flag variable to stop the outer loop
• after no more swaps made during one pass of the inner loop
• the flag is reset before the inner loop starts, and set whenever a swap is
made
• decreases the loop size at end of inner loop (Boundary decremented)
Effective because:
• It prevents unnecessary iterations / passes through the array (i.e. when
the array is already sorted) // terminates the algorithm when all elements
are in order // reduces the number of unnecessary comparisons
NumAvailable ← 0
FOR Index ← 1 TO 10
Available ← FALSE // initialise
IF HireTime[Index] = "Available" // not on hire
THEN
Available ← TRUE // available now
ELSE
TimeBack ← AddTime(HireTime[Index],__
Duration[Index])
IF TimeBack < StartTime // < or <=
THEN
Available ← TRUE // will be available
ENDIF
ENDIF
IF Available = TRUE
THEN
OUTPUT "Boat " , Index , " is available"
NumAvailable ← NumAvailable + 1
ENDIF
ENDFOR
IF NumAvailable > 0
THEN
OUTPUT "There are " , NumAvailable ,__
" boats available."
ELSE
OUTPUT "Sorry, there are no boats available"
ENDIF
ENDPROCEDURE
6(b) 'Pseudocode' solution included here for development and clarification of mark 7
scheme.
Programming language example solutions appear in the Appendix.
HireTime[HBoatNumber] ← HTime
Duration[HBoatNumber] ← HDuration
Cost[HBoatNumber] ← HCost
CLOSEFILE "HireLog.txt"
ENDFUNCTION
Max 7
6(c)(i) 'Pseudocode' solution included here for development and clarification of mark 2
scheme.
Programming language example solutions appear in the Appendix.
One mark per underlined section (Space before bracket for mark scheme
clarification only)
For example:
Test 1
Start time value "10:00", Duration value 30
Expected new time value "10:30"
Test 2
Start time value "10:45", Duration value 30
Expected new time value "11:15"
HireTime(HBoatNumber) = HTime
Duration(HBoatNumber) = HDuration
Cost(HBoatNumber) = HCost
Print(1, FileLine)
PrintLine(1)
Fileclose(1)
End Sub
Q6(b)(i): Pascal
var
Fileline : string;
ThisFile: TextFile;
begin
HireTime[HBoatNumber] := HTime;
Duration[HBoatNumber] := HDuration;
Cost[HBoatNumber] := HCost;
AssignFile(Thisfile, "HireLog.txt");
writeln(ThisFile, FileLine);
CloseFile(ThisFile);
end;
Q6(b)(i): Python
# FileLine : String
# File : File handle
Comma = ','
HireTime[HBoatNumber] = HTime
Duration[HBoatNumber] = HDuration
Cost[HBoatNumber] = HCost
File.write(FileLine)
File.close
Q6(c)(i): Pascal
Q6(c)(i): Python
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
MUHAMMAD ALI KHAN
PAGE 829
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 834
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
MUHAMMAD ALI KHAN
PAGE 835
(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:[email protected]"
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
Name: Sequence
Description: Instructions / lines of code are executed in a fixed order
OR
Name: Assignment
Description: A value is given to a variable
Max 3
Max 2
Note:
Must include reference to given scenario to achieve all 3 marks - Max 2 if no
reference.
2(b)(ii) 6
Notes:
Parameter types must be as shown but ignore parameter names (if given)
Check ← INT(Deviate(Course))
Adjust ← 255
CASE OF Check
-20 to -1: Adjust ← 10
0 : Adjust ← 0
1 to 20 : Adjust ← -10
OTHERWISE CALL Alert()
ENDCASE
RETURN Adjust
ENDFUNCTION
REPEAT
Rnum ← INT(RAND(100)) + 1 // from original question
Exists ← FALSE
FOR Index ← 1 to NextNum - 1 // search for Rnum
IF Random[Index] = Rnum
THEN
Exists ← TRUE
ENDIF
ENDFOR
IF Exists = FALSE
THEN
Random[NextNum] ← Rnum // store Rnum
NextNum ← NextNum + 1 // increment index
ENDIF
UNTIL NextNum > 10
Notes:
Max 5 if statement to generate random number (as given in Q) not present or
incorrectly placed.
Alternative Solution:
Mark as follows:
1 SET Index to 1
2 SELECT the character from input parameter string at Index position
3 IF character is colon then go to 5
4 Else INCREMENT Index and repeat from 2
5 Extract a substring from the left of the parameter string (and assign this to
variable Name)
6 ...Using Index -1 for the length
7 RETURN Name
Note:
Mark points may be combined for equivalent marks
e.g a suitable structured English description of the pseudocode statement
below satisfies MP 5, 6 and 7:
5(b)(i) Description: 4
5(b)(ii) 'Pseudocode' solution included here for development and clarification of mark 8
scheme.
Programming language example solutions appear in the Appendix.
PROCEDURE BubbleSort()
DECLARE Temp : STRING
DECLARE NoSwaps : BOOLEAN
DECLARE Boundary, J : INTEGER
Boundary ← 999
REPEAT
NoSwaps ← TRUE
FOR J ← 1 TO Boundary
IF Contact[J] > Contact[J+1]
THEN
Temp ← Contact[J]
Contact[J] ← Contact[J+1]
Contact[J+1] ← Temp
NoSwaps ← FALSE
ENDIF
ENDFOR
Boundary ← Boundary - 1
UNTIL NoSwaps = TRUE
ENDPROCEDURE
Mark as follows:
StartHours ← STRING_TO_NUM(LEFT(StartTime,2))
StartMinutes ← STRING_TO_NUM(RIGHT(StartTime, 2))
Total ← (StartHours * 60) + StartMinutes + Duration
NewHours ← DIV(Total, 60)
NewMinutes ← MOD(Total, 60)
NewTime ← ""
IF NewHours < 10
THEN
NewTime ← '0' // add leading zero to hours
ENDIF
IF NewMinutes < 10
THEN
NewTime ← NewTime & '0'// add leading zero
ENDIF
RETURN NewTime
ENDFUNCTION
Note:
Accept alternative methods for calculation of NewHours and NewMinutes
Explanation:
Suitable explanation
Note:
Accept times that would also be invalid for the given scenario.
6(c) 'Pseudocode' solution included here for development and clarification of mark 8
scheme.
Programming language example solutions appear in the Appendix.
PROCEDURE GetTotals()
FOR BoatNum ← 1 TO 17
Total[BoatNum] ← 0
ENDFOR
ENDWHILE
CLOSEFILE "Hirelog.txt"
ENDPROCEDURE
Sub BubbleSort()
Dim Temp As String
Dim NoSwaps As Boolean
Dim Boundary, J As Integer
Boundary = 999
Do
NoSwaps = TRUE
For J = 1 To Boundary
If Contact(J) > Contact(J+1) Then
Temp = Contact(J)
Contact(J) = Contact(J+1)
Contact(J+1) = Temp
NoSwaps = FALSE
End If
Next
Boundary = Boundary - 1
Loop Until NoSwaps = TRUE
End Sub
Q5(b)(i): Pascal
procuedre BubbleSort()
var
Temp : String;
NoSwaps : Boolean;
Boundary, J : Integer;
Boundary := 999
repeat
begin
NoSwaps := TRUE
for J := 1 to Boundary do
begin
if Contact[J] > Contact[J+1]then
begin
Temp := Contact[J];
Contact[J] := Contact[J+1];
Contact[J+1] := Temp;
NoSwaps := FALSE;
end;
end;
Boundary := Boundary – 1
end;
until NoSwaps = TRUE;
End Sub
Q5(b)(i): Python
def BubbleSort()
# Temp : String
# NoSwaps : Boolean
# Boundary, J : Integer
Boundary = 999
NoSwaps = TRUE
Boundary = Boundary - 1
End Sub
Sub GetTotals()
For BoatNum = 1 To 17
Total(BoatNum) = 0
Next
File.Close()
End Sub
Q6(c): Pascal
procedure GetTotals()
var
BoatNum : Integer;
Paid : Real;
MyFile : testfile;
for BoatNum := 1 to 17 do
Total[BoatNum] := 0;
assignFile(MyFile, "Hirelog.txt");
reset(MyFile);
close(MyFile)
end;
Q6(c): Python
def GetTotals()
# BoatNum : Integer
# Paid : Real
# File : File Handle
# FileData : String
File.Close()
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
MUHAMMAD ALI KHAN
PAGE 859
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
MUHAMMAD ALI KHAN
PAGE 863
(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:[email protected]"
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
MUHAMMAD ALI KHAN
PAGE 873
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
Reason: Make the problem easier to solve // to make the solution easier to
implement / test / maintain
1(d) • Breakpoints 2
• Single-stepping
• Watch window
Max 2
Max 2
ENDFOR
Alternative
1 Initialisation of Count
2 FOR loop
3 Check column 1 element and increment count
4 Check column 2 element and increment count // nested loops
5 OUTPUT Count together with suitable mesage
3(a) 5
Mark as follows:
• One mark for START and END
• One mark per area outlined
3(b)(i) Error 1 2
• Index stops at 5 – shoud go to 6. Fails to loop correctly through all
characters of string (lines 26 to 38) // Final values for NumUpper is not as
expected (because of loop error)
Error 2
• Trace table row 12 – NumOther assigned wrong value. 0 expected not 3
3(b)(ii) Error 1 2
Line Number: 26 Correction: FOR Index ← 1 to StrLen
Error 2
Line Number: 41 Correction: NumOther ← StrLen –(NumDigit +
NumUpper)
4(a) 'Pseudocode' solution included here for development and clarification of mark 5
scheme.
Programming language example solutions appear in the Appendix.
RETURN Name
ENDFUNCTION
Alternative:
ENDFUNCTION
Mark as follows:
1 Function heading and ending (where required) including parameters
2 Extract (next) character from InString
3 Conditional loop while character is not colon
4 Append character to Name and increment Index in a loop // calculate
substring length and use LEFT() after loop
5 RETURN Name (may be combined with alternative mp 4)
Alternative #1
Header:
PROCEDURE Extract (BYREF Name : STRING, BYREF Email :
STRING, BYVALUE DataItem : STRING)
Explanation:
Could additionally pass the name and email address to the procedure
using BYREF. Procedure would extract name and email and assign
values to BYREF parameters; these would then be available to calling
program.
Alternative #2
Header:
PROCEDURE Extract (DataItem : STRING)
Explanation:
Declare new global variables for the name and email address. These
could be assigned values within the new procedure and these values
would be used by the calling program.
Mark as follows:
• Two marks for header – must be a Procedure not a Function (but see
note below)
• Max Two marks for explanation
Note:
Allow solution based on user-defined record type / record item returned from
modified function.
Max 3
LastService ← ""
ENDWHILE
Close "ServiceLog.txt"
RETURN LastService
ENDFUNCTION
TotHours ← 0
ENDWHILE
Close "HireLog.txt"
RETURN TotHours
ENDFUNCTION
String example 1
• String: "007"
• Reason: Too many characters
String example 2
• String: "4x"
• Reason: String does not represent a numeric value / contains an illegal
character
String example 3
• String: "25"
• Reason: number outside range 1 to 20
5(c) 'Pseudocode' solution included here for development and clarification of mark 8
scheme.
Programming language example solutions appear in the Appendix.
Due ← FALSE
OUTPUT "Boat Service List"
FOR BoatNum ← 1 TO 20
LastService ← GetLastService(NUM_TO_STRING(BoatNum))
Hours ← GetHours(NUM_TO_STRING(BoatNum),LastService)
IF Hours > MaxHours
THEN
OUTPUT NUM_TO_STRING(Boatnum) & ": "__
& NUM_TO_STRING(Hours)
Due ← TRUE
ENDIF
ENDFOR
IF Due = TRUE
THEN
OUTPUT "No boats are due to be serviced"
ENDIF
ENDPROCEDURE
Max 2
• Testing may be carried out before the modules are developed // not ready
for full testing
Max 2
Index = 1
Name = ""
NextChar = Left(InString, 1)
Return Name
End Function
Q4(a): Pascal
const
COLON = ':';
Index := 1;
Name := "";
NextChar := copy(InString, 1, 1);
extract := Name;
end;
Q4(a): Python
def Extract(InString)
# Name : String
# NextChar : Char
# Index : Integer
COLON = ':'
Index = 1
Name = ""
NextChar = InString[1:2]
Return Name
Due = 0
console.writeline("Boat Service List")
For BoatNum = 1 To 20
LastService = GetLastService(CStr(BoatNum))
Hours = GetHours(CStr(BoatNum), LastService)
If Hours > MaxHours Then
Console.Writeline(CStr(Boatnum) & ": " & CStr(Hours))
Due = Due + 1
End If
Next
If Due = 0 Then
Console.Writeline("No boats are due to be serviced")
End If
End Sub
Q5(c): Pascal
var
BoatNum, Due : integer;
LastService : string;
Due := 0
print("Boat Service List")
for BoatNum := 1 to 20 do
begin
LastService := GetLastService(CInt(BoatNum));
Hours := GetHours(BoatNum, Lastservice);
If Hours > MaxHours then
begin
writeln(IntToStr(Boatnum) & ": " & IntToStr(Hours));
Due := Due + 1;
end;
end;
If Due = 0 then
writeln ("No boats are due to be serviced")
End If
End Sub
Q5(c): Python
def ServiceList(MaxHours)
Due = 0
print("Boat Service List")
if Due == 0:
print"No boats are due to be serviced")
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 (LK) 188573/3
© UCLES 2020 [Turn over
PAGE 890
1 ................................................................................................................................................
2 ................................................................................................................................................
3 ................................................................................................................................................
[3]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[2]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(d) Jackie has written a program and has used the identifier names I1, I2, and I3.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
GateOpen FALSE
Alarm TRUE
PowerFail TRUE
Expression Evaluates to
2 (a) User names are stored in a text file. Each line of the file represents one name. Before a new
user name can be issued, a check has to be made to ensure that the new name is unique.
Use structured English to describe an algorithm that would prompt and input a new user
name and output a message to indicate whether or not it is unique.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
Use only the functions and operators described in the Appendix on pages 18–19.
Expression Evaluates to
2 * .......................... ("Kipper") 12
.......................... (9, 2) 1
[5]
© UCLES 2020 9608/21/O/N/20
MUHAMMAD ALI KHAN
PAGE 893
Answer
The procedure is tested using the file MyFile.txt that contains 100 lines of text.
(a) The procedure is correctly called with three parameters of the appropriate data types, but the
procedure does not give the expected result.
1 ................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
3 ................................................................................................................................................
...................................................................................................................................................
[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.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
© UCLES 2020 9608/21/O/N/20 [Turn over
PAGE 896
(i) Describe one type of error that the program could still contain.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(ii) Give two techniques that may be used to identify an error of the type given in part (c)(i).
Technique 1 .......................................................................................................................
...........................................................................................................................................
Technique 2 .......................................................................................................................
...........................................................................................................................................
[2]
(d) State two reasons why the use of library subroutines can be a benefit in program development.
1 ................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
[2]
10
4 A function, FormOut(), takes an integer parameter in the range 0 to 999 999 and returns a
formatted string depending on two other parameter values.
• A prefix string to be added before the integer value (e.g. '$' or "Total: ")
• A comma as a thousand-separator (e.g. "1,000")
(a) Fill in the tables to show two tests that could be carried out to test different aspects of the
function.
TEST 1
Parameter Value
Expected return string:
Number
Prefix ...............................................................
AddComma
TEST 2
Parameter Value
Expected return string:
Number
Prefix ...............................................................
AddComma
[4]
11
Refer to the Appendix on pages 18–19 for the list of built-in functions and operators.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
12
A hashtag is a string consisting of a hash character ‘#’, followed by one or more alphanumeric
characters.
A hashtag may be terminated by a space character, the start of the next hashtag, any other
non-alphanumeric character, or by the end of the message.
A global 1D array of strings, TagString, will store each hashtag in a single element.
Unused array elements will contain an empty string. The array will contain 10 000 elements.
Module Description
• Called with two parameters:
• a message string
• an integer giving the number of the required hashtag.
GetStart() For example, GetStart(Message, 3) would search
for the third hashtag in the string Message
• Returns an integer value representing the start position
RIWKHKDVKWDJLQWKHPHVVDJHVWULQJRUYDOXHíLIWKDW
hashtag does not exist
• Called with two parameters:
• a message string
GetTag() • an integer giving the hashtag start position within the
message
• Returns the hashtag or an empty string if the character in
the message at the hashtag start position is not '#'
• Called with a hashtag as a parameter
• Returns the index position of the hashtag in array
GetIndex() TagString
• 5HWXUQVWKHYDOXHíLIWKHKDVKWDJLVQRWSUHVHQWLQWKH
array
13
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
14
Module Description
• Called with two parameters:
• a message string
• an integer giving the number of the required hashtag. For
example, GetStart(Message, 3) would search for the
GetStart()
third hashtag in the string Message
• Returns an integer value representing the start position of the
KDVKWDJLQWKHPHVVDJHVWULQJRUYDOXHíLIWKDWKDVKWDJGRHV
not exist
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
© UCLES 2020 9608/21/O/N/20
PAGE 902
16
Module Description
• Called with two parameters:
• a message string
• an integer giving the hashtag start position within the
GetTag()
message
• Returns the hashtag or an empty string if the character in the
message at the hashtag start position is not '#'
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
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.
19
Operators (pseudocode)
Operator Description
PAGE 906
• The knowledge / experience / understanding of one programming language
• Can be applied to another / unfamiliar language // will help recognise control structures in another / unfamiliar
language // will help them learn a new language
• Names are not meaningful (or equivalent) // name does not reflect the identifier's use// easy to use the wrong name
• Makes the program more difficult to understand / debug / modify / test
1(e) 1 mark for any two rows correct, 2 marks for all rows correct. 2
Expression Evaluates to
PAGE 907
2 OPEN the file in read mode and close the file
3 Initialise a Boolean variable, e.g. UniqueFlag to TRUE
4 LOOP while not End of File (AND new user name not found)
5 Read a line from the file
6 If line is same as new user name (then set termination condition else repeat from step 4)
7 IF UniqueFlag is TRUE then output ‘Unique’ otherwise output ‘Not unique’
2(b) One mark per row (for expression completed by addition of text shown in bold): 5
Expression Evaluates to
MID("Concatenate", 6, 3) "ten"
2 * LENGTH("Kipper") 12
MOD(9, 2) 1
3(b) 'Pseudocode' solution included here for development and clarification of mark scheme. 7
Programming language example solutions appear in the Appendix.
CLOSE FileName
ENDPROCEDURE
CLOSE FileName
ENDPROCEDURE
3(c)(i) One mark for type plus one for corresponding explanation to max 2 marks 2
• Logic(al) Error
• The program does not perform as expected (or by example)
OR
• Run-time error
PAGE 911
• The program executes an invalid instruction / attempts to divide by zero // the program crashes
Prefix Non-empty
Empty String
String
4(b) FUNCTION FormOut(Num : INTEGER, Prefix : STRING, AddComma : BOOLEAN) RETURNS STRING 8
RETURN OutString
ENDFUNCTION
1 Functon heading and ending (inc parameters) and return data type
2 Use of NUM_TO_STRING
3 Test AddComma and if TRUE …
4 Test number of digits in Num
5 Split NUM_TO_STRING(Num) and
6 Form OutString with inserted comma
7 Concatenate the Prefix with OutString
8 Return OutString
Index ← 1
Found ← FALSE
IF Found = FALSE
THEN
PAGE 915
Index ← -1
ENDIF
RETURN Index
ENDFUNCTION
1 Declaration of Index as Integer and Found as Boolean // RetIndex as Integer if this used for loop termination
2 Initialisation of Index
3 Conditional loop for 10ௗ000 elements while HashTag not found
4 Compare HashTag with element from TagString array in a loop
5 Set termination condition / store current index if match found in a loop
6 Return Integer value
Count ← 0
StartPos ← -1
Index ← 1
MessLength ← LENGTH(Message)
ENDIF
Index ← Index + 1
ENDWHILE
RETURN StartPos
ENDFUNCTION
5(c) ‘Pseudocode’ solution included here for development and clarification of mark scheme. 8
Programming language example solutions appear in the Appendix.
Max 8 marks from 9 mark points
MyString ← ""
EndTag ←FALSE
5(c) ENDIF
IF LENGTH(MyString) = 1
THEN
MyString = "" // when Hash is last char in string
ENDIF
RETURN MyString
ENDFUNCTION
1 Function heading and ending including parameters and return data type (not python)
2 Declaration and initialisation of return string (MyString)
3 Test for valid start character
4 Loop from StartPos+1 while not end of message
5 Extract NextChar
6 Test if NextChar is terminator character in a loop
7 If NextChar not a terminator then concatenate with MyString in a loop
8 Cater for MyString only containing a Hash character (return empty string)
9 Return MyString
PAGE 918
*** End of Mark Scheme – example program code solutions follow ***
File.Close
End Sub
PAGE 919
var
FileData : string;
Count : integer;
ThisFile : textfile;
begin
assignfile(ThisFile, FileName);
reset(ThisFile);
closefile(ThisFile);
end;
PAGE 920
Q3 (b): Python
Count = 1
File = open(FileName, "r")
File.close()
MyString = ""
EndTag = FALSE
NumChars = Len(Message)
If MyString = HASH Then MyString = "" 'When Hash is last char in message
Return MyString
End Function
const
HASH = '#';
SPACE = ' ';
MyString = '';
EndTag = FALSE;
NumChars := Length(Message);
Index := StartPos + 1;
while Index <= NumChars And EndTag = FALSE do;
begin
NextChar := Midstr(Message, Index, 1);
TestChar := UpperCase(NextChar);
If NextChar = SPACE OR NextChar = HASH Or
Not ((TestChar >= 'A' And TestChar <= 'Z') Or
TestChar >= '0' And TestChar <= '9')) then
EndTag := TRUE;
Else
MyString:= MyString + NextChar;
Index := Index + 1;
end;
end;
GetTag := MyString;
end;
Q5 (c): Python
#EndTag as BOOLEAN
#Index as INTEGER
#MyString as STRING
#NextChar, TestChar as CHAR
HASH = '#'
SPACE = ' '
MyString = ""
EndTag = FALSE
PAGE 923
NumChars = len(Message)
if message[Index] == "#":
MyString = HASH
Index = StartPos + 1
if MyString = HASH:
MyString = "" #When Hash is last char in message
return HashTag
PAGE 924
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 926
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
MUHAMMAD ALI KHAN
PAGE 929
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [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 934
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
MUHAMMAD ALI KHAN
PAGE 939
15
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
© UCLES 2020 9608/22/O/N/20 [Turn over
PAGE 940
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
MUHAMMAD ALI KHAN
PAGE 941
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
• Process
• Output
Example answers:
PAGE 944
BOOLEAN FALSE
STRING "Happy"
INTEGER 18
REAL 31234.56
CHAR 'H'
DATE 10/01/2019
Each row must be a different data type together with an appropriate value
1(e) 1 mark for two rows correct, 2 marks for all rows correct. 2
Expression Evaluates to
INPUT A
REPEAT
INPUT B
UNTIL B <> A
REPEAT
INPUT C
UNTIL C <> A AND C <> B
Average ← (A + B + C) / 3
OUTPUT Average
Mark as follows:
1 Declaration of all variables used (at least A, B and C)
2 Uniqueness test on A, B and C
3 Loop(s) to repeat until three unique values have been entered
4 Calculation of average value
5 Determine the largest value
6 Output of average value and largest value
Expression Evaluates to
MID("Stepwise.",5, 4) "wise"
1.5 * LENGTH("OnePointFive") 18
NUM_TO_STRING(27.5) "27.5"
DIV(9, 4) 2
1 Subtasks make the solution more manageable // make the algorithm easier to follow
PAGE 948
2 A subtask makes the problem easier to solve / design / program than the whole task
3 A subtask is useful when a part of the algorithm is repeated
3(a) 'Pseudocode' solution included here for development and clarification of mark scheme. 8
Programming language example solutions appear in the Appendix.
FOR Index ← 1 TO 4
REPEAT
OUTPUT "Input Rotation speed for wheel ",Index
INPUT ThisRot
UNTIL ThisRot >= 0 AND ThisRot <= 1000
Rot[Index] ← ThisRot
ENDFOR
Danger ← FALSE
FOR Index ← 1 TO 4
IF Rot[Index] > (Average * 1.1) OR Rot[Index] < (Average * 0.9)
THEN
Danger ← TRUE
ENDIF
ENDFOR
IF Danger = TRUE
THEN
OUTPUT "Skid Danger"
ENDIF
RETURN Danger
ENDFUNCTION
One of:
4(a) 7
Mark as follows:
• One mark for START and END
• One mark per area outlined
PAGE 951
"BU" 2
2 'U' ""
1
PAGE 952
"B" 2
"B" 3
1 'B' ""
1
""
4(b)(ii) TRUE 1
4(b)(iii) One mark for explanation of problem, one mark for test strings 2
Problem:
• The inner FOR loop removes ALL characters from String2 that match the current character from String1 and not just
one instance
Test Strings:
4(b)(iv) The inner FOR loop should only remove one instance of the character from String2 1
• Single stepping
• Breakpoints
• Variable and expressions report window
• Syntax error highlighting
ENDPROCEDURE
NumUnused ← 0
RETURN NumUnused
ENDFUNCTION
5(c) ‘Pseudocode’ solution included here for development and clarification of mark scheme. 8
Programming language example solutions appear in the Appendix.
Max 8 marks from 9 available mark points
Index ← Index + 1
ENDWHILE
TagString[ArrayIndex] ← HashTag
CountLen ← LENGTH(FileString) - LENGTH(HashTag) - 1
Count ← STR_TO_NUM(RIGHT(FileString, CountLen)) // count
TagCount[ArrayIndex] ← Count
ArrayIndex ← ArrayIndex + 1
ENDWHILE
CLOSE "Backup.txt"
RETURN ArrayIndex
ENDFUNCTION
*** End of Mark Scheme – example program code solutions follow ***
PAGE 957
For Index = 0 To 3
Do
Console.Writeline("Enter Wheel Rotation Speed: "
ThisRot = Console.Readline()
Loop Until ThisRot >= 0 And ThisRot <= 1000
Rot(Index) = ThisRot
Next
Danger = FALSE
PAGE 958
For Index = 0 TO 3
If Rot(Index) > (Average * 1.1) OR Rot(Index) < (Average * 0.9) Then
Danger = TRUE
End If
Next
RETURN Danger
End Function
var
Rot : array [1..4] of integer;
Average : Real;
ThisRot : Integer;
Index : Integer;
Danger : Boolean;
For Index := 1 to 4 do
begin
repeat
write('Enter rotation speed : ');
readln(ThisRot);
until (ThisRot >= 0) And (ThisRot <= 1000);
Rot[Index] := ThisRot;
end;
Danger := FALSE;
For Index := 1 to 4 do
begin
If (Rot[Index] > (Average * 1.1)) OR (Rot[Index] < (Average * 0.9)) then
Danger := TRUE;
end;
CheckSkid := Danger;
end;
def CheckSkid():
# Rot[3] As Integer
# Average As Real
# ThisRot As Integer
# Danger As Boolean
Rot = [0, 0, 0, 0]
for Index in range(0, 4):
while True:
ThisRot = float(input("Enter the rotation speed of the wheel: "))
if ThisRot >= 0 and ThisRot <= 1000:
break
Rot[Index] = ThisRot
Next
Danger = False
for Index in range(0, 4):
PAGE 960
If Danger == True:
print("Skid Danger")
else:
print("No Skid Danger")
return Danger
TagString(arrayIndex) = HashTag
PAGE 961
File.Close
Return ArrayIndex
End Function
var
ArrayIndex, Index, CountLen, Count : Integer;
FileData, HashTag : String;
Backup : Textfile;
const
COMMA = ',';
begin
assignfile(Backup, 'Backup.txt');
reset(File);
Index := 1;
HashTag := "";
while midstr(FileData, Index, 1) <> COMMA do // the hashtag
begin
HashTag := HashTag + midstr(FileData, Index, 1);
Index := Index + 1;
end;
TagString[ArrayIndex] := HashTag;
CountLen := length(FileData) – length(HashTag) – 1;
Count := strtoint(RightStr(FileData, CountLen)); // the count
TagCount[ArrayIndex] := Count;
ArrayIndex := ArrayIndex + 1;
end;
closefile(File);
COMMA = ','
TagString[ArrayIndex] = HashTag
Count = int(FileString[Index+1:]) # the count
PAGE 963
TagCount[ArrayIndex] = Count
ArrayIndex = ArrayIndex + 1
File.close()
return ArrayIndex
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
MUHAMMAD ALI KHAN
PAGE 965
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 966
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
MUHAMMAD ALI KHAN
PAGE 967
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 968
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
MUHAMMAD ALI KHAN
PAGE 969
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [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 976
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
MUHAMMAD ALI KHAN
PAGE 977
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 978
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.
• to express the algorithm in a level of sufficient detail // to split a large task into (smaller) sub-tasks
• so that it can be programmed // so that individual tasks are easier to solve // to make the problem more manageable /
understandable
1(b) Many acceptable answers, must be four different data types together with appropriate values 4
One mark per row
For example:
BOOLEAN FALSE
CHAR '!'
PAGE 980
DATE 01/01/01
INTEGER 27
Note: STRING and REAL are excluded as these are given in the question.
1 Set Total to 0
2 Set AGradeCount to 0
3 Input Mark
PAGE 981
Statement Error
2(c) ‘Pseudocode’ solution included here for development and clarification of mark scheme. 6
Programming language example solutions appear in the Appendix.
Index ← 0
Status ← FALSE
WHILE Status <> TRUE
Status ← TopUp()
Index ← Index + 1
ENDWHILE
Mark as follows:
2 Pre-condition loop
3 Assign value of TopUp() to Status in a loop
4 Increment Index in a loop
5 Test Index greater than 100 after loop
6 If TRUE then Call to SetLevel with param "Super"
3(a) ‘Pseudocode’ solution included here for development and clarification of mark scheme. 7
Programming language example solutions appear in the Appendix.
PROCEDURE BubbleSort()
DECLARE Temp : INTEGER
DECLARE NoSwaps : BOOLEAN
DECLARE Boundary, J : INTEGER
Boundary ← 4999
REPEAT
NoSwaps ← TRUE
FOR J ← 1 TO Boundary
IF ProdNum[J]> ProdNum[J+1]
THEN
Temp ← ProdNum[J]
ProdNum[J] ← ProdNum[J+1]
ProdNum[J+1] ← Temp
NoSwaps ← FALSE
PAGE 984
ENDIF
ENDFOR
Boundary ← Boundary - 1
UNTIL NoSwaps = TRUE
ENDPROCEDURE
RetVal ← -1
Index ← 1
RETURN RetVal
ENDFUNCTION
PAGE 986
Mark as follows:
1 Function heading and ending including parameter
2 Declaration of integer for Index
3 Initialisation and increment of Index (implied in FOR loop)
4 Conditional loop // FOR loop with immediate RETURN if SearchString found
5 Comparison of array element with SearchString AND assigning just the first occurrence to RetVal OR setting
the termination condition
6 Return RetVal (correctly in both cases)
• Program doesn’t perform as expected / does not meet the original specification
• Program contains errors / bugs
• Performance / efficiency needs improving
• New hardware has been introduced
Output Explanation
Added ← FALSE
Index ← 1 // first element
REPEAT
IF TagString[Index] = EMPTY
THEN
TagString[Index} ← HashTag
TagCount[Index] ← 1
Added ← TRUE
ELSE
Index ← Index + 1
ENDIF
PAGE 988
RETURN Added
ENDFUNCTION
1 Declaration of two local variables: Integer for index & Boolean for return value (unless immediate Return used)
2 Conditional loop through all elements until empty element found OR end of array
3 Test if TagString element is empty in a loop
4 If so then assign HashTag to TagString[] and 1 to TagCount[]
5 Set loop termination
6 Return Boolean (for both cases)
5(b) ‘Pseudocode’ solution included here for development and clarification of mark scheme. 6
Programming language example solutions appear in the Appendix.
TagNum ← 0
Found ← TRUE
REPEAT
StartPos ← GetStart(Message, TagNum + 1)
IF StartPos = -1
THEN
Found ← FALSE
ELSE
TagNum ← TagNum + 1
ENDIF
UNTIL NOT Found
PAGE 989
RETURN TagNum
ENDFUNCTION
5(c) ‘Pseudocode’ solution included here for development and clarification of mark scheme. 4
Programming language example solutions appear in the Appendix.
Found ← FALSE
Index ← 1 // first element
REPEAT
IF TagString[Index] = HashTag
THEN
TagCount[Index] ← TagCount[Index] + 1
Found ← TRUE
ELSE
Index ← Index + 1
ENDIF
UNTIL Index > 10000 OR Found = TRUE
PAGE 990
RETURN Found
ENDFUNCTION
Max ← −1
IF Count = 1
THEN
OUTPUT "The most popular hashtag is: ", MostPopTag, "It occurs: ", Max," times.”
ELSE
OUTPUT "The maximum hashtag count is: ",Max,__
"The number of hashtags with this count is: ", Count
ENDIF
ENDPROCEDURE
PROCEDURE OutputMostPop()
DECLARE Index : INTEGER
DECLARE MostPopTag : STRING
DECLARE Max : INTEGER //The integer value of the biggest number
DECLARE MaxCount : INTEGER
PAGE 992
Max ← -1
5(d) MaxCount ← 0
FOR Index ← 1 To 10000
IF TagCount[Index] = Max
THEN
MaxCount ← MaxCount + 1
ENDIF
ENDFOR
IF MaxCount = 1
THEN
OUTPUT "The most popular hashtag is: ", MostPopTag, ". It occurs: ", Max," times.”
ELSE
OUTPUT "The mamimum value is: ",Max, ". It occurred ", MaxCount, " times."
ENDIF
ENDPROCEDURE
*** End of Mark Scheme – example program code solutions follow ***
PAGE 993
Index = 0
Status = FALSE
Do While Status <> TRUE
Status = TopUp()
Index = Index + 1
Loop
Q2 (c): Pascal
Index := 0;
Status := FALSE;
begin
Status := TopUp();
Index := Index + 1;
end;
Index = 0
Status = FALSE
while Status <> TRUE:
Status = TopUp()
Index = Index + 1
Sub BubbleSort()
Dim Temp As Integer
Dim NoSwaps As Boolean
Dim Boundary, J As Integer
Boundary = 4998
Do
NoSwaps = TRUE
PAGE 995
For J = 0 To Boundary
If ProdNum(J)> ProdNum(J+1)Then
Temp = ProdNum(J)
ProdNum(J) = ProdNum(J+1)
ProdNum(J+1) = Temp
NoSwaps = FALSE
End If
Next
Boundary = Boundary - 1
Loop Until NoSwaps = TRUE
End Sub
Peocedure BubbleSort();
var
Temp: Integer;
NoSwaps : Boolean;
Boundary, J : Integer;
begin
Boundary := 4999;
repeat
NoSwaps := TRUE;
for J := 1 To Boundary do
begin
if ProdNum[J] > ProdNum[J+1] then
begin
Temp := ProdNum[J];
ProdNum[J] := ProdNum[J+1];
ProdNum[J+1] := Temp;
NoSwaps := FALSE;
end;
end;
PAGE 996
Boundary := Boundary – 1;
until NoSwaps = TRUE;
end;
def BubbleSort():
# Temp As Integer
# NoSwaps As Boolean
# Boundary, J As Integer
NoSwaps = False
Boundary = 4999
Boundary = Boundary – 1
PAGE 997
TagNum = 0
Found = TRUE
Do
StartPos = GetStart(Message, TagNum + 1)
If StartPos = -1 Then
Found = FALSE
Else
TagNum = TagNum + 1
End If
Loop Until No Found
Return TagNum
End Function
PAGE 998
begin
TagNum := 0;
Found:= TRUE;
repeat
StartPos := GetStart(Message, TagNum + 1);
if StartPos = -1 then
Found := FALSE
else
TagNum := TagNum + 1;
CountHashtag := TagNum;
PAGE 999
end;
TagNum = 0
Found = TRUE
while Found:
StartPos = GetStart(Message, TagNum + 1)
if StartPos == -1:
Found = FALSE
else:
TagNum = TagNum + 1
return TagNum
PAGE 1000
Found = False
Index = 1 'First element
Do
If TagString(Index) = HashTag Then
TagCount(Index) = TagCount(Index) + 1
Found = True
Else
Index = Index + 1
End If
Loop Until Index > 10000 Or Found = True
Return Found
End Function
PAGE 1001
begin
Found := FALSE;
Index := 1; //First element
repeat
If TagString[Index] = HashTag then
begin
TagCount[Index] := TagCount[Index] + 1;
Found := TRUE;
end
else
Index := Index + 1;
IncrementHashtag := Found;
end;
Found = FALSE
Index = 0 #First element
Return Found
PAGE 1003
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) 214717
© UCLES 2021 [Turn over
MUHAMMAD ALI KHAN
PAGE 1005
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/21/M/J/21
PAGE 1008
...................................................................................................................................................
............................................................................................................................................. [2]
[6]
© UCLES 2021 9618/21/M/J/21
PAGE 1010
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/21/M/J/21
PAGE 1022
22
BLANK PAGE
23
BLANK PAGE
24
BLANK PAGE
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of
Cambridge Local Examinations Syndicate (UCLES), which itself is a department of the University of Cambridge.
1(a) 4
Example
Explanation Variable name Data type
value
One mark for each appropriate variable name plus data type
1(b) 5
Statement Error
Should be arithmetic
Result ← 2 & 4 operator (not &) // 2 and 4
should be CHAR / STRING
1(c) Structure: 3
• Record
Justification:
• Allows different data types
• to be stored under one identifier
Mark as follows:
One mark for Structure
Two marks for justification.
Alternative
• Two (1D) arrays
• One of string, one of integer
• Where same index links the name with the score
2(a) 5
• Data from the arrays is written to the files at the end of the day / before the
program is terminated / computer is switched off
• Data can then be read from the files at the start of the next day and written to
/ stored in the arrays
• No need to (re-)enter the data manually // only need to enter data once
3(a)(ii) • The data is retained when the program is terminated / after the computer is 1
switched off // data is stored permanently // non-volatile storage
• Data items are combined to form a single string / saved as a single line in the
file
• Data items are separated by a special character // make each data item a
fixed length
ALTERNATIVE:
Marks as follows:
4(a) 5
Name Flag Index NewName ThisChar
"∇in∇a∇∇Cup"
TRUE 1 ""
'∇'
"∇"
2 'i'
FALSE "∇I"
3 'n'
"∇In"
4 '∇'
TRUE "∇In∇"
5 'a'
FALSE "∇In∇A"
6 '∇'
TRUE "∇In∇A∇"
7 '∇'
"∇In∇A∇∇"
8 'C'
FALSE "∇In∇A∇∇C"
9 'u'
"∇In∇A∇∇Cu"
10 'p'
"∇In∇A∇∇Cup"
Mark as follows:
• One mark for each of columns 2 to 5 (condone missing final 11)
• One mark for final row all correct (including final 11)
ALTERNATIVE:
Line number: 26
5 PROCEDURE Sort() 8
DECLARE Temp : INTEGER
DECLARE NoSwaps : BOOLEAN
DECLARE Boundary, Row, Col : INTEGER
Boundary ← 999
REPEAT
NoSwaps ← TRUE
FOR Row ← 1 TO Boundary
IF Result[Row, 2] > Result[Row + 1, 2] THEN
FOR Col ← 1 TO 2
Temp ← Result [Row, Col]
Result [Row, Col] ← Result [Row + 1, Col]
Result [Row + 1, Col] ← Temp
NEXT Col
NoSwaps ← FALSE
ENDIF
NEXT J
Boundary ← Boundary - 1
UNTIL NoSwaps = TRUE
ENDPROCEDURE
Mark as follows:
1 Outer loop
2 Inner loop
3 Correct comparison in a loop
4 Correct swap of col1 array elements in a loop
5 Correct swap of col2 array elements in a loop (via loop or separate
statements)
6 'NoSwap' mechanism: Conditional outer loop including flag reset
7 'NoSwap' mechanism: Set flag in inner loop to indicate swap
8 Reducing Boundary in the outer loop
• An array (1D) to store the data and a second array (1D) to store the pointers
• An (integer) variable to hold the start pointer and an (integer) variable to store
the next free pointer
ALTERNATIVE:
• Define a record type comprising a data element and a pointer and declare an
array (1D) of this type
• An integer variable to hold the start pointer and an integer variable to store
the next free pointer
Index ← -1
Numfound ← 0
ThisPos ← 1
ENDFUNCTION
7(b) Marks awarded for any reference to each of the following steps of the algorithm: 4
VARIATION:
NextWord ← ""
Done ← FALSE
REPEAT
ThisChar ← MID(FNString, Index, 1)
IF ThisChar <> SPACECHAR THEN
NextWord ← NextWord & ThisChar // build up NextWord
ENDIF
IF ThisChar = SPACECHAR OR Index = LENGTH(FNString) THEN
Done ← TRUE
ENDIF
Index ← Index + 1
RETURN NextWord
ENDFUNCTION
1 Conditional loop
2 Extract char from FNString and compare with SPACECHAR in a
loop
3 Concatenate with NextWord if not SPACECHAR in a loop
4 Exit loop when SPACECHAR encountered or when end of FNString
reached
5 Return NextWord (after reasonable attempt at forming, and must have
been initialised)
Done ← FALSE
NextPos ← Index // must be at least one character in
// the required word
REPEAT
ThisChar ← MID(FNString, NextPos, 1)
IF ThisChar = SPACECHAR OR NextPos =
LENGTH(FNString) THEN
Done ← TRUE
ELSE
NextPos ← NextPos + 1
ENDIF
UNTIL Done = TRUE
ENDFUNCTION
1 Conditional loop
2 ...extract char from FNString and compare with SPACECHAR in a
loop
3 .. increment count if word continues
4 Exit loop when SPACECHAR encountered or when end of FNString
reached
5 Apply substring function and Return
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 1040
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 1052
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED
1(a)(i) 4
Variable Example data value Data type
1(a)(ii) 4
Expression Evaluates to
MID(Name, 1, 3) "Cat"
1(b) 3
Statement Selection Assignment Iteration
Index ← Index + 1 9
ENDWHILE 9
2(a)(i) 4
The number of transitions that result in a different state 3
Current state: S2
• User ID / Username
• Book ID
• Date of loan / return date
2(b)(ii) Many examples but must be data that is NOT required for a loan, but which 1
COULD be required somewhere by the library system.
Answers include:
• Users name / address / phone number / DOB
• Book title / author / publisher / library rack number / ISBN number /
price
• Date of loan / return date (if not already given in part (i))
• The length of the loan (assumed to be the same for all books)
3(d) 2
Count ← 0
FOR Index ← 1 TO 100
RNum[Index] ← INT(RAND(200)) + 1
IF RNum[Index] >= 66 AND RNum[Index] <= 173 THEN
Count ← Count + 1
ENDIF
NEXT Index
OUTPUT Count
Mark as follows:
1 Array declaration
2 Loop for 100 iterations
3 Array element index 'syntax' (left-hand side of assignment
expression) in a loop
4 Use of RAND() to generate value in range (and assign to array
element) in a loop
5 Check if random number within range and if so, increment count in
a loop
6 Output of count (following a reasonable attempt) after the loop
5(b)(i) 4
Answer
FOR Index ← 1 to 6
CharCount[Index] ← 0 //initialise elements
NEXT Index
Index ← 1
CASE OF ThisChar
'a' : CharCount[1] ← CharCount[1] + 1
'e' : CharCount[2] ← CharCount[2] + 1
'i' : CharCount[3] ← CharCount[3] + 1
'o' : CharCount[4] ← CharCount[4] + 1
'u' : CharCount[5] ← CharCount[5] + 1
'a' TO 'z': CharCount[6] ← CharCount[6] + 1
ENDCASE
NEXT Index
FOR Index ← 1 to 6
OUTPUT CharCount[Index] //output results
NEXT Index
ENDPROCEDURE
Mark as follows:
One mark for one correct
Two marks for three correct
Three marks for all correct
Found ← False
Index ← 1
ThisWord ← TO_LOWER(ThisWord)
REPEAT
IF TO_LOWER(IgnoreList[Index]) = ThisWord THEN
Found ← TRUE
ENDIF
Index ← Index + 1
UNTIL Found = TRUE OR Index > 10
RETURN Found
ENDFUNCTION
ThisWordNum ← 0
NewString ← ""
REPEAT
ThisWordNum ← ThisWordNum + 1
Index ← GetStart(ThisWordNum)
IF Index <> -1 THEN //if there is ThisWordNum
NextWord ← GetWord(Index)
IF IgnoreWord(NextWord) = FALSE THEN
NewString ← NewString & UCASE(LEFT(NextWord, 1))
ENDIF
ENDIF
UNTIL Index = -1
OUTPUT NewString
ENDPROCEDURE
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) 222284
© UCLES 2021 [Turn over
MUHAMMAD ALI KHAN
PAGE 1061
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/21/O/N/21 [Turn over
PAGE 1068
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/21/O/N/21 [Turn over
PAGE 1072
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/21/O/N/21
MUHAMMAD ALI KHAN
PAGE 1075
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/21/O/N/21
PAGE 1076
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021
1(a)(ii) One mark for type plus one for corresponding description 2
Description:
• An error in the algorithm / design of the solution
• the program does not behave as expected / give the expected output.
• Accept by example e.g. wrong arithmetic operator used / wrong loop
count
OR
Description:
• The program performs an illegal instruction / invalid operation
• Accept by example: divide by zero or endless loop or simply 'crashes' /
freezes
1(b) 4
Use of variable Data type
1(c)(i) 3
Information Essential Not essential
Departure time 9
Flight Number 9
Departure airport 9
Aircraft type 9
Ticket price 9
1(c)(ii) One mark for technique and one for benefit, Max 1 mark for 'Benefit' 2
Technique: Abstraction
Benefit:
• The solution is simplified so easier / quicker to design / implement
• The system is tailored to the need of the user
Max 2 marks
Max 6 marks
2(b) Count ← 1 6
Flag ← FALSE
WHILE Flag = FALSE AND Count <= 5
CALL ReBoot()
Count ← Count + 1
Flag ← Check()
ENDWHILE
1 Cat
2 Fish
3(b)(i) One mark for data values plus one mark for pointers 3
0 Frog
1 Cat
3 Elk
4 Wasp
5 Bee
3(b)(ii) 2
0 Shark ← End of queue pointer
1 (Cat)
2 (Fish)
3 (Elk)
5 Bee
6 Mouse
7 Dolphin
4(a) 4
Test Test data value Explanation Expected Outcome
4(b) 3
5(a) One mark for the character and one for the corresponding reason. 2
5(b) Design 1
Count ← 0
OPENFILE LogFile FOR APPEND
FOR Index ← 1 TO 2000
FileData ← LogArray[Index]
CLOSEFILE LogFile
RETURN Count
ENDFUNCTION
ENDPROCEDURE
ALTERNATIVE 1:
ALTERNATIVE 2:
Mark as follows:
Found ← FALSE
ThisCol ← StartCol
RETURN ThisCol
ENDFUNCTION
Mark as follows:
Max 7 marks if function heading, including return type, and ending is incorrect
or incomplete
StartCol ← SearchInRow(ThisRow, 1)
IF StartCol = -1 THEN
CentreCol ← StartCol
ELSE
EndCol ← SearchInRow(ThisRow, 1280)
CentreCol ← INT((StartCol + EndCol)/2)
ENDIF
RETURN CentreCol
ENDFUNCTION
Mark as follows:
Max 5 marks if function heading, including return type, and ending is incorrect
or incomplete
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 1086
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
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
MUHAMMAD ALI KHAN
PAGE 1091
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
© UCLES 2021 9618/22/O/N/21 [Turn over
PAGE 1092
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
MUHAMMAD ALI KHAN
PAGE 1095
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
MUHAMMAD ALI KHAN
PAGE 1099
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
MUHAMMAD ALI KHAN
PAGE 1101
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021
1 Breaking down a problem / task into sub problems / steps / smaller parts
2 In order to explain / understand // easier to solve the problem
3 Leading to the concept of program modules // assigning problem parts to
teams
Max 2
1(b) 3
Answer
The technical terms for minimum and Lower bound, upper bound
maximum values that variable n may take
1(c) 4
Expression Evaluates to
ASC('C') 67
2 * STR_TO_NUM ("27") 54
INT(27 / 2) 13
1(d) 2
Expression Evaluates to
2(a) 5
Note:
• Sum and increment steps (bottom-right rectangles) may be in reverse
order in which case sum group will have two output lines
• Data structures
• Algorithms / flowcharts / pseudocode
• Program structure (modules) / use of library routines / module - team
allocation
• User interface // Web-page layout / content (for given scenario)
• Testing method / plan
• Choice of programming language / program environment
Max 3
3(a)(i) Pseudocode: 3
TYPE Student
DECLARE StudentID : STRING
DECLARE Email : STRING
DECLARE Club_1 : INTEGER
DECLARE Club_2 : INTEGER
DECLARE Club_3 : INTEGER
ENDTYPE
Mark as follows:
• Assign a value (of the corrrect data type) outside the normal range to one
of the fields
• Assign an empty string to the StudentID field / Email field
• or value out of range to any club field
Count ← 0
NEXT Index
Mark as follows:
Note:
Max 6 if procedure heading and ending missing or incorrect (but allow array
as parameter)
4(a) 5
Answer
A line number containing a variable being incremented 19 / 21 / 23
4(c)(ii) 15, 23 1
NumRecs ← 0
NumCopied ← 0
Mark as follows:
Note:
MP6: Both counts must have been declared and initialised
Found ← FALSE
WHILE Row <= 800 AND Found = FALSE // top to bottom
Col ← 1
WHILE Col <= 1280 AND Found = FALSE // left to right
IF Screen[Row,Col] = 1 THEN
Found ← TRUE // end function as soon as first
// found
ENDIF
Col ← Col + 1
ENDWHILE
Row ← Row + 1
ENDWHILE
Mark as follows:
Alternative:
• The search algorithms from the original modules are included in the new
module
• The new module needs to return / store the four values (the results of the
four searches)
Disadvantage: (max 1)
• Single module more complex / more error prone / more difficult to
debug ...
• Single module cannot be split among programmers / teams
Max 2
StartRow ← FirstRowSet()
IF StartRow = -1 THEN
CentreRow ← -1 // no 'touch' detected
ELSE
EndRow ← LastRowSet()
StartCol ← FirstColSet()
EndCol ← LastColSet()
CentreRow ← INT((StartRow + EndRow)/2)
CentreCol ← INT((StartCol + EndCol)/2)
ENDIF
ENDPROCEDURE
Mark as follows:
1 Call <any Set function> and check for -1 // check for no element set
2 ...and if so set CentreRow to –1
3 Call all 4 Set functions to get 'extremity' values
4 Calculate centre row and centre column
5 Use of INT() function or DIV operator on values from MP4
6 Assign calculated values to CentreRow and CentreCol
Note:
Max 5 if procedure heading and ending missing or incorrect (ignore array if
passed as a parameter) or any local variables are undefined or of incorrect
type
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 (RW/CGW) 303754/3
© UCLES 2022 [Turn over
PAGE 1110
Refer to the insert for the list of pseudocode functions and operators.
1 (a) A programmer draws a program flowchart to show the sequence of steps required to solve a
problem.
Give the technical term for a sequence of steps that describe how to solve a problem.
...................................................................................................................................................
............................................................................................................................................. [1]
(i) Complete the table by writing the most appropriate data type for each variable.
[4]
(ii) One of the names used for a variable in the table in part 1(b)(i) is not an example of
good practice.
Identify the variable and give a reason why it is not good practice to use that name.
Variable .............................................................................................................................
Reason ..............................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[2]
Expression Evaluation
INT((31 / 3) + 1)
MID(TO_UPPER("Version"), 4, 2)
NUM_TO_STR(27 MOD 3)
[4]
Button-Y
Button-Z | Output-C
START
S1 Button-Z S3
Button-Y
Button-Y | Output-A
Button-X
S2
S4
Button-Z | Output-B
Answer
The number of different inputs
Complete the table to show the inputs, outputs and next states.
Button-Y
none
Button-Z S2
none
[4]
3 The manager of a cinema wants a program to allow users to book seats. The cinema has several
screens. Each screen shows a different film.
(a) Decomposition will be used to break the problem down into sub-problems.
Module 1 ...................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Module 2 ...................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Module 3 ...................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[3]
(b) Two types of program modules may be used in the design of the program.
Identify the type of program module that should be used to return a value.
............................................................................................................................................. [1]
BLANK PAGE
4 A stack is created using a high-level language. Memory locations 200 to 207 are to be used to
store the stack.
Stack Pointer
Memory
Value
location
200
201
202
204 'C'
205 'D'
206 'E'
207 'H'
Answer
The value that has been on the stack for the longest time.
[2]
(b) The following diagram shows the current state of the stack:
Stack Pointer
Memory
Value
location
200
201
203 'Y'
204 'X'
205 'Z'
206 'N'
207 'P'
POP
POP
PUSH 'A'
PUSH 'B'
POP
PUSH 'C'
PUSH 'D'
Complete the diagram to show the state of the stack after the operations have been
performed.
Stack Pointer
Memory
Value
location
200
201
202
203
204
205
206
207
[4]
5 Each line of a text file contains data organised into fixed-length fields as shown:
An algorithm is required to search for the first instance of a given value of Field 2 and, if found, to
output the corresponding values for Field 1 and Field 3.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [6]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
10
CASE OF MySwitch
1: ThisChar 'a'
2: ThisChar 'y'
3: ThisChar '7'
OTHERWISE: ThisChar '*'
ENDCASE
Write pseudocode with the same functionality without using a CASE structure.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
11
Upper-case and lower-case characters need to be treated the same. For example, 'A' is equivalent
to 'a'.
(a) A function IsPalindrome() will take a string parameter. The function will return TRUE if the
string is a palindrome and will return FALSE if the string is not a palindrome.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
12
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
13
For example, the string "never odd or even" becomes a palindrome if the spaces are removed.
START
Set Index to 1
NO
B
E
YES
F
C
D
END
Complete the table by writing the text that should replace each of the labels B, C, D, F and G.
Label Text
G
[4]
© UCLES 2022 9618/21/M/J/22 [Turn over
PAGE 1122
14
8 A program allows a user to save passwords used to login to websites. A stored password is
inserted automatically when the user logs into the corresponding website.
A student is developing a program to generate a password. The password will be of a fixed format,
consisting of three groups of four alphanumeric characters. The groups are separated by the
hyphen character '-'.
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] "yyyyyyyyyyyyyy"
Secret[28, 1] "www.thatwebsite.com"
Secret[28, 2] "yyyyyyyyyyyyyy"
Note:
• For security, passwords are stored in an encrypted form, shown as "yyyyyyyyyyyyyy" in the
example.
• The passwords cannot be used without being decrypted.
• Assume that the encrypted form of a password will not be an empty string.
Module Description
RandomChar() • Generates a single random character from within one of the
following ranges:
ż 'a' to 'z'
ż 'A' to 'Z'
ż '0' to '9'
• Returns the character
Encrypt() • Takes a password as a parameter of type string
• Returns the encrypted form of the password as a string
Decrypt() • Takes an encrypted password as a parameter of type string
• Returns the decrypted form of the password as a string
'A' to 'Z' 65 to 90
'0' to '9' 48 to 57
15
You may wish to refer to the insert for a description of the CHR() function. Other functions
may also be required.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
16
Module Description
FindPassword() • Takes a website domain name as a parameter of type string
• Searches for the website domain name in the array Secret
• If the website domain name is found, the decrypted password
is returned
• If the website domain name is not found, a warning message
is output, and an empty string is returned
Assume that modules Encrypt() and Decrypt() have already been written.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
© UCLES 2022 9618/21/M/J/22
MUHAMMAD ALI KHAN
PAGE 1125
17
(c) The modules Encrypt() and Decrypt() are called from several places in the main
program.
Identify a method that could have been used to test the main program before these modules
were completed. Describe how this would work.
Method ......................................................................................................................................
Description ................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
(d) A validation function is written to check that the passwords generated are valid.
Note: lower-case and upper-case characters are not the same. For example, 'a' is not the
same as 'A'.
Give two password strings that could be used to test different areas of the validation rules.
Password 1 ...............................................................................................................................
Password 2 ...............................................................................................................................
[2]
(e) The RandomChar() module is to be modified so that alphabetic characters are generated
twice as often as numeric characters.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
1(a) An algorithm 1
1(b)(i) 4
Variable Use of variable Data type
1(b)(ii) One mark for variable name, and one for reason 2
Variable: Temp
Reason: Name does not indicate what the variable is used for
1(c) 4
Expression Evaluation
INT((31 / 3) + 1) 11
MID(TO_UPPER("Version"), 4, 2) "SI"
Example answer
3(a) One mark per description of appropriate sub-problem for given scenario. 3
Examples include:
x Allows the user to search for films being shown // input name of film they
want to see
3(b) Function 1
The value that has been on the stack for the longest time. 'H'
4(b) 4
Stack Pointer
Memory
Value
location
200
202 'C'
203 'A'
204 'X'
205 'Z'
206 'N'
207 'P'
OUTPUT Count
Mark as follows:
Alternative Solution:
OUTPUT Count
Mark as follows:
Mark as follows:
IsPal m TRUE
Index m 1
Num m INT(LENGTH(InString) / 2)
ENDFUNCTION
Mark as follows:
7(b) 4
Label Text
F YES
G NO
CASE OF ThisRange
1: ThisChar m CHR(INT(RAND(26) + 65)) // 65 to 90:
'A' to 'Z'
ThisChar m LCASE(ThisChar) // 'a' to 'z'
2: ThisChar m CHR(INT(RAND(26) + 65)) // 65 to 90:
A to Z
3: ThisChar m NUM_TO_STR(INT(RAND(10)) // '0' to '9'
ENDCASE
RETURN ThisChar
ENDFUNCTION
Mark as follows:
Password m ""
Index m 1
RETURN Password
ENDFUNCTION
Mark as follows:
8(c) One mark for the name, one for the description 3
Name:
x Stub testing
Description:
x A simple module is written to replace each of the modules.
x The simple module will return an expected value // will output a message
to show they have been called
One mark for each password example that breaks one of the rules due to:
x Length too long // length too short
x Invalid character
x Incorrect grouping (including number of hyphens)
x Duplicated characters
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
MUHAMMAD ALI KHAN
PAGE 1137
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 1144
(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]
13
BLANK PAGE
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]
Breakpoint
x A description of what the identifier is used for / the purpose of the identifier
x The data type of the identifier
x The number of elements of an array // the length of a string
x An example data value
x Value of any constants used
x The scope of the variable (local or global)
Statement Error
2 4
3(a)(ii) 3
Label Module name
A Head
B Mod_W
C Mod_X
D Mod_V
E Mod-Z
F Mod_Y
Marks as follows:
x Two rows correct – one mark
x Four rows correct – two marks
x All rows correct – three marks
LineY m ""
LineZ m ""
CLOSEFILE ThisFile
OUTPUT LineX
OUTPUT LineY
OUTPUT LineZ
ENDPROCEDURE
Count m 0
OPENFILE ThisFile FOR READ
CLOSEFILE ThisFile
OPENFILE ThisFile FOR READ
OUTPUT LineX
OUTPUT LineY
OUTPUT LineZ
CLOSEFILE ThisFile
ENDPROCEDURE
7 OUTPUT the last three lines in correct sequence, following reasonable attempt
1 Change the procedure header to include a (numeric) parameter (as well as the
filename)
2 Replace LineX, Y and Z with an array
3 Amend shuffle mechanism
4 Use new parameter to determine first line to output
5 Output the lines in a loop
5(a) One mark for type and one mark for condition: 2
Independent marks
Type: pre-condition
Condition: when the value of ThisNum / the input value is equal to zero
5(b) 6
ThisNum ThisChar CountA CountB Flag OUTPUT
0 10 TRUE
12 '1' 1
24 '2'
57 '5' "Ignored"
43 '4' 9 FALSE
56 '5' 4
31 '3' 8
32 '3' 7
47 '4' 6 FALSE
0 4
Marks as follows:
One mark per outlined group
If no marks per group then mark by columns (columns 3 to 6) for max 4
Count m 0
Total m 0
NumString m ""
ENDPROCEDURE
Marks as follows:
1 Declare and initialise Count, Total and NumString
2 Loop for number of characters in InString
3 Extract a character and test for comma in a loop
4 If comma, convert NumString to integer and update Total and Count
5 and reset NumString
6 Otherwise append character to NumString
7 Calculate average AND final output statement(s) outside the loop
InStringLen m LENGTH(InString)
RETURN MidString
ENDFUNCTION
Marks as follows:
1 Function heading and ending including parameters and return type
2 Correct use of one substring functions
3 Correct use of both substring functions (in correct sequence)
4 Return substring after a reasonable attempt
Check that:
x Start and/or Num are >= 1 // positive
x Length of InString is "sufficient" for required operation
Found m FALSE
Index m 1
RETURN Found
ENDFUNCTION
Duplicates m FALSE
IndexA m 1
ENDPROCEDURE
1 Initialise password to empty string at the start and return (attempted) password
at the end of the function
2 Two loops to generate 3 groups of 4 characters // One loop to generate 12 / 14
characters
3 Use of RandomChar()to generate a character in a loop
4 Reject character if Exists()returns TRUE, otherwise form string in a loop
5 (Attempt to) use hyphens to link three groups
6 Three groups of four characters generated correctly with hyphens and without
duplication (completely working algorithm)
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) 302745/3
© UCLES 2022 [Turn over
PAGE 1168
Refer to the insert for the list of pseudocode functions and operators.
State three possible benefits of using library routines in the development of the program.
1 ................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
3 ................................................................................................................................................
...................................................................................................................................................
[3]
(b) The following pseudocode is part of a program that stores names and test marks for use in
other parts of the program.
(i) The pseudocode needs to be changed to allow for data to be stored for up to 30 students.
Explain why it would be good practice to use arrays to store the data.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [3]
State the purpose of the variable Count and give its data type.
Purpose .............................................................................................................................
...........................................................................................................................................
(c) 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.
Assume that any variables used are of the correct type for the given function.
Statement Error
2 A system is being developed to help manage a car hire business. A customer may hire a car for a
number of days.
(a) Explain the process of abstraction and state four items of data that should be stored each
time a car is hired.
Explanation ...............................................................................................................................
...................................................................................................................................................
Item 1 ........................................................................................................................................
Item 2 ........................................................................................................................................
Item 3 ........................................................................................................................................
Item 4 ........................................................................................................................................
[3]
(b) Identify two operations that would be required to process the car hire data.
Operation 1 ...............................................................................................................................
...................................................................................................................................................
Operation 2 ...............................................................................................................................
...................................................................................................................................................
[2]
3 A 1D array Data of type integer contains 200 elements. Each element has a unique value.
An algorithm is required to search for the largest value and output it.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [5]
4 (a) The following diagram shows an Abstract Data Type (ADT) representation of an ordered
linked list. The data item stored in each node is a single character. The data will be accessed
in alphabetical order.
Start pointer
(i) Nodes with data 'A' and 'K' are added to the linked list. Nodes with data 'J' and 'L' are
deleted.
After the changes, the data items still need to be accessed in alphabetical order.
Complete the diagram to show the new state of the linked list.
Start pointer
[4]
(ii) The original data could have been stored in a 1D array in which each element stores a
character.
For example:
Explain the advantages of making the changes described in part (a)(i) when the data is
stored in the linked list instead of an array.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
© UCLES 2022 9618/21/O/N/22
MUHAMMAD ALI KHAN
PAGE 1173
(iii) Explain the disadvantages of making the changes described in part (a)(i) when the data
is stored in the linked list instead of an array.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(b) A program will store data using a linked list like the one shown in part (a).
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
5 A program uses two 1D arrays of type integer. Array1 contains 600 elements and Array2
contains 200 elements.
Array1 contains sample values read from a sensor. The sensor always takes three consecutive
samples and all of these values are stored in Array1.
A procedure Summarise() will calculate the average of three consecutive values from Array1
and write the result to Array2. This will be repeated for all values in Array1.
The diagram below illustrates the process for the first six entries in Array1.
}
10 15 average of first three values
15
}
40
41
42
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [5]
10
6 The following pseudocode algorithm attempts to check whether a string is a valid email address.
Index ĸ 1
Dots ĸ0
Ats 0ĸ
Others ĸ 0
Valid ĸ TRUE
REPEAT
NextChar ĸ
MID(InString, Index, 1)
CASE OF NextChar
'.' : Dots Dots + 1 ĸ
'@' : Ats Ats + 1 ĸ
IF Ats > 1 THEN
Valid FALSE ĸ
ENDIF
OTHERWISE : Others Others + 1 ĸ
ENDCASE
RETURN Valid
ENDFUNCTION
State the values that would result in the condition evaluating to TRUE.
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [1]
11
(b) (i) Complete the trace table by dry running the function when it is called as follows:
Result ĸ IsValid("Liz.123@big@net")
Index NextChar Dots Ats Others Valid
[5]
(ii) State the value returned when IsValid() is called using the expression shown in
part (b)(i).
..................................................................................................................................... [1]
12
<Value1><Operator><Value2>
Assume:
• the string contains only numeric digits and a single operator character
• Value1 and Value2 represent integer values
• 9DOXHDQG9DOXHDUHXQVLJQHG WKH\ZLOOQRWEHSUHFHGHGE\ RU í
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
13
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [7]
(ii) Calculate() is changed to a function that returns the value of the evaluated
expression.
...........................................................................................................................................
..................................................................................................................................... [1]
(b) A string representing an arithmetic expression could be in the correct format but be impossible
to evaluate.
Give an example of a correctly formatted string and explain why evaluation would be
impossible.
Explanation ...............................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[2]
14
Module Description
• takes the name of an existing project file as a parameter of type
string
CheckFile()
• returns TRUE if the file is valid (it contains at least 10 non-blank
lines), otherwise returns FALSE
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
15
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
16
Module Description
• takes a line from a project file as a parameter of type string
CheckLine() • returns zero if the line is blank or contains no syntax error,
otherwise returns an error number as an integer
• takes two parameters:
ż the name of a project file as a string
ż the maximum number of errors as an integer
• uses CheckFile() to test the project file. Outputs an error
CountErrors() message and ends if the project file is not valid
• calls CheckLine() for each line in the project file
• counts the number of errors
• outputs the number of errors or a warning message if the
maximum number of errors is exceeded
(b) CountErrors() is called to check the project file Jim01Prog.txt and to stop if more than
20 errors are found.
...................................................................................................................................................
............................................................................................................................................. [2]
(c) Write pseudocode for module CountErrors(). Assume CheckFile() and CheckLine()
have been written and can be used in your solution.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
© UCLES 2022 9618/21/O/N/22
PAGE 1182
17
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
Two examples of syntax error that cannot be detected from examining a single line are
those involving selection and iteration.
1 ................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[2]
Statement Error
X m STR_TO_NUM("37") + 5 NO ERROR
Or the opposite:
One mark for each TWO data items (not dependent on 'Explanation'):
Items include:
Examples include:
PROCEDURE Summarise()
DECLARE Value : REAL
DECLARE IxA, IxB : INTEGER // Index variables
IxB m 1
ENDPROCEDURE
6(a) One mark for any part correct (accept equivalent wording) (Max 1): 1
0 0 0 TRUE
1 'L' 1
2 'i' 2
3 'z' 3
4 '.' 1
5 '1' 4
6 '2' 5
7 '3' 6
8 '@' 1
9 'b' 7
10 'i' 8
11 'g' 9
12 '@' 2 FALSE
6(b)(ii) FALSE 1
Val1 m STR_TO_NUM(Par1)
Val2 m STR_TO_NUM(Par3)
CASE OF Par2
PLUS : Result m Val1 + Val2
MINUS : Result m Val1 - Val2
MULTIPLY : Result m Val1 * Val2
DIVIDE : Result m Val1 / Val2
ENDCASE
OUTPUT Result
ENDPROCEDURE
Count m 0
Valid m FALSE
OPEN ThisFile FOR READ
CLOSEFILE ThisFile
RETURN Valid
ENDFUNCTION
ErrCount m 0
REPEAT
READFILE, ThisFile, ThisLine
ThisError m CheckLine(ThisLine)
IF ThisError <> 0 THEN
ErrCount m ErrCount + 1
ENDIF
UNTIL ErrCount > MaxErrors OR EOF(ThisFile)
CLOSEFILE ThisFile
ENDIF
ENDPROCEDURE
Examples:
1 Incorrect block structure. Missing keyword denoting part of block (for
example ENDPROCEDURE, ENDFUNCTION, ENDTYPE)
2 Data type errors, for example, assigning an integer value to a string
3 Identifier used before it is declared
4 Incorrect parameter use
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 1192
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]
BLANK PAGE
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
MUHAMMAD ALI KHAN
PAGE 1201
11
BLANK PAGE
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]
15
BLANK PAGE
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]
Term: Parameter(s)
1(b) One mark for test stage, one mark for each description point 4
(Max 3 for Description)
Description:
Expression Evaluation
INT(Count / LENGTH(CharList)) 4
2(a)(ii) Data in a file is saved after the computer is switched off / stored 1
permanently // no need to re-enter the data when the program is re-run
S1
Input-A Output-X S2
Input-A (none) S2
Input-B Output-W S3
Input-A Output-W S4
3(a) One mark for name, Max two for features (Max 3 in total) 3
Name: Queue
Features:
1 Each queue element contains one data item
2 A Pointer to the front / start of the queue
3 A Pointer to the back / end of the queue
4 Data is added at back / end and removed from front / start // works on a
FIFO basis
5 May be circular
ALTERNATIVE:
Features:
1 Each node contains data and a pointer to the next node
2 A Pointer to the start of the list
3 Last node in the list has a null pointer
4 Data may be added / removed by manipulating pointers (not moving
data)
5 Nodes are traversed in a specific sequence
6 Unused nodes are stored on a free list // a free-list pointer to the Free
List
INPUT UserID
Average m GetAverage(UserID)
Total m 0
Index m 4
INPUT UserID
Average m GetAverage(UserID)
Total m 0
FOR Index m 4 TO 6
Last m SameMonth[Index]
IF Average > Last THEN
Total m Total + Average
ELSE
Total m Total + Last
ENDIF
NEXT Index
Num m 0
Found m FALSE
Try m 1
ENDFUNCTION
Mark as follows:
1 Function heading and ending including parameter and return type
2 Declaration of local Integer value for Num and Try
3 Count-controlled Loop from 1 to ThisValue
4 Multiply Try by Num in a loop
5 Compare Try with ThisValue in a loop
6 ...Immediate return of Num if they are the same in a loop
7 Return –1 if ThisValue not found after loop
Try m 1
RETURN -1
ENDFUNCTION
Index m 0
REPEAT
Index m Index + 1
UNTIL ErrCode[Index] >= ErrNum OR Index = 500
ENDPROCEURE
PROCEDURE SortArrays()
DECLARE TempInt, J, Boundary : INTEGER
DECLARE TempStr : STRING
DECLARE NoSwaps : BOOLEAN
Boundary m 499
REPEAT
NoSwaps m TRUE
FOR J m 1 TO Boundary
IF ErrCode[J]> ErrCode[J+1] THEN
//first swap ErrCode elements
TempInt m ErrCode[J]
ErrCode[J] m ErrCode[J+1]
ErrCode[J+1] m TempInt
//now swap corresponding ErrText elements
TempStr m ErrText[J]
ErrText[J] m ErrText[J+1]
ErrText[J+1] m TempStr
NoSwaps m FALSE
ENDIF
NEXT J
Boundary m Boundary - 1
UNTIL NoSwaps = TRUE
ENDPROCEDURE
1 Array of records can store mixed data types / multiple data types under
a single identifer
2 Tighter / closer association between ErrCode and ErrText // simpler
code as fields may be referenced together // values cannot get out of
step as with two arrays
3 Program easier to design / write / debug / test / maintain / understand
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) 338525/4
© UCLES 2023 [Turn over
PAGE 1222
Refer to the insert for the list of pseudocode functions and operators.
(a) Describe how a typical Integrated Development Environment (IDE) could be used to help
debug the program to find the errors in the function Calculate().
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
(b) The algorithm for function Calculate() contains the three pseudocode statements shown.
Describe the error in each statement or write ‘no error’ if the statement contains no error.
Assume any variables used are of the correct type for the given function.
Error ..........................................................................................................................................
...................................................................................................................................................
Error ..........................................................................................................................................
...................................................................................................................................................
Error ..........................................................................................................................................
...................................................................................................................................................
[3]
Variable Value
Active TRUE
Points 75
Exempt FALSE
Expression Evaluation
[2]
(ii) Write expression 4 from the table in part (c)(i) in its simplest form.
..................................................................................................................................... [1]
START
END
[4]
© UCLES 2023 9618/21/M/J/23
MUHAMMAD ALI KHAN
PAGE 1225
Write pseudocode statements to declare StartDate and assign to it the date corresponding
to 15/11/2005.
Declaration ...............................................................................................................................
Assignment ...............................................................................................................................
[3]
A program is used to manage the points system and the table lists some of the information stored
for one customer.
(a) (i) Identify a suitable structure for storing the information for one customer. Explain the
advantage of using this structure.
Structure ............................................................................................................................
Advantage .........................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[4]
(ii) Describe a data structure that could be used to store the information for all customers.
...........................................................................................................................................
..................................................................................................................................... [2]
(b) Customers receive points depending on the amount they spend. The number of points
depends on the band that the amount falls into:
For example, if the amount is $99.77, this amount is in band 2 and therefore the number of
points is 7 ) 99, which is 693 points.
The algorithm to calculate the points from a given amount is expressed as follows:
• work out the appropriate band
• calculate and output the number of points.
Apply the process of stepwise refinement to increase the detail of the algorithm. Structure
your algorithm into a sequence of five steps that could be used to produce pseudocode.
1 ................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
3 ................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
4 ................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
5 ................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[5]
© UCLES 2023 9618/21/M/J/23 [Turn over
PAGE 1228
2. form a new string from the original string where all instances of the original character are
replaced by the new character
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [6]
5 Several companies are developing websites to market a new type of games console. The company
that is first to create a website that can demonstrate the interactive features of the games console
will have an advantage over the others. The requirements for the website are likely to change as
more information about the features of the console are made available.
One company has decided to develop their website using a program development life cycle based
on the waterfall model.
(a) (i) Give two reasons why this may not be the most appropriate model to use in this case.
Reason 1 ...........................................................................................................................
...........................................................................................................................................
Reason 2 ...........................................................................................................................
...........................................................................................................................................
[2]
(ii) Identify a more appropriate program development life cycle model for this scenario.
..................................................................................................................................... [1]
(b) The website has been running in test mode for several weeks.
Identify and describe a final stage of testing that should take place before the website is
made available to all customers.
Stage ........................................................................................................................................
Description ................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[3]
10
6 A video-conferencing program supports up to six users. Speech from each user is sampled and
digitised (converted from analogue to digital). Digitised values are stored in array Sample.
The array Sample consists of 6 rows by 128 columns and is of type integer. Each row contains
128 digitised sound samples from one user.
The digitised sound samples from each user are to be processed to produce a single value which
will be stored in a 1D array Result of type integer. This process will be implemented by procedure
Mix().
Result: 20 20 35 40 46 25
11
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [6]
12
7 A school has a computerised library system that allows students to borrow books for a fixed length
of time. The system uses text files to store details of students, books and loans.
A new module is to be written which will generate emails to each student who has an overdue
book.
(a) Decomposition will be used to break down the problem of designing the new module into
sub-problems.
Identify three program modules that could be used in the design and describe their use.
Module 1 ...................................................................................................................................
Use ...........................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Module 2 ...................................................................................................................................
Use ...........................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Module 3 ...................................................................................................................................
Use ...........................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[3]
13
(b) The program designer produces a structure chart for the new module. Part of the structure
chart is shown:
Module-A()
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
Draw only the part of the structure chart that represents the relationship between
Module-X(), Module-Y() and Module-D().
[3]
© UCLES 2023 9618/21/M/J/23 [Turn over
PAGE 1234
14
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 for each item in the range
ItemNum 4 numeric characters
"0001" to "5999" inclusive
The file is organised in ascending order of ItemNum and does not contain all possible values in
the range.
Module Description
SuppExists() • called with a parameter of type string representing a supplier code
(already written)
• returns TRUE if the supplier code is already in use, otherwise returns
FALSE
IsNewSupp() • called with a parameter of type string representing a new supplier code
• returns TRUE if the string only contains alphabetic characters (either
upper or lower case) and the supplier code is not already in use,
otherwise returns FALSE
15
Module SuppExists() has already been written and should be used as part of your solution.
Module SuppExists() will generate a run-time error if the given parameter is not
5 characters in length.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
16
Module Description
CheckNewItem() • called with a parameter of type string representing a line of
item information
• checks to see whether an item with the same ItemNum already
exists in the file
• returns TRUE if the ItemNum is not already in the file, otherwise
returns FALSE
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
17
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
(c) The program modules SuppExists(), IsNewSupp() and CheckNewItem() are part of a
group of modules that are combined to create a complete stock control program.
Each module in the program is tested individually during development and is debugged as
necessary. It is then added to the program and further testing performed.
..................................................................................................................................... [1]
(ii) One of the modules does not work properly when it is added to the program.
Describe a testing method that can be used to address this problem so that testing can
continue and other modules can be added.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(d) A new module AddItem() will be used to add information to the Stock.txt file.
State the file mode that should be used for the algorithm within this module.
............................................................................................................................................. [1]
(e) A new module FindItem() searches for a given item in the Stock.txt file, which is already
organised in ascending order of ItemNum.
Describe how this organisation may improve the efficiency of the algorithm.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
© UCLES 2023 9618/21/M/J/23
PAGE 1238
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED
Error 2: No Error
1(c)(i) 2
Expression Evaluation
2(a) 4
1 Both prompts
2 Both inputs using correct identifiers as given in question, MyChar and
MyCount
3 Initialise MyString to empty string and subsequent output after loop
4 Loop MyCount iterations including decrement MyCount
5 Use of Concatenate or equivalent pseudocode statement inside loop
Max 4 Marks
Structure: Record
Advantage:
x A set of data / all data related to one customer
x of different types
x is held under a single identifier/entity
3(a)(ii) A (1D) array of records // An array of the given type could be used 2
NewString m ""
FOR Index m 1 TO LENGTH(OldString)
ThisChar m MID(OldString, Index, 1)
IF ThisChar = Char1 THEN
ThisChar m Char2
ENDIF
NewString m NewString & ThisChar
NEXT Index
RETURN NewString
ENDFUNCTION
Mark as follows:
1 Function heading and ending, including parameters and return type
2 Declaration of local variables used including loop counter
3 Loop for length of OldString
4 Extract char and test in a loop
5 Use of concatenate to build NewString replace char if necessary,
in a loop
6 Return NewString after reasonable attempt
Max 2 marks
Description:
1 Testing carried out by a small group of (potential) users
2 Users will check that the website/software works as required / works in
the real world //User will identify errors in the website/software
3 Users will feedback (problems) / suggestions for improvement
4 Problems / suggestions identified are addressed (before the program is
sold)
6 PROCEDURE Mix() 6
DECLARE Count, Total ThisNum : INTEGER
DECLARE ThisUser, ThisSample : INTEGER
ENDPROCEDURE
Mark as follows:
Max 6 Marks
Module: GetOverdueLoan()
Use: Identifies an overdue book
Module: IdentifyStudent()
Use: Identifies a student (with an overdue book)1
Module: GetStudentEmail()
Use: Gets the email address of a student with an overdue book
Module: CreateEmail()
Use: Generates an email to a student with an overdue book
Module: SendEmail()
Use: Sends an email to a student with an overdue book
7(b)(ii) 3
IF SuppExists(ThisString) THEN
RETURN FALSE // SupplierCode already exists
ENDIF
FOR Index m 1 TO 5
ThisChar m TO_LOWER(MID(ThisString, Index, 1))
IF ThisChar < 'a' OR ThisChar > 'z'THEN
RETURN FALSE
ENDIF
NEXT Index
RETURN TRUE
ENDFUNCTION
Mark as follows:
NotFound m TRUE
CLOSEFILE "Stock.txt"
RETURN NotFound
ENDFUNCTION
Mark as follows:
Max 7 marks
8(d) Append 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 (EF/SG) 312086/3
© UCLES 2023 [Turn over
PAGE 1248
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 1250
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]
BLANK PAGE
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
MUHAMMAD ALI KHAN
PAGE 1261
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 1264
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]
Published
This mark scheme is published as an aid to teachers and candidates, to indicate the requirements of the
examination. It shows the basis on which Examiners were instructed to award marks. It does not indicate the
details of the discussions that took place at an Examiners’ meeting before marking began, which would have
considered the acceptability of alternative answers.
Mark schemes should be read in conjunction with the question paper and the Principal Examiner Report for
Teachers.
Cambridge International will not enter into discussions about these mark schemes.
Cambridge International is publishing the mark schemes for the May/June 2023 series for most
Cambridge IGCSE, Cambridge International A and AS Level and Cambridge Pre-U components, and some
Cambridge O Level components.
These general marking principles must be applied by all examiners when marking candidate answers.
They should be applied alongside the specific content of the mark scheme or generic level descriptors
for a question. Each question paper and mark scheme will also comply with these marking principles.
x the specific content of the mark scheme or the generic level descriptors for the question
x the specific skills defined in the mark scheme or in the generic level descriptors for the question
x the standard of response required by a candidate as exemplified by the standardisation scripts.
Marks awarded are always whole marks (not half marks, or other fractions).
x marks are awarded for correct/valid answers, as defined in the mark scheme. However, credit
is given for valid answers which go beyond the scope of the syllabus and mark scheme,
referring to your Team Leader as appropriate
x marks are awarded when candidates clearly demonstrate what they know and can do
x marks are not deducted for errors
x marks are not deducted for omissions
x answers should only be judged on the quality of spelling, punctuation and grammar when these
features are specifically assessed by the question as indicated by the mark scheme. The
meaning, however, should be unambiguous.
Rules must be applied consistently, e.g. in situations where candidates have not followed
instructions or in the application of generic level descriptors.
Marks should be awarded using the full range of marks defined in the mark scheme for the question
(however; the use of the full mark range may be limited according to the quality of the candidate
responses seen).
Marks awarded are based solely on the requirements as defined in the mark scheme. Marks should
not be awarded with grade thresholds or grade descriptors in mind.
1(a)(ii) One mark per bullet point (or equivalent to max 3): 3
x Indentation
x White space
x Comments
x Sensible / meaningful variable names // use of Camel Case
x Capitalised keywords
x BOOLEAN
x REAL
x STRING
2(c) 6
One mark per array definition bullet:
Step2: Use the function DAYINDEX() to return / find the day number from
MyDoB
Step3: Use the returned value as the array index / to access the element
that contains the name / string
3(a)(ii) 7 1
Count m 0
ENDFUNCTION
Mark as follows:
1 Function heading and end, including parameters and return type
2 Declare local Integers for Index and Count
3 Loop for length of ThisString
4 Extract a character and compare with parameter in a loop
5 Increment Count if match in a loop
6 Return Count after loop
5(b) x The rules of the language have not been broken // there are no syntax 1
errors
StringA m ""
ThisChar m NUM_TO_STR(Dim)
StringB m ThisChar
FOR Count m 1 TO Dim - 2
StringB m StringB & FILLER //build up
intermediate line
NEXT Count
StringB m StringB & ThisChar // add final digit
OUTPUT StringA
FOR Count m 1 TO Dim - 2
OUTPUT StringB
NEXT Count
ENDPROCEDURE
CASE OF Dim
1 : OUTPUT "1"
2 : OUTPUT "22"
OUTPUT "22"
3 : OUTPUT "333"
OUTPUT "3*3"
OUTPUT "333"
4 : OUTPUT "4444"
FOR Count m 1 TO 2
OUTPUT "4**4"
NEXT Count
OUTPUT "4444"
5 : OUTPUT "55555"
FOR Count m 1 TO 3
OUTPUT "5***5"
NEXT Count
OUTPUT "55555"
6 : OUTPUT "666666"
FOR Count m 1 TO 4
OUTPUT "6****6"
NEXT Count
OUTPUT "666666"
7 : OUTPUT "7777777"
FOR Count m 1 TO 5
OUTPUT "7*****7"
NEXT Count
OUTPUT "7777777"
8 : OUTPUT "88888888"
FOR Count m 1 TO 6
OUTPUT "8******8"
NEXT Count
OUTPUT "88888888"
9 : OUTPUT "999999999"
FOR Count m 1 TO 7
OUTPUT "9*******9"
NEXT Count
OUTPUT "999999999"
ENDCASE
ENDPROCEDURE
7(a)(ii) One mark for each piece of information and matching justification: 2
x postal address
Justification: sending an email, not a letter
x payment details
Justification: Nothing being bought / sold at this stage
x order history
Justification: Customer preference used to decide if new product is
relevant
7(b) 4
FOR Index m 1 TO 4
IF NOT IS_NUM(MID(NewLine, Index, 1)) THEN
RETURN FALSE
ENDIF
NEXT Index
ThisNum m LEFT(Newline, 4)
RETURN TRUE
ENDFUNCTION
Mark as follows:
1 Test length of parameter
2 Extract first 4 characters of parameter (as ItemNum)
3 Test first four characters are all numeric
4 Test ItemNum in range "0001" to "5999"
5 Extract characters 5 to 7 of parameter (as SupplierCode)
6 Use of OnlyAlpha()with extracted SupplierCode
7 Return BOOLEAN value correctly in all cases, must have been declared
as local
CLOSEFILE "Stock.txt"
CLOSEFILE "NewStock.txt"
ENDPROCEDURE
Mark as follows:
1 Open both files, in correct modes, and subsequently close
2 Conditional loop until end of file Stock.txt
3 Read a line from Stock.txt AND extract ThisItemNum in a
loop
4 Test ThisItemNum > NewItemNum then write NewLine to
NewStock.txt
5 ...including mechanism to only do this once only
6 Write line read from Stock to NewStock
7 Deal with the case where NewLine is the new last line
ENDPROCEDURE
Mark as follows:
1 Open both files, in correct modes, and subsequently close
2 Declare AND initialise Temp array
3 Store NewLine in appropriate array element
4 Loop until end of file Stock.txt
5 Read a line from Stock.txt AND extract Index in a loop
6 Assign line read to appropriate array element in a loop
7 Loop through array, writing non-blank elements to file NewStock.txt
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 1280
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]
BLANK PAGE
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 1286
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [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
MUHAMMAD ALI KHAN
PAGE 1289
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]
1(a) 3
Answer
1(c) Integer 1
INPUT MyChoice 9
Result m SQRT(NextNum) 9
IF DAYINDEX(MyDOB) = 5 THEN
3(a)(i) 6 1
3(a)(ii) 4
3(b)(i) So that the data may be recovered / restored (the next time the program is 1
run)
// the data is permanently saved / data is not lost when the program
terminates
RETURN MyString
ENDFUNCTION
MP1 Function heading and end including parameters and return type
MP2 Declaration of locals Index and MyString
MP3 Test for Count < 1 and if true, assign "ERROR" to MyString /
Immediate RETURN
MP4 Loop for Count iterations
MP5 Use of concatenate – must have been initialised in a loop
MP6 Return STRING (correctly in both cases)
Additional Information:
MP1 The (program/source) code/specification
MP2 test plan // inputs/test data and expected outputs
Explanation:
MP3 The structure / design / algorithm of the program of the program
needs to be known
MP4 …. so that all paths through the program can be tested
5(b) Perfective 1
ENDPROCEDURE
OR:
CheckNum(Number,Total : INTEGER) RETURNS BOOLEAN
MP1 MP2
Two marks for the advantages:
MP3 CheckNum()can be called repeatedly as and when required
MP4 CheckNum()is designed and tested once (then used repeatedly)
MP5 Any subsequent change to CheckNum() needs to be made once
only // is easier to maintain/modify
7(a)(i) x To filter out information (that is not necessary to solve the problem) // 1
to include only essential information
7(a)(ii) Required: 2
Student : Student name / email (address)
Loan: Return/Issue date
Book: Book title
Not Required:
Student: Home address / DoB / tutor / subject choices
Book: Library location / category / author / book title
x Clear the loan // indicate that the book has been returned // update loan
history
x Take the student off 'block' // allow the student to borrow further books
x Send acknowledgement to the student when book is returned
CLOSEFILE "NewStock.txt"
CLOSEFILE "Stock.txt"
RETURN Count
ENDFUNCTION
Count m 0
CLOSEFILE "Stock.txt"
MP1 Output report header (blank lines optional) – Must contain the
parameter code
MP2 Conditional loop until EOF("Stock.txt")
MP3 Read a line from Stock.txt AND extract SupplierCode
in a loop
MP4 Test if SupplierCode = Supp then increment count (must
have been Initialised)
MP5 Extract AND output item and description in a loop
MP6 Output the final line with count
MP1 Must ‘calculate’ the count before any item + description output /
after the file is read once
MP2 Lines to be output have to be stored …
MP3 The file has to be read twice
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/SG) 315866/3
© UCLES 2023 [Turn over
PAGE 1306
Refer to the insert for the list of pseudocode functions and operators.
CASE OF ThisValue
< 30 : Level "Low" ĸ
// less than 30
Check 1 ĸ
< 20 : Level "Very Low" ĸ
// less than 20
Check ThisValue / 2 ĸ
30 TO 40 : Level "Medium" ĸ
// between 30 and 40
Check ThisValue / 3 ĸ
Data[ThisValue] Data[ThisValue] + 1 ĸ
> 40 : Level "High" ĸ
ENDCASE
(a) Complete the table by writing the answer for each row:
Answer
(b) The pseudocode contains four assignments to variable Level. One of these assignments
will never be performed.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
(c) The following line is added immediately before the ENDCASE statement:
...................................................................................................................................................
............................................................................................................................................. [1]
(d) Give the appropriate data types for the variables ThisValue, Check and Level.
ThisValue ..............................................................................................................................
Check .......................................................................................................................................
Level ......................................................................................................................................
[3]
Outline, using stepwise refinement, the five steps for this algorithm which could be used to
produce pseudocode.
Step 1 .......................................................................................................................................
...................................................................................................................................................
Step 2 .......................................................................................................................................
...................................................................................................................................................
Step 3 .......................................................................................................................................
...................................................................................................................................................
Step 4 .......................................................................................................................................
...................................................................................................................................................
Step 5 .......................................................................................................................................
...................................................................................................................................................
[5]
Identify two other programming constructs that will be required when the algorithm is
converted into pseudocode.
Construct 1 ...............................................................................................................................
...................................................................................................................................................
Construct 2 ...............................................................................................................................
...................................................................................................................................................
[2]
• The TopOfStack pointer points to the last item added to the stack.
• The BottomOfStack pointer points to the first item on the stack.
Stack
D1 ĸ TopOfStack
D3
D4
D5
D2 ĸ BottomOfStack
(a) The stack is implemented using two variables and a 1D array of 8 elements as shown.
The variables are used to reference individual elements of the array, in such a way that:
• the array is filled from the lowest indexed element towards the highest
• all the elements of the array are available for the stack.
Complete the diagram to represent the state of the stack as shown above.
Array Data
element
8
5 Variable
4 TopOfStack
3 BottomOfStack
1
[3]
(b) A function Push() will add a value onto the stack by manipulating the array and variables in
part (a).
Before adding a value onto the stack, the algorithm will check that space is available.
If the value is added to the stack, the function will return TRUE, otherwise it will return FALSE.
5. Return .............................. .
[5]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
(b) The global array is changed to a 2D array, organised as 150 rows by 2 columns. It is declared
in pseudocode as follows:
The algorithm for the function in part (a) is changed. Strings will only be counted if both of
the following conditions are true:
Assume that the row index is contained in variable Row and the search string in variable
Search.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
5 An algorithm is designed to find the smallest numeric value from an input sequence and count
how many numeric values have been input.
An example of an input sequence is:
Numeric input values are all integers and non-numeric input is ignored, except for the string "END"
which is used to terminate the sequence.
Min ĸ 999
Count ĸ0
REPEAT
INPUT NextInput
IF IS_NUM(NextInput) = TRUE THEN
Num ĸ
STR_TO_NUM(NextInput)
IF Num > Min THEN
Min Num ĸ
ENDIF
Count ĸ
Count & 1
ENDIF
UNTIL NextInput "END" ĸ
OUTPUT "The minimum value is ", Min, " and the count was ", Count
(a) The pseudocode contains three errors due to the incorrect use of operators.
1 ................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
3 ................................................................................................................................................
...................................................................................................................................................
[3]
(b) The operator errors are corrected and the algorithm is tested as follows:
The algorithm is tested with a different test data sequence. The sequence contains a mix
of integer and non-numeric values. It is terminated correctly but the algorithm produces
unexpected results.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(ii) Give a sequence of four test data values that could be input to demonstrate the problem.
Value 1 ..............................................................................................................................
Value 2 ..............................................................................................................................
Value 3 ..............................................................................................................................
Value 4 ..............................................................................................................................
[2]
10
(a) A new procedure MyOutput() will take a string and a Boolean parameter.
MyOutput() may be called repeatedly and will use concatenation to build a string using a
global variable MyString, up to a maximum length of 255 characters.
For example, the calls to MyOutput() given below would result in the output as shown:
Resulting output:
Notes:
• MyString is initialised to an empty string before MyOutput() is called for the first time.
• No string passed to MyOutput() will be longer than 255 characters.
11
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
(b) The design of the procedure given in part (a) is modified and MyString is changed from a
global to a local variable declared in MyOutput().
When the modified procedure is converted into program code, it does not work as expected.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
12
The table shows the inputs, outputs and states for the algorithm:
Complete the state-transition diagram to represent the information given in the table.
A1 | X1
START
S1
A3
[5]
14
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:
Messages are sent between computers as a string of characters organised into fields as shown:
<STX><DestinationID><SourceID><Data><ETX>
Field
Field name Description
number
a single character marking the start of the message
n/a STX
(ASCII value 02)
1 DestinationID three numeric characters that identify the destination computer
For example, the following message contains the data "Hello Kevin" being sent from computer
"101" to computer "232":
<STX>"232101Hello Kevin"<ETX>
Each computer will run a copy of the same program. Each program will contain a global variable,
MyID of type string, that contains the unique ID of the computer in which the program is running.
The programmer has defined the first two program modules as follows:
Module Description
z takes two parameters:
Transmit() o a string containing a message
(already written) o an integer containing a port number
z transmits the message using the given port
z takes three parameters:
o a string containing a text file name
SendFile() o a string containing a Destination ID
o an integer containing a Port number
z transmits the file one line at a time
z transmits a final message with data string "****"
15
Assume:
• module Transmit() has already been written and is used to transmit a message
• the value of MyID may be used as SourceID
• the file specified contains no blank lines
• the file specified does not contain the line "****"
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
16
(b) Module SendFile() is used to copy a file from one computer to another.
A module within the program running on the destination computer will receive the data and
write it to a new file.
Explain why module SendFile() transmits the message with data string "****" after the
last line of the file.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(c) One of the text files to be sent contains several blank lines (lines that do not contain any text).
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(ii) Explain how the message format could be changed to allow a blank line to be sent.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
18
Module Description
z takes two parameters:
o a string containing a message
GetField() o an integer containing a field number
z If the field number is valid (in the range 1 to 3, inclusive), it
returns a string containing the required field, otherwise it returns
an empty string.
<STX><DestinationID><SourceID><Data><ETX>
Field
Field name Description
number
a single character marking the start of the message
Not applicable STX
(ASCII value 02)
1 DestinationID three numeric characters that identify the destination computer
19
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
Answer
MP1 Level m "Very Low" // the level is assigned value “very low”
Explanation points:
MP2 because CASE clauses are checked in sequence // because of the order
of the clauses
MP3 a value < 30 satisfies the first clause // Clause '< 20' will never be tested
1(c) MP1 all of the possible values are addressed via all / four / three / the other 1
clauses // there are no other possible values to map to OTHERWISE
x ThisValue: INTEGER
x Check: REAL
x Level: STRING
3(a) 3
MP4 Set the element at this index / location / position to the value / data /
item being added
MP5 Return TRUE
Count m 0
ENDFUNCTION
5(b)(i) MP1 If all the numeric input values are greater than 999 // If there are no 2
numeric values in the sequence
MP2 then the minimum will be given as 999 (and not one of the input values)
MP1
Mixture non-numeric and numeric with 3 or 4 values - with all numerics
greater than 999
Examples:
1325, DOG, 7868, 7615
// SNAKE, 3478, SPIDER
ENDPROCEDURE
MP7 (test for length < 255) Test EOL – If TRUE then Output
MP8 … and reset MyString to empty string
6(b) MP1 A new (instance of) variable MyString is created each time the 2
procedure is called / executed
MP2 So the previous contents are lost
7 5
MP1 S2 labelled
MP2 S3, S4 and S5 added
MP3 Line from S1 to S3
MP4 All three lines between S2 and S5 (including S5 to S5)
MP5 Line from S5 to S3 AND from S3 to S4
CLOSEFILE FileName
CALL Transmit(STX & DestID & MyID & "****" & ETX,
Port)
ENDPROCEDURE
Mark as follows:
MP1 OPEN file in READ mode – using parameter - and subsequently CLOSE
MP2 Conditional loop to EOF()
MP3 Use of READFILE to get a line from the file
MP4 ‘Attempt’ to form a message (minimum is DestID, MyID, FileData)
MP5 Message formed is completely correct
MP6 Call Transmit() with correct MP4 string in a loop
MP7 Transmit the "****" message (all parts present) after the loop
MP1 Indicates that all the lines of the file have been sent // it is the end of the
transmission / file transfer
MP2 So that the receiving program can stop waiting for further data
MP3 The file can be closed / saved
8(c)(ii) MP1 Append a (special) character to the start of the message text 2
MP2 interpret the new field data as a blank line
ALTERNATIVE
MP1 Change the message protocol and use an additional field to act as an
indicator
MP2 Interpret the new field data
CASE OF FieldNo
1 : RetString m MID(Msg, 2, 3)
2 : RetString m MID(Msg, 5, 3)
3 : RetString m MID(Msg, 8, LENGTH(Msg) - 8)
OTHERWISE : RetString m ""
ENDCASE
RETURN RetString
ENDFUNCTION
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/SG) 315868/1
© UCLES 2023 [Turn over
PAGE 1330
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
MUHAMMAD ALI KHAN
PAGE 1341
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
MUHAMMAD ALI KHAN
PAGE 1345
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.
1(a) 4
One mark for each row with appropriate variable name and data type
Expression Evaluates to
RIGHT(Description, 7) "(small)"
Declaration
1 Declare a composite / record (type)
2 Declare an array of the given composite / record (type)
Expansion of record:
3 … containing all data items required // containing items of different data
types
Expansion of array:
4 … where each array element represents data for one order / customer
(order)
3(a) 5
Mark as follows:
x One mark for Start_Pointer value
x One mark each group of row(s):
x 2
x 3 and 4
x 5
x 7 and 8
For null pointer: accept 0 / ∅ / an out-of-bound index value less than 1, greater
than 8
PROCEDURE Count()
DECLARE COdd, CEven, ThisNum : INTEGER
COdd m 0
CEven m 0
INPUT ThisNum
ENDPROCEDURE
4(b) One mark per set, including stated purpose. Max 3 marks 3
Example answers:
1 data set with (only) odd values, terminated with 99
2 data set with (only) even values, terminated with 99
3 data sets with same number of odd and even values, terminated with 99
4 data sets with all even / all odd with just one odd/even value, terminated
with 99
5 data sets with no values just final 99
6 data sets without (terminating) 99 // missing or incorrectly placed 99
5 6
Suffix m NUM_TO_STR(Count)
WHILE LENGTH(Suffix) <> 3
Suffix m '0' & Suffix
ENDWHILE
NEXT Count
ENDPROCEDURE
Mark as follows:
1 Procedure heading, including parameters, and ending
2 Loop for NumFiles iterations
3 Attempt to create filename suffix using NUM_TO_STR() in a loop
4 Completely correct filename
5 OPENFILE in WRITE mode and subsequent CLOSE in a loop
6 WRITE initial first line to the file in a loop
6(b)(i) Function 1
6(b)(iii) Read 1
7(a) 4
7(b) Means that Module-A calls either one of Module-X, Module-Y or Module- 2
Z (which one is called is decided at runtime).
DNum m STR_TO_NUM(ThisDest)
Index m 1
Port m -1
REPEAT
IF RouteTable[Index, 1] <> -1 THEN
IF DNum >= RouteTable[Index, 1] AND __
DNum <= RouteTable[Index, 2] THEN
Port m RouteTable[Index, 3]
ENDIF
ENDIF
Index m Index + 1
UNTIL Index = 7 OR Port <> -1 // end of array or
range found
RETURN Port
ENDFUNCTION
Example solution
DNum m STR_TO_NUM(ThisDest)
Port m -1
RETURN Port
ENDFUNCTION
ThisDest m LEFT(ThisMsg, 3)
ENDIF
ENDPROCEDURE
Mark as follows:
1. Ignore message if data field is empty
2. Extract ThisDest from ThisMsg
3. Test if destination is this computer
4. Attempt to use StackMsg()
5. Fully correct use of StackMsg()for both cases / stacks
6. Test StackMsg() return value for both cases
7. Following a reasonable attempt at MP6 output warning if StackMsg()
returns FALSE
Scenario two:
x Stack is Full
x Not all lines can be stored on the stack
x so resulting file will not contain all the original lines
Scenario three:
x (All) the data in a line read can’t be stored on the stack
x Stack elements have not been allocated enough memory
x so only part of each line is stored in the file
Scenario four:
x Stack is empty
x The stack is being read faster than it is being written to
x so blank lines may be inserted into the file
8(c)(ii) Queue 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 (LK/CT) 315870/2
© UCLES 2023 [Turn over
PAGE 1360
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.
1(a) 4
Assignment statement Data type
1(b) 4
Expression Evaluates to
STR_TO_NUM(MID(Code, 4, 2)) + 5 28
LENGTH("TRUE" & Code) 11
2(a) 5
2(b) MP1 Simplifies the algorithm // easier to write / understand / test / debug 2
MP2 It is possible to iterate through the values // can use a loop // allows the
storage of many values using a single identifier
3(a) 3
:
MP1 D3, D4, D1, D2 and D5 in question order or reversed - in any five
consecutive locations
MP2 FoQ value matches index with D3
MP3 EoQ value matches index with D5
Mark as follows:
Steps 1 to 4: One mark for gaps filled as shown
Step 5: One mark for 'element' and one mark for other two terms
FOR Count m 1 TO 25
ThisNum m BaseNum + INT(RAND(StepVal))
OUTPUT ThisNum
BaseNum m BaseNum + StepVal
NEXT Count
ENDPROCEDURE
ALTERNATIVE SOLUTION:
5 6
6 6
FUNCTION TestNum(ThisNum : STRING) RETURNS INTEGER
RETURN 0
ENDFUNCTION
MP1 Function heading and ending including parameter and return type
MP2 Test for Condition 1
MP3 Test for Condition 2
MP4 Test for Condition 3
MP5 Return the highest value if more than one condition is satisfied
MP6 Return zero if no condition matched
CLOSEFILE FileName
ENDPROCEDURE
Problem:
x If the file being sent contains a line of the string "****"
x then the file being written by ReceiveFile() will end at this point //
subsequent file lines will be lost
Solution:
x Read the file (at the sending end) to find the number of lines it contains
x Send an initial message which defines the number of lines in the file
ALTERNATIVE SOLUTION:
Finished m FALSE
REPEAT
Data m GetData()
OUTPUT Data
IF Data = Terminator THEN
Finished m TRUE
ENDIF
ENDPROCEDURE
Conditional loop
MP1 Conditional loop
MP2 Test for terminator in both cases
MP3 Use GetData() to get the data from the message
MP4 OUTPUT the data in a loop
MP5 INPUT the data reply
MP6 ‘Attempted ‘ use of Transmit to send it in a loop
MP7 Correct formation of parameters to Transmit()
Limitation:
1 GetData() does not return a value until a message has been received
2 So once a message has been sent the user has to wait for a reply // chat
is half-duplex
Modification:
3 If no response allow the receiver to exit chat at any time …
4 GetData() should immediately return a suitable message // set a time
limit
5 ... which Chat() can detect and respond by allowing the conversation to
continue