0% found this document useful (0 votes)
26 views

A1 CS P2 2015-2022 Part II

The document is an examination paper for Cambridge International Advanced Subsidiary and Advanced Level Computer Science, focusing on fundamental problem-solving and programming skills. It includes various topics such as basic data types, pseudocode, structure charts, and algorithms, with specific questions requiring candidates to analyze and write pseudocode. The paper consists of 17 pages of content, including instructions and example questions for candidates to answer.

Uploaded by

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

A1 CS P2 2015-2022 Part II

The document is an examination paper for Cambridge International Advanced Subsidiary and Advanced Level Computer Science, focusing on fundamental problem-solving and programming skills. It includes various topics such as basic data types, pseudocode, structure charts, and algorithms, with specific questions requiring candidates to analyze and write pseudocode. The paper consists of 17 pages of content, including instructions and example questions for candidates to answer.

Uploaded by

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

MUHAMMAD ALI KHAN

TOPIC Number of Pages

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 |

1040 | 1086 | 1112 | 1332 | 1362 |

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 |

1009 1064 | 1088 | 1200 | 1226 | 1334 | 1364


10. COMPLETE MISSING 10 | 40 | 68 | 89 | 121 | 140 | 165 | 190 | 219 | 248 | 255 | 312 | 317 | 340
PSEUDO CODES
| 366 | 386 |

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 |

14. Random Numbers 280 | 440 | 641 | 834 | 1368 |

15. ADTs 1017 | 1043 | 1066 | 1116 | 1172 |1174 | 1197 | 1252 | 1286
| 1310 | 1336 | 1366 |

16. STATE TRANSITION


1041 | 1069 | 1113 | 1196 | 1262 | 1318 |
DIAGRAMS

17. RECORD DATA TYPE 1090 |


MUHAMMAD ALI KHAN
PAGE 711

Cambridge Assessment International Education


Cambridge International Advanced Subsidiary and Advanced Level
* 9 7 4 4 6 8 1 1 6 1 *

COMPUTER SCIENCE 9608/21


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2019
2 hours
Candidates answer on the Question Paper.
No Additional Materials are required.
No calculators allowed.

READ THESE INSTRUCTIONS FIRST

Write your centre number, candidate number and name in the spaces at the top of this page.
Write in dark blue or black pen.
You may use an HB pencil for any diagrams, graphs or rough working.
Do not use staples, paper clips, glue or correction fluid.
DO NOT WRITE IN ANY BARCODES.

Answer all questions.


No marks will be awarded for using brand names of software packages or hardware.

At the end of the examination, fasten all your work securely together.
The number of marks is given in brackets [ ] at the end of each question or part question.

The maximum number of marks is 75.

This document consists of 17 printed pages and 3 blank pages.

DC (ST) 171120/3
© UCLES 2019 [Turn over
PAGE 712

1 Study the following pseudocode.

FUNCTION Search() RETURNS INTEGER


DECLARE N, C : INTEGER
DECLARE V, L : REAL
V GetLevel()
L V * 1.34
C 0
FOR N 1 TO 10
V GetLevel()
IF V > L
THEN
C C + 1
ENDIF
ENDFOR
OUTPUT "Process complete"
RETURN C
ENDFUNCTION

(a) (i) This pseudocode lacks features that would make it easier to read and understand.

State three such features.

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

Feature 2 ...........................................................................................................................

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

© UCLES 2019 9608/21/O/N/19


MUHAMMAD ALI KHAN
PAGE 713

(ii) Draw a program flowchart to represent the algorithm implemented in the pseudocode.
Variable declarations are not required in program flowcharts.

[5]

© UCLES 2019 9608/21/O/N/19 [Turn over


PAGE 714

(b) (i) Programming languages support different data types.

Complete the table by giving a suitable data type for each example value.

Example value Data type

"NOT TRUE"

í

NOT FALSE

132

[4]

(ii) Evaluate each expression in the following table.

,IDQH[SUHVVLRQLVLQYDOLGWKHQZULWH¶(5525·

Refer to the Appendix on page 16–17 for the list of built-in functions and operators.

Expression Evaluates to

LEFT("Start", 3) & RIGHT("Apple", 3)

0,' VDPSOH

NUM_TO_STRING(12.3 * 2)

,17 675,1*B72B180  

[4]

© UCLES 2019 9608/21/O/N/19


MUHAMMAD ALI KHAN
PAGE 715

2 (a) A structure chart is often used in modular program design. One feature shown is the sequence
of module execution.

State four other features that may be shown.

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]

(c) By value is one method of passing a parameter to a subroutine.

Identify and describe the other method.

Method ......................................................................................................................................

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

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

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

(d) Explain the term adaptive maintenance.

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

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

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

............................................................................................................................................. [2]
© UCLES 2019 9608/21/O/N/19 [Turn over
PAGE 716

3 The following is a function design in pseudocode.

Line numbers are given for reference only.

10 FUNCTION Check(InString : STRING) RETURNS BOOLEAN


11
12 DECLARE NumDots : INTEGER
13 DECLARE Index : INTEGER
14 DECLARE NumOthers : INTEGER
 
16 NumDots 0
17 NumOthers 0
18 Index 1
19
20 WHILE NumDots < 3 AND Index <= LENGTH(InString)
21
22 IF MID(InString, Index, 1) = '.'
23 THEN
24 NumDots NumDots + 1
 (/6(
26 NumOthers NumOthers + 1
27 ENDIF
28 Index Index + 1
29
30 ENDWHILE
31
32 IF NumDots = NumOthers
33 THEN
34 RETURN TRUE
 (/6(
36 RETURN FALSE
37 ENDIF
38
39 ENDFUNCTION

© UCLES 2019 9608/21/O/N/19


MUHAMMAD ALI KHAN
PAGE 717

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

The number of the line containing a variable being incremented

The range of line numbers containing a pre-condition loop

The number of initialisation statements

The number of the line containing a logical operator

The range of line numbers containing a selection statement

The name of a built-in function

The name of a parameter

[7]

© UCLES 2019 9608/21/O/N/19 [Turn over


PAGE 718

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.

The program will:

• 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:

1. START at the beginning of the string


2. SELECT a character from the string
3. CONVERT the character to upper case
4. CHECK whether the character is alphabetic and INCREMENT as required.
5. REPEAT from step 2 until last character has been checked
6. OUTPUT a suitable message giving the count of each alphabetic character

Step 4 above is not described in sufficient detail.

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 .....................................................................................................................................

Structured English ....................................................................................................................

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

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

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

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

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

© UCLES 2019 9608/21/O/N/19


MUHAMMAD ALI KHAN
PAGE 719

(b) Write pseudocode to implement the program.

You should note the following:

• InString contains the string to be checked. It has been assigned a value.


• The elements of the array Result have all been initialised to zero.
• 7KH$6&,,YDOXHRIOHWWHU¶$·LV

You should assume the following lines of pseudocode have been written:

DECLARE InString : STRING


DECLARE Result : ARRAY [1:26] OF INTEGER

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]

© UCLES 2019 9608/21/O/N/19 [Turn over


PAGE 720

10

5 The following pseudocode checks whether a string is a valid password.

FUNCTION CheckPassword(InString : STRING) RETURNS BOOLEAN

DECLARE Index, Upper, Lower, Digit, Other : INTEGER


DECLARE NextChar : CHAR

Upper 0
Lower 0
Digit 0
Other 0

FOR Index 1 TO LENGTH(InString)

NextChar MID(InString, Index, 1)


IF NextChar >= 'A' AND NextChar <= 'Z'
THEN
Upper Upper + 1
ELSE
IF NextChar >= 'a' AND NextChar <= 'z'
THEN
Lower Lower + 1
ELSE
IF NextChar >= '0' AND NextChar <= '9'
THEN
Digit Digit + 1
ELSE
Other Other + 1
ENDIF
ENDIF
ENDIF

ENDFOR

 ,)8SSHU!$1'/RZHU! $1' 'LJLW2WKHU !


THEN
RETURN TRUE
ELSE
RETURN FALSE
ENDIF

ENDFUNCTION

(a) Describe the validation rules that are implemented by this pseudocode. Refer only to the
contents of the string and not to features of the pseudocode.

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

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

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

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

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

............................................................................................................................................. [3]
© UCLES 2019 9608/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")

Index NextChar Upper Lower Digit Other

[5]

(ii) State the value returned when the function is called using the expression shown. Justify
your answer.

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

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

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

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

© UCLES 2019 9608/21/O/N/19 [Turn over


PAGE 722

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:

<Account Number>'*'<Name>'*'<Telephone Number>

An example of one line from the file is:

*% .HYLQ0DSXQJD 

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:

Module Outline description

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]

© UCLES 2019 9608/21/O/N/19


MUHAMMAD ALI KHAN
PAGE 723

13

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

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

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

Program code

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

............................................................................................................................................. [7]
© UCLES 2019 9608/21/O/N/19 [Turn over
PAGE 724

14

(c) Write pseudocode for the module FindDuplicates().

The module description is given in the table on page 12.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2019 9608/21/O/N/19


MUHAMMAD ALI KHAN
PAGE 725

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.

It will now be called with three parameters as follows:

1. The array
2. The number of elements
3. The initialisation string

You should assume that the lower bound is 1.

(i) Write pseudocode for the modified ClearArray() procedure.

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

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

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

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

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

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

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

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

(ii) Write program code for a statement that calls the modified ClearArray() procedure
to clear the array Duplicates to "Empty".

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

Program code

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

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

© UCLES 2019 9608/21/O/N/19 [Turn over


PAGE 726

16

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

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


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

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

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 10

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


returns leftmost x characters from ThisString

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

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


returns rightmost x characters from ThisString

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

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: ,17  returns 27

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.
Note: This function will also work if x is of type INTEGER

Example: 180B72B675,1*  returns 

STRING_TO_NUM(x : STRING) RETURNS REAL


returns a numeric representation of a string.
Note: This function will also work if x is of type CHAR

Example: 675,1*B72B180  returns 

ASC(ThisChar : CHAR) RETURNS INTEGER


returns the ASCII value of ThisChar

Example: ASC('A') returns 

CHR(x : INTEGER) RETURNS CHAR


returns the character whose ASCII value is x

Example: CHR(87) returns 'W'

© UCLES 2019 9608/21/O/N/19


MUHAMMAD ALI KHAN
PAGE 727

17

UCASE(ThisChar : CHAR) RETURNS CHAR


returns the character value representing the upper case equivalent of ThisChar
If ThisChar is not a lower case alphabetic character, it is returned unchanged.

Example: UCASE('a') returns 'A'

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/21/O/N/19


PAGE 728
9608/21 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

1(a)(i) One mark for each feature: 3

1. meaningful / sensible identifier names // use of Camel case for identifier


names // use of constants
2. blank lines / white space
3. comments

© UCLES 2019 Page 3 of 15


MUHAMMAD ALI KHAN
PAGE 729
9608/21 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

1(a)(ii) Mark as follows: 5


• One mark for START and END
• One mark per area outlined

At least one decision box label (YES/NO) must be


present

© UCLES 2019 Page 4 of 15


PAGE 730
9608/21 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

1(b)(i) One mark per row 4

Example value Data type

"NOT TRUE" STRING

 4.5 REAL

NOT FALSE BOOLEAN

132 INTEGER

1(b)(ii) One mark per row 4

Expression Evaluates to

LEFT("Start", 3) & RIGHT("Apple", 3) "Staple"

MID("sample", 3, 5) ERROR

NUM_TO_STRING(12.3 * 2) "24.6"

INT(STRING_TO_NUM("53.4")) + 7 60

© UCLES 2019 Page 5 of 15


MUHAMMAD ALI KHAN
PAGE 731
9608/21 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

2(a) One mark for each feature: 4

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:

• PrettyPrint // Colour coding


• Colour coding of command words / key words

• Expand and collapse code blocks


• Allows programmer to focus on a section of code // allows quicker navigation
of the code

• Auto(matic) indentation
• Allows the programmer to clearly see the different code sections / easier to
see the code structure

Accept suitable alternatives

2(c) One mark for identification, one mark for description: 2

• 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

2(d) One mark per bullet point: 2

• Changes made to // Updating // Editing a program / algorithm / data structure


/ software / system
• ...as a result of changes to requirements / specification / legislation / available
technology

© UCLES 2019 Page 6 of 15


PAGE 732
9608/21 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

3 7
One mark per row: Answer

The number of the line containing a variable being 24 / 26 / 28


i t d
The range of line numbers containing a pre-condition 20 – 30
loop

The number of initialisation statements 3

The number of the line containing a logical operator 20

The range of line numbers containing a selection 22 - 27 /


statement 32 - 37

The name of a built-in function MID / LENGTH

The name of a parameter InString / Index

© UCLES 2019 Page 7 of 15


MUHAMMAD ALI KHAN
PAGE 733
9608/21 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

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

4(b) DECLARE Index : INTEGER 7


DECLARE Count : INTEGER

FOR Count m 1 TO LENGTH(InString)


NextChar m UCASE(MID(InString, Count, 1))
IF NextChar >= 'A' AND NextChar <= 'Z'
THEN
Index m ASC(NextChar) – 64
Result[Index] m Result[Index] + 1
ENDIF
ENDFOR

FOR Index m 1 TO 26

OUTPUT "Letter " & CHR(Index + 64) & " : "


& NUM_TO_STRING(Result[Index])
ENDFOR

One mark for each of the following (max 7):

1 First loop from 1 to length of InString:


2 Extract each character in turn in a loop
3 Check that character is alphabetic (must cater for lower & upper case) in a
loop
4 Obtain array index using ASC() - 64 in a loop
5 Increment element of Result array in a loop
6 Second loop from 1 to 26:
7 Attempt to OUTPUT character A to Z and corresponding count in a loop
8 Fully complete OUTPUT including any necessary type conversion in a loop

© UCLES 2019 Page 8 of 15


PAGE 734
9608/21 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

5(a) One mark for each point. 3

A valid string must contain:

• At least two // more than one upper case character(s)


• At least five // more than four lower case character(s)
• More digit characters than 'other' characters

© UCLES 2019 Page 9 of 15


MUHAMMAD ALI KHAN
PAGE 735
9608/21 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

5(b)(i) One mark for each area as outlined: 5

Index NextChar Upper Lower Digit Other

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

5(b)(ii) One mark per bullet point: 2

• Returned value is FALSE


• Digit – Other is not greater than zero // Number of Digit same as
Other

© UCLES 2019 Page 10 of 15


PAGE 736
9608/21 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

6(a) To retain data when the computer is shut down / turned off // after the program 1
ends

Accept equivalent answer.

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

FUNCTION SearchFileNtoZ(AccNum : STRING) RETURNS BOOLEAN


DECLARE FileData : STRING
DECLARE Found : BOOLEAN
CONSTANT SearchFile = "UserListNtoZ.txt"
Found m FALSE

OPENFILE SearchFile FOR READ

WHILE NOT EOF(SearchFile) AND NOT Found

READFILE SearchFile, FileData


IF AccNum & '*' = LEFT(FileData, LENGTH(AccNum)+ 1)
THEN
Found m TRUE
ENDIF

ENDWHILE

CLOSEFILE SearchFile

RETURN Found

ENDFUNCTION

One mark for each of the following:

1. Function heading and ending, (ignore parameter) and returned BOOLEAN


2. File OPEN UserListNtoZ.txt in READ mode and CLOSE
3. Conditional loop repeating until EOF() or 'Found'
4. Read a line from the file in a loop
5. Compare the correct number of characters with AccNum in a loop
6. Set termination logic if found in a loop
7. Return Boolean value

© UCLES 2019 Page 11 of 15


MUHAMMAD ALI KHAN
PAGE 737
9608/21 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

6(c) PROCEDURE FindDuplicates() 8

DECLARE Index : INTEGER


DECLARE FileData : STRING
DECLARE Continue : BOOLEAN
DECLARE AccNum : STRING

Index m 1 // assuming array is [1:100]


Continue m TRUE
OPENFILE "UserListAtoM.txt" FOR READ

WHILE NOT EOF("UserListAtoM.txt") AND Continue = TRUE

READFILE "UserListAtoM.txt", FileData

IF MID(FileData, 7, 1) = '*' // six character reference


THEN
AccNum m LEFT(FileData, 6)
ELSE
AccNum m LEFT(FileData, 9)
ENDIF

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

One mark for each of the following (max 8):

1. Declaration and Initialisation of Index and used to index array


Duplicates
2. OPEN file UserListAtoM.txt in READ mode and CLOSE
3. Pre-Condition loop to go through the file until EOF() and early termination
if array full
4. Read line from file and extract account number (AccNum) in a loop
5. Call SearchFileNtoZ (with AccNum) following an attempt at MP4 in a
loop
6. Check if return value is TRUE and if so: in a loop
7. store AccNum in correct array element
8. increment array index following an attempt at MP7
9. If array overflow OUTPUT error message
© UCLES 2019 Page 12 of 15
PAGE 738
9608/21 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

6(d)(i) PROCEDURE ClearArray(BYREF ThisArray : ARRAY, 3


NumElements : INTEGER, InitVal : STRING)

DECLARE Index : INTEGER


FOR Index m 1 TO NumElements
ThisArray[Index] m InitVal
ENDFOR

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.

CALL ClearArray(Duplicates, 100, "Empty")

Mark as follows:

• Procedure call
• Parameter list (in brackets)

© UCLES 2019 Page 13 of 15


MUHAMMAD ALI KHAN
PAGE 739
9608/21 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Program Code Example Solutions

Question 6(b): Visual Basic

Function SearchFileNtoZ(ByVal SearchString As String) As Boolean


Dim FileData As String
Dim Found As Boolean

Found = FALSE

FileOpen(1, "UserListNtoZ.txt", OpenMode.Input)

While Not EOF(1) And Not Found

Filedata = LineInput(1)
If SearchString & '*' = Left(FileData, Len(SearchString)+1) Then
Found = TRUE
End If

End While

FileClose(1)

Return Found

End Function

Question 6(b): Pascal

function SearchFileNtoZ (SearchString : string): boolean;


var
FileData : string;
Found : boolean;
MyFile : text;

begin

Found := FALSE;

assign(MyFile, "UserListNtoZ.txt");
reset (Myfile);

while Not EOF(MyFile) And Not Found do


begin
readLn(MyFile, FileData);
if SearchString + '*' = LeftStr(FileData, length(SearchString)+1)
then
Found := TRUE;

end;

close(MyFile);

result := Found; // SearchFileB := Found;

end;

© UCLES 2019 Page 14 of 15


PAGE 740
9608/21 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question 6(b): Python

def SearchFileNtoZ(SearchString):
## FileData : String
## Found : Boolean
## MyFile : Text

Found = False

MyFile = open("UserListNtoZ.txt", 'r')


FileData = MyFile.readline()
while Filedata != "" and not Found :
if SearchString + '*' == FileData[0: len(SearchString)+1]:
Found = True

FileData = MyFile.readline()

MyFile.close

return(Found)

Question 6(d)(ii): Visual Basic

Call ClearArray(Duplicates, 100, "Empty") 'Call optional

Question 6(d)(ii): Pascal

ClearArray(Duplicates, 100, 'Empty');

Question 6(d)(ii): Python

ClearArray(Duplicates, 100, "Empty")

© UCLES 2019 Page 15 of 15


MUHAMMAD ALI KHAN
PAGE 741

Cambridge Assessment International Education


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

COMPUTER SCIENCE 9608/22


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2019
2 hours
Candidates answer on the Question Paper.
No Additional Materials are required.
No calculators allowed.

READ THESE INSTRUCTIONS FIRST

Write your centre number, candidate number and name in the spaces at the top of this page.
Write in dark blue or black pen.
You may use an HB pencil for any diagrams, graphs or rough working.
Do not use staples, paper clips, glue or correction fluid.
DO NOT WRITE IN ANY BARCODES.

Answer all questions.


No marks will be awarded for using brand names of software packages or hardware.

At the end of the examination, fasten all your work securely together.
The number of marks is given in brackets [ ] at the end of each question or part question.

The maximum number of marks is 75.

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

DC (ST) 171121/3
© UCLES 2019 [Turn over
PAGE 742

1 Study the following pseudocode.

PROCEDURE FillTank()

DECLARE Tries : INTEGER


DECLARE Full : BOOLEAN

Tries 1

Full ReadSensor("F1")

IF NOT Full
THEN
WHILE NOT Full AND Tries < 4
CALL TopUp()
Full ReadSensor("F1")
Tries Tries + 1
ENDWHILE
IF Tries > 3
THEN
OUTPUT "Too many attempts"
ELSE
OUTPUT "Tank now full"
ENDIF
ELSE
OUTPUT "Already full"
ENDIF

ENDPROCEDURE

(a) (i) The pseudocode includes features that make it easier to read and understand.

State three such features.

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

Feature 2 ...........................................................................................................................

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

© UCLES 2019 9608/22/O/N/19


MUHAMMAD ALI KHAN
PAGE 743

(ii) Draw a program flowchart to represent the algorithm implemented in the pseudocode.
Variable declarations are not required in program flowcharts.

[5]

© UCLES 2019 9608/22/O/N/19 [Turn over


PAGE 744

(b) (i) Programming languages support different data types.

Complete the table by giving a suitable data type for each example value.

Example value Data type

43

TRUE

í

í

[4]

(ii) Evaluate each expression in the following table.

,IDQH[SUHVVLRQLVLQYDOLGWKHQZULWH¶(5525·

Refer to the Appendix on page 18 for the list of built-in functions and operators.

Expression Evaluates to

5,*+7 6WRS  /()7 LFK

0,' 180B72B675,1*  

,17 180B72B675,1* 

,17  

[4]

© UCLES 2019 9608/22/O/N/19


MUHAMMAD ALI KHAN
PAGE 745

2 (a) Describe the program development cycle with reference to the following:

• source code
• object code
• corrective maintenance.

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

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

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

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

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

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

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

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

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

(b) Give three features of an Integrated Development Environment (IDE) that can help with
initial error detection while writing the program.

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

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

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

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

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

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

© UCLES 2019 9608/22/O/N/19 [Turn over


PAGE 746

3 A student is developing a program to search through a string of numeric digits to count how many
times each digit occurs. The variable InString will store the string and the 1D array Result will
store the count values.

The program will:

• check each character in the string to count how many times each digit occurs
• record the count for each digit using the array
• output the count for each element of the array together with the corresponding digit.

(a) The array Result is a 1D array of type INTEGER.

Write pseudocode to declare the array and to initialise all elements to zero.

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

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

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

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

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

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

© UCLES 2019 9608/22/O/N/19


MUHAMMAD ALI KHAN
PAGE 747

(b) Write the pseudocode for the program.

Declare any variables you use. Do not implement the code as a subroutine.

Refer to the Appendix on page 18 for the list of built-in functions and operators.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

............................................................................................................................................. [8]

© UCLES 2019 9608/22/O/N/19 [Turn over


PAGE 748

4 A program is being written to control the operation of a portable music player. One part of the
program controls the output volume.

The player has two buttons, one to increase the volume and one to decrease it. Whenever a
button is pressed, a procedure Button() is called with a parameter value representing the button
as follows:

Button Parameter value

Volume increase 10

Volume decrease 20

For example, pressing the volume increase button three times followed by pressing the volume
decrease button once would result in the calls:

  &$//%XWWRQ  9RO/HYHOLQFUHDVHGE\
  &$//%XWWRQ  9RO/HYHOLQFUHDVHGE\
  &$//%XWWRQ  9RO/HYHOLQFUHDVHGE\
  &$//%XWWRQ  9RO/HYHOGHFUHDVHGE\

The program makes use of two global variables of type INTEGER as follows:

Variable Description
9RO/HYHO The current volume setting. This must be in the range 0 to 49.
A value that can be set to limit the maximum value of 9RO/HYHO,
LQRUGHUWRSURWHFWWKHXVHU·VKHDULQJ
0D[9RO
A value in the range 1 to 49 indicates the volume limit.
A value of zero indicates that no volume limit has been set.

The procedure Button() will modify the value of 9RO/HYHO depending on which button has
been pressed and whether a maximum value has been set.

© UCLES 2019 9608/22/O/N/19


MUHAMMAD ALI KHAN
PAGE 749

(a) Write pseudocode for the procedure Button(). Declare any additional variables you use.

The value of 0D[9RO should not be changed within the procedure.

Parameter validation is not necessary.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

............................................................................................................................................. [6]
© UCLES 2019 9608/22/O/N/19 [Turn over
PAGE 750

10

(b) The procedure Button() is to be tested using black-box testing.

Fill in the gaps below to define three tests that could be carried out.

TEST 1 – 9RO/HYHO is changed

Parameter value: 10

0D[9RO: ..................

9RO/HYHO value before call to Button(): 48

9RO/HYHO expected value after call to Button(): ..................

TEST 2 – 9RO/HYHO is not changed

Parameter value: 10

0D[9RO: 34

9RO/HYHO value before call to Button(): ..................

9RO/HYHO expected value after call to Button(): ..................

TEST 3 – 9RO/HYHO is not changed

Parameter value: ..................

0D[9RO: 40

9RO/HYHO value before call to Button(): 0

9RO/HYHO expected value after call to Button(): ..................

[6]

© UCLES 2019 9608/22/O/N/19


MUHAMMAD ALI KHAN
PAGE 751

11

(c) The testing stage is part of the program development cycle.

(i) The program for the music player has been completed. The program does not contain
any syntax errors, but testing could reveal further errors.

Identify and describe one different type of error that testing could reveal.

Type ..................................................................................................................................

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

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

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

(ii) Stub testing is a technique often used in the development of modular programs.

Describe the technique.

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

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

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

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

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

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

© UCLES 2019 9608/22/O/N/19 [Turn over


PAGE 752

12

5 The module headers for three modules in a program are defined in pseudocode as follows:

Pseudocode module header


PROCEDURE Lookup(P4 : INTEGER, BYREF M4 : STRING)
FUNCTION Update(T4 : INTEGER) RETURNS INTEGER
)81&7,219DOLGDWH 6,17(*(53675,1* 5(78516%22/($1

A fourth module, Renew(), calls the three modules in the following sequence.

 9DOLGDWH
Lookup()
Update()

Draw a structure chart to show the relationship between the four modules and the parameters
passed between them.

[7]

© UCLES 2019 9608/22/O/N/19


MUHAMMAD ALI KHAN
PAGE 753

13

Question 6 begins on the next page.

© UCLES 2019 9608/22/O/N/19 [Turn over


PAGE 754

14

6 A text file, 6WXGHQW/LVWW[W, contains a list of information about students in a school.

Each line of the file contains a reference, name and date of birth for one student. All the information
is held as strings and separated by the asterisk character ('*') as follows:

<Reference>'*'<Name>'*'<Date Of Birth>

An example of one line from the file is:

* $OH]D+LOWRQ 

The reference string may be five or eight characters in length and is unique for each student. It is
made up of alphabetic and numeric characters only.

A global 1D array, /HDYHUV, contains the references of all students who have recently left the
school. The array consists of 500 elements of data type STRING. Unused elements contain the
empty string "".

A program is to be written to produce a new text file, 8SGDWHG/LVWW[W, containing information


only for students who are still attending the school.

The program is to be implemented as several modules. The outline description of three of these is
as follows:

Module Outline description


• Read each line from the file 6WXGHQW/LVWW[W
• Check whether the Reference appears in the
array using 6HDUFK/HDYHUV
ProcessStudentList()
• If the Reference does not appear then write the
line to the file 8SGDWHG/LVWW[W
• Return the number of lines not copied.
• Search for a given Reference in the array /HDYHUV
6HDUFK/HDYHUV • If the Reference is found, return TRUE, otherwise
return FALSE
• Take two parameters: the name of an array and a
string.
CountTimes()
• Count the number of elements that are the same as
the string. Return the count value.

© UCLES 2019 9608/22/O/N/19


MUHAMMAD ALI KHAN
PAGE 755

15

(a) Write program code for the module 6HDUFK/HDYHUV . Declare any additional variables
you use.

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

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

Program code

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2019 9608/22/O/N/19 [Turn over


PAGE 756

16

(b) Write pseudocode for the module ProcessStudentList().

The module description is repeated here for reference.

Module Outline description


• Read each line from the file 6WXGHQW/LVWW[W
• Check whether the Reference appears in the
array using 6HDUFK/HDYHUV
ProcessStudentList()
• If the Reference does not appear then write the
line to the file 8SGDWHG/LVWW[W
• Return the number of lines not copied.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

...................................................................................................................................................
© UCLES 2019 9608/22/O/N/19
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.

The module description is repeated here for reference.

Module Outline description


• Take two parameters: the name of an array and a
string.
CountTimes()
• Count the number of elements that are the same as
the string. Return the count value.

Write a statement in program code that uses CountTimes() to assign the count of unused
elements to the variable Result.

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

Program code

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

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

© UCLES 2019 9608/22/O/N/19 [Turn over


PAGE 758

18

Appendix
Built-in functions (pseudocode)

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

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


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

Example: 0,' $%&'()*+ returns "BCD"

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 

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


returns leftmost x characters from ThisString

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

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


returns rightmost x characters from ThisString

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

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: ,17  returns 

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.
Note: This function will also work if x is of type INTEGER

Example: 180B72B675,1*  returns 

STRING_TO_NUM(x : STRING) RETURNS REAL


returns a numeric representation of a string.
Note: This function will also work if x is of type CHAR

Example: 675,1*B72B180  returns 

Operators (pseudocode)

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

© UCLES 2019 9608/22/O/N/19


MUHAMMAD ALI KHAN
PAGE 759
9608/22 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

1(a)(i) Any three from: 3

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

Tries ĸ 1 Mark as follows:


• One mark for START and END
• One mark for each of the 4
Full ĸ
areas outlined
ReadSensor("F1")

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

© UCLES 2019 Page 3 of 13


PAGE 760
9608/22 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

1(b)(i) One mark per row 4

Example value Data type

43 INTEGER

TRUE BOOLEAN

273.16 REAL

"273.16" STRING

1(b)(ii) One mark per row 4

Expression Evaluates to

RIGHT("Stop", 3) & LEFT("ich",2) "topic"

MID(NUM_TO_STRING(2019), 3, 1) "1"

INT(NUM_TO_STRING(-273.16)) ERROR

INT(13/2) 6

Question Answer Marks

2(a) One mark per point: 3

1. The source code represents a solution / design / algorithm expressed in a


high-level language
2. The Object code is produced (by the compiler) during the translation stage
// The Object code is produced by translating the source code (NOT
produced by Interpreter)
3. Corrective maintenance occurs when testing reveals a fault (or error) in the
program and this is corrected // Corrective maintenance is when errors are
found and fixed // Corrective maintenance is when a program is debugged

Accept alternative answers provided they relate to the program development


cycle

2(b) Any three from: 3

1. Dynamic syntax checking // Identification of syntax errors


2. Highlighting undeclared variables // incorrect variable usage...
3. Parameter checking
4. Type checking
5. Auto-indentation
6. PrettyPrint

© UCLES 2019 Page 4 of 13


MUHAMMAD ALI KHAN
PAGE 761
9608/22 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

3(a) DECLARE Result : ARRAY [0:9] OF INTEGER 3


DECLARE Index : INTEGER

FOR Index m 0 TO 9
Result[Index] m 0
ENDFOR

One mark for each of the following:

1. Declaration of RESULT array (10 elements of type INTEGER)


2. Loop
3. Assignment within a loop

3(b) DECLARE Index : INTEGER 8


DECLARE NextChar : CHAR
DECLARE NextCharValue : INTEGER

FOR Index m 1 TO LENGTH(InString)


NextChar m MID(InString, Index, 1)
NextCharValue m STRING_TO_NUM(NextChar)
Result[NextCharValue] m Result[NextCharValue] + 1
ENDFOR

FOR Index m 0 TO 9
OUTPUT "Count of digit " & NUM_TO_STRING(Index) & " : "
& NUM_TO_STRING(Result[Index])
ENDFOR

One mark for each of the following:

1. Declaration of INTEGER variable for Index (or equivalent) to index


Result array
2. First loop from 1 to length of InString:
3. Select each character (e.g MID) in first loop
4. Apply type conversion to obtain integer value for index in first loop
5. Increment element of Result array in a loop
6. Separate second loop to repeat 10 times:
7. Attempt to OUTPUT two items (digit 0 to 9 plus corresponding count) in
any loop
8. OUTPUT statement including index and count in any loop including type
conversion of element from array if required in a loop

© UCLES 2019 Page 5 of 13


PAGE 762
9608/22 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

4(a) PROCEDURE Button(ButtonNum : INTEGER) 6


DECLARE Limit : INTEGER

IF ButtonNum = 10 // increase volume


THEN
IF MaxVol = 0
THEN
Limit m 49
ELSE
Limit m MaxVol
ENDIF
IF VolLevel < Limit
THEN
VolLevel m VolLevel + 1
ENDIF
ELSE // otherwise must be ButtonNum 20 - decrease
IF VolLevel > 0
THEN
VolLevel m VolLevel - 1
ENDIF
ENDIF
ENDPROCEDURE

Mark as follows:

1. Check if parameter value = 10


2. Check if parameter value = 20
3. Check if MaxVol = 0
4. Decrement VolLevel and ensure still in range

If attempting to increase volume (parameter value was 10):

5. Increment VolLevel
6. Ensure VolLevel still in range: for both cases. i.e:
VolLevel <= 49 (for MaxVol = 0)
VolLevel <= MaxVol (for MaxVol <> 0)

4(b) 2 independent marks for each test: 6

Test 1
MaxVol: 0/49
VolLevel expected: 49

Test 2
VolLevel before: 34
VolLevel expected: 34

Test 3
Parameter: 20
VolLevel expected: 0

© UCLES 2019 Page 6 of 13


MUHAMMAD ALI KHAN
PAGE 763
9608/22 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

4(c)(i) One mark for type, one for description: 2

• Type: Logical Error


• Description: Program does not perform as expected
• Type: Run-time error
• Description: Program executes an invalid instruction / out of bounds error /
attempts to divide by zero // program crashes

4(c)(ii) One mark per bullet point: 3

• 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

Question Answer Marks

5 7

One mark for each of:

1. Diagram with boxes as above correctly labelled


2. P3 and S2
3. Return Boolean from Validate()
4. P4
5. M4
6. T4
7. Return parameter from Update()

© UCLES 2019 Page 7 of 13


PAGE 764
9608/22 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

6(a) 'Pseudocode' solution included here for development and clarification of mark 6
scheme.
Programming language example solutions appear in the Appendix.

FUNCTION SearchLeavers(Reference : STRING) RETURNS BOOLEAN

DECLARE Index : INTEGER


DECLARE Found : BOOLEAN

Found m FALSE
Index m 0

WHILE Index < 500 AND NOT Found

IF Reference = Leavers[Index]
THEN
Found m TRUE
ENDIF

Index m Index + 1

ENDWHILE

RETURN Found

ENDFUNCTION

One mark for each of the following:

1. Function heading (and ending) as above


2. Initialisation and increment of Index used to index Leavers array in a
loop
3. Conditional loop repeating while Index < 500 and exit loop if
Reference is found:
4. Compare indexed array element value with Reference in a loop
5. Set termination logic if found in a loop
6. Return Boolean value

© UCLES 2019 Page 8 of 13


MUHAMMAD ALI KHAN
PAGE 765
9608/22 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

6(b) FUNCTION ProcessStudentList() RETURNS INTEGER 9

DECLARE NotCopied : INTEGER


DECLARE FileData : STRING
DECLARE Reference : STRING

NotCopied m 0

OPENFILE "StudentList.txt" FOR READ


OPENFILE "UpdatedList.txt" FOR WRITE

WHILE NOT EOF("StudentList.txt")

READFILE "StudentList.txt", FileData

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

One mark for each of the following:

1. Function heading and ending as above


2. Declaration and use of three local variables and initialisation of count to 0
3. OPEN both files in correct mode and CLOSE
4. Pre-Condition loop to go through the file StudentList.txt until EOF()
5. Read line from StudentList.txt and extract correct Reference (either
5 or 8 characters) in a loop
6. Call SearchLeavers() with Reference (after attempted extraction) in a
loop
7. If result is FALSE then write FileData to UpdatedList.txt in a loop
8. Otherwise increment NotCopied in a loop
9. Return NotCopied count

© UCLES 2019 Page 9 of 13


PAGE 766
9608/22 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

6(c) 'Pseudocode' solution included here for development and clarification of mark 3
scheme.
Programming language example solutions appear in the Appendix.

One mark per underlined section:

Result m CountTimes (Leavers, "")

(Space before open bracket to highlight underlined section only)

© UCLES 2019 Page 10 of 13


MUHAMMAD ALI KHAN
PAGE 767
9608/22 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Program Code Example Solutions

Q6 (a): Visual Basic


Function SearchLeavers(ByVal Reference As String) As Boolean

Dim Index As Integer


Dim Found As Boolean

Found = FALSE
Index = 0

Do While Index < 500 And Not Found

If Reference = Leavers(Index) Then


Found = TRUE
End If

Index = Index + 1

Loop

Return Found

End Function

© UCLES 2019 Page 11 of 13


PAGE 768
9608/22 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Q6 (a): Pascal
function SearchLeavers(Reference : String) : boolean;

var Index : integer;


var Found : boolean;

begin
Found := FALSE;
Index := 0;

While Index < 500 And Not Found


begin
if Reference = Leavers[Index] Then
Found := TRUE;

Index := Index + 1;

end;

result := Found; // SearchLeavers := Found

end;

Q6 (a): Python
def SearchLeavers(Reference):

## Index : Integer
## Found : Boolean

Found = False
Index = 0

while Index < 500 and not Found:


if Reference == Leavers[Index]:
Found = True

Index = Index + 1

return Found

© UCLES 2019 Page 12 of 13


MUHAMMAD ALI KHAN
PAGE 769
9608/22 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Q6 (c): Visual Basic


Result = CountTimes(Leavers, "")

Q6 (c): Pascal
Result := CountTimes(Leavers, "");

Q6 (c): Python
Result = CountTimes(Leavers, "")

© UCLES 2019 Page 13 of 13


PAGE 770

Cambridge Assessment International Education


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

COMPUTER SCIENCE 9608/23


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2019
2 hours
Candidates answer on the Question Paper.
No Additional Materials are required.
No calculators allowed.

READ THESE INSTRUCTIONS FIRST

Write your centre number, candidate number and name in the spaces at the top of this page.
Write in dark blue or black pen.
You may use an HB pencil for any diagrams, graphs or rough working.
Do not use staples, paper clips, glue or correction fluid.
DO NOT WRITE IN ANY BARCODES.

Answer all questions.


No marks will be awarded for using brand names of software packages or hardware.

At the end of the examination, fasten all your work securely together.
The number of marks is given in brackets [ ] at the end of each question or part question.

The maximum number of marks is 75.

This document consists of 16 printed pages.

DC (ST/SG) 171122/4
© UCLES 2019 [Turn over
MUHAMMAD ALI KHAN
PAGE 771

1 (a) (i) Programming languages can support different data types.

Complete the table by naming three different data types together with an example data
value for each.

Data type Example data value

[6]

(ii) Identify the type of programming statement that assigns a data type to a variable.

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

(b) As part of the development of an algorithm, a programmer may construct an identifier table.

Describe what an identifier table contains.

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

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

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

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

(c) (i) Simple algorithms usually consist of three different stages.

Complete the table below. Write each example statement in program code.

The second stage has already been given.

Stage Example statement

Process

[5]

(ii) Write a single statement in program code that contains two of the stages. Do not
repeat any of the statements from part (c)(i).

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

© UCLES 2019 9608/23/O/N/19 [Turn over


PAGE 772

(d) A software developer is writing a program and includes several features to make it easier to
read and understand. One of these features is the use of indentation.

State three other features.

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

Feature 2 ..................................................................................................................................

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

(e) A trace table is often used during program testing.

Identify the type of testing that includes the use of a trace table.

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

© UCLES 2019 9608/23/O/N/19


MUHAMMAD ALI KHAN
PAGE 773

2 (a) (i) 7ZRW\SHVRIORRSWKDWPD\EHIRXQGLQDQDOJRULWKPDUHWKH¶SUHFRQGLWLRQ·DQG¶SRVW


FRQGLWLRQ·ORRS

Identify one other type of loop. Explain when it should be used.

Type ..................................................................................................................................

Explanation .......................................................................................................................

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

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

(ii) Part of a program flowchart is shown.

LOOP

AlarmReset()

Set Status1 to
GetStatus(Sys_A)

Set Status2 to
GetStatus(Sys_B)

Are Status1
NO
and Status2
both TRUE?

YES

Implement the flowchart in pseudocode using a post-condition loop.

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

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

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

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

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

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

© UCLES 2019 9608/23/O/N/19 [Turn over


PAGE 774

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

100 setvar(Count, Integer)


110 setvar(Gross[0-20], Real)
120 setvar(Posn, Real)
130 setvar(Length, Integer)
140 setvar(Rate, Real)
150 Length := 7
160 Rate := 1.175
170
180 For (Count, 0, 20, 2)
190 {
200 Echo "Input next cost"
210 Posn := Read()
220 Gross[Count] := Mult(Posn, Rate) %Apply current tax rate
230 }

Study the code. Identify the relevant features in the following table.

Feature Answer

The symbol used to indicate an assignment

The line numbers for the start and end of a count-controlled loop

The step value of the count-controlled loop

The character that indicates a comment

The name of a function


[5]

(c) A program written in a high-level language cannot be run directly.

Identify one type of translator that can be used to translate the program.

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

© UCLES 2019 9608/23/O/N/19


MUHAMMAD ALI KHAN
PAGE 775

3 Three program modules process updating of passwords in a file. A description of the relationship
between the modules is summarised as follows:

Module name Description

GetPassword()
• Takes two parameters: AccountID and OldPassword
• Returns a string containing the new password
• Takes two parameters: AccountID and NewPassword
UpdateFile() • Returns a Boolean value to indicate whether or not the
update was successful

ChangePassword()
• Calls GetPassword() to obtain the new password then
calls UpdateFile() to write the new password to the file

Draw a structure chart to show the relationship between the three modules and the parameters
passed between them.

[5]

© UCLES 2019 9608/23/O/N/19 [Turn over


PAGE 776

4 The following pseudocode algorithm checks whether a string is a valid email address.

FUNCTION Check(InString : STRING) RETURNS BOOLEAN

DECLARE Index : INTEGER


DECLARE NumDots : INTEGER
DECLARE NumAts : INTEGER
DECLARE NextChar : CHAR
DECLARE NumOthers : INTEGER

NumDots 0
NumAts 0
NumOthers 0

FOR Index 1 TO LENGTH(InString)

NextChar MID(InString, Index, 1)


CASE OF NextChar
'.': NumDots NumDots + 1
'@': NumAts NumAts + 1
OTHERWISE NumOthers NumOthers + 1
ENDCASE

ENDFOR

IF (NumDots >= 1 AND NumAts = 1 AND NumOthers > 5)


THEN
RETURN TRUE
ELSE
RETURN FALSE
ENDIF

ENDFUNCTION

(a) Describe the validation rules that are implemented by this pseudocode. Refer only to the
contents of the string and not to features of the pseudocode.

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

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

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

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

© UCLES 2019 9608/23/O/N/19


MUHAMMAD ALI KHAN
PAGE 777

(b) (i) Complete the trace table by dry running the function when it is called as follows:

Result Check("[email protected]")

Index NextChar NumDots NumAts NumOthers

[5]

(ii) State the value returned when function Check is called as shown in part (b)(i).

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

© UCLES 2019 9608/23/O/N/19 [Turn over


PAGE 778

10

(c) The function Check() is to be tested.

State two different invalid string values that could be used to test the algorithm. Each string
should test a different rule.

Justify your choices.

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

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

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

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

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

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

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

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

5 Abbreviations are often used in place of a full name. Concatenating the first letter of each word in
the name makes an abbreviation.

For example:

Name Abbreviation

United Nations UN

World Wide Web WWW

British Computer Society BCS

A function, Abbreviate(), will take a string representing the full name and return a string
containing the abbreviated form.

You should assume that:

• names only contain alphabetic characters and space characters


• names always start with an alphabetic character
• each word in the name always starts with an uppercase character
• only a single space separates words in the name.

© UCLES 2019 9608/23/O/N/19


MUHAMMAD ALI KHAN
PAGE 779

11

Write pseudocode to implement the function Abbreviate().

Refer to the Appendix on page 16 for the list of built-in functions and operators.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

.................................................................................................................................................... [8]

© UCLES 2019 9608/23/O/N/19 [Turn over


PAGE 780

12

6 A text file, Library.txt, stores information relating to a book collection. The file stores four
pieces of information about each book on separate lines of the file, as follows:

Line n: <Book Title>


Line n + 1: <Author Name>
Line n + 2: <ISBN>
Line n + 3: <Location>

Information is stored as data strings.

Information relating to two books is shown:

File line Data


100 "Learning Python"

101 "Brian Smith"

102 "978-14-56543-21-8"

103 "BD345"

104 "Surviving in the mountains"

105 "C T Snow"

106 "978-35-17635-43-9"

107 "ZX001"

(a) (i) A function, FindBooksBy(), will search Library.txt for all books by a given author.

The function will store the Book Title and Location in the array Result, and will
return a count of the number of books found.

Array Result is a global 2D array of type STRING. It has 100 rows and 2 columns.

Write pseudocode to declare the array Result.

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

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

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

(ii) Function FindBooksBy() will:

• receive the Author Name as a parameter


• search Library.txt for matching entries
• store the Book Title and Location of matching entries in the Result array
• return an integer value giving the number of books by the author that were found.

© UCLES 2019 9608/23/O/N/19


MUHAMMAD ALI KHAN
PAGE 781

13

Write program code for the function FindBooksBy().

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

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

Program code

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

...........................................................................................................................................
© UCLES 2019 9608/23/O/N/19 [Turn over
PAGE 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.

The procedure receives the following two parameters:

• a string containing the author name


• an integer value representing the number of books found

The output should be formatted as in the following example:

Books written by: Brian Smith

Title Location
Learning Python BD345
Arrays are not lists CZ562
Learning Java CZ589

Number of titles found: 3

If no books by the author are found, the following should be output:

Search found no books by: Brian Smith

© UCLES 2019 9608/23/O/N/19


MUHAMMAD ALI KHAN
PAGE 783

15

Write pseudocode for the procedure DisplayResults().

Refer to the Appendix on page 16 for the list of built-in functions and operators.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2019 9608/23/O/N/19 [Turn over


PAGE 784

16

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

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


returns a string of length y starting at position x from ThisString
Example: MID("ABCDEFGH", 2, 3) returns "BCD"

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString
Example: LENGTH("Happy Days") returns 10

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


returns leftmost x characters from ThisString
Example: LEFT("ABCDEFGH", 3) returns "ABC"

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


returns rightmost x characters from ThisString
Example: RIGHT("ABCDEFGH", 3) returns "FGH"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x
Example: INT(27.5415) returns 27

ASC(ThisChar : CHAR) RETURNS INTEGER


returns the ASCII value of ThisChar
Example: ASC('A') returns 65

MOD(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the remainder when ThisNum is divided by ThisDiv
Example: MOD(10,3) returns 1

Operators (pseudocode)

Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE
© UCLES 2019 9608/23/O/N/19
MUHAMMAD ALI KHAN
PAGE 785
9608/23 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

1(a)(i) One mark for each (different) data type ... 6


... and one mark for a corresponding example value

Acceptable types: Integer, Real, String, Char, Boolean, Date,

1(a)(ii) Declaration 1

1(b) Two from (max 2): 2

• A list of identifier / variable names


• Explanations/descriptions (of what they are used for)
• Data types

1(c)(i) One mark for each stage (Input, Output) 5


One mark for each correct example

Stage Example statement

Input Next = Console.Readline()

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

Example correct answers:

• Next = LEN(Console.Input())
• Console.writeline(Name & Address)
• Console.WriteLine(Console.Readline() & " is what you
entered")

1(d) Three from the following (max 3): 3

• Blank lines
• Capitalisation of Keywords
• Sensible variable names
• Use of (library/built-in) functions
• Comments
• PrettyPrint / keywords coloured

1(e) White-box 1

© UCLES 2019 Page 3 of 13


PAGE 786
9608/23 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

2(a)(i) • Count-controlled // FOR loop 2


• Used when the number of iterations is known / fixed

2(a)(ii) REPEAT 4
CALL AlarmReset()
Status1 m GetStatus(Sys_A)
Status2 m GetStatus(Sys_B)
UNTIL (Status1 = TRUE AND Status2 = TRUE)

One mark for each of:

1 REPEAT ... UNTIL


2 Call to AlarmReset()
3 Asignment of Status1 and Status2
4 correct logical test

2(b) 5
Feature Answer

The symbol used to indicate an assignment :=

The line numbers for the start and end of a count- 180/190 and 230
controlled loop

The step value of the count-controlled loop 2

The character that indicates a comment %

The name of a function Mult // Read

2(c) Compiler / Interpreter 1

© UCLES 2019 Page 4 of 13


MUHAMMAD ALI KHAN
PAGE 787
9608/23 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

3 5

One mark for each of the following:

• all three boxes correctly labelled


• parameters in to GetPassword()
• value back from GetPassword()
• parameters in to UpdateFile()
• BOOLEAN value back from UpdateFile()

Question Answer Marks

4(a) One mark for each point. 3

Valid string must contain:

• at least one '.' characters


• one '@' character
• more than 5 other characters.

© UCLES 2019 Page 5 of 13


PAGE 788
9608/23 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

4(b)(i) One mark for each area as outlined: 5

Index NextChar NumDots NumAts NumOthers

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

© UCLES 2019 Page 6 of 13


MUHAMMAD ALI KHAN
PAGE 789
9608/23 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

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.

Correct answers may be:

• without the correct number of '.'


• without the correct number of '@'
• without the correct number of 'other characters'

© UCLES 2019 Page 7 of 13


PAGE 790
9608/23 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

5 FUNCTION Abbreviate(Name : STRING) RETURNS STRING 8

DECLARE NewString : STRING


DECLARE NextChar : CHAR
DECLARE Index : INTEGER
DECLARE Space : BOOLEAN
CONSTANT SPACECHAR = ' '

Space m TRUE
NewString m ""

FOR Index m 1 TO LENGTH(Name)


NextChar m MID(Name,Index,1)
IF Space = TRUE
THEN
NewString m NewString & NextChar // first char
of next word
Space m FALSE
ELSE
IF NextChar = SPACECHAR
THEN
Space m TRUE
ENDIF
ENDIF
ENDFOR

RETURN NewString

ENDFUNCTION

1 mark for each of the following (max 8):

1 Function header, ending and return parameters


2 Declare and Initialise NewString to either "" or first character of
name
3 FOR loop picking out all characters from Name:
4 extract an individual character in a loop
5 check for space character in a loop
6 concatenate the next character to NewString in a loop
7 Return NewString
8 Accommodate a string with trailing space

Question Answer Marks

6(a)(i) One mark per underlined section: 3

DECLARE Result : ARRAY [0:99, 0:1] OF STRING

© UCLES 2019 Page 8 of 13


MUHAMMAD ALI KHAN
PAGE 791
9608/23 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

6(a)(ii) 'Pseudocode' solution included here for development and clarification of 8


mark scheme.
Programming language example solutions appear in the Appendix.

FUNCTION FindBooksBy(SearchAuthor : STRING) RETURNS


INTEGER

DECLARE Title : STRING


DECLARE Author : STRING
DECLARE Isbn : STRING
DECLARE Location : STRING
DECLARE Count : INTEGER

Count m 0

OPENFILE "Library.txt" FOR READ

WHILE NOT EOF ("Library.txt")

READFILE "Library.txt", Title


READFILE "Library.txt", ThisAuthor
READFILE "Library.txt", ISBN
READFILE "Library.txt", Location

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

One mark for each of the following:

1 Function heading (and ending) including parameters


2 Declaration of variables used
3 Open file for reading (Allow Library or Library.txt)
4 WHILE loop checking for EOF():
5 Read all information 'fields', in the correct order, in a loop
6 If the author matches write Title and Location to Result array
in a loop
7 And increment array index in a loop // number found
8 Close file and RETURN Count

© UCLES 2019 Page 9 of 13


PAGE 792
9608/23 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Question Answer Marks

6(b) PROCEDURE DisplayResults(Author:STRING, Count:INTEGER) 7


DECLARE Index, GLen : INTEGER
DECLARE Gap : STRING

Gap m " " // 25 spaces

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

One mark for each of the following (max 7):

1 Procedure heading and ending including parameters


2 Declaration of local INTEGER variable for use as index
3 Test if count = 0 and if so output suitable message including Author
for no books found otherwise output the two header strings (exact
format not important)
4 A FOR loop for Count times
5 ... output two array elements from Result array in a loop
6 Final output statement
7 A reasonable attempt at calculating the number of spaces required to
align 'Location' column:
8 Alignment correct

© UCLES 2019 Page 10 of 13


MUHAMMAD ALI KHAN
PAGE 793
9608/23 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Program Code Example Solutions

Q6 (a) (ii): Visual Basic


FUNCTION FindBooksBy(ByVal SearchAuthor As String) As Integer

Dim Title As String


Dim Author As String
Dim Isbn As String
Dim Location As String
Dim Count As Integer

Count = 0

FileOpen(1, "Library.txt", OpenMode.Input)

While Not EOF(1)


Title = LineInput(1)
ThisAuthor = LineInput(1)
Isbn = LineInput(1)
Location = LineInput(1)

If SearchAuthor = ThisAuthor Then


Result(Count, 0) = Title
Result(Count, 1) = Location
Count = Count + 1
End If
End While

FileClose(1)

Return Count
END FUNCTION

© UCLES 2019 Page 11 of 13


PAGE 794
9608/23 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Q6 (a) (ii): Pascal


function FindBooksBy(SearchAuthor : string) : integer;

var
Title : string;
Author : string;
Isbn : string;
Location : string;
Count : integer;
MyFile : text;

begin
Count := 0;
assign(MyFile, 'Library.txt');
reset(MyFile);

while not EOF(MyFile) do


begin
readln(MyFile, Title);
readln(MyFile, ThisAuthor);
readln(MyFile, Isbn);
readln(MyFile, Location);

if SearchAuthor = ThisAuthor then


begin
Result[Count, 0] := Title;
Result[Count, 1] := Location;
Count := Count + 1;
end;

end;

close(MyFile);
FindBooksBy := Count;

end;

© UCLES 2019 Page 12 of 13


MUHAMMAD ALI KHAN
PAGE 795
9608/23 Cambridge International AS/A Level – Mark Scheme October/November
PUBLISHED 2019

Q6 (a) (ii): Python

def FindBooksBy(SearchAuthor):

## Title : STRING
## Author : STRING
## Isbn : STRING
## Location : STRING
## Count : INTEGER

Count = 0
MyFile = open("Library.txt", 'r')
Title = MyFile.readline()

while Title != "":


ThisAuthor = MyFile.readline()
Isbn= MyFile.readline()
Location = MyFile.readline()
if SearchAuthor == ThisAuthor.strip():
Result[Count][0] = Title
Result[Count][1] = Location
Count = Count + 1
Title = MyFile.readline()

MyFile.close()
return(Count)

© UCLES 2019 Page 13 of 13


PAGE 796

Cambridge International AS & A Level


* 0 6 3 8 5 6 1 5 3 5 *

COMPUTER SCIENCE 9608/21


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2020
2 hours

You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.

This document has 24 pages. Blank pages are indicated.

DC (CE/CB) 180782/4
© UCLES 2020 [Turn over
MUHAMMAD ALI KHAN
PAGE 797

1 (a) Complete this definition of the term algorithm.

An algorithm is a solution to a problem expressed as ..............................................................

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

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

(b) A program design includes the use of subroutines (functions and procedures).

Give three advantages of using subroutines in a program.

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

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

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

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

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

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

(c) Draw lines on the following diagram to connect each computing term with the appropriate
description.

Term Description

Checking that a program


Selection performs as expected

A method for increasing the


Black-box testing level of detail of an algorithm

To test a condition to determine


Stepwise refinement the path of program execution

A method of executing certain


Iteration lines of code more than once

[3]

© UCLES 2020 9608/21/M/J/20


PAGE 798

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:

Module name Description


A customer will pay for each car rental either by bank card or by using their
RentCar()
account with the rental company.
Called with parameter HireCost, representing the cost of the rental.
PayByCard() Returns a BOOLEAN value to indicate whether or not the card payment was
successful.
Called with parameters HireCost, AccountNumber, CurrentBalance
and AccountLimit.
• Checks whether HireCost plus the CurrentBalance would exceed
PayByAccount() the AccountLimit. If so, then the rental is not authorised.
• If the rental is authorised, then the CurrentBalance is updated.
• Returns a BOOLEAN value to indicate whether or not the rental was
authorised.

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.

To be a valid password, a string must:

• be longer than 6 characters


• contain at least one lower case letter
• contain at least one upper case letter
• contain at least one non-alphabetic character.

10 FUNCTION Check(InString : STRING) RETURNS BOOLEAN


11
12 DECLARE Index : INTEGER
13 DECLARE StrLen : INTEGER
14 DECLARE NumUpper, NumLower : INTEGER
15 DECLARE NumNonAlpha : INTEGER
16 DECLARE NextChar : CHAR
17
18 NumUpper 0
19 NumLower 0
20 NumNonAlpha 0
21
22 StrLen LENGTH(InString)
23 IF StrLen < 7
24 THEN
25 RETURN FALSE
26 ELSE
27 FOR Index 1 TO StrLen
28 NextChar MID(InString, Index, 1)
29 IF NextChar >= 'a' AND NextChar <= 'z'
30 THEN
31 NumLower NumLower + 1
32 ELSE
33 IF NextChar > 'A' AND NextChar <= 'Z'
34 THEN
35 NumUpper NumUpper + 1
36 ELSE
37 NumNonAlpha NumNonAlpha + 1
38 ENDIF
39 ENDIF
40 ENDFOR
41 ENDIF
42
43 IF (NumUpper >= 1) AND (NumLower >= 1) AND (NumNonAlpha >= 1)
44 THEN
45 RETURN TRUE
46 ELSE
47 RETURN FALSE
48 ENDIF
49
50 ENDFUNCTION

Refer to the Appendix on page 21 for a list of built-in pseudocode functions and operators.

© UCLES 2020 9608/21/M/J/20


PAGE 800

The pseudocode does not work under all circumstances.

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.

Line number ......................................................................................................................

Correct pseudocode ..........................................................................................................

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

© UCLES 2020 9608/21/M/J/20 [Turn over


MUHAMMAD ALI KHAN
PAGE 801

(iii) Rewrite lines 29 to 39 of the original pseudocode using a CASE structure.

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

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

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

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

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

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

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

© UCLES 2020 9608/21/M/J/20


PAGE 802

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:

Identifier Type Description


TopUp REAL The amount of credit to be added
PhoneNum STRING The unique customer phone number
Balance REAL The current amount of credit
Multiple REAL The amount of credit bonus
Takes the phone number as a parameter and returns the current
GetBalance() FUNCTION
balance
Takes the phone number and the new balance as parameters and
SetBalance() PROCEDURE
updates the account with the new balance

START

Set Multiple
to 1

Set Balance to
GetBalance(PhoneNum)

Is YES Set Multiple to


Balance > 10 ? 1.25

NO

Is YES Set Multiple to


Balance > 5 ? 1.1

NO

Set TopUp to
TopUp * Multiple

SetBalance(PhoneNum, Balance + TopUp)

END

© UCLES 2020 9608/21/M/J/20


MUHAMMAD ALI KHAN
PAGE 803

Write pseudocode to implement the procedure AddCredit(). The pseudocode must follow
the algorithm represented by the flowchart. Declare any local variables used.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2020 9608/21/M/J/20 [Turn over


PAGE 804

10

(b) The following pseudocode searches for a string "Chris" in a 1D array and outputs the index
positions where the string is found.

DECLARE NameList : ARRAY [1:100] OF STRING


DECLARE n : INTEGER

FOR n 1 TO 100
IF NameList[n] = "Chris"
THEN
OUTPUT "Found at: " & NUM_TO_STRING(n)
ENDIF
ENDFOR

The pseudocode needs to be modified as follows:

• 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.

© UCLES 2020 9608/21/M/J/20


MUHAMMAD ALI KHAN
PAGE 805

11

Write the pseudocode for the procedure Search(). Assume the array has been declared
globally.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

............................................................................................................................................. [8]

© UCLES 2020 9608/21/M/J/20 [Turn over


PAGE 806

12

4 (a) An inexperienced user buys a games program. A program fault occurs while the user is
playing the game.

Explain what is meant by a program fault.

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

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

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

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

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

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

............................................................................................................................................. [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.

Define these three types.

Syntax error ..............................................................................................................................

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

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

Logic error ................................................................................................................................

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

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

Run-time error ..........................................................................................................................

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

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

© UCLES 2020 9608/21/M/J/20


MUHAMMAD ALI KHAN
PAGE 807

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>

Number is a four-digit numeric string.


Name is a variable-length string.

For example:

"1024Collins Robbie"

The following pseudocode is an initial attempt at defining a procedure SortContacts()


that will perform a bubble sort on Directory. The array is to be sorted in ascending order of
Name.

Fill in the gaps to complete the pseudocode.

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]

© UCLES 2020 9608/21/M/J/20


PAGE 808

15

(b) The pseudocode contains a mechanism designed to make this an efficient bubble sort.

Describe the mechanism and explain why it may be considered to be efficient.

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

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

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

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

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

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

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

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

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

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

© UCLES 2020 9608/21/M/J/20 [Turn over


MUHAMMAD ALI KHAN
PAGE 809

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.

The three 1D arrays are summarised as follows:

Array Data type Description Example data value


HireTime STRING The time the boat was hired out "10:15"

Duration INTEGER The number of minutes of the hire 30

Cost REAL The cost of the hire 5.75

If an individual boat is not currently on hire, the corresponding element of the HireTime array will
be set to "Available".

The programmer has started to define program modules as follows:

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

© UCLES 2020 9608/21/M/J/20


PAGE 810

17

(a) Write pseudocode for the module ListAvailable().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2020 9608/21/M/J/20 [Turn over


MUHAMMAD ALI KHAN
PAGE 811

18

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

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

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

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

............................................................................................................................................. [8]

© UCLES 2020 9608/21/M/J/20


PAGE 812

19

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

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

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

Program code

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

............................................................................................................................................. [7]
© UCLES 2020 9608/21/M/J/20 [Turn over
MUHAMMAD ALI KHAN
PAGE 813

20

(c) The module description of AddTime()is repeated here for reference.

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.

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

Program code

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

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

(ii) The function AddTime() is to be tested using black-box testing.

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 1 – Boat is returned during the same hour as rental starts

Start time value ....................................... Duration value .......................................

Expected new time value .......................................

Test 2 – Boat is returned during the hour after the rental starts

Start time value ....................................... Duration value .......................................

Expected new time value .......................................


[2]

© UCLES 2020 9608/21/M/J/20


PAGE 814

21

Appendix

Built-in functions (pseudocode)

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


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

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

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 10

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


returns leftmost x characters from ThisString

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

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


returns rightmost x characters from ThisString

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

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: INT(27.5415) returns 27

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value
Note: This function will also work if x is of type INTEGER

Example: NUM_TO_STRING(87.5) returns "87.5"

Operators (pseudocode)

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

© UCLES 2020 9608/21/M/J/20


MUHAMMAD ALI KHAN
PAGE 815
9608/21 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

1(a) An algorithm is a solution to a problem expressed as: 2

a sequence of defined steps / stages / instructions / lines of code

1 mark for each underlined term (or equivalent)

1(b) • Allows the subroutine code to be called from many/multiple places 3


• Subroutine code may be (independently) tested and debugged
• If the subroutine task changes the change needs to be made only once
• Reduces unnecessary duplication / program lines
• Enables sharing of development between programmers

Or equivalent points that relate to a PROGRAM (not an algorithm)

Max 3

1(c) 3

One mark for each correct line to max 3

© UCLES 2020 Page 3 of 15


PAGE 816
9608/21 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

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

2(b)(i) Trace table shows: 2

• 'A' is not treated as an upper case character (row 7)


• NumUpper not incremented as expected
• Incorrect final value for NumUpper (should be 1)

Max 2

2(b)(ii) One mark per point: 2

• Line number: 33
• Correction: IF NextChar >= 'A' AND NextChar <= 'Z'

© UCLES 2020 Page 4 of 15


MUHAMMAD ALI KHAN
PAGE 817
9608/21 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

2(b)(iii) CASE OF NextChar 4

>= 'a' AND <= 'z' : NumLower ← NumLower + 1


> 'A' AND <= 'Z' : NumUpper ← NumUpper + 1
OTHERWISE NumNonAlpha ← NumNonAlpha + 1

ENDCASE

One mark for CASE OF NextChar ... ENDCASE


One mark for each remaining line

Accept alternative range description. E.g. 'a' to 'z'

Accept corrected version for the second range.

© UCLES 2020 Page 5 of 15


PAGE 818
9608/21 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

3(a) PROCEDURE AddCredit(TopUp : REAL, PhoneNum : STRING) 7


DECLARE Multiple : REAL
DECLARE Balance : REAL

Multiple ← 1
Balance ← GetBalance(PhoneNum)

IF Balance > 10
THEN
Multiple ← 1.125
ELSE
IF Balance > 5
THEN
Multiple ← 1.1
ENDIF
ENDIF

TopUp ← TopUp * Multiple

SetBalance(PhoneNum, Balance + TopUp)

ENDPROCEDURE

1 mark for each of the following:

1 PROCEDURE heading and ending including parameters


2 Initialise Multiple
3 Assign value to Balance using GetBalance()
4 Check for Balance > 10 and assignment: Multiple ← 1.25
5 Check for Balance > 5 and assignment: Multiple ← 1.1
6 Assignment: TopUp ← TopUp * Multiple
7 Calling SetBalance()with correct parameters

Note:
MP6 could be included in MP7 statement

© UCLES 2020 Page 6 of 15


MUHAMMAD ALI KHAN
PAGE 819
9608/21 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

3(b) PROCEDURE Search(SearchString : STRING) 8


DECLARE Index, Msg : STRING

Msg ← "Found at:" //initial value

FOR Index ← 1 TO 100


IF NameList[Index, 1] = SearchString__
AND NameList[Index, 2] = "Active"
THEN
Msg ← Msg & " " & NUM_TO_STRING(Index)
ENDIF
ENDFOR

IF Msg = "Found at:" // no change to initial value


THEN
OUTPUT "Search String not found"
ELSE
OUTPUT Msg
ENDIF
ENDPROCEDURE

1 mark for each of the following:

1 PROCEDURE heading and ending including parameter


2 Declare local variables for Index and Msg and initialise Msg to
appropriate string
3 Loop structure
4 Compare SearchString to name (column 1)...
5 ... AND Compare status to "Active" (column 2) in a loop
6 Add Index to Msg when a match is encountered (using type conversion)
7 Condition to determine which string is output after loop
8 Correct output of single message

Note:
Credit alternative solutions for forming and checking a single output string

Question Answer Marks

4(a) A program fault is something that makes the program not do what it is 2
supposed to do under certain circumstances

One mark per underlined phrase or equivalent

© UCLES 2020 Page 7 of 15


PAGE 820
9608/21 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

4(b) Answers include the use of: 3

• Tried and tested (library) subroutines / code


• Modular programming techniques (to break the problem down and make
it easier to solve)
• Good programming practice (formatting, sensible variable names,
comments etc)
• IDE features (parameter type-checking, auto-complete)

Max 3

4(c) Syntax error: 3


A construct / statement in the source code that breaks the rules of the
language

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

© UCLES 2020 Page 8 of 15


MUHAMMAD ALI KHAN
PAGE 821
9608/21 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

5(a)(i) PROCEDURE SortContacts() 8


DECLARE Temp : STRING
DECLARE FirstName, SecondName : STRING
DECLARE NoSwaps : BOOLEAN
DECLARE Boundary, J : INTEGER
Boundary ← 999
REPEAT
NoSwaps ← TRUE
FOR J ← 1 TO Boundary
FirstName ← RIGHT(Directory[J],__
LENGTH(Directory[J]) – 4)
SecondName ← RIGHT(Directory[J + 1],__
LENGTH(Directory[J + 1]) – 4)
IF FirstName > SecondName
THEN
Temp ← Directory[J]
Directory[J] ← Directory[J + 1]
Directory[J + 1] ← Temp
NoSwaps ← FALSE
ENDIF
ENDFOR
Boundary ← Boundary - 1
UNTIL NoSwaps = TRUE
ENDPROCEDURE

One mark per highlighted phrase

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)

Max 3 for description

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

© UCLES 2020 Page 9 of 15


PAGE 822
9608/21 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

6(a) PROCEDURE ListAvailable(StartTime : STRING) 8


DECLARE NumAvailable, Index : INTEGER
DECLARE TimeBack : STRING
DECLARE Available : BOOLEAN

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

1 mark for each of the following:

1 Procedure heading and ending including input parameter


2 Declare local variable for the count of available boats and initialise to 0
3 Loop through all 10 boats
4 Use of AddTime() to calculate TimeBack
5 Check for boats that are not on hire OR those due back in time in a loop
6 Increment count for number of available boats in a loop
7 Output a message for each available boat in a loop
8 Output both messages as appropriate outside a loop

© UCLES 2020 Page 10 of 15


MUHAMMAD ALI KHAN
PAGE 823
9608/21 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

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

PROCEDURE RecordHire(HBoatNumber, HDuration : INTEGER,__


HTime : STRING, HCost : REAL)

DECLARE FileLine : STRING


CONSTANT Comma = ','

HireTime[HBoatNumber] ← HTime
Duration[HBoatNumber] ← HDuration
Cost[HBoatNumber] ← HCost

DailyTakings ← DailyTakings + HCost

OPENFILE "HireLog.txt" FOR APPEND

FileLine ← NUM_TO_STRING(HBoatNumber) & Comma


FileLine ← FileLine & HTime & Comma
FileLine ← FileLine & NUM_TO_STRING(HDuration)
FileLine ← FileLine & Comma & NUM_TO_STRING(HCost)

WRITEFILE "HireLog.txt", FileLine

CLOSEFILE "HireLog.txt"

ENDFUNCTION

One mark for each of the following:

1 Procedure heading and ending (where appropriate), including input


parameters (order not essential)
2 Updating the three arrays from parameter values
3 Totalling DailyTakings
4 OPEN "HireLog.txt" in append mode
5 Creating file text line including separators
6 ....making use of type conversion as required
7 Writing the line to the file
8 Closing the file

Solutions may combine mark points 5 and 6 (and 7)

Max 7

© UCLES 2020 Page 11 of 15


PAGE 824
9608/21 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

6(c)(i) 'Pseudocode' solution included here for development and clarification of mark 2
scheme.
Programming language example solutions appear in the Appendix.

EndTime ← Addtime (BeginTime, 60)

One mark per underlined section (Space before bracket for mark scheme
clarification only)

6(c)(ii) One mark for each test: 2

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"

String values (time) must be enclosed in quotation marks, integer values


(duration) must not. Penalise once then FT.

© UCLES 2020 Page 12 of 15


MUHAMMAD ALI KHAN
PAGE 825
9608/21 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Program Code Example Solutions


To be reviewed at STM

Q6(b)(i): Visual Basic

Sub RecordHire(HBoatNumber, HDuration As Integer, HTime As String, HCost As


Real)

Dim FileLine As String


Const Comma = ','

HireTime(HBoatNumber) = HTime
Duration(HBoatNumber) = HDuration
Cost(HBoatNumber) = HCost

DailyTakings = DailyTakings + HCost

FileOpen(1, "HireLog.txt", OpenMode.Append)

FileLine = CStr(HBoatNumber) & Comma


FileLine = FileLine & HTime & Comma
FileLine = FileLine & CStr(HDuration) & Comma
FileLine = FileLine & CStr(HCost)

Print(1, FileLine)
PrintLine(1)

Fileclose(1)

End Sub

© UCLES 2020 Page 13 of 15


PAGE 826
9608/21 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Q6(b)(i): Pascal

procedure RecordHire(HBoatNumber, HDuration : integer; HTime : string;


HCost : Real);

var
Fileline : string;
ThisFile: TextFile;

const Comma = ',';

begin

HireTime[HBoatNumber] := HTime;
Duration[HBoatNumber] := HDuration;
Cost[HBoatNumber] := HCost;

DailyTakings := DailyTakings + HCost;

AssignFile(Thisfile, "HireLog.txt");

FileLine := IntToStr(HBoatNumber) + Comma;


FileLine := FileLine + HTime + Comma;
FileLine := FileLine + IntToStr (HDuration) + Comma;
FileLine := FileLine + IntToStr (HCost);

writeln(ThisFile, FileLine);

CloseFile(ThisFile);

end;

Q6(b)(i): Python

def RecordHire(HBoatNumber, HDuration, HTime, HCost)

# FileLine : String
# File : File handle

Comma = ','

HireTime[HBoatNumber] = HTime
Duration[HBoatNumber] = HDuration
Cost[HBoatNumber] = HCost

DailyTakings = DailyTakings + HCost

File = Open("HireLog.txt", "a")

FileLine = Str(HBoatNumber) + Comma


FileLine = FileLine + HTime + Comma
FileLine = FileLine + Str(HDuration) + Comma
FileLine = FileLine + Str(HCost)

File.write(FileLine)

File.close

© UCLES 2020 Page 14 of 15


MUHAMMAD ALI KHAN
PAGE 827
9608/21 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Q6(c)(i): Visual Basic

EndTime = Addtime(BeginTime, 60)

Q6(c)(i): Pascal

EndTime := Addtime(BeginTime, 60)

Q6(c)(i): Python

EndTime = Addtime(BeginTime, 60)

© UCLES 2020 Page 15 of 15


PAGE 828

Cambridge International AS & A Level


* 4 8 6 0 2 0 4 7 9 7 *

COMPUTER SCIENCE 9608/22


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2020
2 hours

You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.

This document has 20 pages. Blank pages are indicated.

DC (RW/TP) 180777/4
© UCLES 2020 [Turn over
MUHAMMAD ALI KHAN
PAGE 829

1 (a) Selection and repetition are basic constructs of an algorithm.

Name and describe one other construct.

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

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

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

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

(b) Program coding is a transferable skill.

Explain the term transferable skill.

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

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

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

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

(c) Count-controlled and post-condition are two types of loop.

Describe the characteristics of each of these types of loop.

Count-controlled .......................................................................................................................

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

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

Post-condition ...........................................................................................................................

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

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

(d) Name three features provided by an Integrated Development Environment (IDE) that assist
in the coding and initial error detection stages of the program development cycle.

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

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

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

© UCLES 2020 9608/22/M/J/20 [Turn over


PAGE 830

2 (a) A structure chart is often produced as part of a modular program design. The chart shows the
hierarchy of modules and the sequence of execution.

Give two other features the structure chart can show.

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

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

Feature 2 ..................................................................................................................................

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

(b) Six program modules implement part of an online shopping program. The following table
gives the modules and a brief description of each module:

Module Description
Allows the user to choose a delivery slot, select items to be added to
Shop()
the basket and finally check out

ChooseSlot() Allows the user to select a delivery time. Returns a delivery slot number

FillBasket() Allows the user to select items and add them to the basket

Completes the order by allowing the user to pay for the items. Returns
Checkout()
a Boolean value to indicate whether or not payment was successful

Search() Allows the user to search for a specific item. Returns an item reference

Adds an item to the basket. Takes an item reference and a quantity as


Add()
parameters

(i) The online shopping program has been split into sub-tasks as part of the design process.

Explain the advantages of decomposing the program into modules. Your explanation
should refer to the scenario and modules described in part (b).

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

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

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

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

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

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

© UCLES 2020 9608/22/M/J/20


MUHAMMAD ALI KHAN
PAGE 831

(ii) Complete the structure chart for the six modules described in part (b).

Shop()

[6]

© UCLES 2020 9608/22/M/J/20 [Turn over


PAGE 832

3 A navigation program includes a function, CheckCourse(). This function is called with a real
value, Course, and returns an integer value.

The identifier table and the program flowchart for the function are shown as follows:

Identifier Type Description


Course REAL The value passed to CheckCourse()
Adjust INTEGER The value returned by CheckCourse()
Check INTEGER A local variable
A function that is passed a REAL value representing the
Deviate() FUNCTION course and returns a REAL value representing the current
deviation
Alert() PROCEDURE A procedure that generates a warning

START

Set Check to integer


value of
Deviate(Course)

Set Adjust to 255

CASE OF
Check
–20 to –1
OTHERWISE Set Adjust to 10

0
Set Adjust to 0

Alert()

1 to 20
Set Adjust to –10

RETURN Adjust

END

© UCLES 2020 9608/22/M/J/20


MUHAMMAD ALI KHAN
PAGE 833

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.

DECLARE Random : ARRAY [1:10] OF INTEGER


DECLARE Count, RNum : INTEGER

FOR Count 1 TO 10
Rnum INT(RAND(100)) + 1
Random[Count] RNum
ENDFOR

Refer to the Appendix on page 19 for a list of built-in pseudocode functions and operators.

Rewrite the pseudocode so that there are no duplicated numbers in the list of random
numbers.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

............................................................................................................................................. [6]
© UCLES 2020 9608/22/M/J/20
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]

© UCLES 2020 9608/22/M/J/20 [Turn over


PAGE 836

10

5 A global 1D array, Contact, of type STRING is used to store a list of names and email addresses.

There are 1000 elements in the array. Each element stores one data item. The format of each
data item is as follows:

<Name>':'<EmailAddress>

Name and EmailAddress are both variable-length strings.

For example:

"Sharma Himal:[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]

© UCLES 2020 9608/22/M/J/20


MUHAMMAD ALI KHAN
PAGE 837

11

(b) (i) The array is to be sorted using an efficient bubble sort algorithm. An efficient bubble sort
reduces the number of unnecessary comparisons between elements.

Describe how this could be achieved.

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

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

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

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

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

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

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

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

© UCLES 2020 9608/22/M/J/20 [Turn over


PAGE 838

12

(ii) A procedure, BubbleSort(), is needed to sort the 1D array Contact into ascending
order of Name using an efficient bubble sort algorithm.

Write program code for the procedure BubbleSort().

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

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

Program code ....................................................................................................................

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

..................................................................................................................................... [8]

© UCLES 2020 9608/22/M/J/20


MUHAMMAD ALI KHAN
PAGE 839

13

Question 6 begins on the next page.

© UCLES 2020 9608/22/M/J/20 [Turn over


PAGE 840

14

6 A company hires out rowing boats on a lake. The company has 17 boats numbered from 1 to 17.

Boats may be hired between 9:00 and 18:00, with a maximum hire duration of 90 minutes.

The company is developing a program to help manage and record the boat hire process.

The programmer has decided to store all values relating to hire time as strings. The program will
use a 24-hour clock format. For example:

Time (in words) String value


Nine o’clock in the morning "09:00"
Five minutes past ten o’clock in the morning "10:05"
Ten minutes before three o’clock in the afternoon "14:50"

The programmer has defined the first module as follows:

Module Description
• Takes two parameters:
StartTime: a STRING value representing a time as described
AddTime() Duration: an INTEGER value representing a duration in minutes
• Adds the duration to the time to give a new time
• Returns the new time as a STRING

(a) (i) Write pseudocode for the module AddTime(). Assume both input parameters are valid.

Refer to the Appendix on page 19 for a built-in list of pseudocode functions and
operators.

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2020 9608/22/M/J/20


MUHAMMAD ALI KHAN
PAGE 841

15

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

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

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

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

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

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

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

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

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

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

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

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

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

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

..................................................................................................................................... [8]

(ii) AddTime() will be tested using white-box testing.

State the reason for using white-box testing.

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

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

(iii) A run-time error is one type of error that black-box testing can reveal.

Describe one other type of error that black-box testing can reveal.

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

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

© UCLES 2020 9608/22/M/J/20 [Turn over


PAGE 842

16

(b) The user will input the desired start time of a hire. A new module will be written to validate the
input string as a valid time in 24-hour clock format.

The string is already confirmed as being in the format "NN:NN", where N is a numeric
character.

Give an example of suitable test data that is in this format but which is invalid. Explain your
answer.

Test data ...................................................................................................................................

Explanation ...............................................................................................................................

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

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

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

(c) Each time a boat is hired out, details of the hire are added to a text file, Hirelog.txt. Each
line of the text file corresponds to information about one hire session.

The format of each line is as follows:

<BoatNumber><Date><AmountPaid>

• BoatNumber is a two-digit numeric string


• Date is a six-digit numeric string in the format DDMMYY
• AmountPaid is a variable-length string representing a numeric value, for example
"12.75"

The total hire amount from each boat is to be stored in a global array, Total. This array is
declared in pseudocode as follows:

DECLARE Total : ARRAY [1:17] OF REAL

The programmer has defined module GetTotals() as follows:

Module Description
• Search through the file Hirelog.txt
GetTotals() • Extract the AmountPaid each time a boat is hired
• Store the total of AmountPaid for each boat in the array

© UCLES 2020 9608/22/M/J/20


MUHAMMAD ALI KHAN
PAGE 843

17

Write program code for the module GetTotals().

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

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

Program code

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

............................................................................................................................................. [8]

© UCLES 2020 9608/22/M/J/20


PAGE 844

19

Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.
LENGTH(ThisString : STRING) RETURNS INTEGER
returns the integer value representing the length of ThisString
Example: LENGTH("Happy Days") returns 10

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


returns leftmost x characters from ThisString
Example: LEFT("ABCDEFGH", 3) returns "ABC"

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


returns rightmost x characters from ThisString
Example: RIGHT("ABCDEFGH", 3) returns "FGH"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x
Example: INT(27.5415) returns 27

RAND(x : INTEGER) RETURNS REAL


returns a real number in the range 0 to x (not inclusive of x)
Example: RAND(87) could return 35.43

MOD(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the remainder when ThisNum is divided by ThisDiv
Example: MOD(10,3) returns 1

DIV(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the whole number part of the result when ThisNum is divided
by ThisDiv
Example: DIV(10,3) returns 3

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.
Example: If x has the value 87.5 then NUM_TO_STRING(x) returns "87.5"
Note: This function will also work if x is of type INTEGER

STRING_TO_NUM(x : STRING) RETURNS REAL


returns a numeric representation of a string.
Example: If x has the value "23.45" then STRING_TO_NUM(x) returns 23.45
Note: This function will also work if x is of type CHAR

Operators (pseudocode)
Operator Description

& Concatenates (joins) two strings


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

AND Performs a logical AND on two Boolean values


Example: TRUE AND FALSE produces FALSE

OR Performs a logical OR on two Boolean values


Example: TRUE OR FALSE produces TRUE

© UCLES 2020 9608/22/M/J/20


MUHAMMAD ALI KHAN
PAGE 845
9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

1(a) One mark for name 3


Max two marks for description: one for each underlined word or phrase (or
equivalent)

Name: Sequence
Description: Instructions / lines of code are executed in a fixed order

OR

Name: Assignment
Description: A value is given to a variable

1(b) One mark per bullet point: 2

• Knowledge / experience of one programming language...

• ... can be applied to an unknown language // will help recognise control


structures (accept by example) in an unknown language

1(c) One mark per bullet point: 2

• Count controlled – the number of iterations is known / fixed

• Post condition – the number of iterations depends on some condition


being tested at the end / before the loop is repeated // at least one
iteration is always executed

For conditional: reject answer that also applies to pre-conditional

1(d) Examples include: 3

• context sensitive prompts


• (dynamic) syntax checking
• use of colours to highlight key words / pretty printing / highlighting unused
variables (etc)
• Formatting (incl. collapsing and expanding blocks)
• (UML) modelling
• Text editor (or by reference to a function such as copy & paste)
• Built-in (library) functions

Do not accept answers relating to debugging features

Max 3

© UCLES 2020 Page 3 of 15


PAGE 846
9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

2(a) One mark per bullet point: 2

• Parameters passed between modules // the interface between modules


• Module Iteration
• Module selection

Max 2

2(b)(i) Advantages include: 3

• Easier to solve / implement / program the solution as online shopping is


a complex task

• Easier to debug / maintain as each module can be tested separately e.g.


test FillBasket() first then test Checkout()

• Tasks may be shared among a team of programmer. e.g. Checkout()


and Search() modules could be developed in parallel / by teams with
different expertise

Note:
Must include reference to given scenario to achieve all 3 marks - Max 2 if no
reference.

© UCLES 2020 Page 4 of 15


MUHAMMAD ALI KHAN
PAGE 847
9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

2(b)(ii) 6

One Mark for


1 Three middle row boxes correctly labelled and connected to Shop()
2 Two bottom row boxes correctly labelled and connected to
FillBasket()
3 Iteration arrow on FillBasket()
4 Return parameters from ChooseSlot() and Checkout()
5 Return parameters from Search()
6 Two input parameters to Add()

Notes:
Parameter types must be as shown but ignore parameter names (if given)

© UCLES 2020 Page 5 of 15


PAGE 848
9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

3 FUNCTION CheckCourse(Course : REAL) RETURNS INTEGER 7


DECLARE Adjust, Check : INTEGER

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

1 mark for each of the following:

1 FUNCTION heading and ending including parameter as given above


2 Assign value to Check using integer conversion and intialise Adjust to
255
3 CASE ... ENDCASE
4 Conditions í20 to í1 and 1 to 20 (and corresponding assignments)
5 Condition 0 (and corresponding assignment)
6 OTHERWISE
7 Return Adjust

© UCLES 2020 Page 6 of 15


MUHAMMAD ALI KHAN
PAGE 849
9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

4(a) DECLARE Random : ARRAY [1:10] OF INTEGER 6


DECLARE NextNum, Index, Rnum : INTEGER
DECLARE Exists : BOOLEAN

NextNum ← 1 // index position for the next random number

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

1 mark for each of the following:

1 Conditional (outer) loop to generate 10 values


2 Inner loop to search array for duplicate number
3 Check for duplicate by comparing number generated with array element
in a loop
4 Avoid checking uninitialised elements // array initialisation to rogue value
at start of algorithm
5 If Rnum is a duplicate then repeat outer loop
6 If Rnum not a duplicate then assign to array element and Increment
index

Notes:
Max 5 if statement to generate random number (as given in Q) not present or
incorrectly placed.

4(b) Adaptive Maintenance 1

© UCLES 2020 Page 7 of 15


PAGE 850
9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

5(a) Mark as follows: 7


1 SET Name to ""
2 SET Index to 1
3 SELECT the character from input parameter string at Index position
4 IF character is not colon then concatenate character with Name
5 …INCREMENT Index
6 …REPEAT from step 3
7 RETURN Name

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:

RETURN LEFT(ParamString, Index – 1)

5(b)(i) Description: 4

• Reduce the number of items to be checked by one after each pass

• Use a flag variable to stop the outer loop


• ... after no more swaps made on a single pass of the inner loop
• ... resetting before the inner loop starts, and setting it whenever a swap is
made

© UCLES 2020 Page 8 of 15


MUHAMMAD ALI KHAN
PAGE 851
9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

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:

1 Procedure heading and ending


2 Outer loop
3 Inner loop
4 Correct comparison in a loop
5 Correct swap of array elements in a loop
6 'NoSwap' mechanism: Post-conditional outer loop including flag reset
7 'NoSwap' mechanism: Set flag in inner loop to indicate swap
8 Reducing Boundary in the outer loop

© UCLES 2020 Page 9 of 15


PAGE 852
9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

6(a)(i) FUNCTION AddTime(StartTime : STRING, Duration : INTEGER)_ 8


RETURNS STRING

DECLARE NewTime : STRING


DECLARE StartMinutes, StartHours : INTEGER
DECLARE Total, NewMinutes, NewHours : INTEGER

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

NewTime ← NewTime & NUM_TO_STRING(NewHours) & ':'

IF NewMinutes < 10
THEN
NewTime ← NewTime & '0'// add leading zero
ENDIF

NewTime ← NewTime & NUM_TO_STRING(NewMinutes)

RETURN NewTime

ENDFUNCTION

1 mark for each of the following:

1 Function heading and ending including parameters


2 Extract StartHours and convert to integer
3 Extract StartMinutes and convert to integer
4 Add Duration to StartTime in minutes
5 Use DIV() to extract NewHours
6 Use MOD() to extract NewMinutes
7 Adding leading zeros when necessary to hours and minutes eg “09:05”
8 Return concatentated string

Note:
Accept alternative methods for calculation of NewHours and NewMinutes

6(a)(ii) To test every path through the algorithm 1

6(a)(iii) • Logical error 2


• Algorithm is incorrect // program produces unexpected result / incorrect
calculation is performed

© UCLES 2020 Page 10 of 15


MUHAMMAD ALI KHAN
PAGE 853
9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

6(b) Test data: 2


Any string value where hours are > “24” or minutes > “59”

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()

DECLARE BoatNum : INTEGER


DECLARE Paid : REAL
DECLARE FileLine : STRING

FOR BoatNum ← 1 TO 17
Total[BoatNum] ← 0
ENDFOR

OPENFILE "Hirelog.txt" FOR READ

WHILE NOT EOF("Hirelog.txt")


READFILE "Hirelog.txt", FileLine
BoatNum ← STRING_TO_NUM(LEFT(FileLine, 2))
Paid ← STRING_TO_NUM (RIGHT(FileLine,__
LENGTH(Fileline) – 8))
Total[BoatNum] ← Total[BoatNum] + Paid

ENDWHILE

CLOSEFILE "Hirelog.txt"

ENDPROCEDURE

One mark for each of the following:

1 Procedure heading and ending (where appropriate) with no parameters


2 Initialisation of elements in Total array
3 OPEN "Hirelog.txt" in read mode and CLOSE after use
4 Loop until EOF()
5 Read line from file in a loop
6 Extract and convert BoatNum
7 Extract and convert Paid
8 Update appropriate array total in a loop

© UCLES 2020 Page 11 of 15


PAGE 854
9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Program Code Example Solutions


To be reviewed at STM

Q5(b)(i): Visual Basic

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

© UCLES 2020 Page 12 of 15


MUHAMMAD ALI KHAN
PAGE 855
9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Q5(b)(i): Python

def BubbleSort()
# Temp : String
# NoSwaps : Boolean
# Boundary, J : Integer

Boundary = 999
NoSwaps = TRUE

while NoSwaps == TRUE:


NoSwaps = TRUE
For J in range(Boundary + 1)
If Contact[J] > Contact[J+1]:
Temp = Contact[J]
Contact[J] = Contact[J+1]
Contact[J+1] = Temp
NoSwaps = FALSE

Boundary = Boundary - 1

End Sub

Q6(c): Visual Basic

Sub GetTotals()

Dim BoatNum As Integer


Dim Paid As Real
Dim File As StreamReader("Hirelog.txt")

For BoatNum = 1 To 17
Total(BoatNum) = 0
Next

Do While File.Peek >= 0


FileLine = File.ReadLine()
BoatNum = CInt(Left(FileLine, 2))
Paid = CSng(Right(FileLine, Len(Fileline) – 8))
Total(boatnumber) = Total(boatbnumber) + Paid
Loop

File.Close()

End Sub

© UCLES 2020 Page 13 of 15


PAGE 856
9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

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);

while not eof(MyFile) do


begin
readln(MyFile, FileLine);
BoatNum = StrToInt(copy(FileLine, 1, 2));
Paid = StrToFloat(copy(FileLine, 9, length(Fileline) – 8));
Total(boatnumber) = Total(boatbnumber) + Paid;
end;

close(MyFile)

end;

Alternative FreePascal string functions) :

BoatNum := LeftStr(FileLine, 2);

Paid := StrToFloat(RightStr(FileLine, length(Fileline) – 8));

© UCLES 2020 Page 14 of 15


MUHAMMAD ALI KHAN
PAGE 857
9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Q6(c): Python

def GetTotals()

# BoatNum : Integer
# Paid : Real
# File : File Handle
# FileData : String

For BoatNum in range (1, 18)


Total[BoatNum] = 0
Next

File = open("Hirelog.txt", "r")


FileData = File.readline()
while FileData != "":
FileLine = File.ReadLine()
BoatNum = int(FileLine[1, 3])
Paid = float(FileLine[8, len(Fileline) – 7))
Total[boatnumber] = Total[boatbnumber] + Paid
FileData = File.readline()

File.Close()

© UCLES 2020 Page 15 of 15


PAGE 858

Cambridge International AS & A Level


* 1 7 5 3 4 1 4 9 7 5 *

COMPUTER SCIENCE 9608/23


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2020
2 hours

You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.

This document has 20 pages. Blank pages are indicated.

DC (RW/TP) 180778/4
© UCLES 2020 [Turn over
MUHAMMAD ALI KHAN
PAGE 859

1 (a) Algorithms are produced during program development.

State when you would produce an algorithm during program development and state its
purpose.

When ........................................................................................................................................

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

Purpose ....................................................................................................................................

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

(b) Selection is one of the basic constructs used in algorithms.

Explain the term selection.

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

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

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

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

(c) Explain the process of problem decomposition. State one reason it may be used.

Explanation ...............................................................................................................................

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

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

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

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

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

(d) Name two features provided by a typical Integrated Development Environment (IDE) that
assist in the debugging stage of the program development cycle.

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

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

© UCLES 2020 9608/23/M/J/20 [Turn over


PAGE 860

2 (a) A structure chart is often produced as part of a modular program design. The chart shows the
relationship between modules and the parameters that are passed between them.

Give two other features the structure chart can show.

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

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

Feature 2 ..................................................................................................................................

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

(b) The following structure chart shows the relationship between three modules.

ModuleA()

ParW
ParX

ParZ

ModuleB() ModuleC()

Parameter data types are:

ParW : REAL
ParX : INTEGER
ParZ : STRING

(i) Write the pseudocode header for module ModuleB().

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

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

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

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

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

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

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

© UCLES 2020 9608/23/M/J/20


MUHAMMAD ALI KHAN
PAGE 861

(c) A student is developing an algorithm to count the number of times a given string,
SearchString, appears in a 2D array. The array, Item, consists of 100 elements organised
as 50 rows of 2 columns. SearchString could appear in any row or column.

The array is declared in pseudocode as follows:

DECLARE Item : ARRAY [1:50, 1:2] OF STRING

The structured English description of the algorithm is:

1. SET Count to 0.
2. Examine the first row of the array.
3. IF column 1 element value is equal to SearchString, ADD 1 to Count.
4. IF column 2 element value is equal to SearchString, ADD 1 to Count.
5. REPEAT from step 3 for next row, UNTIL row is last row.
6. OUTPUT a suitable message and Count.

Write pseudocode for the algorithm.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2020 9608/23/M/J/20 [Turn over


PAGE 862

3 (a) Study the following pseudocode.

Error Delta(Plan, Actual)


CASE OF Error
> 10 : Steer 6WHHUí
0 : ZCount ZCount + 1
< -10 : Steer Steer + 10
OTHERWISE OUTPUT "Unexpected Error"
ENDCASE

Draw a program flowchart to represent the pseudocode. Variable declarations are not
required in program flowcharts.

[5]
© UCLES 2020 9608/23/M/J/20 [Turn over
MUHAMMAD ALI KHAN
PAGE 863

(b) The following pseudocode algorithm has been developed to check whether a string contains
a valid password.

To be a valid password, a string must:

• be longer than five characters


• contain at least one numeric digit
• contain at least one upper case letter
• contain at least one other character (not a numeric digit or an upper case letter).

10 FUNCTION Check(InString : STRING) RETURNS BOOLEAN


11
12 DECLARE Index : INTEGER
13 DECLARE StrLen : INTEGER
14 DECLARE NumUpper, NumDigit : INTEGER
15 DECLARE NextChar : CHAR
16 DECLARE NumOther : INTEGER
17
18 NumUpper 0
19 NumDigit 0
20
21 StrLen LENGTH(InString)
22 IF StrLen < 6
23 THEN
24 RETURN FALSE
25 ELSE
26 FOR Index 1 TO StrLen - 1
27 // loop for each character
28 NextChar MID(InString, Index, 1)
29 IF NextChar >= '0' AND NextChar <= '9'
30 THEN
31 NumDigit NumDigit + 1 // count digits
32 ELSE
33 IF NextChar >= 'A' AND NextChar <= 'Z'
34 THEN
35 NumUpper NumUpper + 1 // count upper case
36 ENDIF
37 ENDIF
38 ENDFOR
39 ENDIF
40
41 NumOther StrLen – (NumDigit – NumUpper)
42 IF NumDigit >= 1 AND NumUpper >= 1 AND NumOther >= 1
43 THEN
44 RETURN TRUE
45 ELSE
46 RETURN FALSE
47 ENDIF
48
49 ENDFUNCTION

© UCLES 2020 9608/23/M/J/20


PAGE 864

The pseudocode does not work under all circumstances.

The function was dry run with the string "1234AP" and the following trace table was
produced. The string is an invalid password, but the pseudocode returned the value
TRUE.

Trace
StrLen Index NextChar NumUpper NumDigit NumOther
table row
1 6 0 0
2 1 '1'
3 1
4 2 '2'
5 2
6 3 '3'
7 3
8 4 '4'
9 4
10 5 'A'
11 1
12 3

(i) The pseudocode algorithm contains two errors.

State how the given trace table indicates the existence of each error.

Error 1 ...............................................................................................................................

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

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

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

Error 2 ...............................................................................................................................

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

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

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

© UCLES 2020 9608/23/M/J/20 [Turn over


MUHAMMAD ALI KHAN
PAGE 865

10

(ii) Give the line number of each error in the pseudocode algorithm and write the modified
pseudocode to correct each error.

Line number for error 1 .....................................................................................................

Correct pseudocode ..........................................................................................................

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

Line number for error 2 .....................................................................................................

Correct pseudocode ..........................................................................................................

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

(c) The term adaptive maintenance refers to amendments that are made in response to
changes to the program specification. These changes usually affect the program algorithm.

Name one other part of the design that can change as a result of adaptive maintenance.

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

4 A global 1D array, Contact, of type STRING is used to store a list of names and email addresses.
There are 1000 elements in the array. Each element stores one data item. The format of each
data item is as follows:

<Name>':'<EmailAddress>

Name and EmailAddress are both variable-length strings.

For example:

"Wan Zhu:[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.

© UCLES 2020 9608/23/M/J/20


PAGE 866

11

(a) Write program code for the function Extract().

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

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

Program code

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2020 9608/23/M/J/20 [Turn over


MUHAMMAD ALI KHAN
PAGE 867

12

(b) The original function, Extract(), needs to be modified to separate the name from the email
address. The calling program can then use both of these values.

Write, in pseudocode, the header for the modified subroutine. Explain the changes you have
made.

Subroutine header ....................................................................................................................

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

Explanation ...............................................................................................................................

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

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

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

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

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

5 A company hires out rowing boats on a lake. The company has 20 boats, numbered from 1 to 20.

For safety reasons, the boats have to be serviced (checked and any damage repaired) regularly.

The company is developing a program to help manage the servicing of the boats.

Every time a boat is serviced, details are added at the end of the text file, ServiceLog.txt, as a
single line of information. Each boat is serviced before it is hired out for the first time.

The format of each line is as follows:

<BoatNumber><Date>

BoatNumber and Date are as follows:

• BoatNumber is a two-digit numeric string in the range "01" to "20"


• Date is an 8-digit numeric string in the format YYYYMMDD

The programmer has defined the first module as follows:

Module Description
• Called with a string parameter representing the BoatNumber
GetLastService() • Searches through the file ServiceLog.txt
• Returns the date of the last service in the form "YYYYMMDD"

© UCLES 2020 9608/23/M/J/20


PAGE 868

13

(a) Write pseudocode for the module GetLastService().

Refer to the Appendix on page 19 for a list of built-in pseudocode functions and operators.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

............................................................................................................................................. [8]

© UCLES 2020 9608/23/M/J/20 [Turn over


MUHAMMAD ALI KHAN
PAGE 869

14

(b) (i) Every time a boat is hired out, details of the hire are added at the end of a text file,
Hirelog.txt. Each line of the text file corresponds to information about the hire of one
boat.

The format of each line of information is as follows:

<Date><BoatNumber><HireDuration>

• Date is an 8-digit numeric string in the format YYYYMMDD


• BoatNumber is a two-digit numeric string in the range "01" to "20"
• HireDuration is a variable-length string representing a numeric value in hours.
For example, the string "1.5" would represent a hire duration of 1½ hours.

A module GetHours() is defined as follows:

Module Description
• Takes two parameters:
the BoatNumber as a string
the date of the last service for that boat ("YYYYMMDD")
as a string
GetHours()
• Searches through file Hirelog.txt and calculates the sum of
the hire durations for the given boat after the given date (hire
durations on or before the given date are ignored)

• Returns the total of the hire durations as a real

Note:

Standard comparison operators may be used with dates in this format.


For example:

"20200813" > "20200812" would evaluate to TRUE

Parameter validation is not required.

© UCLES 2020 9608/23/M/J/20


PAGE 870

15

Write pseudocode for the module GetHours().

Refer to the Appendix on page 19 for a list of built-in pseudocode functions and
operators.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

..................................................................................................................................... [8]

© UCLES 2020 9608/23/M/J/20 [Turn over


MUHAMMAD ALI KHAN
PAGE 871

16

(ii) An additional module, Validate(), has been written to check that a given string
corresponds to a valid BoatNumber. A valid BoatNumber is a two-digit numeric string in
the range "01" to "20".

Give three test strings that are invalid for different reasons. Explain your choice in each
case.

String 1 ..............................................................................................................................

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

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

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

String 2 ..............................................................................................................................

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

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

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

String 3 ..............................................................................................................................

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

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

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

(c) A new module is described as follows:

Module Description
• Takes an integer as a parameter that represents the maximum
number of hours before a boat must be serviced

• Uses GetLastService() and GetHours()

• Outputs:
a suitable heading
the BoatNumber of each boat hired for more than the
maximum number of hours since its last service
ServiceList() the total hire duration for each of these boats

An example output list is:


Boat Service List
4: 123
17: 117

If no boats are due to be serviced, the output is:


Boat Service List
No boats are due to be serviced

© UCLES 2020 9608/23/M/J/20


PAGE 872

17

Write program code for the module ServiceList().

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

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

Program code

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

............................................................................................................................................. [8]
© UCLES 2020 9608/23/M/J/20 [Turn over
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.

Explain this process.

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

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

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

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

(iii) Explain how single stepping may be used to help find a logic error in a program.

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

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

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

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

© UCLES 2020 9608/23/M/J/20


PAGE 874

19

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

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 10

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


returns leftmost x characters from ThisString

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

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


returns rightmost x characters from ThisString

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

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


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

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

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: INT(27.5415) returns 27

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.
Note: This function will also work if x is of type INTEGER

Example: NUM_TO_STRING(87.5) returns "87.5"

STRING_TO_NUM(x : STRING) RETURNS REAL


returns a numeric representation of a string.
Note: This function will also work if x is of type CHAR

Example: STRING_TO_NUM("23.45") returns 23.45

Operators (pseudocode)

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

© UCLES 2020 9608/23/M/J/20


MUHAMMAD ALI KHAN
PAGE 875
9608/23 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

1(a) When: when designing a solution to a problem 2

Purpose: to describe the solution as a sequence of steps / actions

One mark per answer

Accept equivalent phrase for 'purpose' but reject specific programming


references

1(b) Testing a condition 2


to determine the sequence of execution

One mark per underlined phrase (or equivalent)

1(c) Explanation: Breaking a problem down into sub tasks 2

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

Question Answer Marks

2(a) • Sequence of (module) execution 2


• Module Iteration
• Module selection

One mark per item

Max 2

2(b)(i) FUNCTION ModuleB (ParX : INTEGER) RETURNS BOOLEAN 3

One mark for each underlined part


Ignore BYVALUE for ParX

2(b)(ii) PROCEDURE ModuleC (BYREF ParW: REAL, BYVALUE ParZ : 3


STRING)

One mark for each underlined part


BYVALUE not essential for ParZ

© UCLES 2020 Page 3 of 16


PAGE 876
9608/23 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

2(c) DECLARE Index, Count : INTEGER 5


Count ← 0
FOR Index ← 1 TO 50
IF Item[Index, 1] = SearchString
THEN
Count ← Count + 1
ENDIF
IF Item[Index, 2] = SearchString
THEN
Count ← Count + 1
ENDIF

ENDFOR

OUTPUT "The number of times SearchString found: ", Count

Alternative

DECLARE I, J, Count : INTEGER


Count ← 0
FOR I ← 1 TO 50
FOR J ← 1 TO 2
IF Item[I, J] = SearchString
THEN
Count ← Count + 1
ENDIF
ENDFOR
ENDFOR
OUTPUT "The number of times SearchString found: ", Count

One mark for each of the following:

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

© UCLES 2020 Page 4 of 16


MUHAMMAD ALI KHAN
PAGE 877
9608/23 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

3(a) 5

Mark as follows:
• One mark for START and END
• One mark per area outlined

All outputs from CASE must be labelled

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

One mark per bullet

© UCLES 2020 Page 5 of 16


PAGE 878
9608/23 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

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)

One mark for each line number with correction

3(c) Data Structure 1

© UCLES 2020 Page 6 of 16


MUHAMMAD ALI KHAN
PAGE 879
9608/23 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

4(a) 'Pseudocode' solution included here for development and clarification of mark 5
scheme.
Programming language example solutions appear in the Appendix.

FUNCTION Extract(InString : STRING) RETURNS STRING


DECLARE Name : STRING
DECLARE NextChar : CHAR
DECLARE Index : INTEGER
CONSTANT COLON = ':'
Index ← 1
Name ← ""
NextChar ← LEFT(InString, 1)

WHILE NextChar <> COLON


Name ← Name & NextChar
Index ← Index + 1
NextChar ← MID(InString, Index, 1)
ENDWHILE

RETURN Name

ENDFUNCTION

Alternative:

FUNCTION Extract(InString : STRING) RETURNS STRING


DECLARE Name : STRING
DECLARE Index : INTEGER
CONSTANT COLON = ':'
Index ← 1

WHILE MID(InString, Index, 1)<> COLON


Index ← Index + 1
ENDWHILE

Name ← LEFT(InString, Index)


RETURN Name

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)

© UCLES 2020 Page 7 of 16


PAGE 880
9608/23 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

4(b) Two alternatives: 3

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

© UCLES 2020 Page 8 of 16


MUHAMMAD ALI KHAN
PAGE 881
9608/23 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

5(a) FUNCTION GetLastService(BoatNum : STRING) RETURNS STRING 8


DECLARE LastService, FileData : STRING

LastService ← ""

OPEN "ServiceLog.txt" FOR READ

WHILE NOT EOF("ServiceLog.txt")


READFILE "ServiceLog.txt", FileData
IF LEFT(FileData, 2) = BoatNum
THEN
LastService ← RIGHT(FileData, 8)
ENDIF

ENDWHILE

Close "ServiceLog.txt"

RETURN LastService

// Most recent service will be the last one read

ENDFUNCTION

1 mark for each of the following:

1 Function heading and ending including parameters


2 Declaration of variables for LastService and FileData
3 Open file in read mode and close
4 Conditional loop - while not EOF()
5 Read line from file in a loop
6 Compare BoatNum with data from file in a loop
7 If matched, assign value to LastService in a loop
8 Return LastService

© UCLES 2020 Page 9 of 16


PAGE 882
9608/23 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

5(b)(i) FUNCTION GetHours(BNum, SDate, : STRING)RETURNS REAL 8

DECLARE FileData, HString : STRING


DECLARE TotHours : REAL
DECLARE HLength : INTEGER

TotHours ← 0

OPEN "HireLog.txt" FOR READ

WHILE NOT EOF("HireLog.txt")


READFILE "HireLog.txt" FileData
IF MID(FileData, 9, 2) = BNum
THEN
IF LEFT(FileData, 8) > SDate
THEN
HLength ← LENGTH(Filedata) – 10
HString ← RIGHT(Filedata, HLength)
TotHours ← TotHours + STRING_TO_NUM(HString)
ENDIF
ENDIF

ENDWHILE

Close "HireLog.txt"

RETURN TotHours

ENDFUNCTION

1 mark for each of the following:

1 Function heading and ending including parameters


2 Declaration of TotHours as integer
3 ...and initialisation to zero
4 Extract and compare BoatNum …
5 … extract date and compare to ServData and if later then...
6 ... extract HireDuration and …
7 … convert HireDuration to REAL and sum TotHours
8 Return TotHours

© UCLES 2020 Page 10 of 16


MUHAMMAD ALI KHAN
PAGE 883
9608/23 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

5(b)(ii) Three different tests 6

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

Illegal character can only be used in one test

One mark for string plus one for corresponding explanation

© UCLES 2020 Page 11 of 16


PAGE 884
9608/23 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

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

PROCEDURE ServiceList(MaxHours : INTEGER)

DECLARE BoatNum, Hours : INTEGER


DECLARE LastService : STRING
DECLARE Due : BOOLEAN

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

One mark for each of the following:

1 Procedure heading and ending (where appropriate) including parameter


2 Output "report header" line not in a loop
3 Loop from 1 to 20
4 Call GetLastService
5 Call GetHours
6 Check return value from GetHours > MaxHours
7 Suitable Output statement in a loop
8 Mechanism to initialise, count and produce final output if no boats to be
serviced

5(d)(i) One mark per bullet point 2

• The use of tried and tested (library) subroutines


• The use of modular programming (to break the problem down and make
it easier to solve)
• The use of programming practice to make the code easier to read (e.g.
format, use of sensible variable names)

Max 2

© UCLES 2020 Page 12 of 16


MUHAMMAD ALI KHAN
PAGE 885
9608/23 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

5(d)(ii) One mark per bullet point 2

• Testing may be carried out before the modules are developed // not ready
for full testing

• Module stubs contain simple code to provide a known response //


temporary replacement for a called module / return a fixed value / output
a message to confirm the module has been called

5(d)(iii) One mark per bullet point 2

• Executes a line of code at a time


• Used to trace the path of execution (sequence)
• Track variable values using a watch window

Max 2

© UCLES 2020 Page 13 of 16


PAGE 886
9608/23 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Program Code Example Solutions

Q4(a): Visual Basic

Function Extract(InString As String) As String


Dim Name As String
Dim NextChar As Char
Dim Index As Integer
Const COLON = ':'

Index = 1
Name = ""
NextChar = Left(InString, 1)

While NextChar <> COLON


Name = Name & NextChar
Index = Index + 1
NextChar = Mid(Instring, Index, 1)
Loop

Return Name

End Function

Function Extract(InString As String) As String


Return Mid(Instring, 1, Instring.IndexOf(":"))
End Function

Q4(a): Pascal

function extract(InString : string) : string;


var
Name : string;
NextChar : char;
Index : integer;

const
COLON = ':';

Index := 1;
Name := "";
NextChar := copy(InString, 1, 1);

While NextChar <> COLON do


begin
Name := Name & NextChar;
Index := Index + 1;
NextChar := copy(Instring, Index, 1);
end;

extract := Name;

end;

© UCLES 2020 Page 14 of 16


MUHAMMAD ALI KHAN
PAGE 887
9608/23 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Q4(a): Python

def Extract(InString)
# Name : String
# NextChar : Char
# Index : Integer

COLON = ':'

Index = 1
Name = ""
NextChar = InString[1:2]

While NextChar <> COLON:


Name = Name + NextChar
Index = Index + 1
NextChar = Instring[index, Index + 1]

Return Name

Q5(c): Visual Basic

Sub ServiceList(MaxHours As Integer)

Dim BoatNum, Due As Integer


Dim LastService As String

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

© UCLES 2020 Page 15 of 16


PAGE 888
9608/23 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Q5(c): Pascal

procedure ServiceList(MaxHours : Integer)

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)

# BoatNum, Due : Integer


# LastService : String

Due = 0
print("Boat Service List")

For BoatNum in range(1, 21):


LastService = GetLastService(str(BoatNum))
Hours = GetHours(BoatNum, LastService)
if Hours > MaxHours:
print(str(Boatnum) & ": " & str(Hours))
Due = Due + 1

if Due == 0:
print"No boats are due to be serviced")

© UCLES 2020 Page 16 of 16


MUHAMMAD ALI KHAN
PAGE 889

Cambridge International AS & A Level


* 6 3 4 1 3 6 2 7 4 2 *

COMPUTER SCIENCE 9608/21


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2020
2 hours

You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.

This document has 20 pages. Blank pages are indicated.

DC (LK) 188573/3
© UCLES 2020 [Turn over
PAGE 890

1 (a) Translation is one stage of the program development cycle.

State three other stages.

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

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

3 ................................................................................................................................................
[3]

(b) Define the following types of maintenance.

Corrective maintenance ............................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Adaptive maintenance ..............................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[2]

(c) Experienced programmers have a transferable skill.

Explain how this skill might be useful for a programmer.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

(d) Jackie has written a program and has used the identifier names I1, I2, and I3.

Explain why this is not good practice.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2020 9608/21/O/N/20


MUHAMMAD ALI KHAN
PAGE 891

(e) A pseudocode algorithm assigns values to three variables as follows:

GateOpen FALSE
Alarm TRUE
PowerFail TRUE

Evaluate the expressions given in the following table:

Expression Evaluates to

Alarm OR NOT PowerFail

NOT (Alarm AND PowerFail)

(GateOpen OR Alarm) AND PowerFail

(GateOpen AND Alarm) OR NOT PowerFail


[2]

© UCLES 2020 9608/21/O/N/20 [Turn over


PAGE 892

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]

(b) Complete the pseudocode expressions in the following table.

Use only the functions and operators described in the Appendix on pages 18–19.

Expression Evaluates to

........................ ("Stepwise" , ........................) & "art" "Start"

........................ ("Concatenate" , ........................ , ........................) "ten"

2 * .......................... ("Kipper") 12

TRUE .......................... FALSE TRUE

.......................... (9, 2) 1

[5]
© UCLES 2020 9608/21/O/N/20
MUHAMMAD ALI KHAN
PAGE 893

(c) Study the following pseudocode.

Line numbers are given for reference only.

01 PROCEDURE StringClean(InString : STRING)


02
03 DECLARE NextChar : CHAR
04 DECLARE OutString : STRING
05 DECLARE Index : INTEGER
06
07 OutString ""
08
09 FOR Index 1 TO LENGTH(InString)
10
11 NextChar MID(InString, Index, 1)
12 NextChar LCASE(NextChar)
13
14 IF NextChar >= 'a' AND NextChar <= 'z'
15 THEN
16 OutString OutString & NextChar
17 ENDIF
18
19 ENDFOR
20
21 OUTPUT OutString
22
23 ENDPROCEDURE

Complete the following table by entering an appropriate answer.

Answer

The name for the type of loop used

A line number of a selection statement

The scope of OutString

The name of a function that is called

A line number containing a logical operator


[5]

© UCLES 2020 9608/21/O/N/20 [Turn over


PAGE 894

3 The procedure OutputLines() outputs a number of lines from a text file.

An example of the use of the procedure is given by the following pseudocode:

CALL OutputLines(FileName, StartLine, NumberLines)

Parameter Data type Description

FileName STRING The name of the text file

StartLine INTEGER The number of the first line to be output

NumberLines INTEGER The number of lines to be output

The procedure is tested using the file MyFile.txt that contains 100 lines of text.

The procedure gives the expected result when called as follows:

CALL OutputLines("MyFile.txt", 1, 10)

(a) The procedure is correctly called with three parameters of the appropriate data types, but the
procedure does not give the expected result.

Give three different reasons why this might happen.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................

3 ................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2020 9608/21/O/N/20


MUHAMMAD ALI KHAN
PAGE 895

(b) Write program code for the procedure OutputLines().

Note: Parameter validation is not necessary.

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language .............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]
© UCLES 2020 9608/21/O/N/20 [Turn over
PAGE 896

(c) A program is compiled without producing any errors.

(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]

© UCLES 2020 9608/21/O/N/20


MUHAMMAD ALI KHAN
PAGE 897

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.

Formatting may incorporate the use of:

• A prefix string to be added before the integer value (e.g. '$' or "Total: ")
• A comma as a thousand-separator (e.g. "1,000")

The function will be called as follows:

MyString FormOut(Number, Prefix, AddComma)

Parameter Data type Description

Number INTEGER The positive integer value to be formatted.


A string that will appear in front of the numeric value. Set to an
Prefix STRING
empty string if no prefix is required.
TRUE if a comma is required in the formatted string.
AddComma BOOLEAN
FALSE if a comma is not required in the formatted string.

(a) Fill in the tables to show two tests that could be carried out to test different aspects of the
function.

Give the expected result for each test.

TEST 1
Parameter Value
Expected return string:
Number

Prefix ...............................................................

AddComma

TEST 2
Parameter Value
Expected return string:
Number
Prefix ...............................................................
AddComma
[4]

© UCLES 2020 9608/21/O/N/20


PAGE 898

11

(b) Write pseudocode for the function FormOut().

Refer to the Appendix on pages 18–19 for the list of built-in functions and operators.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2020 9608/21/O/N/20 [Turn over


MUHAMMAD ALI KHAN
PAGE 899

12

5 A message may contain several hashtags.

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.

For example, the following message contains three hashtags:

"#Error27 is the result of #PoorPlanning by the #Designer"

The hashtags in the message are "#Error27", "#PoorPlanning" and "#Designer".

A program is being developed to process a message and extract each hashtag.

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.

A developer has started to define the modules as follows:

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

© UCLES 2020 9608/21/O/N/20


PAGE 900

13

(a) Write pseudocode for the module GetIndex().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2020 9608/21/O/N/20 [Turn over


MUHAMMAD ALI KHAN
PAGE 901

14

(b) Write pseudocode for the module GetStart().

The module description is repeated here for reference.

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

(c) Write program code for the module GetTag().

The module description is repeated here for reference.

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.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2020 9608/21/O/N/20


MUHAMMAD ALI KHAN
PAGE 903

17

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2020 9608/21/O/N/20 [Turn over


PAGE 904

18

Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of string ThisString

Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString

Example: LEFT("ABCDEFGH", 3) returns string "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString

Example: RIGHT("ABCDEFGH", 3) returns string "FGH"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: INT(27.5415) returns 27

MOD(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the remainder when ThisNum is divided by ThisDiv

Example: MOD(10,3) returns 1

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString

Example: MID("ABCDEFGH", 2, 3) returns string "BCD"

LCASE(ThisChar : CHAR) RETURNS CHAR


returns the character value representing the lower case equivalent of ThisChar
If ThisChar is not an upper-case alphabetic character, it is returned unchanged.

Example: LCASE('W') returns 'w'

DIV(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the whole number part of the result when ThisNum is divided
by ThisDiv

Example: DIV(10,3) returns 3

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.
Note: This function will also work if x is of type INTEGER

Example: NUM_TO_STRING(87.5) returns "87.5"

© UCLES 2020 9608/21/O/N/20


MUHAMMAD ALI KHAN
PAGE 905

19

Operators (pseudocode)

Operator Description

Concatenates (joins) two strings


&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"

Performs a logical AND on two Boolean values


AND
Example: TRUE AND FALSE produces FALSE

Performs a logical OR on two Boolean values


OR
Example: TRUE OR FALSE produces TRUE

© UCLES 2020 9608/21/O/N/20


9608/21 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED

Question Answer Marks

1(a) One mark per bullet point, max 3 marks 3

• Analysis / Problem Definition


• Design
• Code // Implement
• Test

1(b) One mark per bullet point 2

• Corrective: changes to correct a bug / problem / error in the program


• Adaptive: changes due to change in specification / requirements / legislation / available technology

1(c) One mark per bullet point 2

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

1(d) One mark per bullet point 2

• 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

© UCLES 2020 Page 4 of 22


MUHAMMAD ALI KHAN
9608/21 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

1(e) 1 mark for any two rows correct, 2 marks for all rows correct. 2

Expression Evaluates to

Alarm OR NOT PowerFail TRUE

NOT (Alarm AND PowerFail) FALSE

(GateOpen OR Alarm) AND PowerFail TRUE

(GateOpen AND Alarm) OR NOT PowerFail FALSE

2(a) One mark per step (or equivalent) to max 6 marks 6

1 Prompt / output string and input the new user name

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’

© UCLES 2020 Page 5 of 22


9608/21 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

2(b) One mark per row (for expression completed by addition of text shown in bold): 5

Expression Evaluates to

LEFT("Stepwise", 2) & "art" "Start"

MID("Concatenate", 6, 3) "ten"

2 * LENGTH("Kipper") 12

TRUE OR FALSE TRUE

MOD(9, 2) 1

2(c) One mark per row: 5


Answer

The name for the type of loop used Count-controlled


PAGE 908

A line number of a selection statement 14

The scope of OutString Local

The name of a function that is called LENGTH // MID // LCASE

A line number containing a logical operator 14

© UCLES 2020 Page 6 of 22


9608/21 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

3(a) Reasons include: 3


1 FileName given does not exist / access denied / file is of wrong type
2 The StartLine line does not exist in file
3 There are less than NumLines lines after the StartLine
4 Code does not read the required number of lines (description of logical error)

One mark per point to 3 max marks

3(b) 'Pseudocode' solution included here for development and clarification of mark scheme. 7
Programming language example solutions appear in the Appendix.

PROCEDURE OutputLines(FileName: STRING, StartLine, NumLines: INTEGER)

DECLARE FileData : STRING


DECLARE Count : INTEGER

OPENFILE FileName FOR READ

FOR Count ← 1 TO StartLine + NumLines - 1


PAGE 909

READFILE FileName, FileData


IF Count >= StartLine
THEN
OUTPUT FileData
ENDIF
ENDFOR

CLOSE FileName

ENDPROCEDURE

© UCLES 2020 Page 7 of 22

MUHAMMAD ALI KHAN


9608/21 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

3(b) 1 mark for each of the following:

1 Procedure heading (including parameters) and ending


2 Declare local variable for FileData and Count
3 Open FileName in READ mode and subsequent Close
4 Loop
5 Read Filedata in a loop
6 Check if current line is to be printed (i.e. if Count in range)
7 If so Output FileData in a loop

Alternative 'Seek' solution

PROCEDURE OutputLines(FileName: STRING, StartLine, NumLines: INTEGER)

DECLARE FileData : STRING


DECLARE Count : INTEGER

OPENFILE FileName FOR READ


PAGE 910

FOR Count ← 1 TO StartLine - 1 // read up to StartLine


READFILE FileName, FileData
ENDFOR

FOR Count ← 1 TO NumLines // then Output NumLines lines from here


READFILE FileName, FileData
OUTPUT FileData
ENDFOR

CLOSE FileName

ENDPROCEDURE

© UCLES 2020 Page 8 of 22


9608/21 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

3(b) 1 mark for each of the following:

1 Procedure heading (including parameters) and ending


2 Declare local variable for FileData and Count
3 Open FileName in READ mode and subsequent close
4 First loop to read up to StartLine
5 Read Filedata in a loop
6 Second loop for Numlines times
7 Read and Output Filedata in a loop

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

Award mark for 'description' without type

3(c)(ii) Max 2 marks, techniques include: 2

• White-box testing // use of suitable test data


• Dry-run / use of a trace table
• IDE features such as breakpoints, stepping, watch windows

3(d) Max 2 marks, reasons include: 2

• They are tried and tested / free from bugs


• They are already available so their use saves development time
• Perform a function which the programmer does not have the skills to write

© UCLES 2020 Page 9 of 22

MUHAMMAD ALI KHAN


9608/21 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

4(a) There are many correct answers. 4

There are eight relevant combinations (2 × 2 × 2 options) as follows:

Parameter Option A Option B

Number <= 999 >= 1000

Prefix Non-empty
Empty String
String

AddComma TRUE FALSE

Tests must be different by at least one option

For each test (2 in total):

• One mark for parameter values


PAGE 912

• One mark for expected return

© UCLES 2020 Page 10 of 22


9608/21 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

4(b) FUNCTION FormOut(Num : INTEGER, Prefix : STRING, AddComma : BOOLEAN) RETURNS STRING 8

DECLARE OutString : STRING


DECLARE ThouDigits : INTEGER // just to simplify later expression

CONSTANT COMMA = ','

OutString ← NUM_TO_STRING(Num) // convert integer to string


IF AddComma = TRUE
THEN
NumLength ← LENGTH(OutString)
IF NumLength > 3
THEN
ThouDigits ← NumLength - 3
OutString ← LEFT(OutString, ThouDigits) & COMMA & RIGHT(OutString, 3)
ENDIF
ENDIF

concatenate string with Prefix


PAGE 913

OutString ← Prefix & OutString //

RETURN OutString

ENDFUNCTION

© UCLES 2020 Page 11 of 22

MUHAMMAD ALI KHAN


9608/21 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

4(b) 1 mark for each of the following:

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

MP3 and MP4 could easily appear in reverse sequence


PAGE 914

© UCLES 2020 Page 12 of 22


9608/21 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

5(a) FUNCTION GetIndex(HashTag : STRING) RETURNS INTEGER 6

DECLARE Index : INTEGER


DECLARE Found : BOOLEAN

Index ← 1
Found ← FALSE

WHILE Index <= 10000 AND Found = FALSE


IF TagString[Index] = HashTag
THEN
Found ← TRUE
ELSE
Index ← Index + 1
ENDIF
ENDWHILE

IF Found = FALSE
THEN
PAGE 915

Index ← -1
ENDIF

RETURN Index
ENDFUNCTION

1 mark for each of the following:

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

© UCLES 2020 Page 13 of 22

MUHAMMAD ALI KHAN


9608/21 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

5(b) FUNCTION GetStart(Message : STRING, TagNum : INTEGER) RETURNS INTEGER 6

DECLARE MessLength, Index, StartPos, Count: INTEGER


CONSTANT HASH = '#'

Count ← 0
StartPos ← -1
Index ← 1
MessLength ← LENGTH(Message)

WHILE Index <= MessLength AND Count < TagNum


IF MID(Message, Index, 1) = HASH
THEN
Count ← Count + 1
IF Count = TagNum
THEN
StartPos ← Index // found the required hashtag
ENDIF
PAGE 916

ENDIF
Index ← Index + 1
ENDWHILE

RETURN StartPos
ENDFUNCTION

1 mark for each of the following:

1 Conditional loop until required hashtag found or end of message encountered


2 Extract a character and compare with hash character in a loop
3 If hash found, increment Count / decrement TagNum
4 Test if this is the required hashtag
5 Set termination condition / store current index if match found in a loop
6 Return integer value from correct function declaration

© UCLES 2020 Page 14 of 22


9608/21 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

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

FUNCTION GetTag(Message : STRING, StartPos : INTEGER) RETURNS STRING


DECLARE Index : INTEGER
DECLARE MyString : STRING
DECLARE NextChar, TestChar : CHAR
DECLARE EndTag : BOOLEAN
CONSTANT HASH = '#'
CONSTANT SPACE = ' '

MyString ← ""
EndTag ←FALSE

IF MID(Message, StartPos, 1) = HASH // check first char is HASH


THEN
MyString ← HASH // store HASH as first char of hashtag
Index ← StartPos + 1 // start loop with first char after #
PAGE 917

WHILE Index <= LENGTH(Message) AND EndTag = FALSE


NextChar ← MID(Message, Index, 1)
TestChar ← UCASE(NextChar)
IF TestChar = SPACE OR TestChar = HASH __
OR NOT ((TestChar >= 'A' AND TestChar <= 'Z') __
OR (TestChar >= '0' AND TestChar <= '9'))
THEN
EndTag ← TRUE
ELSE
MyString ← MyString & NextChar
ENDIF
Index ← Index + 1
ENDWHILE

© UCLES 2020 Page 15 of 22

MUHAMMAD ALI KHAN


9608/21 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

5(c) ENDIF
IF LENGTH(MyString) = 1
THEN
MyString = "" // when Hash is last char in string
ENDIF
RETURN MyString
ENDFUNCTION

1 mark for each of the following:

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 ***

© UCLES 2020 Page 16 of 22


9608/21 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Program Code Example Solutions

Q3 (b): Visual Basic

Sub OutputLines(FileName As String, StartLine As Integer, NumLines As Integer)

Dim FileData As String


Dim Count As Integer
Dim File As New StreamReader(FileName)

For Count = 1 To StartLine + NumLines - 1


FileData = File.ReadLine()
If Count >= StartLine Then Console.Writeline(FileData)
Next

File.Close

End Sub
PAGE 919

© UCLES 2020 Page 17 of 22

MUHAMMAD ALI KHAN


9608/21 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q3 (b): Pascal

Procedure OutputLines(FileName : string; StartLine : integer; NumLines : integer);

var
FileData : string;
Count : integer;
ThisFile : textfile;

begin
assignfile(ThisFile, FileName);
reset(ThisFile);

for Count := 1 to StartLine + NumLines - 1 do


begin
readln(ThisFile, Filedata);
if Count >= StartLine then writeln(Filedata);
end;

closefile(ThisFile);
end;
PAGE 920

Q3 (b): Python

def OutputLines(FileName, StartLine, NumLines):


#Count as INTEGER
#File as FILEOBJECT
#FileData as STRING

Count = 1
File = open(FileName, "r")

for Count in range(1, StartLine + NumLines):


FileData = File.readline()
if Count >= StartLine:
print(FileData)

File.close()

© UCLES 2020 Page 18 of 22


9608/21 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q5 (c): Visual Basic

Function GetTag(Message As String, StartPos As Integer) As String

Dim NumChars, Index As Integer


Dim MyString As String
Dim NextChar, TestChar As Char
Dim EndTag As Boolean
Const HASH = "#"
Const SPACE = " "

MyString = ""
EndTag = FALSE

NumChars = Len(Message)

If Mid(Message, StartPos, 1) = HASH Then 'Check for valid hashtag


MyString = HASH
Index = StartPos + 1
Do While Index <= NumChars And EndTag = FALSE
NextChar = Mid(Message, Index, 1)
TestChar = Ucase(NextChar)
PAGE 921

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
End If
Index = Index + 1
Loop
End If

If MyString = HASH Then MyString = "" 'When Hash is last char in message

Return MyString

End Function

© UCLES 2020 Page 19 of 22

MUHAMMAD ALI KHAN


9608/21 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q5 (c): Pascal

Function GetTag(Message : string, StartPos : integer) : String;


var
NumChars, Index : Integer;
MyString: String;
NextChar, TestChar : String;
EndTag : Boolean;

const
HASH = '#';
SPACE = ' ';

MyString = '';
EndTag = FALSE;

NumChars := Length(Message);

if midstr(Message, StartPos, 1) = HASH then // Check for valid hashtag


begin
MyString:= HASH;
PAGE 922

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;

© UCLES 2020 Page 20 of 22


9608/21 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
If MyString = HASH then MyString := ""; // When Hash is last char in message

GetTag := MyString;

end;

Q5 (c): Python

def GetTag(Message, StartPostion):

#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

while Index <= NumChars And EndTag == FALSE:


NextChar = Message[Index]
TestChar = NextChar.upper()
if NextChar == SPACE OR NextChar == HASH
or not ((TestChar >= 'A' and TestChar <= 'Z') or
TestChar >= '0' and TestChar <= '9')):
EndTag = True
else:
MyString = MyString + NextChar
Index = Index + 1

© UCLES 2020 Page 21 of 22

MUHAMMAD ALI KHAN


9608/21 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED

if MyString = HASH:
MyString = "" #When Hash is last char in message

return HashTag
PAGE 924

© UCLES 2020 Page 22 of 22


MUHAMMAD ALI KHAN
PAGE 925

Cambridge International AS & A Level


* 7 1 8 7 0 7 4 0 4 6 *

COMPUTER SCIENCE 9608/22


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2020
2 hours

You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.

This document has 20 pages. Blank pages are indicated.

DC (CJ) 188580/2
© UCLES 2020 [Turn over
PAGE 926

1 (a) Algorithms usually consist of three different stages.

One stage is INPUT.

Name the other stages.

1 ................................................................................................................................................

2 ................................................................................................................................................
[1]

(b) An algorithm may be documented using different methods. These include structured English,
a program flowchart, and pseudocode.

State what a program designer represents using one or more of these methods.

...................................................................................................................................................

............................................................................................................................................. [2]

(c) Programming languages support different data types.

Complete the table by giving four different data types together with an example data value
for each.

Data type Example data value

[4]

© UCLES 2020 9608/22/O/N/20


MUHAMMAD ALI KHAN
PAGE 927

(d) Draw lines to connect each of the following computing terms with the appropriate description.

Term Description

A structure for the


Black-box testing
temporary storage of data

A method used when the


File structure of the program is
unknown

A method of setting the


Assignment
value of a variable

A structure for the


Array
permanent storage of data

[3]

(e) A pseudocode algorithm assigns values to three variables as follows:

FlagA TRUE
FlagB FALSE
FlagC TRUE

Evaluate the expressions given in the following table:

Expression Evaluates to

NOT FlagB AND FlagC

NOT (FlagB OR FlagC)

(FlagA AND FlagB) OR FlagC

NOT (FlagA AND FlagB) OR NOT FlagC

[2]

© UCLES 2020 9608/22/O/N/20 [Turn over


PAGE 928

2 (a) The following pseudocode is an attempt to define an algorithm that takes two numbers as
input and outputs the larger of the two numbers.

DECLARE A, B : INTEGER
INPUT A
INPUT B
IF A > B
THEN
OUTPUT A
ELSE
OUTPUT B
ENDIF

The algorithm needs to be amended to include the following changes:

1. Input three values, ensuring that each value input is unique.


2. Output the average.
3. Output the largest value.

Write the pseudocode for the amended algorithm.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2020 9608/22/O/N/20
MUHAMMAD ALI KHAN
PAGE 929

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

(b) Complete the pseudocode expressions in the following table.

Use only functions and operators described in the Appendix on pages 18–19.

Expression Evaluates to

"ALARM: " & ...................... ("Time: 1202" , ......................) "ALARM: 1202"

...................... ("Stepwise." , ...................... , ......................) "wise"

1.5 * .......................... ("OnePointFive") 18

...................................... (27.5) "27.5"

.......................... (9, 4) 2
[5]

(c) A problem may be decomposed into sub-tasks when designing an algorithm.

Give three benefits of using sub-tasks.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................

3 ................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2020 9608/22/O/N/20 [Turn over


PAGE 930

3 A car has the ability to detect a skid by monitoring the rate of rotation (the rotational speed) of
each wheel. If the rate of rotation of any wheel is not within 10% of the average of all four wheels,
the car skids.

A function, CheckSkid(), is being developed.

The function will:

• simulate real-time data acquisition, by prompting for the input of four integer values in the
range 0 to 1000 inclusive, representing the rate of rotation of each wheel
• calculate the average value
• check whether any individual value is more than 10% greater than the average or more than
10% less than the average
• return TRUE if any individual value is more than 10% greater than the average or more than
10% less than the average and FALSE otherwise
• output a suitable warning message.

(a) Write program code for the function CheckSkid().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2020 9608/22/O/N/20


MUHAMMAD ALI KHAN
PAGE 931

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

(b) Give two sets of test data that could be used to test the function.

Test 1 – No skid detected

Value1 Value2 Value3 Value4

Test 2 – Skid detected

Value1 Value2 Value3 Value4

[2]

© UCLES 2020 9608/22/O/N/20 [Turn over


PAGE 932

4 (a) The following structured English describes an algorithm used to count the number of odd and
even digits in an input sequence.

1. Initialise variables OddCount and EvenCount to zero.


2. Prompt and input an integer.
3. If the integer is not in the range 0 to 9 then go to step 7.
4. If the integer is an even number then add 1 to EvenCount.
5. Otherwise add 1 to OddCount.
6. Repeat from step 2.
7. Output "Same" if there are the same number of odd and even integers.
8. Output "Odd" if there are more odd than even integers.
9. Output "Even" if there are more even than odd integers.

Draw a flowchart on the following page to represent the algorithm.

© UCLES 2020 9608/22/O/N/20


MUHAMMAD ALI KHAN
PAGE 933

[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.

FUNCTION Compare(String1, String2 : STRING) RETURNS BOOLEAN


DECLARE x, y, Len1, Len2 : INTEGER
DECLARE RetFlag : BOOLEAN
DECLARE NextChar : CHAR
DECLARE New : STRING

Len1 LENGTH(String1)
RetFlag TRUE

FOR x 1 TO Len1 // for each char in String1


Len2 LENGTH(String2)
NextChar MID(String1, x, 1) // get NextChar from String1
New ""
FOR y 1 TO Len2 // for each char in String2
IF NextChar <> MID(String2, y, 1) // no match
THEN
New New & MID(String2, y, 1) // save this char from String2
ENDIF
ENDFOR
String2 New // replace String2 with New
ENDFOR

IF LENGTH(String2) <> 0 // anything left in String2 ?


THEN
RetFlag FALSE
ENDIF

RETURN RetFlag

ENDFUNCTION

© UCLES 2020 9608/22/O/N/20


MUHAMMAD ALI KHAN
PAGE 935

11

(i) Complete the trace table below by performing a dry run of the function when it is called
as follows:

Result Compare("SUB", "BUS")

The first row has been completed for you.

String1 String2 Len1 RetFlag x Len2 NextChar New y


"SUB" "BUS" 3 TRUE 1

[5]

(ii) State the value returned.

..................................................................................................................................... [1]

© UCLES 2020 9608/22/O/N/20 [Turn over


PAGE 936

12

(iii) There is an error in the algorithm, which means that under certain circumstances, the
function will return an incorrect value.

Describe the problem. Give two test strings that would demonstrate it.

Problem .............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

Test String1 .......................................................................................................................

Test String2 .......................................................................................................................


[2]

(iv) Describe the modification that needs to be made to the algorithm to correct the error.

Do not use pseudocode or program code in your answer.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [1]

(v) State the name given to the type of testing that makes use of a trace table.

..................................................................................................................................... [1]

(vi) State two features found in a typical Integrated Development Environment (IDE) that
may be used for debugging a program.

1 ........................................................................................................................................

2 ........................................................................................................................................
[2]

© UCLES 2020 9608/22/O/N/20


MUHAMMAD ALI KHAN
PAGE 937

13

Question 5 begins on the next page.

© UCLES 2020 9608/22/O/N/20 [Turn over


PAGE 938

14

5 A hashtag is used on a social media network. A hashtag is a string consisting of a hash character
‘#’ followed by one or more alphanumeric characters.

A program is being developed to monitor the use of hashtags.

The program will include two global arrays each containing 10 000 elements:

• A 1D array, TagString, of type STRING stores each hashtag in a single element. All unused
array elements contain an empty string ("").

• A 1D array, TagCount, of type INTEGER stores a count of the number of times each hashtag
is used. The count value at a given index relates to the element stored at the corresponding
index in the TagString array.

The contents of the two arrays will be stored in a text file Backup.txt. The format of each line of
the file is:

<Hashtag><','><Count>

For example:

"#ComputerScienceClass,978"

A developer has started to define the modules as follows:

Module Description
InitArrays() • Initialise the arrays
• The contents of the two arrays are stored in the text file Backup.txt
Existing file contents will be overwritten
SaveArrays() • Each hashtag and count are stored in one line of the file, as in the example
above
• Unused TagString elements are not added to the file
• Returns the total number of unused TagString elements

LoadArrays()
• Values from the text file Backup.txt are stored in the two arrays
• The number of elements stored is returned

(a) Write pseudocode for the module InitArrays().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]
© UCLES 2020 9608/22/O/N/20
MUHAMMAD ALI KHAN
PAGE 939

15

(b) Write pseudocode for the module SaveArrays().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]
© UCLES 2020 9608/22/O/N/20 [Turn over
PAGE 940

16

(c) Write program code for the module LoadArrays().

The module description is repeated here for reference.

Module Description
• Values from the text file Backup.txt are stored in the
LoadArrays() two arrays
• The number of elements stored is returned

You should assume:

• each line of the file contains a string of the correct format and no validation checks are
required
• there are no more than 10 000 lines in the file.

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2020 9608/22/O/N/20
MUHAMMAD ALI KHAN
PAGE 941

17

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2020 9608/22/O/N/20 [Turn over


PAGE 942

18

Appendix
Built-in functions (pseudocode)

Each function returns an error if the function call is not properly formed.

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of string ThisString

Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString

Example: LEFT("ABCDEFGH", 3) returns string "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString

Example: RIGHT("ABCDEFGH", 3) returns string "FGH"

MOD(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the remainder when ThisNum is divided by ThisDiv

Example: MOD(10,3) returns 1

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString

Example: MID("ABCDEFGH", 2, 3) returns string "BCD"

DIV(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the whole number part of the result when ThisNum is
divided by ThisDiv
Example: DIV(10,3) returns 3

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.
Note: This function will also work if x is of type INTEGER

Example: NUM_TO_STRING(87.5) returns "87.5"

STRING_TO_NUM(x : STRING) RETURNS REAL


returns a numeric representation of a string.
Note: This function will also work if x is of type CHAR

Example: STRING_TO_NUM("23.45") returns 23.45

© UCLES 2020 9608/22/O/N/20


MUHAMMAD ALI KHAN
PAGE 943

19

Operators (pseudocode)

Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE

© UCLES 2020 9608/22/O/N/20


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED

Question Answer Marks

1(a) One mark for both answers: 1

• Process
• Output

Order not important.

1(b) One mark per bullet point (or equivalent) 2

They all represent:

• A solution to a problem / a way to perform a task


• Expressed as a sequence / series of steps / stages / instructions

1(c) 1 mark per row to max 4 marks 4

Example answers:
PAGE 944

Data type Example data value

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

© UCLES 2020 Page 4 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

1(d) Max 3 marks, one mark for each correct line 3


PAGE 945

© UCLES 2020 Page 5 of 24

MUHAMMAD ALI KHAN


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

1(e) 1 mark for two rows correct, 2 marks for all rows correct. 2

Expression Evaluates to

NOT FlagB AND FlagC TRUE

NOT (FlagB OR FlagC) FALSE

(FlagA AND FlagB) OR FlagC TRUE

NOT (FlagA AND FlagB) OR NOT FlagC TRUE


PAGE 946

© UCLES 2020 Page 6 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

2(a) DECLARE A, B, C : INTEGER 6


DECLARE Average : REAL

INPUT A
REPEAT
INPUT B
UNTIL B <> A

REPEAT
INPUT C
UNTIL C <> A AND C <> B

Average ← (A + B + C) / 3
OUTPUT Average

IF A > B AND A > C


THEN
OUTPUT A
ELSE
PAGE 947

IF B > A AND B > C


THEN
OUTPUT B
ELSE
OUTPUT C
ENDIF
ENDIF

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

© UCLES 2020 Page 7 of 24

MUHAMMAD ALI KHAN


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

2(b) One mark per correct row 5


(Completed parts shown in bold)

Expression Evaluates to

"ALARM: " & RIGHT("Time: 1202",4) "ALARM: 1202"

MID("Stepwise.",5, 4) "wise"

1.5 * LENGTH("OnePointFive") 18

NUM_TO_STRING(27.5) "27.5"

DIV(9, 4) 2

2(c) One mark per point, example points: 3

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

© UCLES 2020 Page 8 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

3(a) 'Pseudocode' solution included here for development and clarification of mark scheme. 8
Programming language example solutions appear in the Appendix.

FUNCTION CheckSkid() RETURNS BOOLEAN


DECLARE Rot : ARRAY[1:4] OF INTEGER
DECLARE Average : REAL
DECLARE ThisRot : INTEGER
DECLARE Danger : BOOLEAN

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

Average ← (Rot[1] + Rot[2] + Rot[3] + Rot[4]) / 4


PAGE 949

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

© UCLES 2020 Page 9 of 24

MUHAMMAD ALI KHAN


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

3(a) 1 mark for each of the following:

1 Function heading and ending


2 Declare local integers for 4 rotation values and a real for the average / tolerance
3 Prompt and input four rotation values
4 Validate each input value in a loop
5 Calculate average rotation AND calculate acceptable max and min (or single tolerance, or alternative method)
6 Compare rotational value of each wheel
7 Test if rotational value of (each) wheel is within the acceptable range
8 Output a warning message and return the correct value in all cases

3(b) Example answers: 2

Test1 – No Skid detected

Value 1 Value2 Value 3 Value 4

100 100 100 100


PAGE 950

One of:

Test2 – Skid detected (one wheel too fast)

Value 1 Value2 Value 3 Value 4

100 100 100 160

Test2 – Skid detected (one wheel too slow)

Value 1 Value2 Value 3 Value 4

100 100 100 40

Independent marks: one mark each for Test1 and Test 2

© UCLES 2020 Page 10 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

4(a) 7

Mark as follows:
• One mark for START and END
• One mark per area outlined
PAGE 951

Outputs from conditional diamond must have at least one label

© UCLES 2020 Page 11 of 24

MUHAMMAD ALI KHAN


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

4(b)(i) One mark per region as indicated. 5

Strin String RetFl Len NextCh


Len1 X New y
g1 2 ag 2 ar
"SUB" "BUS" 3 TRUE 1
3 'S' ""
"B" 1
"BU" 2
3

"BU" 2
2 'U' ""
1
PAGE 952

"B" 2

"B" 3
1 'B' ""
1

""

© UCLES 2020 Page 12 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

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:

• ‘SAME’ and ‘MASS’ (for example)

4(b)(iv) The inner FOR loop should only remove one instance of the character from String2 1

4(b)(v) • Dry run // White-box testing 1

4(b)(vi) Max 2 marks, features include: 2


PAGE 953

• Single stepping
• Breakpoints
• Variable and expressions report window
• Syntax error highlighting

© UCLES 2020 Page 13 of 24

MUHAMMAD ALI KHAN


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

5(a) PROCEDURE InitArrays() 4

DECLARE Index : INTEGER

FOR Index ← 1 TO 10000


TagString[Index] ← ""
TagCount[Index] ← 0
ENDFOR

ENDPROCEDURE

1 mark for each of the following:

1 Procedure heading and ending (as shown)


2 Declaration of Index (e.g.) as integer
3 Loop for 10000 iterations
4 Initialise TagString element to ""
PAGE 954

© UCLES 2020 Page 14 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

5(b) FUNCTION SaveArrays() RETURNS INTEGER 8

DECLARE Index, NumUnused : INTEGER


DECLARE FileString : STRING
CONSTANT COMMA = ','

NumUnused ← 0

OPEN "Backup.txt" FOR WRITE


FOR Index ← 1 to 10000
IF TagString[Index] <> ""
THEN
FileString ← TagString[Index] & COMMA & NUM_TO_STRING(TagCount[Index])
WRITEFILE "Backup.txt", FileString
ELSE
NumUnused ← NumUnused + 1
ENDIF
ENDFOR
CLOSEFILE "Backup.txt"
PAGE 955

RETURN NumUnused
ENDFUNCTION

1 mark for each of the following:

1 Function heading and ending


2 Open the file Backup.txt in write mode and close file
3 Loop through 10000 elements
4 Test if TagString[Index] is "" in a loop
5 If not then form FileString from array elements with separator and using NUM_TO_STRING()in a loop
6 Write string to file in a loop
7 Count the number of unused elements
8 Return NumUnused not in a loop

© UCLES 2020 Page 15 of 24

MUHAMMAD ALI KHAN


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

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

FUNCTION LoadArrrays() RETURNS INTEGER

DECLARE ArrayIndex, Index, CountLen, Count : INTEGER


DECLARE FileString, HashTag : STRING
CONSTANT COMMA = ','

ArrayIndex ← 0 // first element

OPEN "Backup.txt" FOR READ


WHILE NOT EOF("Backup.txt")
READFILE "Backup.txt", FileString
Index ← 1
HashTag ← ""
WHILE MID(FileString, Index, 1) <> COMMA // hashtag
HashTag ← HashTag & MID(FileString, Index, 1)
PAGE 956

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

© UCLES 2020 Page 16 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

5(c) 1 mark for each of the following:

1 Function heading and ending


2 Declare and initialise ArrayIndex (or equivalent name)
3 Open the file Backup.txt in read mode and close the file
4 Loop until end of the Backup.txt file // string read is null
5 Read a line from the file in a loop
6 Extract hashtag and count in a loop
7 Store hashtag in TagString array and count in TagCount array after type conversion
8 Increment ArrayIndex in a loop
9 Return number of array elements

*** End of Mark Scheme – example program code solutions follow ***
PAGE 957

© UCLES 2020 Page 17 of 24

MUHAMMAD ALI KHAN


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Appendix: Program Code Example Solutions

Q3 (a): Visual Basic

Function CheckSkid() As Boolean

Dim Rot(3) As Integer


Dim Average As Double
Dim ThisRot As Integer
Dim Danger As Boolean

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

Average = (Rot(0) + Rot(1) + Rot(2) + Rot(3)) / 4

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

If Danger = TRUE Then


Console.Writeline("Skid Danger")
Else
Console.Writeline("No Skid Danger")
End if

RETURN Danger

End Function

© UCLES 2020 Page 18 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q3 (a): Pascal

Function CheckSkid() : Boolean;

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;

Average := (Rot[1] + Rot[2] + Rot[3] + Rot[4]) / 4;


PAGE 959

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;

If Danger = TRUE then


writeln('Skid Danger')
Else
writeln('No Skid Danger');

CheckSkid := Danger;

end;

© UCLES 2020 Page 19 of 24

MUHAMMAD ALI KHAN


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q3 (a): Python

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

Average = (Rot[0] + Rot[1] + Rot[2] + Rot[3]) / 4

Danger = False
for Index in range(0, 4):
PAGE 960

if Rot[Index] > (Average * 1.1) or Rot[Index] < (Average * 0.9):


Danger = True

If Danger == True:
print("Skid Danger")
else:
print("No Skid Danger")

return Danger

© UCLES 2020 Page 20 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q5 (c): Visual Basic

Function LoadArrrays () As Integer

Dim ArrayIndex, Index, CountLen, Count As Integer


Dim FileString, HashTag As String
Dim File As New StreamReader("Backup.txt")

Const COMMA = ','

ArrayIndex = 0 ' First element

Do While File.Peek <> -1


FileString = File.ReadLine()
Index = 1
HashTag = ""
Do While Mid(FileString, Index, 1) <> COMMA ' the hashtag
HashTag = HashTag & MID(FileString, Index, 1)
Index = Index + 1
Loop

TagString(arrayIndex) = HashTag
PAGE 961

CountLen = Len(fileString) – Len(HashTag) – 1


Count = CInt(Right(FileString, CountLen)) ' the count
TagCount(ArrayIndex) = Count
ArrayIndex = ArrayIndex + 1
Loop

File.Close

Return ArrayIndex
End Function

© UCLES 2020 Page 21 of 24

MUHAMMAD ALI KHAN


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q5 (c): Pascal

Function LoadArrrays () : Integer;

var
ArrayIndex, Index, CountLen, Count : Integer;
FileData, HashTag : String;
Backup : Textfile;

const
COMMA = ',';

begin
assignfile(Backup, 'Backup.txt');
reset(File);

ArrayIndex := 0; //First element

while not EOF(File) do


begin
readln(Backup, FileData);
PAGE 962

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);

© UCLES 2020 Page 22 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q5 (c): Python

def LoadArrays ():

# ArrayIndex, Index, CountLen, Count As Integer


# FileString, HashTag As String
# File As StreamReader("Backup.txt")

COMMA = ','

File = open("Backup.txt", "r")


ArrayIndex = 0 #First element

for FileString in File:


Index = 0
HashTag = ""
while FileString[Index] != COMMA: # the hashtag
HashTag = HashTag + FileString[Index]
Index = Index + 1

TagString[ArrayIndex] = HashTag
Count = int(FileString[Index+1:]) # the count
PAGE 963

TagCount[ArrayIndex] = Count
ArrayIndex = ArrayIndex + 1

File.close()

return ArrayIndex

© UCLES 2020 Page 24 of 24

MUHAMMAD ALI KHAN


PAGE 964

Cambridge International AS & A Level


* 5 4 7 9 1 0 0 9 4 4 *

COMPUTER SCIENCE 9608/23


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2020
2 hours

You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.

This document has 16 pages. Blank pages are indicated.

DC (JC/CT) 188579/4
© UCLES 2020 [Turn over
MUHAMMAD ALI KHAN
PAGE 965

1 (a) A programmer uses the process of stepwise refinement to break down a problem.

Explain the purpose of stepwise refinement.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

(b) Programming languages support different data types. These usually include STRING and
REAL.

Complete the table by giving four other data types and an example data value for each.

Data type Example data value

[4]

(c) An experienced programmer is working on a program that is written in a language she is not
familiar with.

(i) State one feature of the program that she should be able to recognise.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) State the type of skill that would allow her to recognise this feature.

...........................................................................................................................................

..................................................................................................................................... [1]

(d) Give three methods that may be used to identify and locate errors in a program after it has
been written.

You may include one feature found in a typical Integrated Development Environment (IDE).

1 ................................................................................................................................................

2 ................................................................................................................................................

3 ................................................................................................................................................
[3]
© UCLES 2020 9608/23/O/N/20
PAGE 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.

Document the algorithm using structured English.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

(b) Each pseudocode statement in the following table contains an error.

State the error in each case.

Refer to the Appendix on page 16 for the list of built-in functions and operators.

Statement Error

Code LEFT(3, "Europe")

Hour MID("ALARM:12:02", 7, 6)

Size LENGTH(27.5)

Num INT(27 / (Count + 3)

Result "Conditional" AND "Loop"

[5]
© UCLES 2020 9608/23/O/N/20 [Turn over
MUHAMMAD ALI KHAN
PAGE 967

(c) Part of a program flowchart is shown.

Set Index to 0

Set Status to FALSE

LOOP

Is YES
Status = TRUE
?

NO
NO Is Index > 100
?
Set Status to TopUp()
YES

SetLevel("Super")
Set Index to Index + 1

Write program code to implement the flowchart shown. Variable declarations are not
required.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]
© UCLES 2020 9608/23/O/N/20
PAGE 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.

Write program code for the procedure BubbleSort().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ....................................................................................................................

Program code

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................
© UCLES 2020 9608/23/O/N/20 [Turn over
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.

DECLARE NameList : ARRAY [1:100] OF STRING


DECLARE SearchString : STRING

PROCEDURE Search()
DECLARE Index : INTEGER

FOR Index 1 TO 100


IF NameList[Index] = SearchString
THEN
OUTPUT "Found at " & NUM_TO_STRING(Index)
ENDIF
ENDFOR
ENDPROCEDURE

The specification of module Search() changes. The pseudocode needs to be amended to


meet a new requirement.

The procedure needs to be implemented as a function, Search(), which will:

• take the search value as a parameter


• return an integer which is:

• either the index value where the search value is first found
• or –1 if the search value is not found.

© UCLES 2020 9608/23/O/N/20


PAGE 970

Write the pseudocode for the function Search().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

(b) A change to the specification in part (a) required a modification of the algorithm.

Give the term used for this type of modification.

............................................................................................................................................. [1]

(c) A change to the specification is only one reason to modify an algorithm.

Give another reason for the modification of an algorithm.

............................................................................................................................................. [1]

© UCLES 2020 9608/23/O/N/20 [Turn over


MUHAMMAD ALI KHAN
PAGE 971

(d) Consider the following pseudocode:

10 DECLARE VarA : INTEGER


11 VarA 20
12
13 CALL ProcA(VarA)
14 OUTPUT VarA // first value output
15
16 CALL ProcB(VarA)
17 OUTPUT VarA // second value output
18
19
20 PROCEDURE ProcA(BYVALUE ThisValue : INTEGER)
21 ThisValue ThisValue + 5
22 ENDPROCEDURE
23
24 PROCEDURE ProcB(BYREF ThisValue : INTEGER)
25 ThisValue ThisValue + 5
26 ENDPROCEDURE

Procedures ProcA() and ProcB() use two methods of passing parameters.

Complete the following table.

Output Explanation

.........................................................................................................
First
value
..................... .........................................................................................................
(line 14)
.........................................................................................................

.........................................................................................................
Second
value
..................... .........................................................................................................
(line 17)
.........................................................................................................
[4]

© UCLES 2020 9608/23/O/N/20


PAGE 972

(e) The procedures ProcA and ProcB in part (d) are examples of program modules.

Give two advantages of using program modules in program design.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2020 9608/23/O/N/20 [Turn over


MUHAMMAD ALI KHAN
PAGE 973

10

5 A hashtag is used on a social media network to make it easier to find messages with a specific
theme or content. A hashtag is a string consisting of a hash character ‘#’ followed by a number of
alphanumeric characters.

A message may contain several hashtag strings. A hashtag may be terminated by a space
character, the start of the next hashtag, or by the end of the message.

For example, the following message contains three hashtags:

"#Alarm34 is the result of #BatteryFailure in the #PowerModule"

The hashtags in this message are "#Alarm34", "#BatteryFailure" and "#PowerModule".

A program is being developed to monitor their use.

The program will include two global arrays each containing 10 000 elements:

• A 1D array, TagString, of type STRING storing each hashtag in a single element of the
array. All unused array elements contain an empty string ("").

• A 1D array, TagCount, of type INTEGER storing a count of the number of times each hashtag
is used. The count value in a given element relates to the hashtag value stored in the element
in the TagString array with the corresponding index value.

A developer has started to define the modules. Module GetStart() has already been written.

Module Description

• Called with two parameters:


• a message of type STRING
• an integer giving the number of the required hashtag;
for example, GetStart(Message, 3) would search
GetStart()
for the third hashtag in the string Message
• Returns an integer value representing the start position of
WKHKDVKWDJLQWKHPHVVDJHRUYDOXHíLIWKDWKDVKWDJ
does not exist
• Called with a hashtag of type STRING
• Copies the hashtag to the next free element of the
TagString array, and sets the corresponding element of
AddHashtag()
the TagCount array to 1
• Returns FALSE if there are no unused elements in the
TagString array, otherwise returns TRUE
• Called with a message of type STRING
CountHashtag()
• Searches the message for hashtags using GetStart()
• Returns a value representing the number of hashtags in the
message
• Called with a hashtag of type STRING
• Increments the value of the appropriate element in the
IncrementHashtag() TagCount array if the hashtag is found
• Returns TRUE if the hashtag is found, or FALSE if the
hashtag is not found

© UCLES 2020 9608/23/O/N/20


PAGE 974

11

(a) Write pseudocode for the module AddHashtag().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2020 9608/23/O/N/20 [Turn over


MUHAMMAD ALI KHAN
PAGE 975

12

(b) Write program code for the module CountHashtag().

The module description is repeated here for reference.

Module Description

• Called with a message of type STRING


CountHashtag()
• Searches the message for hashtags using GetStart()
• Returns a value representing the number of hashtags in the
message

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language .............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]
© UCLES 2020 9608/23/O/N/20
PAGE 976

13

(c) Write program code for the module IncrementHashtag().

The module description is repeated here for reference.

Module Description

• Called with a hashtag of type STRING


• Increments the value of the appropriate element in the
IncrementHashtag() TagCount array if the hashtag is found
• Returns TRUE if the hashtag is found, or FALSE if the
hashtag is not found

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language .............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]
© UCLES 2020 9608/23/O/N/20 [Turn over
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.

In both cases, the procedure must also output a suitable message.

You can assume that the arrays contain data for at least one hashtag.

Write pseudocode for the OutputMostPop() procedure.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2020 9608/23/O/N/20
PAGE 978

15

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................ . [8]

© UCLES 2020 9608/23/O/N/20 [Turn over


MUHAMMAD ALI KHAN
PAGE 979

16

Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of string ThisString
Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString
Example: LEFT("ABCDEFGH", 3) returns string "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString
Example: RIGHT("ABCDEFGH", 3) returns string "FGH"

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString
Example: MID("ABCDEFGH", 2, 3) returns string "BCD"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x
Example: INT(27.5415) returns 27

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.
Note: This function will also work if x is of type INTEGER
Example: NUM_TO_STRING(87.5) returns "87.5"

Operators (pseudocode)
Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE

Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the
publisher will be pleased to make amends at the earliest possible opportunity.

To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.

Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of
Cambridge Local Examinations Syndicate (UCLES), which itself is a department of the University of Cambridge.

© UCLES 2020 9608/23/O/N/20


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED

Question Answer Marks

1(a) One mark per bullet point 2

The purpose is:

• 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:

Data type Example data value

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(c)(i) Max 1 mark, features include: 1

• Control Structures / selection statements / iteration statements / IO statements


• Modular structure (functions, procedures)
• Parameters to / from subroutines
• Variable declaration / assignment /data structures / OOP ref

© UCLES 2020 Page 4 of 27


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

1(c)(ii) • Transferable skill 1

1(d) Max 3 marks, methods include: 3

• IDE features: breakpoints / single stepping / watch window


• Manually check program code / reading error report
• Trace table / dry run / White-box testing
• Use of appropriate test data
• Addition of output statement to follow changes to variables

Question Answer Marks

2(a) One mark per step (or equivalent): 8

1 Set Total to 0
2 Set AGradeCount to 0
3 Input Mark
PAGE 981

4 Add Mark to Total


5 If Mark > 75 then increment AGradeCount
6 Repeat from Step 3 for 30 times
7 Output AGradeCount
8 Output Total / 30

© UCLES 2020 Page 5 of 27

MUHAMMAD ALI KHAN


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

2(b) One mark per row: 5

Statement Error

Code ← LEFT(3, "Europe") Parameters are reversed

Third param too big (should be max 5) // string too


Hour ← MID("ALARM:12:02", 7, 6)
short

Size ← LENGTH(27.5) Invalid type – param should be a string

Num ← INT(27/ (Count + 3) Missing closing bracket

Result ← "Conditional" AND "Loop" Wrong variable types / operator


PAGE 982

© UCLES 2020 Page 6 of 27


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

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

IF Index > 100


THEN
SetLevel("Super")
ENDIF

Mark as follows:

1 Set Index to 0 and Status to FALSE


PAGE 983

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"

© UCLES 2020 Page 7 of 27

MUHAMMAD ALI KHAN


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

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

© UCLES 2020 Page 8 of 27


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

3(a) Mark as follows, max 7 marks from 8 possible marks:

1 Procedure heading and ending


2 Conditional outer loop (may be count-controlled but if so must be >= 4999 iterations)
3 An inner loop
4 Correct range for inner loop
5 Comparison (element n with n + 1) in a loop
6 Swap array element in a loop
7 'No-Swap' mechanism: (both needed for mark):
o Conditional outer loop including flag reset
o Flag set in inner loop to indicate swap
8 Reducing Boundary in the outer loop
PAGE 985

© UCLES 2020 Page 9 of 27

MUHAMMAD ALI KHAN


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

4(a) FUNCTION Search(SearchString : STRING) RETURNS INTEGER 6

DECLARE RetVal : INTEGER


DECLARE Index : INTEGER

RetVal ← -1
Index ← 1

WHILE Index <= 100 AND RetVal = -1


IF NameList[Index] = SearchString
THEN
RetVal ← Index
ENDIF
Index ← Index + 1
ENDWHILE

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)

© UCLES 2020 Page 10 of 27


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

4(b) • Adaptive maintenance 1

4(c) Ma 1 mark, reasons include: 1

• 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

4(d) One mark for each value 4


One mark for each explanation

Output Explanation

20 A copy of the variable itself is passed

25 A pointer to / the address of the variable is passed


PAGE 987

4(e) Max 2 marks, example answers: 2

• Allows the module to be called from many / multiple places // re-used


• Module code can be (independently) tested and debugged once and can then be used repeatedly
• If the module task changes the change needs to be made only once
• Reduces unnecessary code duplication
• Allows modules to be shared among many programmers / given to programmers with specific skills
• Makes the program easier to work on / debug / test / etc

© UCLES 2020 Page 11 of 27

MUHAMMAD ALI KHAN


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

5(a) FUNCTION AddHashtag (HashTag : STRING) RETURNS BOOLEAN 6


DECLARE Index : INTEGER
DECLARE Added : BOOLEAN
CONSTANT EMPTY = ""

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

UNTIL Index > 10000 OR Added = TRUE

RETURN Added
ENDFUNCTION

1 mark for each of the following:

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)

© UCLES 2020 Page 12 of 27


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

5(b) ‘Pseudocode’ solution included here for development and clarification of mark scheme. 6
Programming language example solutions appear in the Appendix.

FUNCTION CountHashtag (Message : STRING) RETURNS INTEGER


DECLARE TagNum, StartPos : INTEGER
DECLARE Found : BOOLEAN

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

1 mark for each of the following:

1 Function heading and ending including parameter


2 Declaration and initialisation of local integer for count (TagNum)
3 Conditional loop through message
4 Use of GetStart() in a loop
5 Test GetStart() return value for -1 and increment count accordingly in a loop
6 Return integer value

© UCLES 2020 Page 13 of 27

MUHAMMAD ALI KHAN


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

5(c) ‘Pseudocode’ solution included here for development and clarification of mark scheme. 4
Programming language example solutions appear in the Appendix.

FUNCTION IncrementHashtag (HashTag : STRING) RETURNS BOOLEAN


DECLARE Index : INTEGER
DECLARE Found : BOOLEAN

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

1 mark for each of the following:

1 Conditional loop until hashtag found or end of array


2 Compare element value to parameter in a loop
3 If found, increment corresponding TagCount element
4 Return Boolean correctly in both cases

© UCLES 2020 Page 14 of 27


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

5(d) PROCEDURE OutputMostPop() 8


DECLARE Index : INTEGER
DECLARE MostPopTag : STRING
DECLARE Max : INTEGER // the integer value of the biggest number
DECLARE Count : INTEGER

CONSTANT EMPTY = ""

Max ← −1

FOR Index ← 1 To 10000


IF TagCount[Index] > Max
THEN
Max ← TagCount[Index]
Count ← 1 // there is only one max value
MostPopTag ← TagString[Index]
ELSE
IF TagCount[Index] = Max
THEN
PAGE 991

Count ← Count + 1 // another max value


ENDIF
ENDIF
ENDFOR

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

© UCLES 2020 Page 15 of 27

MUHAMMAD ALI KHAN


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

5(d) 1 mark for each of the following:

1 Initialise Max to a value less than 1 or to TagCount[1]


2 Loop through all elements
3 Test if TagCount value > Max in a loop
4 and if so set Max to TagCount value
5 and save TagString element (or array index) and set Count to 1 (unless counting is separate)
6 ELSE If TagCount value = Max, increment Count (or via separate loop)
7 Output for single max after the loop
8 Or Output for multiple max after the loop

Alternative "two-loop" solution:

PROCEDURE OutputMostPop()
DECLARE Index : INTEGER
DECLARE MostPopTag : STRING
DECLARE Max : INTEGER //The integer value of the biggest number
DECLARE MaxCount : INTEGER
PAGE 992

CONSTANT EMPTY = ""

Max ← -1

FOR Index ← 1 To 10000


IF TagCount[Index] > Max
THEN
Max ← TagCount[Index]
MostPopTag ← TagString[Index]
ENDIF
ENDFOR

© UCLES 2020 Page 16 of 27


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

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

© UCLES 2020 Page 17 of 27

MUHAMMAD ALI KHAN


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Program Code Example Solutions

Q2 (c): Visual Basic

Index = 0
Status = FALSE
Do While Status <> TRUE
Status = TopUp()
Index = Index + 1
Loop

If Index > 100 Then


SetLevel("Super")
End If

Q2 (c): Pascal

Index := 0;
Status := FALSE;

while Status <> TRUE do


PAGE 994

begin
Status := TopUp();
Index := Index + 1;
end;

if Index > 100 then


SetLevel("Super");

© UCLES 2020 Page 18 of 27


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q2 (c): Python

Index = 0
Status = FALSE
while Status <> TRUE:
Status = TopUp()
Index = Index + 1

if Index > 100:


SetLevel("Super")

Q3: Visual Basic

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

© UCLES 2020 Page 19 of 27

MUHAMMAD ALI KHAN


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q3: Pascal

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;

© UCLES 2020 Page 20 of 27


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q3: Python

def BubbleSort():
# Temp As Integer
# NoSwaps As Boolean
# Boundary, J As Integer

NoSwaps = False
Boundary = 4999

while not NoSwaps:


NoSwaps = True
for J in range(Boundary):
if ProdNum[J]> ProdNum[J+1]:
Temp = ProdNum[J]
ProdNum[J] = ProdNum[J+1]
ProdNum[J+1] = Temp
NoSwaps = FALSE

Boundary = Boundary – 1
PAGE 997

© UCLES 2020 Page 21 of 27

MUHAMMAD ALI KHAN


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q5 (b): Visual Basic

Function CountHashtag (Message As STRING) As INTEGER


Dim TagNum As INTEGER
Dim StartPos As INTEGER
Dim Found As BOOLEAN

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

© UCLES 2020 Page 22 of 27


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q5 (b): Pascal

Function CountHashtag (Message : STRING) : INTEGER;


var
TagNum : Integer;
StartPos : Integer;
Found : Boolean;

begin
TagNum := 0;
Found:= TRUE;

repeat
StartPos := GetStart(Message, TagNum + 1);
if StartPos = -1 then
Found := FALSE
else
TagNum := TagNum + 1;

until Not Found;

CountHashtag := TagNum;
PAGE 999

end;

© UCLES 2020 Page 23 of 27

MUHAMMAD ALI KHAN


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q5 (b): Python

def CountHashtag (Message)


# TagNum, StartPos As INTEGER
# Found As BOOLEAN

TagNum = 0
Found = TRUE

while Found:
StartPos = GetStart(Message, TagNum + 1)
if StartPos == -1:
Found = FALSE
else:
TagNum = TagNum + 1

return TagNum
PAGE 1000

© UCLES 2020 Page 24 of 27


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q 5 (c): Visual Basic

Function IncrementHashtag (HashTag As String) As Boolean


Dim Index As Integer
Dim Found As Boolean

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

© UCLES 2020 Page 25 of 27

MUHAMMAD ALI KHAN


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q 5 (c): Pascal

Function IncrementHashtag (HashTag : String) : Boolean;


var
Index : Integer;
Found : Boolean

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;

until Index > 10000 OR Found = TRUE;


PAGE 1002

IncrementHashtag := Found;

end;

© UCLES 2020 Page 26 of 27


9608/23 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q 5 (c): Python

def IncrementHashtag (HashTag):


# Index As Integer
# Found As Boolean

Found = FALSE
Index = 0 #First element

while not Found and Index < 10000:


if TagString[Index] == HashTag:
TagCount[Index] = TagCount[Index] + 1
Found = TRUE
else:
Index = Index + 1

Return Found
PAGE 1003

© UCLES 2020 Page 27 of 27

MUHAMMAD ALI KHAN


PAGE 1004

Cambridge International AS & A Level


* 0 9 1 0 1 4 3 9 3 6 *

COMPUTER SCIENCE 9618/21


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2021
2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 24 pages. Any blank pages are indicated.

DC (PQ) 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.

Complete the following identifier table.

Example
Explanation Variable name Data type
value

The preferred name of the member


"Wong"
joining the football club

A value to indicate whether an


FALSE existing member of the club lives at
the same address

When the member joined the football


19/02/1983
club

The number of points a member has


1345 earned. Members of the club earn
points for different activities.
[4]

(b) Each pseudocode statement in the following table may contain an error due to the incorrect
use of the function or operator.

Describe the error in each case, or write ‘NO ERROR’ if the statement contains no error.

You can assume that none of the variables referenced are of an incorrect type.

Statement Error

Result 2 & 4

SubString MID("pseudocode", 4, 1)

IF x = 3 OR 4 THEN

Result Status AND INT(x/2)

Message "Done" + LENGTH(MyString)

[5]

© UCLES 2021 9618/21/M/J/21


PAGE 1006

(c) The following data items need to be stored for each student in a group:

• student name (a string)


• test score (an integer).

State a suitable data structure and justify your answer.

Structure ...................................................................................................................................

Justification ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2021 9618/21/M/J/21 [Turn over


MUHAMMAD ALI KHAN
PAGE 1007

2 (a) Four program modules form part of a program for a library.

A description of the relationship between the modules is summarised as follows:

Module name Description

UpdateLoan() • Calls either LoanExtend() or LoanReturn()


• Called with parameters LoanID and BookID
• Calls CheckReserve() to see whether the book has been
LoanExtend() reserved for another library user
• Returns TRUE if the loan has been extended, otherwise returns
FALSE
• Called with BookID
CheckReserve() • Returns TRUE if the book has been reserved, otherwise returns
FALSE
• Called with parameters LoanID and BookID
LoanReturn() • Returns a REAL (which is the value of the fine to be paid in the
case of an overdue loan)

Draw a structure chart to show the relationship between the four modules and the parameters
passed between them.

[5]
© UCLES 2021 9618/21/M/J/21
PAGE 1008

(b) The definition for module LoanReturn() is amended as follows:

Module name Description


Called with parameters LoanID, BookID and Fine
LoanReturn() The module code checks whether the book has been returned on time
and then assigns a new value to Fine

• LoanID and BookID are of type STRING


• Fine is of type REAL

Write the pseudocode header for the amended module LoanReturn().

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2021 9618/21/M/J/21 [Turn over


MUHAMMAD ALI KHAN
PAGE 1009

(c) A program will:

• input 50 unique integer values


• output the largest value
• output the average of the values excluding the largest value.

Draw a program flowchart to represent the algorithm.

Variable declarations are not required.

It is not necessary to check that each input value is unique.

[6]
© UCLES 2021 9618/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:

• name of person booking


• number of people in the group (for example a family ticket or a school party)
• event type.

Suggest how data relating to each booking may be stored in a text file.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2021 9618/21/M/J/21


MUHAMMAD ALI KHAN
PAGE 1011

(b) A procedure Preview() will:

• take the name of a text file as a parameter


• output a warning message if the file is empty
• otherwise output the first five lines from the file (or as many lines as there are in the file if
this number is less than five).

Write pseudocode for the procedure Preview().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

© UCLES 2021 9618/21/M/J/21 [Turn over


PAGE 1012

10

4 Study the following pseudocode. Line numbers are for reference only.

10 FUNCTION Convert(Name : STRING) RETURNS STRING


11
12 DECLARE Flag: BOOLEAN
13 DECLARE Index : INTEGER
14 DECLARE ThisChar : CHAR
15 DECLARE NewName : STRING
16
17 CONSTANT SPACECHAR = ' '
18
19 Flag TRUE
20 Index 1
21 NewName "" // formatted name string
22
23 WHILE Index <= LENGTH(Name)
24 ThisChar MID(Name, Index, 1)
25 IF Flag = TRUE THEN
26 NewName NewName & UCASE(ThisChar)
27 IF ThisChar <> SPACECHAR THEN
28 Flag FALSE
29 ENDIF
30 ELSE
31 NewName NewName & ThisChar
32 ENDIF
33 IF ThisChar = SPACECHAR THEN
34 Flag TRUE
35 ENDIF
36 Index Index + 1
37 ENDWHILE
38
39 RETURN NewName
40
41 ENDFUNCTION

© UCLES 2021 9618/21/M/J/21


MUHAMMAD ALI KHAN
PAGE 1013

11

(a) Complete the trace table below by dry running the function when it is called as follows:

Result Convert("|in|a||Cup")

Note: The symbol '|' has been used to represent a space character.
Use this symbol for any space characters in the trace table.

The first row has been completed for you.

Name Flag Index NewName ThisChar

"|in|a||Cup"

[5]

© UCLES 2021 9618/21/M/J/21 [Turn over


PAGE 1014

12

(b) The pseudocode for Convert() contains a conditional loop.

State a more appropriate loop structure.

Justify your answer.

Loop structure ...........................................................................................................................

...................................................................................................................................................

Justification ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[2]

(c) Two changes need to be made to the algorithm.

Change 1: Convert to lower case any character that is not the first character after a space.
Change 2: Replace multiple spaces with a single space.

(i) Change 1 may be implemented by modifying one line of the pseudocode.

Write the modified line.

...........................................................................................................................................

.......................................................................................................................................[1]

(ii) Change 2 may be implemented by moving one line of the pseudocode.

Write the number of the line to be moved and state its new position.

Line number ......................................................................................................................

New position ......................................................................................................................

...........................................................................................................................................
[2]

© UCLES 2021 9618/21/M/J/21


MUHAMMAD ALI KHAN
PAGE 1015

14

5 A global 2D array Result of type INTEGER is used to store a list of exam candidate numbers
together with their marks. The array contains 2000 elements, organised as 1000 rows and
2 columns.

Column 1 contains the candidate number and column 2 contains the mark for the corresponding
candidate. All elements contain valid exam result data.

A procedure Sort() is needed to sort Result into ascending order of mark using an efficient
bubble sort algorithm.

Write pseudocode for the procedure Sort().

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

© UCLES 2021 9618/21/M/J/21


PAGE 1016

15

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [8]

© UCLES 2021 9618/21/M/J/21 [Turn over


MUHAMMAD ALI KHAN
PAGE 1017

16

6 The following diagram represents an Abstract Data Type (ADT) for a linked list.

A C D E Ø

The free list is as follows:

(a) Explain how a node containing data value B is added to the list in alphabetic sequence.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]

(b) Describe how the linked list in part (a) may be implemented using variables and arrays.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2021 9618/21/M/J/21


PAGE 1018

18

7 A program is needed to take a string containing a full name and produce a new string of initials.

Some words in the full name will be ignored. For example, "the", "and", "of", "for" and "to" may all
be ignored.

Each letter of the abbreviated string must be upper case.

For example:

Full name Initials

Integrated Development Environment IDE

The American Standard Code for Information Interchange ASCII

The programmer has decided to use a global variable FNString of type STRING to store the full
name.

It is assumed that:

• words in the full name string are separated by a single space character
• space characters will not occur at the beginning or the end of the full name string
• the full name string contains at least one word.

The programmer has started to define program modules as follows:

Module Description
• Called with an INTEGER as a parameter, representing the number of a
word in FNString.
GetStart()
• Returns the character start position of that word in FNString or
returns –1 if that word does not exist
• For example: if FNString contains the string "hot and cold",
GetStart(3) returns 9
• Called with a parameter representing the position of the first character
of a word in FNString
GetWord() • Returns the word from FNString
• For example: if FNString contains the string "hot and cold",
GetWord(9) returns "cold"

© UCLES 2021 9618/21/M/J/21


MUHAMMAD ALI KHAN
PAGE 1019

19

(a) Write pseudocode for the module GetStart().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2021 9618/21/M/J/21 [Turn over


PAGE 1020

20

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

(b) The programmer has decided to use a global ten-element 1D array IgnoreList of type
STRING to store the ignored words. Unused elements contain the empty string ("") and may
occur anywhere in the array.

A new module AddWord() is needed as follows:

Module Description
• Called with a parameter representing a word
• Stores the word in an unused element of the IgnoreList array
AddWord() and returns TRUE
• Returns FALSE if the array was already full or if the word was
already in the array

Write a detailed description of the algorithm for AddWord(). Do not include pseudocode
statements in your answer.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]

© UCLES 2021 9618/21/M/J/21


MUHAMMAD ALI KHAN
PAGE 1021

21

(c) As a reminder, the module description of GetWord() is repeated:

Module Description
• Called with a parameter representing the position of the first
character of a word in FNString
GetWord() • Returns the word from FNString
• For example: if FNString contains the string "hot and cold",
GetWord(9) returns "cold"

Write pseudocode for the module GetWord().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]
© UCLES 2021 9618/21/M/J/21
PAGE 1022

22

BLANK PAGE

© UCLES 2021 9618/21/M/J/21


MUHAMMAD ALI KHAN
PAGE 1023

23

BLANK PAGE

© UCLES 2021 9618/21/M/J/21


PAGE 1024

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.

© UCLES 2021 9618/21/M/J/21


MUHAMMAD ALI KHAN
PAGE 1025
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

1(a) 4
Example
Explanation Variable name Data type
value

"Wong" The preferred name of the MemberName STRING


member joining the
football club

FALSE A value to indicate FamilyMember BOOLEAN


whether an existing
member of the club lives
at the same address

19/02/1983 When the member joined StartDate DATE


the football club

1345 The number of points a Points INTEGER


member has earned.
Members of the club earn
points for different
activities.

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

SubString ← MID("pseudocode", 4, 1) NO ERROR

Not Boolean values /


IF x = 3 OR 4 THEN incorrect operator //
Condition incorrect

INT(X/2) doesn't evaluate


Result ← Status AND INT(X/2) to a boolean value /
incorrect operator

Can’t add string to number /


Message ← "Done" + LENGTH(MyString)
"Done" is not a number

One mark for each row

© UCLES 2021 Page 3 of 16


PAGE 1026
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

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

© UCLES 2021 Page 4 of 16


MUHAMMAD ALI KHAN
PAGE 1027
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

2(a) 5

One mark for:

1 All four boxes correctly labelled and positioned


2 Selection diamond (only on UpdateLoan and no iteration arrows)
3 Parameters to and from LoanExtend()
4 Parameters to and from CheckReserve()
5 Parameters to and from LoanReturn()

2(b) PROCEDURE LoanReturn (LoanID, BookID : STRING, 2


BYREF Fine : REAL)

One mark for each underlined part

© UCLES 2021 Page 5 of 16


PAGE 1028
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

2(c) Example solution: 6

One mark for each functional group as listed below:

© UCLES 2021 Page 6 of 16


MUHAMMAD ALI KHAN
PAGE 1029
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

2(c) Explanation of mark points:


1 Initialise MAX to first value input
2 Set Total to zero
3 Input 49 more values (or 50 values in total)
4 Sum all values input
5 Set new MAX when Input value > MAX in a loop
6 Sum all but largest (or subtract MAX from total), calculate and output
average

Question Answer Marks

3(a)(i) One mark per bullet point: 2

• 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

Note: Max 2 marks

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

3(a)(iii) One mark per bullet point: 2

• 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:

• Convert all data items / 'number of people' to strings


• Consecutive / each line stores a separate data item

© UCLES 2021 Page 7 of 16


PAGE 1030
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

3(b) PROCEDURE Preview (ThisFile : STRING) 5


DECLARE LineNum : INTEGER
DECLARE ThisLine : STRING

OPENFILE ThisFile FOR READ


IF EOF(ThisFile) THEN
OUTPUT “Warning Message”
ELSE
LineNum ← 1
WHILE LineNum < 6 AND NOT EOF(ThisFile)
READFILE Thisfile, ThisLine
OUTPUT ThisLine
LineNum ← LineNum + 1
ENDWHILE
ENDIF
CLOSEFILE ThisFile
ENDPROCEDURE

Marks as follows:

1 Procedure heading (including parameter) and ending


2 File OPEN and subsequently CLOSE
3 Check if file is empty and output a warning message if it is
4 Conditional Loop
5 Output line (including blank lines) and read next line in a loop

© UCLES 2021 Page 8 of 16


MUHAMMAD ALI KHAN
PAGE 1031
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

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"

FALSE 11 "∇In∇A∇∇Cup" 'p'

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)

© UCLES 2021 Page 9 of 16


PAGE 1032
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

4(b) Loop structure: A count-controlled loop 2

Justification: The number of iterations is known

One mark per point

4(c)(i) A couple of solutions: 1

24 ThisChar ← LCASE(MID(Name, Index, 1)

ALTERNATIVE:

31 NewName ← NewName & LCASE(ThisChar)

Ignore line number

4(c)(ii) One mark for each: 2

Line number: 26

New position: Move to after line 27 / line 28

© UCLES 2021 Page 10 of 16


MUHAMMAD ALI KHAN
PAGE 1033
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

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

Question Answer Marks

6(a) One mark per point: 4

1 Check for a free node


2 Search for correct insertion point
3 Assign data value B to first node in free list / node pointed to by start
pointer of free list
4 Pointer from A will be changed to point to node containing B (instead of
C)
5 Pointer from B will be changed to point to node containing C
6 Start pointer in free list moved to point to next free node

Note: max 4 marks

© UCLES 2021 Page 11 of 16


PAGE 1034
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

6(b) One mark per point: 2

• 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

© UCLES 2021 Page 12 of 16


MUHAMMAD ALI KHAN
PAGE 1035
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

7(a) FUNCTION GetStart (WordNum : INTEGER) RETURNS INTEGER 7


DECLARE Index, ThisPos, NumFound : INTEGER
DECLARE ThisChar : Char

CONSTANT SPACECHAR = ' '

Index ← -1
Numfound ← 0
ThisPos ← 1

IF WordNum = 1 THEN // if looking for word 1...


Index ← 1 // Word 1 always starts at index
// position 1
ELSE
// Otherwise start counting spaces...
WHILE ThisPos <= LENGTH(FNString) AND Index = -1
ThisChar ← MID(FNString, ThisPos, 1)
IF ThisChar = SPACECHAR THEN
NumFound ← NumFound + 1
IF NumFound = WordNum - 1 THEN
Index ← ThisPos + 1 // the start of the
// required word
ENDIF
ENDIF
ThisPos ← ThisPos + 1
ENDWHILE
ENDIF
RETURN Index

ENDFUNCTION

1 mark for each of the following:

1 Function heading, including return type and function end


2 Loop counting spaces until word found or end of FNString
3 extract a character from FNString in a loop
4 compare with SPACECHAR and increment count if equal in a loop
5 compare count with WordNum - 1 (depending on initialisation
value) in a loop
6 if equal then set flag or Index to ThisPos + 1 in a loop
7 Return Index (correctly in all cases / following a reasonable attempt)
8 Works for special case when looking for word 1

Note: Max 7 marks

© UCLES 2021 Page 13 of 16


PAGE 1036
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

7(b) Marks awarded for any reference to each of the following steps of the algorithm: 4

1 Mention of variable for use as array index


2 Use of a loop (to check through the array)
3 If word is the same as the current array element then return FALSE /
set flag
4 If word not already in array, loop to find unused element (second loop)
5 Store word in unused element and return TRUE, otherwise return
FALSE

VARIATION:

1 Mention of variable for use as array index


2 Use of a loop (to check through the array)
3 Save index of (first) unused element found
4 If word is the same as the current array element then return FALSE /
set flag
5 If word not already in array and unused element available, store word in
unused element and return TRUE otherwise return FALSE

Note: Max 4 marks

© UCLES 2021 Page 14 of 16


MUHAMMAD ALI KHAN
PAGE 1037
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

7(c) FUNCTION GetWord (Index : INTEGER) RETURNS STRING 5

DECLARE NextWord : STRING


DECLARE Done : BOOLEAN
DECLARE ThisChar : CHAR
DECLARE Index : INTEGER

CONSTANT SPACECHAR = ' '

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

UNTIL Done = TRUE

RETURN NextWord

ENDFUNCTION

1 mark for each of the following:

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)

© UCLES 2021 Page 15 of 16


PAGE 1038
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

7(c) The ‘length and substring’ solution:

FUNCTION GetWord (Index : INTEGER) RETURNS STRING


DECLARE Done : BOOLEAN
DECLARE ThisChar : CHAR
DECLARE Index, NextPos : INTEGER

CONSTANT SPACECHAR = ' '

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

IF NextPos = LENGTH(FNString) THEN


NextPos ← NextPos - 1 // special case when last word
ENDIF

RETURN MID(FNString, Index, NextPos - Index)

ENDFUNCTION

1 mark for each of the following:

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

© UCLES 2021 Page 16 of 16


MUHAMMAD ALI KHAN
PAGE 1039

Cambridge International AS & A Level


* 3 0 1 3 8 0 7 6 7 4 *

COMPUTER SCIENCE 9618/22


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2021
2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 16 pages. Any blank pages are indicated.

DC (MB/FC) 200588/5
© UCLES 2021 [Turn over
PAGE 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.

Variable Example data value Data type


Name "Catherine"
Index 100
Modified FALSE
Holiday 25/12/2020
[4]

(ii) Evaluate each expression in the following table by using the initial data values shown in
part (a)(i).

Expression Evaluates to
Modified OR Index > 100
LENGTH("Student: " & Name)
INT(Index + 2.9)
MID(Name, 1, 3)
[4]

(b) Each pseudocode statement in the following table contains an example of selection,
assignment or iteration.

Put one tick (‘’) in the appropriate column for each statement.

Statement Selection Assignment Iteration


Index Index + 1
IF Modified = TRUE THEN
ENDWHILE
[3]

© UCLES 2021 9618/22/M/J/21


MUHAMMAD ALI KHAN
PAGE 1041

2 (a) Examine the following state-transition diagram.

Low level detected | Activate pump

Low level detected

X S2
S1

Normal level detected Normal level detected | Deactivate pump


S3

(i) Complete the table with reference to the diagram.

Answer
The number of transitions that result in a different state
The number of transitions with associated outputs
The label that should replace ‘X’
The final or halting state
[4]

(ii) The current state is S1. The following inputs occur.

1. Low level detected


2. Low level detected
3. Low level detected
4. Low level detected

Give the number of outputs and the current state.

Number of outputs .............................................................................................................

Current state .....................................................................................................................


[2]

© UCLES 2021 9618/22/M/J/21 [Turn over


PAGE 1042

(b) A system is being developed to help manage book loans in a library.

Registered users may borrow books from the library for a period of time.

(i) State three items of data that must be stored for each loan.

1 ........................................................................................................................................

2 ........................................................................................................................................

3 ........................................................................................................................................
[2]

(ii) State one item of data that will be required in the library system but does not need to be
stored for each loan.

..................................................................................................................................... [1]

(iii) One operation that manipulates the data stored for each loan, would produce a list of all
overdue books.

Identify two other operations.

Operation 1 .......................................................................................................................

...........................................................................................................................................

Operation 2 .......................................................................................................................

...........................................................................................................................................
[2]

© UCLES 2021 9618/22/M/J/21


MUHAMMAD ALI KHAN
PAGE 1043

3 The following diagram represents an Abstract Data Type (ADT).

A B
Dolphin Cat Fish Elk

(a) Identify this type of ADT.

............................................................................................................................................. [1]

(b) Give the technical term for the item labelled A in the diagram.

............................................................................................................................................. [1]

(c) Give the technical term for the item labelled B in the diagram.

Explain the meaning of the value given to this item.

Term ..........................................................................................................................................

Meaning ....................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[2]

(d) Complete the diagram to show the ADT after the data has been sorted in alphabetical order.

Dolphin Cat Fish Elk

[2]

© UCLES 2021 9618/22/M/J/21 [Turn over


PAGE 1044

4 A teacher uses a paper-based system to store marks for a class test. The teacher requires a
program to assign grades based on these results.

The program will output the grades together with the average mark.

Write a detailed description of the algorithm that will be needed.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [6]

© UCLES 2021 9618/22/M/J/21


MUHAMMAD ALI KHAN
PAGE 1045

5 (a) A student is learning about arrays.

She wants to write a program to:

• declare a 1D array RNum of 100 elements of type INTEGER


• assign each element a random value in the range 1 to 200 inclusive
• count and output how many numbers generated were between 66 and 173 inclusive.

(i) Write pseudocode to represent the algorithm.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [6]

(ii) The student decides to modify the algorithm so that each element of the array will contain
a unique value.

Describe the changes that the student needs to make to the algorithm.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

© UCLES 2021 9618/22/M/J/21 [Turn over


PAGE 1046

(b) The following is a pseudocode function.

Line numbers are given for reference only.

01 FUNCTION StringClean(InString : STRING) RETURNS STRING


02
03 DECLARE NextChar : CHAR
04 DECLARE OutString : STRING
05 DECLARE Counter : INTEGER
06
07 OutString ""
08
09 FOR Counter 1 TO LENGTH(InString)
10 NextChar MID(InString, Counter, 1)
11 NextChar LCASE(NextChar)
12 IF NOT((NextChar < 'a') OR (NextChar > 'z')) THEN
13 OutString OutString & NextChar
14 ENDIF
15 NEXT Counter
16
17 RETURN OutString
18
19 ENDFUNCTION

(i) Examine the pseudocode and complete the following table.

Answer

Give a line number containing an example of an initialisation statement.

Give a line number containing the start of a repeating block of code.

Give a line number containing a logic operation.

Give the number of parameters to the function MID().


[4]

(ii) Write a simplified version of the statement in line 12.

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2021 9618/22/M/J/21


MUHAMMAD ALI KHAN
PAGE 1047

10

6 A procedure CountVowels() will:

• be called with a string containing alphanumeric characters as its parameter


• count and output the number of occurrences of each vowel (a, e, i, o, u) in the string
• count and output the number of occurrences of the other alphabetic characters (as a single
total).

The string may contain both upper and lower case characters.

Each count value will be stored in a unique element of a global 1D array CharCount of type
INTEGER. The array will contain six elements.

Write pseudocode for the procedure CountVowels().

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

© UCLES 2021 9618/22/M/J/21


PAGE 1048

11

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [8]

7 A procedure, FormatName():

• is called with a string containing words and spaces as its parameter. In this context, a word is
any sequence of characters that does not contain a space character.

• creates a new formatted string from this string with the following requirements:
1. Any leading spaces removed (spaces before the first word).
2. Any trailing spaces removed (spaces after the last word).
3. Any multiple spaces between words converted to a single space.
4. All characters converted to lower case.

The FormatName() procedure has been written in a programming language and is to be tested
using the black-box method.

(a) Give a test string that could be used to show that all four formatting requirements have been
applied correctly.

Use the symbol ‘”’ to represent a space character.

............................................................................................................................................. [3]

(b) The FormatName() procedure should assign a value to the global variable FString.

There is a fault in the program, which means that the assignment does not always take place.

Explain two ways of exposing the fault.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2021 9618/22/M/J/21 [Turn over


MUHAMMAD ALI KHAN
PAGE 1049

12

8 A program is needed to take a string containing a full name and to produce a new string of initials.

Some words in the full name will be ignored. For example, “the”, “and”, “of”, “for” and “to” may all
be ignored.

Each letter of the new string must be upper case.

For example:

Full name Initials


Integrated Development Environment IDE
The American Standard Code for Information Interchange ASCII

The programmer has decided to use the following global variables:

• a ten element 1D array IgnoreList of type STRING to store the ignored words
• a string FNString to store the full name string.

Assume that:

• each alphabetic character in the full name string may be either upper or lower case
• the full name string contains at least one word.

The programmer has started to define program modules as follows:

Module Description
• Called with an INTEGER as its parameter, representing the number of
a word in FNString
GetStart() • Returns the character start position of that word in FNString or
returns -1 if that word does not exist
• For example: GetStart(3) applied to "hot and cold" returns 9
• Called with the position of the first character of a word in FNString
as its parameter
GetWord() • Returns the word from FNString
• For example: if FNString contains the string "hot and cold",
GetWord(9) returns "cold"
• Called with a STRING parameter representing a word
IgnoreWord() • Searches for the word in the IgnoreList array
• Returns TRUE if the word is found, otherwise returns FALSE
• Processes the sequence of words in the full name one word at a time
GetInitials()
• Calls GetStart(), GetWord() and IgnoreWord() to process
each word to form the new string
• Outputs the new string

© UCLES 2021 9618/22/M/J/21


PAGE 1050

13

(a) Write pseudocode for the module IgnoreWord().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

© UCLES 2021 9618/22/M/J/21 [Turn over


MUHAMMAD ALI KHAN
PAGE 1051

14

(b) Write pseudocode for the module GetInitials().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]
© UCLES 2021 9618/22/M/J/21
PAGE 1052
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

1(a)(i) 4
Variable Example data value Data type

Name "Catherine" STRING

Index 100 INTEGER

Modified FALSE BOOLEAN

Holiday 25/12/2020 DATE

One mark per data type

1(a)(ii) 4
Expression Evaluates to

Modified OR Index > 100 FALSE

LENGTH("Student: " & Name) 18

INT(Index + 2.9) 102

MID(Name, 1, 3) "Cat"

One mark per value


Quotation marks must be present for final row and must be capital C

1(b) 3
Statement Selection Assignment Iteration

Index ← Index + 1 9

IF Modified = TRUE THEN 9

ENDWHILE 9

One mark per row

Question Answer Marks

2(a)(i) 4
The number of transitions that result in a different state 3

The number of transitions with associated outputs 2

The label that should replace ‘X’ Start

The final or halting state S3

One mark per row

© UCLES 2021 Page 3 of 10


MUHAMMAD ALI KHAN
PAGE 1053
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

2(a)(ii) Number of outputs: 1 2

Current state: S2

2(b)(i) Answers include: 2

• User ID / Username
• Book ID
• Date of loan / return date

One mark for 1 correct


Two marks for all 3 correct

Note: Max 2 marks

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.

Note: must be data relating to users, books or loans

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)

2(b)(iii) Many examples including: 2

• Create loan / borrow book


• Return book
• Send letter / email / contact a user ref an overdue book
• View the loan history for a given book
• View the loan history for a given user

One mark for each

Note: Max 2 marks

Question Answer Marks

3(a) Linked list 1

3(b) Start pointer 1

3(c) One mark for each: 2

Name: Null pointer

Meaning: There are no further nodes in the list

© UCLES 2021 Page 4 of 10


PAGE 1054
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

3(d) 2

One mark for:

• Start Pointer pointing to ‘Cat’ node


• Remaining arrows: Cat → Dolphin → Elk → Fish

Question Answer Marks

4 Marks awarded for a description of each of the following steps of the 6


algorithm:

1 Reference variables for Count of students and Total marks


2 Loop through all students (Count)
3 Input individual mark (in loop)
4 Compare mark with threshold / boundary values to determine grade
(in loop)
5 Output the grade for a student (in loop)
6 Maintain a Total (and Count if required) (in loop)
7 Calculate average by dividing Total by Count and Output (after loop)

Note: Max 6 marks

© UCLES 2021 Page 5 of 10


MUHAMMAD ALI KHAN
PAGE 1055
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

5(a)(i) DECLARE RNum : ARRAY[1:100] OF INTEGER 6


DECLARE Index, Count : INTEGER

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(a)(ii) One mark per bullet / sub-bullet point 3

1 Initialise the array to a rogue value (to indicate 'unassigned' element)


2 Add a conditional loop to:
3 Generate and store a random number (in the correct range)
4 Check the stored number against values already in the array
5 If the stored number is found then generate another random value
6 Otherwise add it to the array (and exit loop)

Note: Max 3 marks

5(b)(i) 4
Answer

Give a line number containing an example of an 07


initialisation statement.

Give a line number containing the start of a repeating 09 / 10


block of code.

Give a line number containing a logic statement. 12

Give the number of parameters of function MID(). 3

One mark for each row

5(b)(ii) IF (NextChar >= 'a') AND (NextChar <= 'z') THEN 2

One mark for IF ... AND ...


One mark for both conditions

© UCLES 2021 Page 6 of 10


PAGE 1056
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

6 PROCEDURE CountVowels(ThisString : STRING) 8

DECLARE Index : INTEGER


DECLARE ThisChar : CHAR

FOR Index ← 1 to 6
CharCount[Index] ← 0 //initialise elements
NEXT Index
Index ← 1

FOR Index ← 1 TO LENGTH(ThisString)


ThisChar ← LCASE(MID(ThisString, 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

1 mark for each of the following:

1 Procedure heading (with parameter) and ending


2 Declare local variable for Index as loop counter but not CharCount
array
3 Initialise elements of CharCount array to zero
4 Loop through all characters in ThisString
5 Use of MID() to extract single character
6 Test for each vowel and increment associated count
7 Test for consonants and increment associated count
8 Output the results (supporting text not necessary) after the loop

Note: Max 7 if CharCount not used to store count

© UCLES 2021 Page 7 of 10


MUHAMMAD ALI KHAN
PAGE 1057
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

7(a) Test string should contain: 3

• At least one leading space (before the first word)


• at least one trailing space (after the last word)
• at least one instance of multiple spaces between words
• At least one upper case character

Mark as follows:
One mark for one correct
Two marks for three correct
Three marks for all correct

7(b) One mark for each: 2

• Dry run / produce a trace table / walk through the code


• Add output statements to allow the code to be tracked
• Insert a Breakpoint into the program // use single-stepping to execute
instructions // monitor variables using a watch window
• Try different test values to see which ones fail

Note: Max 2 marks

© UCLES 2021 Page 8 of 10


PAGE 1058
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

8(a) FUNCTION IgnoreWord (ThisWord : STRING) RETURNS BOOLEAN 5

DECLARE Found : BOOLEAN


DECLARE Index : INTEGER

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

1 mark for each of the following:

1 Loop through array elements


2 Convert both strings to same case
3 Compare array element with parameter in a loop
4 Set a flag (or similar) if match found (after reasonable attempt at
MP3) in a loop
5 Return TRUE or FALSE in all cases

Note: Max 4 if function declaration incorrect

© UCLES 2021 Page 9 of 10


MUHAMMAD ALI KHAN
PAGE 1059
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

8(b) Procedure GetInitials() 8

DECLARE NewString, NextWord : STRING


DECLARE ThisWordNum, Index : INTEGER

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

1 mark for each of the following:


1 Declare NewString and initialise to empty string
2 Conditional loop to pick out all words from FNString
3 Evaluate result of GetStart() in a loop
4 Test result <> -1 and if not:
5 Assign result of GetWord()to a variable in a loop
6 Test result of IgnoreWord()in a loop
7 If not ignored, add the next initial letter to NewString in a
loop
8 Increment ThisWordNum (must have been initialised) in a loop
9 Output NewString (must be all upper case) outside loop

Note: Max 8 marks

© UCLES 2021 Page 10 of 10


PAGE 1060

Cambridge International AS & A Level


* 2 3 9 0 7 0 8 1 6 9 *

COMPUTER SCIENCE 9618/21


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2021
2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (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.

Type of error ......................................................................................................................

Description ........................................................................................................................

...........................................................................................................................................
[2]

(b) Complete the following table by giving the appropriate data type in each case.

Use of variable Data type


The average mark in a class of 40 students
An email address
The number of students in the class
To indicate whether an email has been read
[4]

© UCLES 2021 9618/21/O/N/21


PAGE 1062

(c) An airline wants to provide passengers with information about individual flights and allow
them to book their flight using an online booking system.

(i) Tick () one box in each row of the table to indicate whether each item of information
would be essential for the customer when making the booking.

Information Essential Not essential


Departure time
Flight number
Departure airport
Aircraft type
Ticket price
Number of seats in aircraft
[3]

(ii) Identify the technique used to filter out information that is not essential when designing
the booking system and state one benefit of this technique.

Technique ..........................................................................................................................

Benefit ...............................................................................................................................

...........................................................................................................................................
[2]

(iii) Identify two additional pieces of essential information that a passenger might need
when booking a flight.

1 ........................................................................................................................................

2 ........................................................................................................................................
[2]

© UCLES 2021 9618/21/O/N/21 [Turn over


MUHAMMAD ALI KHAN
PAGE 1063

2 (a) An algorithm to sort a 1D array into ascending order is described as follows:

• move the largest value to the end


• keep repeating until the array is sorted.

Apply the process of stepwise refinement to this algorithm in order to produce a more detailed
description.

Write the more detailed description using structured English. Your explanation of the
algorithm should not include pseudocode statements.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2021 9618/21/O/N/21 [Turn over


PAGE 1064

(b) The program flowchart shown describes a simple algorithm.

START

Set Count to 1

Set Flag to FALSE

Is Flag = YES
FALSE AND
Count <= 5 ?

NO
ReBoot()

Set Count to Count + 1

Set Flag to Check()

Is Flag = YES
FALSE ?

NO
Alert(27)

END

© UCLES 2021 9618/21/O/N/21


MUHAMMAD ALI KHAN
PAGE 1065

Write pseudocode for the simple algorithm shown on page 6.

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

............................................................................................................................................................ [6]

© UCLES 2021 9618/21/O/N/21 [Turn over


PAGE 1066

3 (a) The diagram below represents a queue Abstract Data Type (ADT) that can hold a maximum
of eight items.

The operation of this queue may be summarised as follows:

• The front of queue pointer points to the next item to be removed.


• The end of queue pointer points to the last item added.
• The queue is circular so that empty storage elements can be reused.

0 Frog Front of queue pointer


1 Cat
2 Fish
3 Elk End of queue pointer
4
5
6
7

(i) Describe how “Octopus” is added to the given queue.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(ii) Describe how the next item in the given queue is removed and stored in the variable
AnimalName.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(iii) Describe the state of the queue when the front of queue and the end of queue pointers
have the same value.

...........................................................................................................................................

..................................................................................................................................... [1]

© UCLES 2021 9618/21/O/N/21


MUHAMMAD ALI KHAN
PAGE 1067

(b) Some operations are carried out on the original queue given in part (a).

(i) The current state of the queue is:

0 Frog
1 Cat
2 Fish
3 Elk
4
5
6
7

Complete the diagram to show the state of the queue after the following operations:

Add “Wasp”, “Bee” and “Mouse”, and then remove two data items.
[3]

(ii) The state of the queue after other operations are carried out is shown:

0 Frog
1 Cat
2 Fish
3 Elk Front of queue pointer
4 Wasp
5 Bee
6 Mouse End of queue pointer
7 Ant

Complete the following diagram to show the state of the queue after the following
operations:

Remove one item, and then add “Dolphin” and “Shark”.

0
1
2
3
4
5
6
7
[2]
© UCLES 2021 9618/21/O/N/21 [Turn over
PAGE 1068

10

(c) The queue is implemented using a 1D array.

Describe the algorithm that should be used to modify the end of queue pointer when adding
an item to the queue.

Your algorithm should detect any potential error conditions.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2021 9618/21/O/N/21


MUHAMMAD ALI KHAN
PAGE 1069

11

4 A program controls the heating system in a sports hall.

Part of the program involves reading a value from a sensor. The sensor produces a numeric value
that represents the temperature. The value is an integer, which should be in the range 0 to 40
inclusive.

A program function has been written to validate the values from the sensor.

(a) A test plan is needed to test the function.

Complete the table. The first line has been completed for you.

You can assume that the sensor will generate only integer data values.

Test Test data value Explanation Expected outcome


1 23 Normal data Data is accepted
2
3
4
5
[4]

(b) A program module controls the heaters. This module operates as follows:

• If the temperature is below 10, switch the heaters on.


• If the temperature is above 20, switch the heaters off.

Complete the following state-transition diagram for the heating system:

Start
Heaters Heaters
Off On

[3]

© UCLES 2021 9618/21/O/N/21 [Turn over


PAGE 1070

12

5 The following data items will be recorded each time a student successfully logs on to the school
network:

Data item Example data


Student ID "CJL404"
Host ID "Lib01"
Time and date "08:30, June 01, 2021"

The Student ID is six characters long. The other two data items are of variable length.

A single string will be formed by concatenating the three data items. A separator character will
need to be inserted between items two and three.

For example:

"CJL404Lib01<separator>08:30, June 01, 2021"

Each string represents one log entry.

A programmer decides to store the concatenated strings in a 1D array LogArray that contains
2000 elements. Unused array elements will contain an empty string.

(a) Suggest a suitable separator character and give a reason for your choice.

Character ..................................................................................................................................

Reason .....................................................................................................................................

...................................................................................................................................................
[2]

(b) The choice of data structure was made during one stage of the program development life
cycle.

Identify this stage.

............................................................................................................................................. [1]

© UCLES 2021 9618/21/O/N/21


MUHAMMAD ALI KHAN
PAGE 1071

13

(c) A function LogEvents() will:

• take a Student ID as a parameter


• for each element in the array that matches the Student ID parameter:
ƕ add the value of the array element to the existing text file LogFile
ƕ assign an empty string to the array element
• count the number of lines added to the file
• return this count.

Write pseudocode for the function LogEvents().

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [7]
© UCLES 2021 9618/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.

Many array elements are set to 1 by a single touch of a finger or a stylus.

The following diagram shows a simplified touchscreen. The dark line represents a touch to the
screen. All grid elements that are wholly or partly inside the outline will be set to 1. These elements
are shaded.
The element shaded in black represents the centre point.

11

A program is needed to find the coordinates (the row and column) of the centre point. The centre
point on the diagram above is row 6, column 11.

Assume:

• the user may only touch one area at a time


• screen rotation does not affect the touchscreen.

The programmer has started to define program modules as follows:

Module Description
• Called with three parameters of type INTEGER:
SetRow() ƕa row number
(generates test ƕthe number of pixels to be skipped starting from column 1
data) ƕthe number of pixels that should be set to 1
• Sets the required number of pixels to 1
For example, SetRow(3, 8, 5) will give row 3 as in the diagram shown.
• Takes two parameters of type INTEGER:
ƕa row number
ƕa start column (1 or 1280)
SearchInRow() • Searches the given row from the start column (either left to right or right to left)
for the first column that contains an element set to 1
• Returns the column number of the first element in the given row that is set to 1
• 5HWXUQVíLIQRHOHPHQWLVVHWWR
• Takes two parameters of type INTEGER:
ƕ
a column number
ƕ
a start row (1 or 800)
SearchInCol() • Searches the given column from the start row (either up or down) for the first
row that contains an element set to 1
• Returns the row number of the first element in the given column that is set to 1
• 5HWXUQVíLIQRHOHPHQWLVVHWWR

© UCLES 2021 9618/21/O/N/21


MUHAMMAD ALI KHAN
PAGE 1073

15

(a) Write pseudocode to implement the module SetRow().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

© UCLES 2021 9618/21/O/N/21 [Turn over


PAGE 1074

16

(b) The module description of SearchInRow() is provided here for reference.

Module Description
• Takes two parameters of type INTEGER:
ƕa row number
ƕa start column (1 or 1280)
SearchInRow() • Searches the given row from the start column (either left to right or right to left)
for the first column that contains an element set to 1
• Returns the column number of the first element in the given row that is set to 1
• 5HWXUQVíLIQRHOHPHQWLVVHWWR

Write pseudocode to implement the module SearchInRow().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2021 9618/21/O/N/21
MUHAMMAD ALI KHAN
PAGE 1075

17

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

(c) The following new module is introduced:

Module Description
• Called with a row number as an INTEGER
• Uses SearchInRow() to find the first and last columns in the given row which
GetCentreCol() have an array element set to 1
• Returns the index of the column midway between the first and last columns
• 5HWXUQVíLIQRHOHPHQWLVVHWWR

Write pseudocode to implement the module GetCentreCol().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...............................................................................................................................................[6]
© UCLES 2021 9618/21/O/N/21
PAGE 1076
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

1(a)(i) One from: 1

• The program obeys the rules / grammar of the programming language


used
• The program will run // it can be compiled / interpreted
• Accept by example. e.g. 'no mis-spelt keywords' / 'all brackets match'

1(a)(ii) One mark for type plus one for corresponding description 2

Type of error: A logic error

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

Type of error: Run-time error

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

The average mark in a class of 40 students REAL

An email address STRING

The number of students in the class INTEGER

Indicate whether an email has been read BOOLEAN

One mark per row

© UCLES 2021 Page 3 of 11


MUHAMMAD ALI KHAN
PAGE 1077
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

1(c)(i) 3
Information Essential Not essential

Departure time 9

Flight Number 9

Departure airport 9

Aircraft type 9

Ticket price 9

Number of seats in aircraft 9

One mark for two rows correct


Two mark for four rows correct
Three mark for all rows correct

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

1(c)(iii) Answers include: 2

• Destination / arrival airport


• Arrival time / flight duration
• Date of flight
• Seat number
• Seat availability

Max 2 marks

Question Answer Marks

2(a) One mark for reference to: 6

1 The use a variable as an index to the array


2 A loop to iterate through the array
3 An Inner loop (with a reducing range)
4 Test if current element is greater than next element
5 if so then swap elements
6 Description of swap
7 Attempt at efficient algorithm

Max 6 marks

© UCLES 2021 Page 4 of 11


PAGE 1078
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

2(b) Count ← 1 6
Flag ← FALSE
WHILE Flag = FALSE AND Count <= 5
CALL ReBoot()
Count ← Count + 1
Flag ← Check()
ENDWHILE

IF Flag = FALSE THEN


CALL Alert(27)
ENDIF

One mark per point:

1 Initialisation of Count AND Flag


2 WHILE ... ENDWHILE // REPEAT ... UNTIL loop
3 ... including both conditions
4 Call ReBoot() AND increment Count inside the loop
5 Assign return value from Check() to Flag inside the loop
6 Final test of Flag AND call to Alert(27) not in a loop

Question Answer Marks

3(a)(i) One mark per point: 2

• EoQ pointer will move to point to location 4 // incremented EoQ (by 1)


• Data value "Octopus" will be stored in location pointed to be EoQ /
location 4

3(a)(ii) One mark for each bullet 2

• Value "Frog" // value pointed to by FoQ / location 0 is assigned to variable


AnimalName
• FoQ pointer will move to point to location 1 / point to "Cat" // incremented
FoQ (by 1)

0 Frog ← Front of queue pointer

1 Cat

2 Fish

3 Elk ← End of queue pointer

3(a)(iii) There is only one data item in the queue 1

© UCLES 2021 Page 5 of 11


MUHAMMAD ALI KHAN
PAGE 1079
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

3(b)(i) One mark for data values plus one mark for pointers 3

0 Frog

1 Cat

2 Fish ← Front of queue pointer

3 Elk

4 Wasp

5 Bee

6 Mouse ← End of queue pointer

One mark for each pointer


One mark for three new data values

3(b)(ii) 2
0 Shark ← End of queue pointer

1 (Cat)

2 (Fish)

3 (Elk)

4 Wasp ← Front of queue pointer

5 Bee

6 Mouse

7 Dolphin

One mark for BOTH pointers


One mark for all data values as shown

3(c) One mark per point: 3

1 If incremented EoQ = FoQ then error condition: queue is full


2 Increment the EoQ
3 Manage wrap-around

© UCLES 2021 Page 6 of 11


PAGE 1080
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

4(a) 4
Test Test data value Explanation Expected Outcome

1 23 Normal Data Data is accepted

2 0 Boundary Data Data is accepted

3 40 Boundary Data Data is accepted

4 >= 41 Abnormal Data Data is rejected

5 <= í1 Abnormal Data Data is rejected

One mark per row for rows 2 to 5.

4(b) 3

One mark for each label:

• Temp < 10 (Heaters Off to Heaters On)


• Temp > 20 (Heaters On to Heaters Off)
• on BOTH loops (non-contradictory values)

Question Answer Marks

5(a) One mark for the character and one for the corresponding reason. 2

• Character: Any except alphabetic, numeric, ',' ':' or space

• Reason: character doesn't occur in data to be recorded

5(b) Design 1

© UCLES 2021 Page 7 of 11


MUHAMMAD ALI KHAN
PAGE 1081
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

5(c) FUNCTION LogEvents(StudentID : STRING) RETURNS INTEGER 7

DECLARE FileData : STRING


DECLARE Index, Count : INTEGER

CONSTANT LogFile = "LogFile"

Count ← 0
OPENFILE LogFile FOR APPEND
FOR Index ← 1 TO 2000
FileData ← LogArray[Index]

IF LEFT(FileData, 6) = StudentID THEN


WRITEFILE (LogFile, FileData) //brackets optional
Count ← Count + 1
LogArray[Index] ← "" // clear the element
ENDIF
NEXT Index

CLOSEFILE LogFile

RETURN Count

ENDFUNCTION

1 mark for each of the following:

1 Function heading and ending including parameter and return type


2 OPEN file LogFile for APPEND and subsequent CLOSE
3 Loop for 2000 iterations
4 Extract first 6 characters from array element in a loop
5 Compare first 6 characters with parameter in a loop
6 If equal:
• write whole array element string to file and
• increment Count and
• clear array element in a loop
7 Return Count (must have been declared and initialised)

© UCLES 2021 Page 8 of 11


PAGE 1082
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

6(a) PROCEDURE SetRow(Row, SkipNum, SetNum : INTEGER) 5


DECLARE Col : INTEGER

// array is 1280 x 800

FOR Col ← SkipNum + 1 TO SkipNum + SetNum


Screen[Row, Col] ← 1
NEXT Index

ENDPROCEDURE

ALTERNATIVE 1:

FOR Col ← 1 TO SetNum


Screen[Row, SkipNum + Col] ← 1
NEXT Col

ALTERNATIVE 2:

WHILE SetNum > 0


Screen[Row, SkipNum + SetNum] ← 1
SetNum ← SetNum - 1
ENDWHILE

Mark as follows:

1 Procedure heading and ending including parameters


2 Declaration of local Integer for Col
3 Count-controlled loop with meaningful start number
4 correct stop number
5 Reference Screen Array element and set to 1 in a loop

© UCLES 2021 Page 9 of 11


MUHAMMAD ALI KHAN
PAGE 1083
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

6(b) FUNCTION SearchInRow(ThisRow, StartCol : INTEGER) RETURNS 8


INTEGER
DECLARE ThisCol, Step : INTEGER
DECLARE Found: BOOLEAN

// array is 1280 x 800

Found ← FALSE
ThisCol ← StartCol

// first decide which way to search


IF StartCol = 1 THEN
Step ← 1
EndCol ← 1281
ELSE
Step ← -1
EndCol ← 0
ENDIF

WHILE ThisCol <> EndCol AND Found = FALSE


IF Screen[ThisRow, ThisCol] <> 1 THEN
ThisCol ← ThisCol + Step
ELSE
Found ← TRUE
ENDIF
ENDWHILE

IF Found = FALSE THEN


ThisCol ← -1
ENDIF

RETURN ThisCol

ENDFUNCTION

Mark as follows:

1 Interpreting StartCol parameter to determine direction of search


2 An attempt at searching both up and down
3 Conditional Loop / Count-controlled loop with use of ThisCol index
4 Using correct values for StartCol, EndCol and Step
5 Reference a Screen element and compare with 1 in a loop
6 If equal save column or immediately Return column in a loop
7 Return column number or í1
Loop(s) terminate when element with value = 1 found

Max 7 marks if function heading, including return type, and ending is incorrect
or incomplete

© UCLES 2021 Page 10 of 11


PAGE 1084
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

6(c) FUNCTION GetCentreCol(ThisRow : INTEGER) RETURNS INTEGER 6


DECLARE StartCol, EndCol, CentreCol : INTEGER

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:

1 Declaration of local INTEGER for return value


2 Use SearchInRow() with correct parameters and check for -1
3 Use SearchInRow(ThisRow, 1) and SearchInRow(ThisRow,
1280)
4 Calculate centre column
5 Use of INT() function // use of DIV
6 Return –1 or centre value

Max 5 marks if function heading, including return type, and ending is incorrect
or incomplete

© UCLES 2021 Page 11 of 11


MUHAMMAD ALI KHAN
PAGE 1085

Cambridge International AS & A Level


* 9 6 0 1 3 8 7 0 0 9 *

COMPUTER SCIENCE 9618/22


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2021
2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (LK/CGW) 213669/3
© UCLES 2021 [Turn over
PAGE 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]

(b) The following pseudocode assigns a value to an element of an array:

ThisArray[n] ĸ 42
Complete the following table by writing the answer for each row.

Answer

The number of dimensions of ThisArray

The technical terms for minimum and


maximum values that the variable n may take
The technical term for the variable n in the
pseudocode statement
[3]

(c) Complete the pseudocode expressions so that they evaluate to the values shown.

Any functions and operators used must be defined in the insert.

Expression Evaluates to

67
.......................................... ('C')

54
2 * ......................................... ("27")

13
................................ (27 / .................................)

"Sub" & .................... ("Abstraction" , .................... , ....................) "Subtract"

[4]

© UCLES 2021 9618/22/O/N/21


MUHAMMAD ALI KHAN
PAGE 1087

(d) Evaluate the expressions given in the following table. The variables have been assigned
values as follows:

PumpOn ĸ TRUE
ĸ
PressureOK TRUE
HiFlow ĸ FALSE

Expression Evaluates to

PressureOK AND HiFlow

PumpOn OR PressureOK

NOT PumpOn OR (PressureOK AND NOT HiFlow)

NOT (PumpOn OR PressureOK) AND NOT HiFlow


[2]

© UCLES 2021 9618/22/O/N/21 [Turn over


PAGE 1088

2 (a) An algorithm will:

1. input an integer value


2. jump to step 6 if the value is zero
3. sum and count the positive values
4. sum and count the negative values
5. repeat from step 1
6. output the two sum values and the two count values.

Draw a program flowchart on the following page to represent the algorithm.

Note that variable declarations are not required in program flowcharts.

© UCLES 2021 9618/22/O/N/21


MUHAMMAD ALI KHAN
PAGE 1089

(b) A software company is working on a project to develop a website for a school.

The school principal has some ideas about the appearance of the website but is unclear
about all the details of the solution. The principal would like to see an initial version of the
website.

(i) Identify a life cycle method that would be appropriate in this case.

Give a reason for your choice.

Life cycle method ..............................................................................................................

Reason ..............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[2]

(ii) The website project has progressed to the design stage.

State three activities that will take place during the design stage of the program
development life cycle.

1 ........................................................................................................................................

2 ........................................................................................................................................

3 ........................................................................................................................................
[3]

© UCLES 2021 9618/22/O/N/21


PAGE 1090

3 A programmer is writing a program to help manage clubs in a school.

Data will be stored about each student in the school and each student may join up to three clubs.

The data will be held in a record structure of type Student.

The programmer has started to define the fields that will be needed as shown in the following
table.

Field Typical value Comment


StudentID "CF1234" Unique to each student
Email "[email protected]" Contains letters, numbers and certain symbols
Club_1 1 Any value in the range 1 to 99 inclusive
Club_2 14 Any value in the range 1 to 99 inclusive
Club_3 27 Any value in the range 1 to 99 inclusive

(a) (i) Write pseudocode to declare the record structure for type Student.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

(ii) A 1D array Membership containing 3000 elements will be used to store the student
data.

Write pseudocode to declare the Membership array.

...........................................................................................................................................

..................................................................................................................................... [2]

(iii) Some of the elements of the array will be unused.

Give an appropriate way of indicating an unused array element.

...........................................................................................................................................

..................................................................................................................................... [1]

(iv) Some students are members of less than three clubs.

State one way of indicating an unused club field.

...........................................................................................................................................

..................................................................................................................................... [1]
© UCLES 2021 9618/22/O/N/21
MUHAMMAD ALI KHAN
PAGE 1091

(b) A procedure GetIDs() will:

• prompt and input the number of a club


• output the StudentID of all the students who are members of that club
• output a count of all students in the given club.

Write pseudocode for the procedure GetIDs().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]
© UCLES 2021 9618/22/O/N/21 [Turn over
PAGE 1092

10

4 The following is a procedure design in pseudocode.

Line numbers are given for reference only.

10 PROCEDURE Check(InString : STRING)


11 DECLARE Odds, Evens, Index : INTEGER
12
13 Odds ĸ0
14 Evens ĸ0
15 Index ĸ1
16
17 WHILE Index <= LENGTH(InString)
18 IF STR_TO_NUM(MID(InString, Index, 1)) MOD 2 <> 0 THEN
19 Odds ĸ
Odds + 1
20 ELSE
21 Evens ĸ
Evens + 1
22 ENDIF
23 Index ĸ
Index + 1
24 ENDWHILE
25
26 CALL Result(Odds, Evens)
27 ENDPROCEDURE

(a) Complete the following table by giving the answers, using the given pseudocode.

Answer
A line number containing a variable being incremented

The type of loop structure

The number of functions used

The number of parameters passed to STR_TO_NUM()

The name of a procedure other than Check()


[5]

(b) The pseudocode includes several features that make it easier to read and understand.

Identify three of these features.

1 ................................................................................................................................................

2 ................................................................................................................................................

3 ................................................................................................................................................
[3]

© UCLES 2021 9618/22/O/N/21


MUHAMMAD ALI KHAN
PAGE 1093

11

(c) (i) The loop structure used in the pseudocode is not the most appropriate.

State a more appropriate loop structure and justify your choice.

Loop structure ...................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[2]

(ii) The appropriate loop structure is now used. Two lines of pseudocode are changed and
two lines are removed.

Write the line numbers of the two lines that are removed.

...........................................................................................................................................

..................................................................................................................................... [1]

© UCLES 2021 9618/22/O/N/21 [Turn over


PAGE 1094

12

5 A company has several departments. Each department stores the name, email address and the
status of each employee in that department in its own text file. All text files have the same format.

Employee details are stored as three separate data strings on three consecutive lines of the file.
An example of the first six lines of one of the files is as follows:

File line Comment


1 First employee name

2 First email address

3 First employee status

4 Second employee name

5 Second email address

6 Second employee status

A procedure MakeNewFile() will:

• take three parameters as strings:


ż an existing file name
ż a new file name
ż a search status value

• create a new text file using the new file name


• write all employee details to the new file where the employee status is not equal to the search
status value
• count the number of sets of employee details that were in the original file
• count the number of sets of employee details that were written to the new file
• produce a summary output.

An example summary output is as follows:

File Marketing contained 54 employee details


52 employee sets of details were written to file NewMarketingList

(a) Write pseudocode for the procedure MakeNewFile().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2021 9618/22/O/N/21
MUHAMMAD ALI KHAN
PAGE 1095

13

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2021 9618/22/O/N/21 [Turn over


PAGE 1096

14

(b) An alternative format could be used for storing the data.

A text file will still be used.

(i) Describe the alternative format.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) State one advantage and one disadvantage of the alternative format.

Advantage .........................................................................................................................

...........................................................................................................................................

Disadvantage ....................................................................................................................

...........................................................................................................................................
[2]

© UCLES 2021 9618/22/O/N/21


MUHAMMAD ALI KHAN
PAGE 1097

16

6 A mobile phone has a touchscreen. The screen is represented by a grid, divided into 800 rows
and 1280 columns.

The grid is represented by a 2D array Screen of type INTEGER. An array element will be set to 0
unless the user touches that part of the screen.

Many array elements will set to 1 by a single touch of a finger or a stylus.

The following diagram shows a simplified touchscreen. The dark line represents a touch on the
screen. All grid elements that are wholly or partly inside the outline will be set to 1. These elements
are shaded.
The element shaded in black represents the centre point of the touch.

11

A program is needed to find the coordinates (the row and column) of the centre point. The centre
point on the diagram shown is row 6, column 11.

Assume:

• the user may only touch one area at a time


• screen rotation does not affect the touchscreen.

The programmer has decided to use global values CentreRow and CentreCol as coordinate
values for the centre point.

The programmer has started to define program modules as follows:

Module Description
• Searches for the first row that has an array element set to 1
FirstRowSet() • Returns the index of that row (1 is the first row)
• 5HWXUQVíLIWKHUHDUHQRHOHPHQWVVHWWR
• Searches for the last row that has an array element set to 1
LastRowSet() • Returns the index of that row
• 5HWXUQVíLIWKHUHDUHQRHOHPHQWVVHWWR
• Searches for the first column that has an array element set to 1
FirstColSet() • Returns the index of that column (1 is the first column)
• 5HWXUQVíLIWKHUHDUHQRHOHPHQWVVHWWR
• Searches for the last column that has an array element set to 1
LastColSet() • Returns the index of that column
• 5HWXUQVíLIWKHUHDUHQRHOHPHQWVVHWWR

© UCLES 2021 9618/22/O/N/21


PAGE 1098

17

(a) Write efficient pseudocode for the module FirstRowSet().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [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]

© UCLES 2021 9618/22/O/N/21


PAGE 1100

19

(d) An additional module GetCentre() is defined as follows:

Module Description
• Calculates the coordinates of the centre point
• Uses the four modules: FirstRowSet(), LastRowSet(),
GetCentre() FirstColSet(), LastColSet()
• Assigns values to CentreRow and CentreCol
• Sets CentreRowWRíLIQRVFUHHQWRXFKLVGHWHFWHG

Write pseudocode for the module GetCentre().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]
© UCLES 2021 9618/22/O/N/21
MUHAMMAD ALI KHAN
PAGE 1101
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

1(a) The process involves: 2

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 number of dimensions of ThisArray 1

The technical terms for minimum and Lower bound, upper bound
maximum values that variable n may take

The technical term for the variable n in the Index / Subscript


pseudocode expression.

One mark per row

1(c) 4
Expression Evaluates to

ASC('C') 67

2 * STR_TO_NUM ("27") 54

INT(27 / 2) 13

"Sub" & MID("Abstraction" , 4 , 5) "Subtract"

One mark per row

Function names must be exactly as shown

1(d) 2
Expression Evaluates to

PressureOK AND HiFlow FALSE

PumpOn OR PressureOK TRUE

NOT PumpOn OR (PressureOK AND NOT HiFlow) TRUE

NOT (PumpOn OR PressureOK) AND NOT HiFlow FALSE

1 mark for any two rows correct


2 marks for all rows correct.

© UCLES 2021 Page 3 of 10


PAGE 1102
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

2(a) 5

One mark for each outlined group.

Note:
• Sum and increment steps (bottom-right rectangles) may be in reverse
order in which case sum group will have two output lines

• Max 4 for non-working solution

© UCLES 2021 Page 4 of 10


MUHAMMAD ALI KHAN
PAGE 1103
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

2(b)(i) One mark for each: 2

Life cycle method: Iterative // Rapid Application Development (RAD)

Reason: Provides a working model / prototype at an early stage for the


principal to approve / review

2(b)(ii) Decisions will be made regarding: 3

• 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

Question Answer Marks

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:

• One mark for TYPE and ENDTYPE


• One mark for StudentID and Email fields as STRING
• One mark for all Club fields as INTEGER

3(a)(ii) DECLARE Membership : ARRAY [1:3000] OF Student 2

One mark per underlined phrase

3(a)(iii) One mark for any one of: 1

• 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

3(a)(iv) A number outside the range 1 to 99 1

© UCLES 2021 Page 5 of 10


PAGE 1104
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

3(b) PROCEDURE GetIDs() 7


DECLARE Index : INTEGER
DECLARE ThisClub, Count : INTEGER

OUTPUT "Please Input Club Number: "


INPUT ThisClub

Count ← 0

FOR Index ← 1 TO 3000


IF Membership[Index].Club_1 = ThisClub OR __
Membership[Index].Club_2 = ThisClub OR __
Membership[Index].Club_3 = ThisClub THEN
Count ← Count + 1
OUTPUT Membership[Index].StudentID
ENDIF

NEXT Index

OUTPUT "There are ", Count, " Students in the club"


ENDPROCEDURE

Mark as follows:

1 Declare and initialise Count


2 Prompt and Input club number before the loop
3 Loop through 3000 elements
4 Compare one club field with number input
5 Compare all Club fields with number input
6 If number found, OUTPUT of StudentID field and increment Count
7 Final OUTPUT of Count outside the loop

Note:

Max 6 if procedure heading and ending missing or incorrect (but allow array
as parameter)

Question Answer Marks

4(a) 5
Answer
A line number containing a variable being incremented 19 / 21 / 23

The type of loop structure pre-condition

The number of functions used 3

The number of parameters passed to function 1


STR_TO_NUM()

The name of a procedure other than Check() Result

© UCLES 2021 Page 6 of 10


MUHAMMAD ALI KHAN
PAGE 1105
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

4(b) One mark per point: 3

• Meaningful variable names


• Indentation / white space / blank lines
• Capitalisation of keywords

4(c)(i) One mark per point: 2

Structure: A count-controlled loop

Justification: The number of iterations is known // repeats for the length of


InString

4(c)(ii) 15, 23 1

One mark for both line numbers

© UCLES 2021 Page 7 of 10


PAGE 1106
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

5(a) PROCEDURE MakeNewFile(OldFile, NewFile, Status : STRING) 7


DECLARE Line1, Line2, Line3 : STRING
DECLARE NumCopied, NumRecs : INTEGER

NumRecs ← 0
NumCopied ← 0

OPENFILE OldFile FOR READ


OPENFILE NewFile FOR WRITE

WHILE NOT EOF(OldFile)


READFILE OldFile, Line1
READFILE OldFile, Line2
READFILE OldFile, Line3
NumRecs ← NumRecs + 1
IF Line3 <> Status THEN
WRITEFILE NewFile, Line1
WRITEFILE NewFile, Line2
WRITEFILE NewFile, Line3
NumCopied ← NumCopied + 1
ENDIF
ENDWHILE

OUTPUT "File " , OldFile , " contained " , NumRecs ,__


" employee details"
OUTPUT Numcopied , " employee sets of details were __
written to file", NewFile
CLOSEFILE OldFile
CLOSEFILE NewFile
ENDPROCEDURE

Mark as follows:

1 Procedure heading and ending, including parameters


2 OPEN OldFile for READ and NewFile for WRITE and subsequently
CLOSE both files
3 Conditional loop until EOF(OldFile)
4 Read three lines from OldFile in a loop
5 Compare 3rd line read with Status parameter and if not equal write
3 lines to NewFile in a loop
6 Count number of sets read and those written in a loop
7 Final output including both counts and file names with suitable text after a
loop

Note:
MP6: Both counts must have been declared and initialised

5(b)(i) Store all three items on one line 1

© UCLES 2021 Page 8 of 10


MUHAMMAD ALI KHAN
PAGE 1107
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

5(b)(ii) One mark per point: 2

Advantage: Fewer file operations required

Disadvantage: Algorithm to combine / extract individual data items is more


complex

Question Answer Marks

6(a) FUNCTION FirstRowSet() RETURNS INTEGER 7


DECLARE Row, Col : INTEGER
DECLARE Found : BOOLEAN

// array is 1280 × 800


Row ← 1

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

IF Found = FALSE THEN // nothing found


Row ← 0
ENDIF
RETURN Row - 1
ENDFUNCTION

Mark as follows:

1 Function heading and ending and return type


2 (Conditional) outer loop 1 to 800 (row)
3 (Conditional) inner loop 1 to 1280 // 1280 to 1 (column)
4 Reference Screen element and test for = 1 // <> 0
5 and if true save row number and exit loops
6 Increment index variables in both inner and outer loop
7 Return Row number or í1, following a reasonable attempt

6(b) One mark for: 2

• (A flag is used to) exit the loops // iteration is terminated


• as soon as a Screen element with value 1 is found

© UCLES 2021 Page 9 of 10


PAGE 1108
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2021

Question Answer Marks

6(c)(i) One mark for: 2


• Parameter(s) need to be passed to the module to identify the type of
search
• Search algorithm is controlled by (global) variables / parameters

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)

6(c)(ii) One mark for advantage and one for disadvantage: 2


Advantage: (max 1)
• Only have to change one module if specification changes
• Less repetitive code / fewer lines of code
• Aids re-usability

Disadvantage: (max 1)
• Single module more complex / more error prone / more difficult to
debug ...
• Single module cannot be split among programmers / teams

Max 2

6(d) PROCEDURE GetCentre () 6


DECLARE StartRow, EndRow, StartCol, EndCol : INTEGER

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

© UCLES 2021 Page 10 of 10


MUHAMMAD ALI KHAN
PAGE 1109

Cambridge International AS & A Level


* 6 7 8 5 4 5 4 5 5 5 *

COMPUTER SCIENCE 9618/21


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2022
2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (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]

(b) The table lists some of the variables used in a program.

(i) Complete the table by writing the most appropriate data type for each variable.

Variable Use of variable Data type

Temp Stores the average temperature

PetName Stores the name of my pet

To calculate the number of days until my next


MyDOB
birthday

LightOn Stores state of light; light is only on or off

[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]

(c) Complete the table by evaluating each expression.

Expression Evaluation

INT((31 / 3) + 1)

MID(TO_UPPER("Version"), 4, 2)

TRUE AND (NOT FALSE)

NUM_TO_STR(27 MOD 3)

[4]

© UCLES 2022 9618/21/M/J/22


MUHAMMAD ALI KHAN
PAGE 1111

2 Examine the following state-transition diagram.

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

(a) Complete the table with reference to the diagram.

Answer
The number of different inputs

The number of different outputs

The single input value that could result in S4


[3]

(b) The initial state is S1.

Complete the table to show the inputs, outputs and next states.

Input Output Next state

Button-Y

none

Button-Z S2

none
[4]

© UCLES 2022 9618/21/M/J/22 [Turn over


PAGE 1112

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.

Describe three program modules that could be used in the design.

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]

© UCLES 2022 9618/21/M/J/22


MUHAMMAD ALI KHAN
PAGE 1113

BLANK PAGE

© UCLES 2022 9618/21/M/J/22 [Turn over


PAGE 1114

4 A stack is created using a high-level language. Memory locations 200 to 207 are to be used to
store the stack.

The following diagram represents the current state of the stack.

TopOfStack points to the last value added to the stack.

Stack Pointer
Memory
Value
location
200

201

202

203 'F' TopOfStack

204 'C'

205 'D'

206 'E'

207 'H'

(a) Complete the following table by writing the answers.

Answer

The value that has been on the stack for the longest time.

The memory location pointed to by TopOfStack if three POP


operations are performed.

[2]

© UCLES 2022 9618/21/M/J/22


MUHAMMAD ALI KHAN
PAGE 1115

(b) The following diagram shows the current state of the stack:

Stack Pointer
Memory
Value
location
200

201

202 'W' TopOfStack

203 'Y'

204 'X'

205 'Z'

206 'N'

207 'P'

The following operations are performed:

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]

© UCLES 2022 9618/21/M/J/22 [Turn over


PAGE 1116

5 Each line of a text file contains data organised into fixed-length fields as shown:

<Field 1><Field 2><Field 3>

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.

Describe the algorithm needed.

Do not include pseudocode statements in your answer.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [6]

© UCLES 2022 9618/21/M/J/22


MUHAMMAD ALI KHAN
PAGE 1117

6 (a) An algorithm will:


• output each integer value between 100 and 200 that ends with the digit 7, for example,
107
• output a final count of the number of values that are output.

Write pseudocode for this algorithm.

Any variables used must be declared.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

© UCLES 2022 9618/21/M/J/22 [Turn over


PAGE 1118

10

(b) Study the following pseudocode.

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]

© UCLES 2022 9618/21/M/J/22


MUHAMMAD ALI KHAN
PAGE 1119

11

7 A string is a palindrome if it reads the same forwards as backwards.

The following strings are examples of palindromes:


"Racecar"
"madam"
"12344321"

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.

Write pseudocode for IsPalindrome().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2022 9618/21/M/J/22 [Turn over


PAGE 1120

12

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2022 9618/21/M/J/22


MUHAMMAD ALI KHAN
PAGE 1121

13

(b) Strings may consist of several words separated by spaces.

For example, the string "never odd or even" becomes a palindrome if the spaces are removed.

The program flowchart represents an algorithm to produce a string OutString by removing


all spaces from a string InString.

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.

Note: the text may be written as a pseudocode statement.

Label Text

A Set OutString to ""

E Set Index to Index + 1

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 '-'.

An example of a password is: "FxAf-3haV-Tq49"

A global 2D array Secret of type STRING stores the passwords together with the website domain
name where they are used. Secret contains 1000 elements organised as 500 rows by 2 columns.

Unused elements contain the empty string (""). These may occur anywhere in the array.

An example of a part of the array is:

Array element Value

Secret[27, 1] "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.

The programmer has started to define program modules as follows:

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

For reference, relevant ASCII values are as follows:

Character range ASCII range

'a' to 'z' 97 to 122

'A' to 'Z' 65 to 90

'0' to '9' 48 to 57

© UCLES 2022 9618/21/M/J/22


MUHAMMAD ALI KHAN
PAGE 1123

15

(a) Write pseudocode for module RandomChar().

You may wish to refer to the insert for a description of the CHR() function. Other functions
may also be required.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2022 9618/21/M/J/22 [Turn over


PAGE 1124

16

(b) A new module is defined as follows:

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

Write pseudocode for module FindPassword().

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.

To be valid, each password must:


• be 14 characters long
• be organised as three groups of four case-sensitive alphanumeric characters. The
groups are separated by hyphen characters
• not include any duplicated characters, except for the hyphen characters.

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.

Describe how this might be achieved.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2022 9618/21/M/J/22


PAGE 1126
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

1(a) An algorithm 1

1(b)(i) 4
Variable Use of variable Data type

Temp Stores the average temperature REAL

PetName Stores the name of my pet STRING

MyDOB To calculate how many days until my DATE


next birthday

LightOn Stores state of light; light is only on or off BOOLEAN

One mark for each 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"

TRUE AND (NOT FALSE) TRUE

NUM_TO_STR(27 MOD 3) "0"

One mark per row

Question Answer Marks

2(a) One mark per row 3


Answer

The number of different inputs 3

The number of different outputs 3

The single input value that could result in S4 Button-Y

© UCLES 2022 Page 3 of 12


MUHAMMAD ALI KHAN
PAGE 1127
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

2(b) One mark per row 4

Example answer

Note: Accept other valid answers

Question Answer Marks

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

x Allows the user to search for available seats

x Calculate cost of booking

x Book a given number of seats for a particular screening

3(b) Function 1

Question Answer Marks

4(a) One mark per row 2


Answer

The value that has been on the stack for the longest time. 'H'

The memory location pointed to by TopOfStack if three


206
POP operations are performed.

© UCLES 2022 Page 4 of 12


PAGE 1128
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

4(b) 4
Stack Pointer

Memory
Value
location

200

201 'D' m TopOfStack

202 'C'

203 'A'

204 'X'

205 'Z'

206 'N'

207 'P'

One mark for:


1 TopOfStack pointing to 'D'
2 Value 'D' in 201
3 Values 'C' & 'A' in 202 and 203
4 Values 'X' to 'P' unchanged (204 to 207)

Question Answer Marks

5 One mark per point to Max 6 6


1 Open file in read mode
2 Set up a conditional loop, repeating until the value is found or the EOF()
is reached
3 Read a line from the file in a loop
4 Extract Field 2
5 Description of how Field 2 could be extracted e.g. using substring
function and lengths of Field 1 and Field 2
6 Compare extracted field with search value
7 If search value found, extract Field 1and Field 3 and output them
8 Close the file after loop has finished

© UCLES 2022 Page 5 of 12


MUHAMMAD ALI KHAN
PAGE 1129
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

6(a) Simple Solution: 5

DECLARE ThisInt, Count : INTEGER


Count m 0

FOR ThisInt m 100 TO 200


IF ThisInt MOD 10 = 7 THEN
OUTPUT ThisInt
Count m Count + 1
ENDIF
NEXT ThisInt

OUTPUT Count

Mark as follows:

1 Declare loop variable and counter as integers, counter initialised


2 Loop 100 to 200, no step defined
3 Test value in a loop
4 Output selected value and incrementing a counter in a loop
5 Output the counter, following a reasonable attempt, after the loop

Alternative Solution:

DECLARE ThisInt, Count : INTEGER


Count m 0

FOR ThisInt m 107 TO 197 STEP 10


OUTPUT ThisInt
Count m Count + 1
NEXT ThisInt

OUTPUT Count

Mark as follows:

1 Declare loop variable and counter as integers, , counter initialised


2 Loop (107 to 197)
3 STEP 10 or explicit increment if conditional loop used
4 Output each value and incrementing a counter in a loop
5 Output the counter, following a reasonable attempt, after the loop

© UCLES 2022 Page 6 of 12


PAGE 1130
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

6(b) IF MySwitch = 1 THEN 4


ThisChar m 'a'
ELSE
IF MySwitch = 2 THEN
ThisChar m 'y'
ELSE
IF MySwitch = 3 THEN
ThisChar m '7'
ELSE
ThisChar m '*'
ENDIF
ENDIF
ENDIF

Mark as follows:

1. ANY test of MySwitch = 1, 2 or 3


2. All three comparisons and corresponding assignments
3. OTHERWISE, or initial assignment of default value
4. Completely correct IF...THEN...ELSE...ENDIF syntax

© UCLES 2022 Page 7 of 12


MUHAMMAD ALI KHAN
PAGE 1131
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

7(a) FUNCTION IsPalindrome(InString : STRING) RETURNS BOOLEAN 7


DECLARE IsPal : BOOLEAN
DECLARE Index, Num : INTEGER
DECLARE CharA, CharB : CHAR

IsPal m TRUE
Index m 1

Num m INT(LENGTH(InString) / 2)

WHILE Index <= Num AND IsPal = TRUE


CharA m MID(InString, Index, 1)
CharB m MID(Instring, LENGTH(Instring) – Index + 1,
1)
IF UCASE(CharA) <> UCASE(CharB) THEN
IsPal m FALSE // RETURN FALSE
ENDIF
Index m Index + 1
ENDWHILE

RETURN IsPal // RETURN TRUE

ENDFUNCTION

Mark as follows:

1 Functions header including parameter, ending and return type


2 Calculation of number of pairs to match (length or half length)
3 Loop for half or whole string
4 …Extracting characters to compare // create reverse string
5 Convert characters to same case
6 Check for mismatch of characters inside loop / test for mismatch after
loop for reversed string
7 Returning Boolean in both cases

© UCLES 2022 Page 8 of 12


PAGE 1132
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

7(b) 4
Label Text

A Set OutString to ""

B Is Index > LENGTH(InString)?

C Is MID(InString, Index, 1) = " "?

Set OutString to OutString & MID(InString, Index,


D
1)

E Set Index to Index + 1

F YES

G NO

Mark for each of:


x B
x D
x C
x ...F and G

Note: The mark for F and G is dependent on a reasonable attempt at C

© UCLES 2022 Page 9 of 12


MUHAMMAD ALI KHAN
PAGE 1133
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

8(a) FUNCTION RandomChar() RETURNS CHAR 6


DECLARE ThisRange : INTEGER
DECLARE ThisChar : CHAR

//First select the range


ThisRange m INT(RAND(3)) + 1 // 1 to 3

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:

1 Generation of any integer random number


2 Randomly decide which of the three ranges to select
3 Selection structure based on range
4 One alphanumeric character range correct
5 All alphanumeric character ranges correct
6 Return ThisChar, following a reasonable attempt to generate a
character in each range

© UCLES 2022 Page 10 of 12


PAGE 1134
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

8(b) FUNCTION FindPassword(Name: STRING) RETURNS STRING 7


DECLARE Index : INTEGER
DECLARE Password : STRING

Password m ""
Index m 1

WHILE Password = "" AND Index <= 500


IF Secret[Index, 1] = Name THEN
Password m Decrypt(Secret[Index, 2])
ELSE
Index m Index + 1
ENDIF
ENDWHILE

IF Password = "" THEN


OUTPUT "Domain name not found"
ENDIF

RETURN Password

ENDFUNCTION

Mark as follows:

1 Declare all local variables used, attempted solution has to be reasonable


2 Conditional loop while not found and not end of array
3 Compare value of element in column 1 with parameter passed into
function
4 ...and use Decrypt() with element in column 2 as parameter
5 …use the return value of Decrypt()
6 Output warning message if parameter not found
7 Return STRING value

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

8(d) Accept one example of a valid password to Max 2 2

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

© UCLES 2022 Page 11 of 12


MUHAMMAD ALI KHAN
PAGE 1135
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

8(e) One mark for each part: 3

x Generate a random integer divisible by 3


x Split range into 1/3 and set as numeric
x Else alphabetic character

© UCLES 2022 Page 12 of 12


PAGE 1136

Cambridge International AS & A Level


* 6 6 4 6 7 4 9 2 2 0 *

COMPUTER SCIENCE 9618/22


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2022
2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (KN/SW) 303772/3
© UCLES 2022 [Turn over
MUHAMMAD ALI KHAN
PAGE 1137

Refer to the insert for the list of pseudocode functions and operators.

1 (a) A programmer is testing a program using an Integrated Development Environment (IDE).


The programmer wants the program to stop when it reaches a specific instruction or program
statement in order to check the value assigned to a variable.

Give the technical term for the position at which the program stops.

............................................................................................................................................. [1]

(b) The following table lists some activities from the program development life cycle.

Complete the table by writing the life cycle stage for each activity.

Activity Life cycle stage


An identifier table is produced.

Syntax errors can occur.

The developer discusses the program requirements with the customer.

A trace table is produced.


[4]

(c) An identifier table includes the names of identifiers used.

State two other pieces of information that the identifier table should contain.

1 ................................................................................................................................................

2 ................................................................................................................................................
[2]

(d) The pseudocode statements in the following table may contain errors.

State the error in each case or write 'NO ERROR' if the statement contains no error.

You can assume that none of the variables referenced are of an incorrect type.

Statement Error

Status TRUE AND FALSE

IF LENGTH("Password") < "10" THEN

Code LCASE("Electrical")

Result IS_NUM(-27.3)

[4]

© UCLES 2022 9618/22/M/J/22


PAGE 1138

2 An algorithm is described as follows:


1. Input an integer value.
2. Jump to step 6 if the value is less than zero.
3. Call the function IsPrime() using the integer value as a parameter.
4. Keep a count of the number of times function IsPrime() returns TRUE.
5. Repeat from step 1.
6. Output the value of the count with a suitable message.

Draw a program flowchart to represent the algorithm.

START

END

[4]

© UCLES 2022 9618/22/M/J/22 [Turn over


MUHAMMAD ALI KHAN
PAGE 1139

3 (a) The module headers for five modules in a program are defined in pseudocode as follows:

Pseudocode module header


FUNCTION Mod_V(S2 : INTEGER) RETURNS BOOLEAN
PROCEDURE Mod_W(P4 : INTEGER)
PROCEDURE Mod_X(T4 : INTEGER, BYREF P3 : REAL)
PROCEDURE Mod_Y(W3 : REAL, Z8 : INTEGER)
FUNCTION Mod_Z(F3 : REAL) RETURNS INTEGER

An additional module Head() repeatedly calls three of the modules in sequence.

A structure chart has been partially completed.

(i) Complete the structure chart to include the information given about the six modules.

Do not label the parameters and do not write the module names.

B C D

E F

[3]

© UCLES 2022 9618/22/M/J/22


PAGE 1140

(ii) Complete the table using the information in part 3(a) by writing each module name to
replace the labels A to F.

Label Module name

F
[3]

(b) The structure chart represents part of a complex problem. The process of decomposition is
used to break down the complex problem into sub-problems.

Describe three benefits of this approach.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................

3 ................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2022 9618/22/M/J/22 [Turn over


MUHAMMAD ALI KHAN
PAGE 1141

4 (a) A procedure LastLines() will:


• take the name of a text file as a parameter
• output the last three lines from that file, in the same order as they appear in the file.

Note:
• Use local variables LineX, LineY and LineZ to store the three lines from the file.
• You may assume the file exists and contains at least three lines.

Write pseudocode for the procedure LastLines().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2022 9618/22/M/J/22


PAGE 1142

(b) The algorithm in part (a) is to be amended. The calling program will pass the number of lines
to be output as well as the name of the text file.

The number of lines could be any value from 1 to 30.

It can be assumed that the file contains at least the number of lines passed.

Outline three changes that would be needed.

1 ................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

3 ................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2022 9618/22/M/J/22 [Turn over


MUHAMMAD ALI KHAN
PAGE 1143

5 Study the following pseudocode. Line numbers are for reference only.

10 PROCEDURE Encode()
11 DECLARE CountA, CountB, ThisNum : INTEGER
12 DECLARE ThisChar : CHAR
13 DECLARE Flag : BOOLEAN
14 CountA 0
15 CountB 10
16 Flag TRUE
17 INPUT ThisNum
18 WHILE ThisNum <> 0
19 ThisChar LEFT(NUM_TO_STR(ThisNum), 1)
20 IF Flag = TRUE THEN
21 CASE OF ThisChar
22 '1' : CountA CountA + 1
23 '2' : IF CountB < 10 THEN
24 CountA CountA + 1
25 ENDIF
26 '3' : CountB CountB - 1
27 '4' : CountB CountB - 1
28 Flag FALSE
29 OTHERWISE : OUTPUT "Ignored"
30 ENDCASE
31 ELSE
32 IF CountA > 2 THEN
33 Flag NOT Flag
34 OUTPUT "Flip"
35 ELSE
36 CountA 4
37 ENDIF
38 ENDIF
39 INPUT ThisNum
40 ENDWHILE
41 OUTPUT CountA
42 ENDPROCEDURE

(a) Procedure Encode() contains a loop structure.

Identify the type of loop and state the condition that ends the loop.

Do not include pseudocode statements in your answer.

Type ..........................................................................................................................................

Condition ..................................................................................................................................

...................................................................................................................................................
[2]
© UCLES 2022 9618/22/M/J/22
PAGE 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

The first row is already complete.

ThisNum ThisChar CountA CountB Flag OUTPUT

0 10 TRUE

[6]

(c) Procedure Encode() is part of a modular program. Integration testing is to be carried out on
the program.

Describe integration testing.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2022 9618/22/M/J/22 [Turn over


MUHAMMAD ALI KHAN
PAGE 1145

10

6 A string represents a series of whole numbers, separated by commas.

For example:
"12,13,451,22"

Assume that:
• the comma character ',' is used as a separator
• the string contains only the characters '0' to '9' and the comma character ','.

A procedure Parse will:


• take the string as a parameter
• extract each number in turn
• calculate the total value and average value of all the numbers
• output the total and average values with a suitable message.

Write pseudocode for the procedure.

PROCEDURE Parse(InString : STRING)

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

© UCLES 2022 9618/22/M/J/22


PAGE 1146

11

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

ENDPROCEDURE [7]

© UCLES 2022 9618/22/M/J/22 [Turn over


MUHAMMAD ALI KHAN
PAGE 1147

12

7 A programming language has string functions equivalent to those given in the insert.

The language includes a LEFT() and a RIGHT() function, but it does not have a MID() function.

(a) Write pseudocode for an algorithm to implement your own version of the MID() function
which will operate in the same way as that shown in the insert.

Do not use the MID() function given in the insert, but you may use any of the other functions.

Assume that the values passed to the function will be correct.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]

(b) The values passed to your MID() function in part (a) need to be validated.

Assume that the values are of the correct data type.

State two checks that could be applied to the values passed to the function.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2022 9618/22/M/J/22


PAGE 1148

13

BLANK PAGE

© UCLES 2022 9618/22/M/J/22 [Turn over


MUHAMMAD ALI KHAN
PAGE 1149

14

8 A program allows a user to save passwords used to log in to websites. A stored password is then
inserted automatically when the user logs in to the corresponding website.

A global 2D array Secret of type STRING stores the passwords together with the website domain
name where they are used. Secret contains 1000 elements organised as 500 rows by 2 columns.

Unused elements contain the empty string (""). These may occur anywhere in the array.

An example of a part of the array is:

Array element Value


Secret[27, 1] "thiswebsite.com"
Secret[27, 2] "yyyyyyyyyyyy"
Secret[28, 1] "thatwebsite.com"
Secret[28, 2] "yyyyyyyyyyyy"

Note:
• For security, the passwords are stored in an encrypted form, shown as "yyyyyyyyyyyy" in the
example.
• The passwords cannot be used without being decrypted.
• You may assume that the encrypted form of a password will NOT be an empty string.

The programmer has started to define program modules as follows:

Module Description
• Takes two parameters:
  ż DVWULQJ
  ż DFKDUDFWHU
Exists()
• Performs a case-sensitive search for the character in the string
• Returns TRUE if the character occurs in the string, otherwise
returns FALSE
• Takes a password as a parameter of type string
Encrypt()
• Returns the encrypted form of the password as a string
• Takes an encrypted password as a parameter of type string
Decrypt()
• Returns the decrypted form of the password as a string

Note: in a case-sensitive comparison, 'a' is not the same as 'A'.

© UCLES 2022 9618/22/M/J/22


PAGE 1150

15

(a) Write pseudocode for the module Exists().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

© UCLES 2022 9618/22/M/J/22 [Turn over


MUHAMMAD ALI KHAN
PAGE 1151

16

(b) A new module SearchDuplicates() will:


• search for the first password that occurs more than once in the array and output a
message each time a duplicate is found.
For example, if the same password was used for the three websites ThisWebsite.com,
website27.net and websiteZ99.org, then the following messages will be output:

"Password for ThisWebsite.com also used for website27.net"


"Password for ThisWebsite.com also used for websiteZ99.org"

• end once all messages have been output.

The module will output a message if no duplicates are found.


For example:
"No duplicate passwords found"

Write efficient pseudocode for the module SearchDuplicates(). Encrypt() and


Decrypt() functions have been written.

Note: It is necessary to decrypt each password before checking its value.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2022 9618/22/M/J/22


PAGE 1152

17

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2022 9618/22/M/J/22 [Turn over


MUHAMMAD ALI KHAN
PAGE 1153

18

(c) A password has a fixed format, consisting of three groups of four alphanumeric characters,
separated by the hyphen character '-'.

An example of a password is:


"FxAf-3haV-Tq49"

Each password must:


• be 14 characters long
• be organised as three groups of four alphanumeric characters. The groups are separated
by hyphen characters
• not include any duplicated characters, except for the hyphen characters.

An algorithm is needed for a new function GeneratePassword(), which will generate and
return a password in this format.

Assume that the following modules have already been written:

Module Description
• Takes two parameters:
  ż DVWULQJ
  ż DFKDUDFWHU
Exists() • Performs a case-sensitive search for the character in the
string
• Returns TRUE if the character occurs in the string, otherwise
returns FALSE
• Generates a single random character from within one of the
following ranges:
  ż D WR ]
RandomChar()
  ż $ WR =
  ż  WR 
• Returns the character

Note: in a case-sensitive comparison, 'a' is not the same as 'A'.

© UCLES 2022 9618/22/M/J/22


PAGE 1154

19

Describe the algorithm for GeneratePassword().

Do not use pseudocode statements in your answer.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2022 9618/22/M/J/22


MUHAMMAD ALI KHAN
PAGE 1155
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

1(a) Correct answer only: 1

Breakpoint

1(b) One mark per row 4

Activity Life cycle stage

An identifier table is produced. Design

Syntax errors can occur. Coding

The developer discusses the program requirements with the Analysis


customer.

A trace table is produced. Testing

1(c) One mark per bullet point to Max 2 2

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)

1(d) One mark per row 4

Statement Error

Status m TRUE AND FALSE NO ERROR

IF LENGTH("Password") < "10" shouldn’t be a string // must be an


"10" THEN integer

Code m Parameter must be a char // cannot be a


LCASE("Electrical") string
Alternative:
LCASE should be TO_LOWER

Result m IS_NUM(-27.3) Parameter must be a string / char //


cannot be a number

© UCLES 2022 Page 3 of 14


PAGE 1156
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

2 4

One mark per point:

1 Initialise Count before loop AND Input NextNum in a loop


2 Loop until NextNum < 0 AND OUTPUT statement including Count plus a
message
3 Use of IsPrime(NextNum)as a function (must return a value)
4 Check return value AND increment Count if appropriate

© UCLES 2022 Page 4 of 14


MUHAMMAD ALI KHAN
PAGE 1157
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

3(a)(i) One mark per red annotation 3

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

3(b) One mark per point: 3


x Breaking a complex problem down makes it easier to understand / solve //
smaller problems are easier to understand / solve
x Smaller problems are easier to program / test / maintain
x Sub-problems can be given to different teams / programmers with different
expertise // can be solved separately

© UCLES 2022 Page 5 of 14


PAGE 1158
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

4(a) PROCEDURE LastLines(ThisFile : STRING) 6


DECLARE ThisLine, LineX, LineY, LineZ : STRING

OPENFILE ThisFile FOR READ

LineY m ""
LineZ m ""

WHILE NOT EOF(ThisFile)


READFILE Thisfile, ThisLine // read a line
LineX m LineY
LineY m LineZ
LineZ m ThisLine
ENDWHILE

CLOSEFILE ThisFile

OUTPUT LineX
OUTPUT LineY
OUTPUT LineZ

ENDPROCEDURE

Marks as follows to Max 6:

1 Procedure heading (including parameter) and ending


2 Declaration of local variables for three lines AND File OPEN in READ mode AND
CLOSE
3 Loop until EOF(ThisFile)
4 Read line from file... in a loop
5 Attempt at a shuffle… in a loop
6 Correctly shuffle LineX, LineY and LineZ in a loop
7 OUTPUT the three lines in correct sequence, following reasonable attempt

© UCLES 2022 Page 6 of 14


MUHAMMAD ALI KHAN
PAGE 1159
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

4(a) Alternative (using two loops):

PROCEDURE LastLines(ThisFile : STRING)


DECLARE ThisLine, LineX, LineY, LineZ : STRING
DECLARE Count, Count2 : INTEGER

Count m 0
OPENFILE ThisFile FOR READ

WHILE NOT EOF(ThisFile)


READFILE Thisfile, ThisLine // read a line
Count m Count + 1
ENDWHILE

CLOSEFILE ThisFile
OPENFILE ThisFile FOR READ

FOR Count2 m 1 TO Count - 3


READFILE Thisfile, ThisLine // read a line
NEXT Count2

READFILE Thisfile, LineX


READFILE Thisfile, LineY
READFILE Thisfile, LineZ

OUTPUT LineX
OUTPUT LineY
OUTPUT LineZ

CLOSEFILE ThisFile

ENDPROCEDURE

Marks as follows to Max 6:

1 Procedure heading (including parameter) and ending


2 Declaration of local variables for three lines AND (at least one) File OPEN in
READ mode AND CLOSE
3 Loop until EOF(ThisFile)
4 Read line from file and increment Count in a loop
5 Two separate loops, closing and re-opening the file between loops

6 Read Count - 3 lines from the file

7 OUTPUT the last three lines in correct sequence, following reasonable attempt

© UCLES 2022 Page 7 of 14


PAGE 1160
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

4(b) One mark per point to Max 3: 3

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

Alternative 'two loop' solution to Max 3:


1 Change the procedure header to include a numeric parameter (as well as the
filename)
2 A loop to count the total number of lines in the file
3 Ref use of single variable rather than LineX, LineY and LineZ
4 Close and re-open the file
5 Use the new parameter value to determine first line to output
6 Output the lines in a loop

© UCLES 2022 Page 8 of 14


MUHAMMAD ALI KHAN
PAGE 1161
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

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

22 '2' TRUE "Flip"

31 '3' 8

32 '3' 7

47 '4' 6 FALSE

99 '9' TRUE "Flip"

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

5(c) One mark per point: 2


x Modules that have already been tested individually
x are combined into a single (sub) program which is then tested as a whole

© UCLES 2022 Page 9 of 14


PAGE 1162
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

6 PROCEDURE Parse(InString : STRING) 7


DECLARE Count, Total, Index : INTEGER
DECLARE Average : REAL
DECLARE NumString : STRING
DECLARE ThisChar : CHAR

CONSTANT COMMA = ','

Count m 0
Total m 0
NumString m ""

FOR Index m 1 to LENGTH(InString)


ThisChar m MID(InString, Index, 1)
IF ThisChar = COMMA THEN
Total m Total + STR_TO_NUM(NumString)
Count m Count + 1
NumString m ""
ELSE
NumString m NumString & ThisChar // build the number
string
ENDIF
NEXT Index

// now process the final number


Total m Total + STR_TO_NUM(NumString)
Count m Count + 1

Average m Total / Count


OUTPUT "The total was ", Total, " and the average was ",
Average

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

© UCLES 2022 Page 10 of 14


MUHAMMAD ALI KHAN
PAGE 1163
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

7(a) FUNCTION MID(InString : STRING, Start, Num : INTEGER) 4


RETURNS STRING
DECLARE MidString : STRING
DECLARE InStringLen : INTEGER

InStringLen m LENGTH(InString)

// solution for RIGHT() then LEFT()


MidString m RIGHT(InString, InStringLen – Start + 1)
MidString m LEFT(MidString, Num)

// alternative solution for LEFT() then RIGHT()


MidString m LEFT(InString, Start + Num - 1)
MidString m RIGHT(MidString, Num)

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

7(b) One mark per point 2

Check that:
x Start and/or Num are >= 1 // positive
x Length of InString is "sufficient" for required operation

© UCLES 2022 Page 11 of 14


PAGE 1164
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

8(a) FUNCTION Exists(ThisString : STRING, Search : CHAR) 5


RETURNS BOOLEAN
DECLARE Found : BOOLEAN
DECLARE Index : INTEGER

Found m FALSE
Index m 1

WHILE Found = FALSE AND Index <= LENGTH(ThisString)


IF MID(ThisString, Index, 1) = Search THEN
Found m TRUE
ELSE
Index m Index + 1
ENDIF
ENDWHILE

RETURN Found

ENDFUNCTION

Marks as follows (Conditional loop solution):


1 Conditional loop while character not found and not end of string
2 Extract a char in a loop
3 Compare with parameter without case conversion in a loop
4 If match found, set termination logic in a loop
5 Return BOOLEAN value

ALTERNATIVE (Using Count-controlled loop):


FOR Index m 1 TO LENGTH(ThisString)
IF MID(ThisString, Index, 1) = Search THEN
RETURN TRUE
ENDIF
NEXT Index
RETURN FALSE

Marks as follows (Count-controlled loop variant):


1 Loop for length of ThisString (allow from 0 or 1)
2 Extract a char in a loop
3 Compare with parameter without case conversion in a loop
4 If match found, immediate RETURN of TRUE
5 Return FALSE after the loop // Return Boolean if no immediate RETURN

© UCLES 2022 Page 12 of 14


MUHAMMAD ALI KHAN
PAGE 1165
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

8(b) PROCEDURE SearchDuplicates() 8


DECLARE IndexA, IndexB : INTEGER
DECLARE ThisPassword, ThisValue : STRING
DECLARE Duplicates : BOOLEAN

Duplicates m FALSE
IndexA m 1

WHILE Duplicates = FALSE AND IndexA < 500


ThisValue m Secret[IndexA, 2]
IF ThisValue <> "" THEN
ThisPassword m Decrypt(ThisValue)
FOR IndexB m IndexA + 1 TO 500 //
IF Secret[IndexB, 2] <> "" THEN
IF Decrypt(Secret[IndexB, 2]) = ThisPassword
THEN
OUTPUT "Password for " & Secret[IndexA, 1] &
"also used for " & Secret[IndexB, 1]
Duplicates m TRUE
ENDIF
ENDIF
NEXT IndexB
ENDIF
IndexA m IndexA + 1
ENDWHILE

IF Duplicates = FALSE THEN


OUTPUT "No duplicate passwords found"
ENDIF

ENDPROCEDURE

Marks as follows to Max 8:

1. (Any) conditional loop...


2. ... from 1 to 499 while (attempt at) no duplicate
3. Skip unused password
4. Use Decrypt() and assign return value to ThisPassword
5. Inner loop from outer loop index + 1 to 500 searching for duplicates
6. Compare ThisPassword with subsequent passwords (after use of
Decrypt())
7. If match found, set outer loop termination
8. and attempt an Output message giving duplicate
9. Output 'No duplicate passwords found' message if no duplicates found after the
loop

© UCLES 2022 Page 13 of 14


PAGE 1166
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2022
PUBLISHED

Question Answer Marks

8(c) One mark for each point that is referenced: 6

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)

© UCLES 2022 Page 14 of 14


MUHAMMAD ALI KHAN
PAGE 1167

Cambridge International AS & A Level


* 7 3 4 4 0 3 2 3 6 4 *

COMPUTER SCIENCE 9618/21


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2022
2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (PQ) 302745/3
© UCLES 2022 [Turn over
PAGE 1168

Refer to the insert for the list of pseudocode functions and operators.

1 (a) An algorithm includes a number of complex calculations. A programmer is writing a program


to implement the algorithm and decides to use library routines to provide part of the solution.

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.

DECLARE Name1, Name2, Name3 : STRING


DECLARE Mark1, Mark2, Mark3 : INTEGER
INPUT Name1
INPUT Mark1
INPUT Name2
INPUT Mark2
INPUT Name3
INPUT Mark3

(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]

© UCLES 2022 9618/21/O/N/22


MUHAMMAD ALI KHAN
PAGE 1169

(ii) The following pseudocode statement includes array references:

OUTPUT "Student ", Name[Count], " scored ", Mark[Count]

State the purpose of the variable Count and give its data type.

Purpose .............................................................................................................................

...........................................................................................................................................

Data type ...........................................................................................................................


[2]

(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

IF EMPTY ĸ "" THEN


Status ĸ IS_NUM(-23.4)
X ĸ STR_TO_NUM("37") + 5
Y ĸ STR_TO_NUM("37" + "5")
[4]

© UCLES 2022 9618/21/O/N/22 [Turn over


PAGE 1170

2 A system is being developed to help manage a car hire business. A customer may hire a car for a
number of days.

An abstract model needs to be produced.

(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]

© UCLES 2022 9618/21/O/N/22


MUHAMMAD ALI KHAN
PAGE 1171

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.

Describe the steps that the algorithm should perform.

Do not include pseudocode statements in your answer.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [5]

© UCLES 2022 9618/21/O/N/22 [Turn over


PAGE 1172

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.

The symbol Ø represents a null pointer.

Start pointer

'C' 'J' 'L' Ø

(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

'C' 'J' 'L'

[4]

(ii) The original data could have been stored in a 1D array in which each element stores a
character.

For example:

'C' 'J' 'L'

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).

Explain how the linked list can be implemented.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]

© UCLES 2022 9618/21/O/N/22 [Turn over


PAGE 1174

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.

Array1 Array2 Comment

}
10 15 average of first three values

20 41 average of next three values

15

}
40

41

42

Write pseudocode for the procedure Summarise().

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [5]

© UCLES 2022 9618/21/O/N/22


MUHAMMAD ALI KHAN
PAGE 1175

10

6 The following pseudocode algorithm attempts to check whether a string is a valid email address.

FUNCTION IsValid(InString : STRING) RETURNS BOOLEAN


DECLARE Index, Dots, Ats, Others : INTEGER
DECLARE NextChar : CHAR
DECLARE Valid : BOOLEAN

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

IF Dots > 1 AND Ats = 0 THEN


Valid FALSE ĸ
ELSE
Index ĸ
Index + 1
ENDIF

UNTIL Index > LENGTH(InString) OR Valid = FALSE

IF NOT (Dots >= 1 AND Ats = 1 AND Others > 8) THEN


Valid FALSE ĸ
ENDIF

RETURN Valid

ENDFUNCTION

(a) Part of the validation is implemented by the line:

IF NOT (Dots >= 1 AND Ats = 1 AND Others > 8) THEN

State the values that would result in the condition evaluating to TRUE.

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [1]

© UCLES 2022 9618/21/O/N/22


PAGE 1176

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]

© UCLES 2022 9618/21/O/N/22 [Turn over


MUHAMMAD ALI KHAN
PAGE 1177

12

7 A simple arithmetic expression is stored as a string in the format:

<Value1><Operator><Value2>

$QRSHUDWRUFKDUDFWHULVRQHRIWKHIROORZLQJ    í       

Example arithmetic expression strings:


"803+1904"
"34/7"

(a) A procedure Calculate() will:

• take an arithmetic expression string as a parameter


• evaluate the expression
• output the result.

Assume:

• the string contains only numeric digits and a single operator character
• Value1 and Value2 represent integer values
• 9DOXHDQG9DOXHDUHXQVLJQHG WKH\ZLOOQRWEHSUHFHGHGE\  RU í 

(i) Write pseudocode for the procedure Calculate().

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

© UCLES 2022 9618/21/O/N/22


PAGE 1178

13

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [7]

(ii) Calculate() is changed to a function that returns the value of the evaluated
expression.

Write the header for the function in pseudocode.

...........................................................................................................................................

..................................................................................................................................... [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.

Example string ..........................................................................................................................

Explanation ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2022 9618/21/O/N/22 [Turn over


MUHAMMAD ALI KHAN
PAGE 1179

14

8 A teacher is designing a program to perform simple syntax checks on programs written by


students. Student programs are submitted as text files, which are known as project files.

A project file may contain blank lines.

The teacher has defined the first program module as follows:

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

(a) Write pseudocode for module CheckFile().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2022 9618/21/O/N/22


PAGE 1180

15

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2022 9618/21/O/N/22 [Turn over


MUHAMMAD ALI KHAN
PAGE 1181

16

Further modules are defined as follows:

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.

Write the pseudocode statement for this call.

...................................................................................................................................................

............................................................................................................................................. [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]

(d) Module CheckLine() includes a check for syntax errors.

Two examples of syntax error that cannot be detected from examining a single line are
those involving selection and iteration.

Give two other examples.

1 ................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2022 9618/21/O/N/22


MUHAMMAD ALI KHAN
PAGE 1183
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2022

Question Answer Marks

1(a) One mark per point: 3

1 They are tried and tested so free from errors


2 They perform a function that you may not be able to program yourself
(for example encryption)
3 They are readily available / speed up development time

1(b)(i) One mark per point: 3

1 Algorithm to process / search / organise the data is easier to implement


// Values may be accessed via a loop-controlled variable / iterated
through using index
2 Makes the program easier to design / code / test / understand
3 Multiple instances referenced via a single identifier / so fewer identifiers
needed // Easier to amend the program when the number of students
increases

1(b)(ii) One mark per point: 2

Purpose: It identifies / references an individual array element // provides the


index to the array

Data type: Integer

1(c) One mark per row: 4

Statement Error

IF EMPTY m "" THEN Should be "=" not m

Status m IS_NUM(-23.4) Parameter should be a string (or


char) // should not be a real

X m STR_TO_NUM("37") + 5 NO ERROR

Y m STR_TO_NUM("37" + "5") Wrong operator – should be & or


Parameter is not a string

© UCLES 2022 Page 3 of 10


PAGE 1184
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2022

Question Answer Marks

2(a) One mark for Explanation: 3

x Abstraction is used to filter out information / data that is not necessary


for the task

Or the opposite:

x To keep only information / data that is necessary for the task

One mark for each TWO data items (not dependent on 'Explanation'):

Items include:

x Car details: ID, Car Registration, car type etc


x Customer details: ID, name, address, licence details etc
x Start date (of hire)
x Return date / Number of days (of hire)
x Cost of hire

2(b) One mark for each (Max 2) 2

Examples include:

1 Input customer details


2 Input car details
3 Input payment details
4 Create hire / start hire
5 Return car / end hire
6 Change / check car status (hired / available / written-off)
7 Cancel hire
8 Process payment / calculate hire cost

Question Answer Marks

3 One mark per point (Max 5): 5

1 Declare a variable / an integer Max


2 Assign value of first / any element to Max
3 Set up a loop to repeat 200 times / from start to end of array
4 Use the loop counter as the array index
5 If value of current element is greater than Max...
6 ...then assign value to Max
7 After the loop, Output Max

© UCLES 2022 Page 4 of 10


MUHAMMAD ALI KHAN
PAGE 1185
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2022

Question Answer Marks

4(a)(i) One mark for each: 4

1 Data A and K stored in new / existing nodes


2 Start pointer points to Node A
3 Node A points to Node C and Node C points to Node K
4 Node K contains Null Pointer

4(a)(ii) One mark per point: 2

1 Pointers determine the ordering of data // only the pointers need to be


changed when data changed
2 Easier to add / delete data (to maintain correct sequence) in a linked list
// description of moving data to maintain correct sequence when array
used

4(a)(iii) One mark per point: 2

1 Need to store pointers as well as data


2 More complex (to setup / implement)

4(b) One mark per point (Max 4): 4

1 Declare two (1D) arrays


2 One for data, one for pointers
3 Elements from same index represent one node
4 Declare an integer / variable for StartPointer // explain its use
5 Define appropriate value for null pointer // explain its use
6 Declare an integer / variable for FreeList pointer // explain its use
7 Routines are needed to add / delete / search

Alternative MP1, 2 and 3 for record-based implementation:

1 Define a record type with fields for data and pointer


2 Declare one (1D) array
3 ...of the defined record type

© UCLES 2022 Page 5 of 10


PAGE 1186
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2022

Question Answer Marks

5 Mark as follows (Max 5): 5

1 Procedure heading and ending and declaration of both indexes


2 Loop to process all elements from Array1
3 Sum (any) three consecutive values from Array1 and divide by 3
in a loop
4 Convert result to Integer
5 Assign value to correct element of Array2 in a loop
6 Increment Array2 index in a loop

PROCEDURE Summarise()
DECLARE Value : REAL
DECLARE IxA, IxB : INTEGER // Index variables

IxB m 1

FOR IxA m 1 TO 598 STEP 3


Value m Array1[IxA] + Array1[IxA + 1] + Array1[IxA + 2]
Value m Value / 3
Array2[IxB] m INT(Value)
IxB m IxB + 1
NEXT IxA

ENDPROCEDURE

Question Answer Marks

6(a) One mark for any part correct (accept equivalent wording) (Max 1): 1

x Condition evaluates to TRUE if bracket contents evaluate to FALSE:

x Bracket contents evaluate to FALSE if:

x Dots: zero / less than one


or
x Ats: not equal to one
or
x Others: less than nine

© UCLES 2022 Page 6 of 10


MUHAMMAD ALI KHAN
PAGE 1187
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2022

Question Answer Marks

6(b)(i) One mark for each area as outlined: 5

Index NextChar Dots Ats Others Valid

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

© UCLES 2022 Page 7 of 10


PAGE 1188
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2022

Question Answer Marks

7(a)(i) One mark per point (Max 7) as follows: 7

1 Declaration of local variables for Par1 Par2 and Par3


2 Loop to end of (parameter) string // until operator is found
3 Extract a character in a loop...
4 Attempt at extraction of three parts of expression using substring
functions
5 Completely correct extraction of all three parts of expression
6. Convert string to Integer using STR_TO_NUM(<something
sensible>)
7 Attempt to interpret at least two operators (Par2): + - * /
8 Corresponding correct calculation (all operators) and final Output of
result

PROCEDURE Calculate(Expression : STRING)


DECLARE Val1, Val2, Index : INTEGER
DECLARE Result : REAL
DECLARE Par1, Par2, Par3 : STRING

CONSTANT PLUS = '+'


CONSTANT MINUS = '-'
CONSTANT MULTIPLY = '*'
CONSTANT DIVIDE = '/'

FOR Index m 1 TO LENGTH(Expression) //search for


operator
ThisChar m MID(Expression, Index, 1)
IF IS_NUM(ThisChar) = FALSE THEN
Par1 m LEFT(Expression, Index – 1)
Par2 m ThisChar
Par3 m RIGHT(Expression, LENGTH(Expression) –
Index)
ENDIF
NEXT Index

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

7(a)(ii) FUNCTION Calculate(Expression : STRING) RETURNS REAL 1

© UCLES 2022 Page 8 of 10


MUHAMMAD ALI KHAN
PAGE 1189
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2022

Question Answer Marks

7(b) Example string: "23/0" (Any divide by zero example) 2

Reason: The result is infinity / cannot be represented / is undefined // will


cause the program to crash

Question Answer Marks

8(a) One mark for each point (Max 7) as follows: 7


1 Function heading and ending including parameter and return type
2 Declaration and initialisation of local Integer for Count
3 OPEN in READ mode and CLOSE
4 Conditional loop until EOF()
5 Read a line in a loop
6 If non-blank, increment count in a loop
7 Terminate loop when 10 non-blank lines have been read
8 Return Boolean in both cases

FUNCTION CheckFile(Thisfile : STRING) RETURNS BOOLEAN


DECLARE Valid : BOOLEAN
DECLARE ThisLine : STRING
DECLARE Count : INTEGER

Count m 0
Valid m FALSE
OPEN ThisFile FOR READ

WHILE NOT EOF(ThisFile) AND Valid = FALSE


READFILE ThisFile, ThisLine
IF ThisLine <> "" THEN
Count m Count + 1
IF Count > 9 THEN
Valid m TRUE
ENDIF
ENDIF
ENDWHILE

CLOSEFILE ThisFile
RETURN Valid

ENDFUNCTION

8(b) CALL CountErrors("Jim01Prog.txt", 20) 2

One mark for each:

1 Module name, at least one parameter in brackets and one parameter


correct
2 Completely correct statement

© UCLES 2022 Page 9 of 10


PAGE 1190
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2022

Question Answer Marks

8(c) Mark as follows: 8


1 Procedure heading and ending including parameters
2 Declaration and initialisation of local Integer value for ErrCount
3 Use of CheckFile(), output message and terminate if it returns
FALSE
4 Conditional loop until EOF()
5 ...or ErrCount > MaxErrors
6 Read line and use as parameter to CheckLine()in a loop
7 Test return value and increment ErrCount if non-zero in a loop
8 Output either message once only as appropriate

PROCEDURE CountErrors(ThisFile : STRING, MaxErrors :


INTEGER)
DECLARE ErrCount, ThisError : INTEGER
DECLARE ThisLine : STRING

ErrCount m 0

IF CheckFile(ThisFile) = FALSE THEN


OUTPUT "That program file is not valid"
ELSE
OPEN ThisFile FOR READ

REPEAT
READFILE, ThisFile, ThisLine
ThisError m CheckLine(ThisLine)
IF ThisError <> 0 THEN
ErrCount m ErrCount + 1
ENDIF
UNTIL ErrCount > MaxErrors OR EOF(ThisFile)

IF EOF(ThisFile) = FALSE THEN


OUTPUT "Check terminated – too many errors"
ELSE
OUTPUT "There were ", ErrCount, " errors."
ENDIF

CLOSEFILE ThisFile
ENDIF

ENDPROCEDURE

8(d) One mark for each (Max 2): 2

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

© UCLES 2022 Page 10 of 10


MUHAMMAD ALI KHAN
PAGE 1191

Cambridge International AS & A Level


* 5 9 0 4 1 3 6 4 7 7 *

COMPUTER SCIENCE 9618/22


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2022
2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (LK/JG) 302746/2
© UCLES 2022 [Turn over
PAGE 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]

(ii) A procedure header is shown in pseudocode:

PROCEDURE MyProc(Count : INTEGER, Message : STRING)

Give the correct term for the identifiers Count and Message and explain their use.

Term ..................................................................................................................................

Use ....................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[2]

(b) The algorithm in part (a) is part of a program that will be sold to the public.
All the software errors that were identified during in-house testing have been corrected.

Identify and describe the additional test stage that may be carried out before the program is
sold to the public.

Test stage .................................................................................................................................

Description ................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[4]

© UCLES 2022 9618/22/O/N/22


MUHAMMAD ALI KHAN
PAGE 1193

(c) Part of an identifier table is shown:

Variable Type Example value


FlagDay DATE 23/04/2004
CharList STRING "ABCDEF"
Count INTEGER 29

Complete the table by evaluating each expression using the example values.

Expression Evaluation
MID(CharList, MONTH(FlagDay), 1)
INT(Count / LENGTH(CharList))
(Count >= 29) AND (DAY(FlagDay) > 23)
[3]

2 (a) An algorithm will process data from a test taken by a group of students. The algorithm will
prompt and input the name and test mark for each of the 35 students.

The algorithm will add the names of all the students with a test mark of less than 20 to an
existing text file Support_List.txt, which already contains data from other group tests.

(i) Describe the steps that the algorithm should perform.

Do not include pseudocode statements in your answer.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [5]

© UCLES 2022 9618/22/O/N/22 [Turn over


PAGE 1194

(ii) Explain why it may be better to store the names of the students in a file rather than in an
array.

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [1]

(iii) Explain why WRITE mode cannot be used in the answer to part 2(a)(i).

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [1]

(b) Examine the following state-transition diagram.

Input-A Output-X
Input-B Output-W

Input-B
START
S1 S2
S3

Input-A
Input-A

Input-B
S4 Input-A Output-W

Complete the table to show the inputs, outputs and next states.

Input Output Next state

S1

Input-A

S2

Output-W

Output-W

[4]

© UCLES 2022 9618/22/O/N/22


MUHAMMAD ALI KHAN
PAGE 1195

3 A stack is used in a program to store string data which needs to be accessed in several modules.

(a) A stack is an example of an Abstract Data Type (ADT).

Identify one other example of an ADT and describe its main features.

Example ....................................................................................................................................

Features ...................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

(b) Explain how the stack can be implemented using an array.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

© UCLES 2022 9618/22/O/N/22 [Turn over


PAGE 1196

(c) A second stack is used in the program. The diagram below shows the initial state of this
stack. Value X is at the top of the stack and was the last item added.

Upper-case letters are used to represent different data values.

Stack operations are performed in three groups as follows:

Group 1:
PUSH D
PUSH E

Group 2:
POP
POP
POP

Group 3:
PUSH A
PUSH B
POP
PUSH C

Complete the diagram to show the state of the stack after each group of operations has been
performed.

Include the current stack pointer (SP) after each group.

Memory Initial After After After


location state Group 1 Group 2 Group 3

957

956

955

954

953 X ĸSP
952 Y

951 Z

950 P

[5]

© UCLES 2022 9618/22/O/N/22


MUHAMMAD ALI KHAN
PAGE 1197

BLANK PAGE

© UCLES 2022 9618/22/O/N/22 [Turn over


PAGE 1198

4 The program flowchart represents a simple algorithm.

START

INPUT UserID

Set Average to
GetAverage(UserID)

Set Total to 0

Set Index to 4

Add 1 to Index

YES
Is Index < 7 ?

NO Set Last to
SameMonth[Index]

Is Average NO
> Last ? Add Last to Total

YES

Add Average to Total

Update(UserID, Total)

END

© UCLES 2022 9618/22/O/N/22


MUHAMMAD ALI KHAN
PAGE 1199

(a) Write the equivalent pseudocode for the algorithm represented by the flowchart.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

(b) Give the name of the iterative construct in the flowchart.

............................................................................................................................................. [1]

© UCLES 2022 9618/22/O/N/22 [Turn over


PAGE 1200

10

5 Examine the following pseudocode.

IF A = TRUE THEN
IF B = TRUE THEN
IF C = TRUE THEN
CALL Sub1()
ELSE
CALL Sub2()
ENDIF
ENDIF
ELSE
IF B = TRUE THEN
IF C = TRUE THEN
CALL Sub4()
ELSE
CALL Sub3()
ENDIF
ELSE
IF C = FALSE THEN
CALL Sub3()
ELSE
CALL Sub4()
ENDIF
ENDIF
ENDIF

A programmer wants to re-write the pseudocode as four separate IF...THEN...ENDIF


statements, each containing a single CALL statement. This involves writing a single, simplified
logic expression as the condition in each statement.

Write the amended pseudocode.

1 .......................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

2 .......................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

3 .......................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

4 .......................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................
[4]
© UCLES 2022 9618/22/O/N/22
MUHAMMAD ALI KHAN
PAGE 1201

11

BLANK PAGE

© UCLES 2022 9618/22/O/N/22 [Turn over


PAGE 1202

12

6 (a) The factorial of an integer number is the product of all the integers from that number down
to 1.

In general, the factorial of n is n ) Qí ) ... ) 2 ) 1

For example, the factorial of 5 is 5 ) 4 ) 3 ) 2 ) 1 = 120

In this question, n will be referred to as the BaseNumber.

A function FindBaseNumber() will:


• be called with a positive, non-zero integer value as a parameter
• return BaseNumber if the parameter value is the factorial of the BaseNumber
• UHWXUQíLIWKHSDUDPHWHUYDOXHis not a factorial.

For example:

Parameter value Value returned


120 5
12 í
6 3
1 1

FindBaseNumber(12)ZLOOUHWXUQíEHFDXVHLVQRWDIDFWRULDO

You may use the rest of this page for rough working.

© UCLES 2022 9618/22/O/N/22


MUHAMMAD ALI KHAN
PAGE 1203

13

Write pseudocode for the function FindBaseNumber().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2022 9618/22/O/N/22 [Turn over


PAGE 1204

14

(b) A program is written to allow a user to input a sequence of values to be checked using the
function FindBaseNumber().

The user will input one value at a time. The variable used to store the user input has to be of
type string because the user will input ‘End’ to end the program.

Valid input will be converted to an integer and passed to FindBaseNumber() and the return
value will be output.

Complete the table by giving four invalid strings that may be used to test distinct aspects of
the required validation. Give the reason for your choice in each case.

Input Reason for choice

......................................................................................................

......................................................................................................

......................................................................................................

......................................................................................................

......................................................................................................

......................................................................................................

......................................................................................................

......................................................................................................

......................................................................................................

......................................................................................................

......................................................................................................

......................................................................................................

[4]

© UCLES 2022 9618/22/O/N/22


MUHAMMAD ALI KHAN
PAGE 1205

15

BLANK PAGE

© UCLES 2022 9618/22/O/N/22 [Turn over


PAGE 1206

16

7 A teacher is designing a program to perform simple syntax checks on programs written by


students.

Two global 1D arrays are used to store the syntax error data. Both arrays contain 500 elements.
• Array ErrCode contains integer values that represent an error number in the range 1 to 800.
• Array ErrText contains string values that represent an error description.

The following diagram shows an example of the arrays.

Index ErrCode ErrText


1 10 "Invalid identifier name"
2 20 "Bracket mismatch"
3 50 "Undeclared variable"
4 60 "Type mismatch in assignment"

500 999 <Undefined>

Note:
• There may be less than 500 error numbers so corresponding elements in both arrays may be
unused. Unused elements in ErrCode have the value 999. The value of unused elements in
ErrText is undefined.
• Values in the ErrCode array are stored in ascending order but not all values may be present,
for example, there may be no error code 31.

The teacher has defined two program modules as follows:

Module Description

• takes two parameters as integers:


ż a line number in the student’s program
ż an error number
• searches for the error number in the ErrCode array:
OutputError() ż if found, outputs the corresponding error description and the
line number, for example:
"Bracket mismatch on line 34"
ż if not found, outputs the line number and a warning, for
example:
"Unknown error on line 34"

SortArrays() sorts the arrays into ascending order of ErrCode

© UCLES 2022 9618/22/O/N/22


MUHAMMAD ALI KHAN
PAGE 1207

17

(a) Write efficient pseudocode for module OutputError().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2022 9618/22/O/N/22 [Turn over


PAGE 1208

18

(b) Write an efficient bubble sort algorithm in pseudocode for module SortArrays().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2022 9618/22/O/N/22


MUHAMMAD ALI KHAN
PAGE 1209

19

(c) Two 1D arrays were described at the beginning of the question. Both arrays contain 500
elements.
• Array ErrCode contains integer values that represent an error number in the range
1 to 800.
• Array ErrText contains string values that represent an error description.

The two arrays will be replaced by a single array. A user-defined data type (record structure)
has been declared as follows:
TYPE ErrorRec
DECLARE ErrCode : STRING
DECLARE ErrText : STRING
ENDTYPE

(i) State the error in the record declaration.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) State two benefits of using the single array of the user-defined data type.

1 ........................................................................................................................................

...........................................................................................................................................

2 ........................................................................................................................................

...........................................................................................................................................
[2]

(iii) Write the declaration for the single array in pseudocode.

..................................................................................................................................... [1]

© UCLES 2022 9618/22/O/N/22


PAGE 1210
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2022

Question Answer Marks

1(a)(i) One mark for each point (Max 2): 2

x When a task which is repeated / reused / performed in several places


x When a part of an algorithm performs a specific task
x Reduces complexity of program / program is simplified // subroutine
already available
x Testing / debugging / maintenance is easier

1(a)(ii) One mark for each part: 2

Term: Parameter(s)

Use: to pass values / arguments to the procedure

1(b) One mark for test stage, one mark for each description point 4
(Max 3 for Description)

Test stage: Beta testing

Description:

1 Testing carried out by a small group of (potential) users


2 Users will check that the software works as required / works in the real
world / does not contain errors
3 Users will feedback problems / suggestions for improvement
4 Problems / suggestions identified are addressed (before the program is
sold)

1(c) One mark per row: 3

Expression Evaluation

MID(CharList, MONTH(FlagDay), 1) 'D'

INT(Count / LENGTH(CharList)) 4

(Count >= 99) AND (DAY(FlagDay) > 23) FALSE

© UCLES 2022 Page 3 of 13


MUHAMMAD ALI KHAN
PAGE 1211
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2022

Question Answer Marks

2(a)(i) One mark per step (or equivalent): 5

1 Open file in APPEND mode (and subsequent Close)


2 Prompt and Input a student name and mark
3 If mark greater than or equal to 20 jump to step 5
4 Write only the name to the file
5 Repeat from Step 2 for 35 times / the number of students

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

2(a)(iii) Example answer: 1

So that existing file data is not overwritten.

2(b) One mark per row (row 2 to 5): 4

Input Output Next state

S1

Input-A Output-X S2

Input-A (none) S2

Input-B Output-W S3

Input-A Output-W S4

© UCLES 2022 Page 4 of 13


PAGE 1212
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2022

Question Answer Marks

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:

Name: Linked List

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

3(b) One mark per point (Max 5): 5

1 Declare a (1D) array of data type STRING


2 The number of elements in that array corresponds to the size of the
required stack
3 Declare an integer / variable for StackPointer
4. Declare an integer / variable for the size of the stack // for the max value
of StackPointer
5 Use the StackPointer as an index to the array
6 Pointers and variables initialised to indicate empty stack
7 Store each item on the stack as one array element / Each stack item
maps to one array element
8 Attempt to describe Push and Pop operations
9 Push and Pop routines need to check for full or empty conditions

© UCLES 2022 Page 5 of 13


MUHAMMAD ALI KHAN
PAGE 1213
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2022

Question Answer Marks

3(c) One mark for each: 5

1 Data 'After Group 1' (as shown, including blank cells)


2 Data 'After Group 2' (as shown, including blank cells)
3 Data 'After Group 3' (as shown, including blank cells)
4 SP 'After Group 1' pointing to location 955
5 Final two SPs pointing to locations 952 and 954

© UCLES 2022 Page 6 of 13


PAGE 1214
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2022

Question Answer Marks

4(a) One mark per point: 6

1 Input UserID and use of GetAverage()and assignment


2 Initialisation of Total to zero and Index to 4
3 Conditional loop with Index from 4 to 6
4 Assignment of Last from element SameMonth[Index] in a loop
5 Structure: IF...THEN...ELSE...ENDIF in a loop
6 Correct assignments and final call to Update()after the loop

INPUT UserID
Average m GetAverage(UserID)
Total m 0
Index m 4

WHILE Index < 7 // REPEAT


Last m SameMonth[Index]
IF Average > Last THEN
Total m Total + Average
ELSE
Total m Total + Last
ENDIF
Index m Index + 1
ENDWHILE // UNTIL Index = 7

CALL Update(UserID, Total)

Alternative solution using FOR loop:

One mark per point FOR loop solution:


1 Input UserID and use of GetAverage()and assignment
2 Initialisation of Total to zero
3 loop Index from 4 to 6
4 Assignment of Last from array SameMonth in a loop
5 Comparison IF...THEN...ELSE...ENDIF in a loop
6 Appropriate assignments in a loop AND final call to Update()after
the loop

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

CALL Update(UserID, Total)

© UCLES 2022 Page 7 of 13


MUHAMMAD ALI KHAN
PAGE 1215
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2022

Question Answer Marks

4(b) Pre-condition (loop) / count-controlled (loop) 1

Question Answer Marks

5 One mark per IF...THEN...ENDIF clause: 4

1 IF A AND B AND C THEN


CALL Sub1()
ENDIF

2 IF (A AND B) AND NOT C THEN


CALL Sub2()
ENDIF

3 IF (NOT A) AND (NOT C) THEN


CALL Sub3()
ENDIF

4 IF (NOT A) AND C THEN


CALL Sub4()
ENDIF

© UCLES 2022 Page 8 of 13


PAGE 1216
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2022

Question Answer Marks

6(a) Example by repeated multiplication: 7

Mark as follows (multiplication solution), (Max 7):

1 Function heading and ending including parameter and return type


2 Declaration and initialisation of local Num
3 Any conditional loop
4 Conditional loop until ThisValue found or Try out of range
5 Multiply Try by Num in a loop
6 Compare Try with ThisValue and set termination if the same in
a loop
7 Increment Num and repeat in a loop
8 Attempt to Return Num if ThisValue is a factorial or -1 otherwise

FUNCTION FindBaseNumber(ThisValue : INTEGER) RETURNS


INTEGER
DECLARE Num, Try : INTEGER
DECLARE Found : BOOLEAN

Num m 0
Found m FALSE
Try m 1

WHILE Try <= ThisValue AND Found = FALSE


Num m Num + 1
Try m Try * Num
IF Try = ThisValue THEN //BaseNumber found
Found m TRUE
ENDIF
ENDWHILE

IF Found = TRUE THEN


RETURN Num
ELSE
RETURN -1
ENDIF

ENDFUNCTION

© UCLES 2022 Page 9 of 13


MUHAMMAD ALI KHAN
PAGE 1217
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2022

Question Answer Marks

6(a) Alternative FOR LOOP solution.

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

FUNCTION FindBaseNumber(ThisValue : INTEGER) RETURNS


INTEGER
DECLARE Num, Try : INTEGER

Try m 1

FOR Num m 1 TO ThisValue


Try m Try * Num
IF Try = ThisValue THEN //BaseNumber found
RETURN Num
ENDIF
NEXT Num

RETURN -1

ENDFUNCTION

6(b) One mark per row. 4

Examples of invalid strings:

1 Non-numeric but not "End" // contains space or other non-numeric


characters
2 Real number
3 Integer value out of range (i.e. <= 0)
4 Empty string
5 Correct word but wrong case e.g. "end" rather than "End"

Input Reason for choice

"Aardvark" Non-numeric (and not "End")

"27.3" Numeric but not an integer

"-3" // "0" A non-positive integer

"" An empty string

© UCLES 2022 Page 10 of 13


PAGE 1218
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2022

Question Answer Marks

7(a) One mark per point (Max 6): 6

1 Procedure heading and ending including parameters


2 Conditional loop containing incrementing Index...
3 ...terminating when ErrNum found
4 ...terminating when ErrCode[Index] > ErrNum (i.e. ErrNum
not found)
5 ... OR after element 500 tested
6 Test if found and OUTPUT 'Found' message
7 ...otherwise OUTPUT 'Not Found' message

PROCEDURE OutputError(LineNum, ErrNum : INTEGER)


DECLARE Index : INTEGER

Index m 0

// Search until ErrNum found OR not present OR end of


array

REPEAT
Index m Index + 1
UNTIL ErrCode[Index] >= ErrNum OR Index = 500

IF ErrCode[Index] = ErrNum THEN


OUTPUT ErrText[Index], " on line ", LineNum
//Found
ELSE
OUTPUT "Unknown error on line ", LineNum //Not
found
ENDIF

ENDPROCEURE

© UCLES 2022 Page 11 of 13


MUHAMMAD ALI KHAN
PAGE 1219
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2022

Question Answer Marks

7(b) One mark per point (Max 8): 8

1 Procedure heading and ending as shown


2 Conditional loop correctly terminated
3 An inner loop
4 Correct range for inner loop
5 Comparison (element J with J+1) in a loop
6 Swap elements in both arrays in a loop
7 'No-Swap' mechanism:
x Conditional outer loop including flag reset
x Flag set in inner loop to indicate swap
8 Efficiency (this scenario): terminate inner loop when ErrCode = 999
9 Reducing Boundary in the outer loop

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

7(c)(i) ErrCode should be an INTEGER // ErrCode should not be a STRING 1

© UCLES 2022 Page 12 of 13


PAGE 1220
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2022

Question Answer Marks

7(c)(ii) Benefits include: 2

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

One mark per point

Note: Max 2 marks

7(c)(iii) DECLARE Error : ARRAY[1:500] OF ErrorRec 1

© UCLES 2022 Page 13 of 13


MUHAMMAD ALI KHAN
PAGE 1221

Cambridge International AS & A Level


* 1 2 8 1 9 6 8 3 4 2 *

COMPUTER SCIENCE 9618/21


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2023

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (EF/SG) 338525/4
© UCLES 2023 [Turn over
PAGE 1222

Refer to the insert for the list of pseudocode functions and operators.

1 A programmer has written a program which includes the function Calculate().


When the program is run, the function returns an unexpected value.

(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.

Statement 1: Index STR_TO_NUM(("27") + 2)

Error ..........................................................................................................................................

...................................................................................................................................................

Statement 2: Index STR_TO_NUM(MID("CPE1704TKS", 4, 2))

Error ..........................................................................................................................................

...................................................................................................................................................

Statement 3: IF MONTH(ThisDate) > '6' THEN

Error ..........................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2023 9618/21/M/J/23


MUHAMMAD ALI KHAN
PAGE 1223

(c) The program contains variables with values as follows:

Variable Value
Active TRUE
Points 75
Exempt FALSE

(i) Complete the table by evaluating each expression.

Expression Evaluation

1 (Points > 99) OR Active

2 (Points MOD 2 = 0) OR Exempt

3 (Points <= 75) AND (Active OR Exempt)

4 (Active OR NOT Active) AND NOT Exempt

[2]

(ii) Write expression 4 from the table in part (c)(i) in its simplest form.

..................................................................................................................................... [1]

© UCLES 2023 9618/21/M/J/23 [Turn over


PAGE 1224

2 A program contains an algorithm to output a string of a specified length containing identical


characters.

(a) The algorithm is described as follows:


1. prompt and input a character and store in MyChar
2. prompt and input an integer and store in MyCount
3. generate a string consisting of MyChar repeated MyCount times
4. output the string.

Draw a program flowchart to represent the algorithm.

START

END

[4]
© UCLES 2023 9618/21/M/J/23
MUHAMMAD ALI KHAN
PAGE 1225

(b) A different part of the program uses the variable StartDate.

Write pseudocode statements to declare StartDate and assign to it the date corresponding
to 15/11/2005.

Declaration ...............................................................................................................................

Assignment ...............................................................................................................................
[3]

© UCLES 2023 9618/21/M/J/23 [Turn over


PAGE 1226

3 Customers collect points every time they make a purchase at a store.

A program is used to manage the points system and the table lists some of the information stored
for one customer.

Information Data type required


Name String
Number of points collected Integer
Date of birth Date

(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]

© UCLES 2023 9618/21/M/J/23


MUHAMMAD ALI KHAN
PAGE 1227

(b) Customers receive points depending on the amount they spend. The number of points
depends on the band that the amount falls into:

Band Amount Points


1 Less than $10 5 per whole dollar ($)
2 Between $10 and $100 inclusive 7 per whole dollar ($)
3 Over $100 10 per whole dollar ($)

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.

Write the five steps.

1 ................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

3 ................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

4 ................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

5 ................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[5]
© UCLES 2023 9618/21/M/J/23 [Turn over
PAGE 1228

4 Function Replace() will:


1. take three parameters:
• a string (the original string)
• a char (the original character)
• a char (the new character)

2. form a new string from the original string where all instances of the original character are
replaced by the new character

3. return the new string.

Write pseudocode for function Replace().

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [6]

© UCLES 2023 9618/21/M/J/23


MUHAMMAD ALI KHAN
PAGE 1229

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]

© UCLES 2023 9618/21/M/J/23 [Turn over


PAGE 1230

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().

A procedure Mix() will:


• calculate the average of each of the 6 sound samples in a column
• ignore sound sample values of 10 or less
• store the average value in the corresponding position in Result
• repeat for each column in array Sample

The diagram uses example values to illustrate the process:

1 2 3 ... 126 127 128


1 20 20 20 30 30 2
2 20 20 30 50 30 3
3 20 20 40 40 40 4
Sample:
4 20 20 50 40 50 20
5 20 3 5 6 60 4
6 20 4 2 4 70 30

Result: 20 20 35 40 46 25

© UCLES 2023 9618/21/M/J/23


MUHAMMAD ALI KHAN
PAGE 1231

11

Write pseudocode for procedure Mix().

Assume Sample and Result are global.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [6]

© UCLES 2023 9618/21/M/J/23 [Turn over


PAGE 1232

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]

© UCLES 2023 9618/21/M/J/23


MUHAMMAD ALI KHAN
PAGE 1233

13

(b) The program designer produces a structure chart for the new module. Part of the structure
chart is shown:

Module-A()

Module-B() Module-C() Module-D()

(i) Explain the relationship between the four modules shown.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(ii) Two new modules are added: Module-X() and Module-Y().


• Module-X() has no parameters.
• Module-Y() will take a string and a real number as parameters and return a
Boolean value.
• Module-D() will call either Module-X() or Module-Y().

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>

Item information is as follows:

Format Comment
unique for each item in the range
ItemNum 4 numeric characters
"0001" to "5999" inclusive

SupplierCode 5 alphabetic characters to identify the supplier of the item

Description a string a minimum of 12 characters

The file is organised in ascending order of ItemNum and does not contain all possible values in
the range.

A programmer has started to define program modules as follows:

Module Description
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

© UCLES 2023 9618/21/M/J/23


MUHAMMAD ALI KHAN
PAGE 1235

15

(a) Write pseudocode for module IsNewSupp().

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]

© UCLES 2023 9618/21/M/J/23 [Turn over


PAGE 1236

16

(b) A new module has been defined:

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

Write efficient pseudocode for module CheckNewItem().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2023 9618/21/M/J/23


MUHAMMAD ALI KHAN
PAGE 1237

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.

(i) Identify this method of testing.

..................................................................................................................................... [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

Question Answer Marks

1(a) For example: 4

Could set a breakpoint to stop the program at a particular point / instruction


then the value of variables could be checked using a report/watch window
while single stepping can be used to execute one statement/line at a time.

Marks available as follows:

x One mark for each underlined term


x One mark for an explanation of each term

Note: max 4 marks

1(b) One mark for correct description of: 3

Error 1: Brackets mismatch // 2/value should be added after


brackets/function // Addition between a string and a number is not valid //
STR_TO_NUM / the function needs to be passed a string / not an integer

Error 2: No Error

Error 3: MONTH() returns an integer and this is being compared with a


character/string // Integer cannot be compared to a string // 6 should not be
in quotes

1(c)(i) 2
Expression Evaluation

1 (Points > 99) OR Active TRUE

2 (Points MOD 2 = 0) OR Exempt FALSE

3 (Points <= 75) AND (Active OR Exempt) TRUE

4 (Active OR NOT Active) AND NOT Exempt TRUE

One mark for any two rows correct


Two marks for all rows correct

1(c)(ii) NOT Exempt 1

© UCLES 2023 Page 3 of 11


MUHAMMAD ALI KHAN
PAGE 1239
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

2(a) 4

One mark per point:

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

2(b) One mark for declaration: 3

DECLARE StartDate : DATE

One mark for each underlined part of assignment:

StartDate m SETDATE (15, 11, 2005)

© UCLES 2023 Page 4 of 11


PAGE 1240
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

3(a)(i) One mark for structure 4

Structure: Record

One mark for each point

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

One mark per underlined word

3(b) One mark for reference to each: 5

1 Reference to the use of constants or variables for the two threshold


values of 10 and 100 // Input amount spent (by customer and store in a
numeric variable)
2 Work out one band that amount maps to
3 Work out all bands that amount maps to
4 Calculate rounded value of amount / whole number part of amount
5 Calculate the points by multiplying the (rounded) amount by the
appropriate value for appropriate band /all bands
6 Output the number of points

Note: Max 5 from available points

© UCLES 2023 Page 5 of 11


MUHAMMAD ALI KHAN
PAGE 1241
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

4 Function Replace(OldString : STRING, Char1, Char2 : 6


CHAR) __ RETURNS : STRING
DECLARE NewString : STRING
DECLARE ThisChar : CHAR
DECLARE Index : INTEGER

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

Question Answer Marks

5(a)(i) Reasons include: 2


1 No working software until late in the life cycle so slower to market than
competitors // Does not allow the creation of early versions/prototypes
(which can be updated later)
2 More difficult/slower to cope with changes to the requirements //
website slower to be updated to reflect new requirements
3 Needs high involvement/feedback of the stake holders /customer / client

One mark per point

Max 2 marks

5(a)(ii) Iterative / Rapid Application Development / RAD 1

© UCLES 2023 Page 6 of 11


PAGE 1242
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

5(b) One mark for Stage 3

Stage: Beta testing

Max 2 marks for Description

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)

Question Answer Marks

6 PROCEDURE Mix() 6
DECLARE Count, Total ThisNum : INTEGER
DECLARE ThisUser, ThisSample : INTEGER

FOR ThisSample m 1 TO 128


Count m 0
Total m 0
FOR ThisUser m 1 TO 6
IF Sample[ThisUser, ThisSample] > 10 THEN
Count m Count + 1
Total m Total + Sample[ThisUser, ThisSample]
ENDIF
NEXT ThisUser
Result[ThisSample] m INT(Total / Count)
NEXT ThisSample

ENDPROCEDURE

Mark as follows:

1 Declaration and initialisation before inner loop of Count and Total


2 Outer Loop for 128 iterations
3 Inner loop for six iterations
4 Test for sample > 10 in a loop
5 and if true sum Total and increment Count
6 Calculate average value and assign to Result array after inner loop
and within outer loop
7 Use of INT()/ DIV to convert average to integer

Max 6 Marks

© UCLES 2023 Page 7 of 11


MUHAMMAD ALI KHAN
PAGE 1243
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

7(a) Examples include: 3

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

One mark for name and use

Note: Max 3 marks

7(b)(i) One mark per point: 2


x Module-A calls the other three modules
x The process is repeated

7(b)(ii) 3

One mark per bullet point:


x All rectangles correctly labelled and interconnected
x All and only parameters as shown
x Selection diamond

© UCLES 2023 Page 8 of 11


PAGE 1244
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

8(a) FUNCTION IsNewSupp(ThisString : STRING) RETURNS BOOLEAN 7


DECLARE Index : INTEGER
DECLARE ThisChar : CHAR

IF LENGTH(ThisString) <> 5 THEN


RETURN FALSE // invalid SupplierCode length
ENDIF

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:

1 Check ThisString is exactly 5 characters in length


2 Use of SuppExists() with a string of 5 characters as a parameter
3 Loop for 5 iterations // loops for length of string parameter
4 Extract a character in a loop
5 Test if char is alphabetic in a loop
6 …catering for both upper and lower case
7 Return Boolean following a reasonable attempt

© UCLES 2023 Page 9 of 11


MUHAMMAD ALI KHAN
PAGE 1245
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

8(b) FUNCTION CheckNewItem(NewLine : STRING) RETURNS BOOLEAN 7


DECLARE NotFound : BOOLEAN
DECLARE NewItemNum, ThisItemNum, ThisLine : STRING

NotFound m TRUE

OPENFILE "Stock.txt" FOR READ


NewItemNum m LEFT(NewLine, 4)
ThisItemNum m "0000" //rogue initial value

WHILE NOT EOF("Stock.txt") AND NotFound = TRUE AND__


ThisItemNum < NewItemNum
READFILE("Stock.txt", ThisLine) //brackets optional
ThisItemNum m LEFT(ThisLine, 4)
IF ThisItemNum = NewItemNum THEN
NotFound m FALSE
ENDIF
ENDWHILE

CLOSEFILE "Stock.txt"

RETURN NotFound
ENDFUNCTION

Mark as follows:

1 Open Stock.txt in READ mode and subsequently close


2 Extract NewItemNum from parameter
3 Conditional loop until EOF("Stock.txt")
4 ... OR NewItemNum found
5 ... OR when ThisItemNum < NewItemNum
6 Read a line from Stock.txt AND extract ThisItemNum in a
loop
7 If ThisItemNum = NewItemNum then terminate loop / set flag in
a loop
8 Return Boolean after reasonable attempt

Max 7 marks

Max 6 if function wrapper (heading and ending) missing or incorrect

8(c)(i) Integration testing 1

8(c)(ii) Two marks for the description: 2

x A dummy/simple module is written to replace the module that does not


work properly
x The dummy/simple module will return an expected value // will output a
message to show it has been called

8(d) Append 1

© UCLES 2023 Page 10 of 11


PAGE 1246
9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

8(e) One mark for each part: 3

x The algorithm / search / iteration can stop /only iterates


x if the current value read from the file // current line in file
x is greater than the value being searched for

© UCLES 2023 Page 11 of 11


MUHAMMAD ALI KHAN
PAGE 1247

Cambridge International AS & A Level


* 3 0 3 3 2 5 1 8 2 6 *

COMPUTER SCIENCE 9618/22


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2023

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (EF/SG) 312086/3
© UCLES 2023 [Turn over
PAGE 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:

IF Weight < 250 AND ValidAddress = TRUE THEN


ItemPostalCost 3.75 // set postal cost for item to $3.75
ItemStatus "Valid" // item can be sent
ENDIF

(a) (i) Identify a more appropriate way of representing the postal costs.

..................................................................................................................................... [1]

(ii) Describe the advantages of your answer to part (a)(i) with reference to this program.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

(b) The lines of pseudocode contain features that make them easier to understand.

State three of these features.

1 ................................................................................................................................................

2 ................................................................................................................................................

3 ................................................................................................................................................
[3]

(c) Give the appropriate data types for the following variables:

ValidAddress ........................................................................................................................

ItemPostalCost ...................................................................................................................

ItemStatus ............................................................................................................................
[3]

© UCLES 2023 9618/22/M/J/23


MUHAMMAD ALI KHAN
PAGE 1249

2 A program stores a user’s date of birth using a variable MyDOB of type DATE.

(a) Write a pseudocode statement, using a function from the insert, to assign the value
corresponding to 17/11/2007 to MyDOB.

............................................................................................................................................. [1]

(b) MyDOB has been assigned a valid value representing the user’s date of birth.

Write a pseudocode statement to calculate the number of months from the month of the
user’s birth until the end of the year and to assign this to the variable NumMonths.

For example, if MyDOB contains a value representing 02/07/2008, the value 5 would be
assigned to NumMonths.

............................................................................................................................................. [2]

(c) The program will output the day of the week corresponding to MyDOB.

For example, given the date 22/06/2023, the program will output "Thursday".

An algorithm is required. An array will be used to store the names of the days of the week.

Define the array and describe the algorithm in four steps.

Do not use pseudocode statements in your answer.

Array definition ..........................................................................................................................

...................................................................................................................................................

Step 1 .......................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Step 2 .......................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Step 3 .......................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Step 4 .......................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[6]
© UCLES 2023 9618/22/M/J/23 [Turn over
PAGE 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.

The operation of this queue may be summarised as follows:


• The Front of Queue Pointer points to the next data item to be removed.
• The End of Queue Pointer points to the last data item added.
• The queue is circular so that locations can be reused.

0
1
2
3
4
5 Red Front of Queue Pointer
6 Green
7 Blue
8 Pink End of Queue Pointer
9

(i) Describe how the data items Orange and Yellow are added to the queue shown in the
diagram.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [4]

© UCLES 2023 9618/22/M/J/23


MUHAMMAD ALI KHAN
PAGE 1251

(ii) The following diagram shows the state of the queue after several operations have been
performed. All queue locations have been used at least once.

0 D4
1 D3 End of Queue Pointer
2 D27
3 D8
4 D33
5 D17 Front of Queue Pointer
6 D2
7 D1
8 D45
9 D60

State the number of data items in the queue.

..................................................................................................................................... [1]

(b) The design of the queue is completed and the number of locations is increased.

A function AddToQueue() has been written. It takes a string as a parameter and adds this to
the queue. The function will return TRUE if the string was added successfully.

A procedure FileToQueue() will add each line from the file to the queue. This procedure
will end when all lines have been added or when the queue is full.

Describe the algorithm for procedure FileToQueue().

Do not use pseudocode in your answer.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

© UCLES 2023 9618/22/M/J/23 [Turn over


PAGE 1252

4 A function GetNum() will:


1. take two parameters: a string and a character
2. count the number of times that the character occurs in the string
3. return the count.

Any comparison between characters needs to be case sensitive. For example, character 'a' and
character 'A' are not identical.

Write pseudocode for function GetNum().

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [6]

© UCLES 2023 9618/22/M/J/23


MUHAMMAD ALI KHAN
PAGE 1253

BLANK PAGE

© UCLES 2023 9618/22/M/J/23 [Turn over


PAGE 1254

5 A programmer has produced the following pseudocode to output the square root of the numbers
from 1 to 10.

Line numbers are for reference only.

10 DECLARE Num : REAL


11 Num 1.0
...

40 REPEAT
41 CALL DisplaySqrt(Num)
42 Num Num + 1.0
43 UNTIL Num > 10
...

50 PROCEDURE DisplaySqrt(BYREF ThisNum : REAL)


51 OUTPUT ThisNum
52 ThisNum SQRT(ThisNum) // SQRT returns the square root
53 OUTPUT " has a square root of ", ThisNum
54 ENDPROCEDURE

The pseudocode is correctly converted into program code.

Function SQRT() is a library function and contains no errors.

The program code compiles without errors, but the program gives unexpected results. These are
caused by a design error.

(a) Explain why the program gives unexpected results.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

(b) Explain why the compiler does not identify this error.

...................................................................................................................................................

............................................................................................................................................. [1]

© UCLES 2023 9618/22/M/J/23


MUHAMMAD ALI KHAN
PAGE 1255

(c) Describe how a typical Integrated Development Environment (IDE) could be used to identify
this error.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

(d) The pseudocode is converted into program code as part of a larger program.

During compilation, a complex statement generates an error.

The programmer does not want to delete the complex statement but wants to change the
statement so that it is ignored by the compiler.

State how this may be achieved.

...................................................................................................................................................

............................................................................................................................................. [1]

© UCLES 2023 9618/22/M/J/23 [Turn over


PAGE 1256

10

6 A procedure Square() will take an integer value in the range 1 to 9 as a parameter and output a
number square.

The boundary of a number square is made up of the character representing the parameter value.
The inside of the number square is made up of the asterisk character (*).

Parameter value 1 2 3 4 ... 9

1 22 333 4444 ... 99 9 9 99 9 9 9


22 3*3 4**4 9 * * * ** * * 9
333 4**4 9 ** * *** * 9
4444 9 *** **** 9
Output 9 * * * ** * * 9
9 * * * ** * * 9
9 ** * *** * 9
9 ******* 9
999999999

The pseudocode OUTPUT command starts each output on a new line. For example, the following
three OUTPUT statements would result in the outputs as shown:

OUTPUT "Hello"
OUTPUT "ginger"
OUTPUT "cat"

Resulting output:

Hello
ginger
cat

© UCLES 2023 9618/22/M/J/23


MUHAMMAD ALI KHAN
PAGE 1257

11

Write pseudocode for procedure Square().

Parameter validation is not required.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

© UCLES 2023 9618/22/M/J/23 [Turn over


PAGE 1258

12

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [6]

© UCLES 2023 9618/22/M/J/23


MUHAMMAD ALI KHAN
PAGE 1259

14

7 A computer system for a shop stores information about each customer. The items of information
include name and address (both postal and email) together with payment details and order history.
The system also stores the product categories they are interested in and how they would like to be
contacted.

(a) The shop wants to add a program module that will generate emails to be sent to customers
who may be interested in receiving details of new products.

(i) State three items of information that the new module would need. Justify your choice in
each case.

Information ........................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................

Information ........................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................

Information ........................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................
[3]

(ii) Identify two items of customer information that would not be required by the new module.
Justify your choice in each case.

Information ........................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................

Information ........................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................
[2]

© UCLES 2023 9618/22/M/J/23


PAGE 1260

15

(b) The program includes a module to validate a Personal Identification Number (PIN). This is
used when customers pay for goods using a bank card.

A state-transition diagram has been produced for this module.

The table show the inputs, outputs and states for this part of the program:

Current state Input Output Next state


S1 Input PIN S2
S2 Re-input PIN Display error S2
S2 Cancel Re-prompt S1
S2 Valid PIN Enable payment S4
S2 Too many tries Block Account S3

Complete the state-transition diagram to represent the information given in the table.

S2

START
S1

Cancel | Re-prompt

[4]
© UCLES 2023 9618/22/M/J/23 [Turn over
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>

Valid item information is as follows:

Format Comment
unique number for each item in the range
ItemNum 4 numeric characters
ƎƎWRƎƎLQFOXVLYH

SupplierCode 3 alphabetic characters to identify the supplier of the item

Description a string a minimum of 12 characters

The file is organised in ascending order of ItemNum and does not contain all possible values in
the range.

A programmer has started to define program modules as follows:

Module Description
OnlyAlpha() • called with a parameter of type string
(already written)
• returns TRUE if the string contains only alphabetic characters,
otherwise returns FALSE
CheckInfo() • called with a parameter of type string representing a line of item
information
• checks to see whether the item information in the string is valid
• returns TRUE if the item information is valid, otherwise returns
FALSE

© UCLES 2023 9618/22/M/J/23


PAGE 1262

17

(a) Write pseudocode for module CheckInfo().

Module OnlyAlpha() should be used as part of your solution.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2023 9618/22/M/J/23 [Turn over


MUHAMMAD ALI KHAN
PAGE 1263

18

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

(b) A new module is defined as follows:

Module Description
AddItem() • called with a parameter of type string representing valid information
for a new item that is not currently in the Stock.txt file
• creates a new file NewStock.txt from the contents of the file
Stock.txt and adds the new item information at the appropriate
place in the NewStock.txt file

As a reminder, the file Stock.txt is organised in ascending order of ItemNum and does not
contain all possible values in the range.

Write pseudocode for module AddItem().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2023 9618/22/M/J/23
PAGE 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]

© UCLES 2023 9618/22/M/J/23


MUHAMMAD ALI KHAN
PAGE 1265

Cambridge International AS & A Level

COMPUTER SCIENCE 9618/22


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2023
MARK SCHEME
Maximum Mark: 75

Published

This mark scheme is published as an aid to teachers and candidates, to indicate the requirements of the
examination. It shows the basis on which Examiners were instructed to award marks. It does not indicate the
details of the discussions that took place at an Examiners’ meeting before marking began, which would have
considered the acceptability of alternative answers.

Mark schemes should be read in conjunction with the question paper and the Principal Examiner Report for
Teachers.

Cambridge International will not enter into discussions about these mark schemes.

Cambridge International is publishing the mark schemes for the 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.

This document consists of 14 printed pages.

© UCLES 2023 [Turn over


PAGE 1266
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Generic Marking Principles

These general marking principles must be applied by all examiners when marking candidate answers.
They should be applied alongside the specific content of the mark scheme or generic level descriptors
for a question. Each question paper and mark scheme will also comply with these marking principles.

GENERIC MARKING PRINCIPLE 1:

Marks must be awarded in line with:

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.

GENERIC MARKING PRINCIPLE 2:

Marks awarded are always whole marks (not half marks, or other fractions).

GENERIC MARKING PRINCIPLE 3:

Marks must be awarded positively:

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.

GENERIC MARKING PRINCIPLE 4:

Rules must be applied consistently, e.g. in situations where candidates have not followed
instructions or in the application of generic level descriptors.

GENERIC MARKING PRINCIPLE 5:

Marks should be awarded using the full range of marks defined in the mark scheme for the question
(however; the use of the full mark range may be limited according to the quality of the candidate
responses seen).

GENERIC MARKING PRINCIPLE 6:

Marks awarded are based solely on the requirements as defined in the mark scheme. Marks should
not be awarded with grade thresholds or grade descriptors in mind.

© UCLES 2023 Page 2 of 14


MUHAMMAD ALI KHAN
PAGE 1267
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

1(a)(i) Use of constants 1

1(a)(ii) One mark per bullet point (or equivalent to max 3): 3

1 Postal rates are entered once only


2 Avoids input error / changing the cost accidentally // avoids different
values for postal rates at different points in the program
3 When required, the constant representing the postal rate value is
changed once only // easier to maintain the program when the postal
rates change
4 Makes the program easier to understand

Note: Max 3 marks

1(b) One mark per bullet point: 3

x Indentation
x White space
x Comments
x Sensible / meaningful variable names // use of Camel Case
x Capitalised keywords

Note: Max 3 marks

1(c) One mark per bullet point: 3

x BOOLEAN
x REAL
x STRING

Question Answer Marks

2(a) MyDOB m SETDATE(17, 11, 2007) 1

2(b) NumMonths m 12 - MONTH(MyDOB) 2

One mark per underlined part

© UCLES 2023 Page 3 of 14


PAGE 1268
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

2(c) 6
One mark per array definition bullet:

x A (1D) array containing 7 elements


x of type STRING

One mark per Step:

Step1: Assign value "Sunday" to first element, "Monday" to second


element etc.

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

Step4: Output the element / name / string

Note: Max 2 for Array definition, Max 4 for steps

Question Answer Marks

3(a)(i) One mark per point: 4

1 Check that the queue is not full


2 EoQ pointer will move to point to location 9
3 Data item Orange will be stored in location referenced by EoQ pointer
4 EoQ pointer will move to point to location 0
5 Data item Yellow will be stored in location referenced by EoQ pointer

Note: max 4 marks

3(a)(ii) 7 1

3(b) One mark per bullet: 5

1 Open file in READ mode


2 Loop to EOF()// read / process all the lines in file
3 Loop will end when return value from AddToQueue() is FALSE / queue
is full
4 Read a line from the file in a loop
5 Pass string to AddToQueue()// AddToQueue()is executed with
line as parameter

© UCLES 2023 Page 4 of 14


MUHAMMAD ALI KHAN
PAGE 1269
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

4 Function GetNum(ThisString : STRING, ThisChar : CHAR) 6


RETURNS INTEGER
DECLARE Index, Count : INTEGER

Count m 0

FOR Index m 1 TO LENGTH(ThisString)


IF MID(ThisString, Index, 1) = ThisChar THEN
Count m Count + 1
ENDIF
NEXT Index
RETURN Count

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

Question Answer Marks

5(a) One mark per point: 3

x parameter / Num has been passed by reference // should have been


passed by value
x so when the value / ThisNum is modified (in procedure
DisplaySqrt())
x the new value will be used in the loop (lines 40–43) // Num will be
changed to modified value

5(b) x The rules of the language have not been broken // there are no syntax 1
errors

5(c) Could use an IDE to: 3

x Set a breakpoint to stop the program at a certain line / statement / point


x Step through the program line by line / statement by statement
x checking the value of 'num' / a variable using a report / watch window

One mark per bullet

© UCLES 2023 Page 5 of 14


PAGE 1270
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

5(d) Answers include: 1

x Change the statement into a comment


x Change the statement to a string representing a literal value and assign
it to a variable / output it

Note: max 1 mark

© UCLES 2023 Page 6 of 14


MUHAMMAD ALI KHAN
PAGE 1271
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

6 Example of iterative solution: 6

PROCEDURE Square(Dim : INTEGER)


DECLARE Count : INTEGER
DECLARE ThisChar : CHAR
DECLARE StringA, StringB : STRING
CONSTANT FILLER = '*'

StringA m ""

ThisChar m NUM_TO_STR(Dim)

FOR Count m 1 TO Dim


StringA m StringA & ThisChar //build up first &
last line
NEXT Count

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

IF Dim <> 1 THEN


OUTPUT StringA
ENDIF

ENDPROCEDURE

For loop-based solutions, mark as follows:


1 Procedure heading and ending including parameter
2 Loop using parameter, containing attempt to construct first line / last line
3 Construct first line / last line
4 Attempt at loop to construct intermediate line
5 Output first / last line of square when Dim > 2
6 Output all intermediate lines in a loop
7 Correct output of first two squares

Note: Max 6 marks

© UCLES 2023 Page 7 of 14


PAGE 1272
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

6 Example of selection-based solution:

PROCEDURE Square(Dim : INTEGER)


DECLARE Count : INTEGER

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

For in-line / selection-based solutions, mark as follows:


1 Procedure heading and ending including parameter
2 Correct use of parameter to select all required squares
3 Correct output of first two squares
4 At least six squares correctly output
5 At least one loop to output lines with multiple asterisks
6 All number squares output correctly

© UCLES 2023 Page 8 of 14


MUHAMMAD ALI KHAN
PAGE 1273
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

7(a)(i) Correct answers include: 3

x Information: customer name


Justification: to personalise / address the email

x Information: email address


Justification: so that the email can be delivered correctly

x Information: product category preference


Justification: to check that the customer would be interested in the
product

x Information: contact preference


Justification: to check that the customer will accept contact via email

x Information: order history


Justification: to send details of product similar to that already bought //
to identify frequent shoppers

x Information: new product information


Justification: to include information about the new product in the email

One mark for each piece of information and matching justification

Note: Max 3 marks

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

Note: Max 2 marks

© UCLES 2023 Page 9 of 14


PAGE 1274
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

7(b) 4

One mark for each:

1 Line from S1 to S2 and label


2 S2 loop label
3 S3 circle and label on incoming
4 S4 circle and label on incoming

© UCLES 2023 Page 10 of 14


MUHAMMAD ALI KHAN
PAGE 1275
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

8(a) FUNCTION CheckInfo(NewLine: STRING) RETURNS BOOLEAN 7


DECLARE ThisNum : STRING
DECLARE Index : INTEGER

IF LENGTH(NewLine) < 19 THEN


RETURN FALSE
ENDIF

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)

IF ThisNum < "0001" OR ThisNum > "5999" THEN


RETURN FALSE
ENDIF

IF NOT OnlyAlpha(MID(Newline, 5, 3)) THEN


RETURN FALSE
ENDIF

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

© UCLES 2023 Page 11 of 14


PAGE 1276
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

8(b) PROCEDURE AddItem(NewLine : STRING) 7


DECLARE NewItemNum, ThisItemNum : STRING

OPENFILE "Stock.txt" FOR READ


OPENFILE "NewStock.txt" FOR WRITE
NewItemNum m LEFT(NewLine, 4)

WHILE NOT EOF("Stock.txt")


READFILE("Stock.txt", ThisLine)
ThisItemNum m LEFT(ThisLine, 4)
IF ThisItemNum > NewItemNum THEN
WRITEFILE("NewStock.txt", NewLine) // write New
Line...
NewItemNum m "9999" // ...once only
ENDIF
WRITEFILE("NewStock.txt", ThisLine)
ENDWHILE

IF NewItemNum <> "9999" THEN


WRITEFILE("NewStock.txt", NewLine) //New last line
in the file
ENDIF

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

© UCLES 2023 Page 12 of 14


MUHAMMAD ALI KHAN
PAGE 1277
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

8(b) Example of array-based solution:

PROCEDURE AddItem(NewLine : STRING)


DECLARE ThisItemNum, ThisLine : STRING
DECLARE Temp : ARRAY [1:5999] OF STRING
DECLARE Index : INTEGER

FOR Index m 1 TO 5999


Temp[Index] m "" //Initialise array
NEXT Index

Index m STR_TO_NUM(LEFT(NewLine, 4))


Temp[Index] m NewLine //Add new line to array

OPENFILE "Stock.txt" FOR READ

WHILE NOT EOF("Stock.txt")


READFILE("Stock.txt", ThisLine)
Index m STR_TO_NUM(LEFT(ThisLine, 4))
Temp[Index] m ThisLine //Add line from file to
array
ENDWHILE
CLOSEFILE "Stock.txt"

OPENFILE "NewStock.txt" FOR WRITE


FOR Index m 1 TO 5999
IF Temp[Index] <> "" THEN //Write non-blank
element...
WRITEFILE("NewStock.txt", Temp[Index]) //...to
new file
ENDIF
NEXT Index
CLOSEFILE "NewStock.txt"

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

© UCLES 2023 Page 13 of 14


PAGE 1278
9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

8(c) One mark for method: 3

Method: Stub testing

Two marks for description:

x The modules SuppExists() and CheckSupplier() are replaced by


dummy modules
x ...which return a known result / contain an output statement to show
they have been called

© UCLES 2023 Page 14 of 14


MUHAMMAD ALI KHAN
PAGE 1279

Cambridge International AS & A Level


* 3 1 4 1 1 6 4 8 5 5 *

COMPUTER SCIENCE 9618/23


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2023

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (PQ/CB) 312089/3
© UCLES 2023 [Turn over
PAGE 1280

Refer to the insert for the list of pseudocode functions and operators.

1 The following pseudocode represents part of the algorithm for a program.

Line numbers are for reference only.

10 DECLARE Sheet4 : ARRAY[1:2, 1:50] OF INTEGER

100 FOR PCount 0 TO 49


101 Sheet4[1, PCount] 0
102 Sheet4[2, PCount] 47
103 NEXT PCount

(a) The pseudocode contains references to an array.

Complete the table by writing the answer for each row.

Answer
The dimension of the array
The name of the variable used as an array index
The number of elements in the array
[3]

(b) The pseudocode contains two errors. One error is that variable PCount has not been
declared.

Identify the other error and state the line number where it occurs.

Error ..........................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Line number ..............................................................................................................................


[2]

(c) The pseudocode does not include a declaration for PCount.

State the data type that should be used in the declaration.

............................................................................................................................................. [1]

© UCLES 2023 9618/23/M/J/23


MUHAMMAD ALI KHAN
PAGE 1281

(d) The pseudocode statements given in the following table are used in other parts of the
algorithm.

Complete the table by placing one or more ticks () in each row.

The first row has already been completed.

Pseudocode statement Input Process Output

INPUT MyChoice 
OUTPUT FirstName & LastName

WRITEFILE YourFile, TextLine

READFILE MyFile, TextLine

Result SQRT(NextNum)
[4]

© UCLES 2023 9618/23/M/J/23 [Turn over


PAGE 1282

2 A program stores a date of birth for a student using a variable, MyDOB, of type DATE.

(a) MyDOB has been assigned a valid value corresponding to Kevin’s date of birth.

Complete the pseudocode statement to test whether Kevin was born on a Thursday.

IF ........................................................................................................................ THEN [2]

(b) A function CheckDate()will take three integer parameters representing a day, month and
year of a given date.

The function will validate the date of birth for a student that the parameters passed to it
represent.
For a date to be valid, a student must be at least 18 in year 2020.

(i) Two of the parameter values can be checked without reference to the third parameter.

Describe these two checks.

Check 1 .............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

Check 2 .............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[2]

(ii) Several values of the parameter representing the day can only be checked completely
by referring to the value of one other parameter.

Describe this check.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2023 9618/23/M/J/23


MUHAMMAD ALI KHAN
PAGE 1283

BLANK PAGE

© UCLES 2023 9618/23/M/J/23 [Turn over


PAGE 1284

3 A program processes data using a stack. The data is copied to a text file before the program ends.

(a) The following diagram shows the current state of the stack.

The operation of this stack may be summarised as follows:

• The TopOfStack pointer points to the last item added to the stack.
• The BottomOfStack pointer points to the first item on the stack.
• The stack grows upwards when items are added.

Stack Pointer

Memory location Value

506

505 WWW TopOfStack

504 YYY

503 XXX

502 ZZZ

501 NNN

500 PPP BottomOfStack

(i) An error will be generated if an attempt is made to POP a value when the stack is empty.

State the maximum number of consecutive POP operations that could be performed on
the stack shown above before an error is generated.

..................................................................................................................................... [1]

(ii) The following operations are performed:

1. POP and store value in variable Data1


2. POP and store value in variable Data2
3. PUSH value AAA
4. PUSH value BBB
5. POP and discard value
6. POP and store value in variable Data2

© UCLES 2023 9618/23/M/J/23


MUHAMMAD ALI KHAN
PAGE 1285

Complete the diagram to show the state of the stack and the variables after the given
operations have been performed.

Stack Pointer

Memory location Value

506

505

504

503

502 Variable Value

501 Data1

500 Data2
[4]
(b) 7KHGDWDLVFRSLHGWRDWH[W¿OHEHIRUHWKHSURJUDPHQGV

(i) State an advantage of writing the data from the stack to a text file before the program
ends.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) A module SaveStack() will write the data from the stack to a text file.

Express an algorithm for SaveStack() as five steps that could be used to produce
pseudocode.

Write the five steps.

Step 1 ................................................................................................................................

...........................................................................................................................................

Step 2 ................................................................................................................................

...........................................................................................................................................

Step 3 ................................................................................................................................

...........................................................................................................................................

Step 4 ................................................................................................................................

...........................................................................................................................................

Step 5 ................................................................................................................................

...........................................................................................................................................
[5]
© UCLES 2023 9618/23/M/J/23 [Turn over
PAGE 1286

4 A function MakeString() will:

1. take two parameters:


• a count as an integer
• a character
2. generate a string of length equal to the count, made up of the character
3. return the string generated, or return "ERROR" if the count is less than 1.

For example, the function call:

MakeString(3, 'Z') will return the string "ZZZ"

Write pseudocode for function MakeString().

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [6]

© UCLES 2023 9618/23/M/J/23


MUHAMMAD ALI KHAN
PAGE 1287

5 A program is designed, coded and compiled without errors. The compiled code is sent for testing.

(a) The program will be tested using the walkthrough method.

Additional information will be needed before this method can be used.

Identify this additional information and explain why it is needed.

Additional information ...............................................................................................................

...................................................................................................................................................

Explanation ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

(b) Testing is completed and the program is made available to users.

Some time later, changes are made to the program to improve the speed of response.

State the type of maintenance that has been applied to the program.

............................................................................................................................................. [1]

© UCLES 2023 9618/23/M/J/23 [Turn over


PAGE 1288

10

6 A procedure Select() will:

1. take two integer values as parameters representing start and end values where both values
are greater than 9 and the end value is greater than the start value
2. output each integer value between the start and the end value (not including the start and
end values), where the sum of the last two digits is 6, for example, 142.

(a) Write pseudocode for procedure Select().

Parameter validation is not required.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]
© UCLES 2023 9618/23/M/J/23
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.

The new function CheckNum() will:

• allow the required sum to be specified (not just 6)


• check one number
• return an appropriate value.

Describe the function interface and two advantages of this modular approach.

Interface ....................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Advantage 1 .............................................................................................................................

...................................................................................................................................................

Advantage 2 .............................................................................................................................

...................................................................................................................................................
[4]

© UCLES 2023 9618/23/M/J/23 [Turn over


PAGE 1290

12

7 A school has a library system which allows students to borrow books for a length of time.
Information relating to students and books is stored in text files. Student information includes
name, home address, email address, date of birth, tutor and subject choices. Book information
includes author, title, subject category, library location and the date that the book was borrowed.

A program helps the staff to manage the borrowing of books.

(a) A new module needs to be written to generate emails to send to students who have an
overdue book. Students who are sent an email are prevented from borrowing any more books
until the overdue book is returned.

The process of abstraction has been used when designing the new module.

(i) State the purpose of applying abstraction to this problem.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) Identify one item of information that is required and one item that is not required in the
new module. Justify your choices.

Item required .....................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

Item not required ...............................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[2]

(iii) Identify two operations that would be required to process data when an overdue book is
returned.

Operation 1 .......................................................................................................................

...........................................................................................................................................

Operation 2 .......................................................................................................................

...........................................................................................................................................
[2]

© UCLES 2023 9618/23/M/J/23


MUHAMMAD ALI KHAN
PAGE 1291

13

(b) Part of the library program contains program modules with headers as follows:

Pseudocode module header


PROCEDURE Module-X()
PROCEDURE Module-Y(BYREF RA : INTEGER, SA : REAL)
PROCEDURE Overlay()
FUNCTION Replace(RA : INTEGER, RB : BOOLEAN) RETURNS BOOLEAN
FUNCTION Reset(TA : STRING) RETURNS INTEGER

Module-X() and Module-Y() are both called from module Overlay().

Complete the structure chart.

[3]

© UCLES 2023 9618/23/M/J/23 [Turn over


PAGE 1292

14

8 A computer shop assembles desktop computers, using items bought from several suppliers. A text
file Stock.txt contains information about each item.

Information for each item is stored as a single line in the Stock.txt file in the format:

<ItemNum><SupplierCode><Description>

Item information is as follows:

Format Comment
unique number for each item in the range “0001”
ItemNum 4 numeric characters
to “5999” inclusive
SupplierCode 3 alphabetic characters code to identify the supplier of the item

Description a string a minimum of 12 characters

The file is organised in ascending order of ItemNum and does not contain all possible values in
the range.

The programmer has defined the first program module as follows:

Module Description
ChangeSupp() • called with two parameters Code1 and Code2 of type string that represent
valid supplier codes
• creates a new file NewStock.txt from the contents of the
file Stock.txt where any reference to Code1 is replaced by Code2
• returns a count of the number of items that have had their supplier code
changed

© UCLES 2023 9618/23/M/J/23


MUHAMMAD ALI KHAN
PAGE 1293

15

(a) Write pseudocode for module ChangeSupp().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2023 9618/23/M/J/23 [Turn over


PAGE 1294

16

(b) A new module is required:

Module Description
Report_1() • takes a parameter of type string that represents a SupplierCode
• searches the Stock.txt file for each line of item information that
contains the given SupplierCode
• produces a formatted report of items for the given SupplierCode,
for example, for supplier DRG, the output could be:

Report for Supplier: DRG

Item Description

1234 USB Printer Cable 3 m


1273 32GB USB Flash Drive
1350 Mouse Mat 320 x 240 mm

Number of items listed: 3

Write pseudocode for module Report_1().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2023 9618/23/M/J/23


MUHAMMAD ALI KHAN
PAGE 1295

17

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2023 9618/23/M/J/23 [Turn over


PAGE 1296

18

(c) The format of the output from module Report_1() from part (b) is changed. The number of
items listed is moved to the top of the report as shown in the example:

Report for Supplier: DRG


Number of items listed: 3

Item Description

1234 USB Printer Cable 3 m


1273 32GB USB Flash Drive
1350 Mouse Mat 320 x 240 mm

(i) Explain why this new layout would increase the complexity of the algorithm.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(ii) The algorithm will be modified to produce the report in the new format. The modified
algorithm will be implemented so that the file Stock.txt is only read once.

Describe the modified algorithm.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

© UCLES 2023 9618/23/M/J/23


MUHAMMAD ALI KHAN
PAGE 1297
9618/23 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

1(a) 3
Answer

The dimension of the array 2

The name of the variable used as an array index PCount

The number of elements in the array 100

1(b) One mark per point: 2

x The (second dimension/index of the) array is declared from 1 to 50 but


the loop runs from 0 to 49

x Line number: 10 / 100 / 101 / 102

1(c) Integer 1

1(d) One mark for each of rows 2 - 5 4

Pseudocode statement Input Process Output

INPUT MyChoice 9

OUTPUT FirstName & LastName 9 9

WRITEFILE OutputFile, TextLine 9

READFILE MyFile, TextLine 9

Result m SQRT(NextNum) 9

Question Answer Marks

2(a) One mark for each underlined part 2

IF DAYINDEX(MyDOB) = 5 THEN

2(b)(i) MP1 Value for month is between 1 and 12 (inclusive) 2


MP2 Value of year is <= 2002

2(b)(ii) MP1 Reference to month and day 2


MP2 Clear description for a check that the day number matches with a
relevant month
(Either day matches with month // month matches with day)

© UCLES 2023 Page 3 of 10


PAGE 1298
9618/23 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

3(a)(i) 6 1

3(a)(ii) 4

One mark for:


MP1 Values 'BBB' and 'AAA'
MP2 Values 'XXX' to 'PPP' (unchanged)
MP3 Both pointers and labelled22
MP4 Values of both variables

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

3(b)(ii) Max 5 marks 5


MP1 Open the text file in WRITE mode
MP2 Check there is a value on the stack
MP3 POP value ….
MP4 Write value to the text file
MP5 Repeat from Step 2 // loop referencing the stack items

Alternative solution: Not using POP primitive

MP1 Open the text file in WRITE mode


MP2 Check there is a value on the stack
MP3 Read value from ToS location
MP4 Write the value to the text file – Must some attempt at ‘the value’
NOT ‘all the values’
MP5 Decrement ToS
MP6 Repeat from step 2 // loop referencing the stack items

© UCLES 2023 Page 4 of 10


MUHAMMAD ALI KHAN
PAGE 1299
9618/23 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

4 FUNCTION MakeString(Count : INTEGER, AChar : CHAR) 6


RETURNS STRING
DECLARE MyString : STRING
DECLARE Index : INTEGER

IF Count < 1 THEN


MyString m "ERROR"
ELSE
MyString m ""
FOR Index m 1 TO Count
MyString m MyString & AChar
NEXT Index
ENDIF

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)

Question Answer Marks

5(a) Max 3 marks 3

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

© UCLES 2023 Page 5 of 10


PAGE 1300
9618/23 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

6(a) Max 7 marks 7

PROCEDURE Select(Start, End : INTEGER)


DECLARE ThisNum, Total: INTEGER
DECLARE ThisString : STRING
DECLARE Char1, Char2 : CHAR

FOR ThisNum m Start+1 TO End-1


ThisString m NUM_TO_STR(ThisNum)
Char1 m RIGHT(ThisString, 1)
Char2 m LEFT(RIGHT(ThisString, 2), 1)
Total m STR_TO_NUM(Char1) + STR_TO_NUM(Char2)
IF Total = 6 THEN
OUTPUT ThisString
ENDIF
NEXT ThisNum

ENDPROCEDURE

MP1 Procedure heading and ending


MP2 (Count-controlled) Loop
MP3 …. with correct range from Start+1 to End-1
MP4 Convert ThisNum (loop counter) to a string
MP5 Extract the last two/first/second ’character digit(s)’ required in a
loop
MP6 Extract the second individual ‘character digit’ required in a loop
MP7 Calculate the sum of the last two digits
MP8 If sum = 6 then OUTPUT the number (either string or integer) in a
loop

6(b) Max 4 marks 4


MP1 The function will take two integer parameters - the number and the
(required) total
MP2 … and return a Boolean

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

Question Answer Marks

7(a)(i) x To filter out information (that is not necessary to solve the problem) // 1
to include only essential information

© UCLES 2023 Page 6 of 10


MUHAMMAD ALI KHAN
PAGE 1301
9618/23 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

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

7(a)(iii) Max 2 marks 2

Examples could include:

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

7(b) Max 3 marks 3

MP1 All modules correctly labelled and interconnected.


MP2 Correct parameters and return type to Module-X and Reset
MP3 Correct parameters and return type to Module-Y and Replace
MP4 Correct parameters and return type to Overlay and Module-Y

© UCLES 2023 Page 7 of 10


PAGE 1302
9618/23 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

8(a) FUNCTION ChangeSupp(Code1, Code2 : STRING) RETURNS 8


INTEGER
DECLARE Count : INTEGER
DECLARE ThisLine, ThisCode : STRING

OPENFILE "Stock.txt" FOR READ


OPENFILE "NewStock.txt" FOR WRITE
Count m 0
WHILE NOT EOF("Stock.txt")
READFILE("Stock.txt ", ThisLine) // brackets
optional
ThisCode m MID(ThisLine, 5, 3)
IF ThisCode = Code1 THEN
ThisLine m LEFT(ThisLine, 4) & Code2
& RIGHT(ThisLine,
LENGTH(ThisLine) - 7)
Count m Count + 1
ENDIF
WRITEFILE("NewStock.txt", ThisLine) // brackets
optional
ENDWHILE

CLOSEFILE "NewStock.txt"
CLOSEFILE "Stock.txt"

RETURN Count
ENDFUNCTION

MP1 Open both files, in correct modes, and subsequently close


MP2 Conditional loop until EOF(“Stock.txt”)
MP3 Read a line from Stock.txt AND extract ThisCode in a loop
MP4 Test ThisCode = Code1 AND if true, increment Count (must
have been Initialised)in a loop
MP5 Update ThisLine using substring functions and '&' in a loop
MP6 completely correct update of ThisLine in a loop
MP7 Write ThisLine to NewStock.txt in a loop
MP8 Return count after loop

© UCLES 2023 Page 8 of 10


MUHAMMAD ALI KHAN
PAGE 1303
9618/23 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

8(b) PROCEDURE Report_1(Supp : STRING) 6


DECLARE Count : INTEGER
DECLARE ThisItemNum, ThisDesc, ThisLine, ThisCode :
STRING

Count m 0

OPENFILE "Stock.txt" FOR READ

OUTPUT "Report for Supplier:" & Supp


OUTPUT "" //Blank line as per example
OUTPUT "Item Description"
OUTPUT "" //Blank line as per example

WHILE NOT EOF("Stock.txt")


READFILE("Stock.txt", ThisLine)
ThisCode m Mid(ThisLine, 5, 3)
IF ThisCode = Supp THEN
ThisItemNum m LEFT(ThisLine, 4)
ThisDesc m RIGHT(ThisLine, LENGTH(ThisLine) - 7)
OUTPUT ThisItem & " " & ThisDesc
Count m Count + 1
ENDIF
ENDWHILE

CLOSEFILE "Stock.txt"

OUTPUT "" //Blank line as per example


OUTPUT "Number of items listed: ", Count
ENDPROCEDURE

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

8(c)(i) Max 2 marks 2

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

© UCLES 2023 Page 9 of 10


PAGE 1304
9618/23 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED

Question Answer Marks

8(c)(ii) One mark per point: 3

MP1 Loop through the file calculating the count


MP2 Save ‘selected’ items in an array
MP3 (After all lines have been read), output the header lines / count
MP4 Loop through the array to output each array element

© UCLES 2023 Page 10 of 10


MUHAMMAD ALI KHAN
PAGE 1305

Cambridge International AS & A Level


* 0 1 1 3 5 2 0 5 9 2 *

COMPUTER SCIENCE 9618/21


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2023

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (LK/SG) 315866/3
© UCLES 2023 [Turn over
PAGE 1306

Refer to the insert for the list of pseudocode functions and operators.

1 The following pseudocode represents part of the algorithm for a program:

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

The value assigned to Level when ThisValue is 40

The value assigned to Check when ThisValue is 36

The value assigned to Level when ThisValue is 18

The number of elements in array Data that may be incremented


[4]

(b) The pseudocode contains four assignments to variable Level. One of these assignments
will never be performed.

Identify this assignment and explain why this is the case.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

(c) The following line is added immediately before the ENDCASE statement:

OTHERWISE : Level ĸ "Undefined"


State why this assignment is never performed.

...................................................................................................................................................

............................................................................................................................................. [1]

© UCLES 2023 9618/21/O/N/23


MUHAMMAD ALI KHAN
PAGE 1307

(d) Give the appropriate data types for the variables ThisValue, Check and Level.

ThisValue ..............................................................................................................................

Check .......................................................................................................................................

Level ......................................................................................................................................
[3]

2 (a) An algorithm is expressed as follows:

• input 100 numbers, one at a time


• keep a total of all numbers input that have a value between 30 and 70 inclusive and
output this total after the last number has been input.

Outline, using stepwise refinement, the five steps for this algorithm which could be used to
produce pseudocode.

Do not use pseudocode statements in your answer.

Step 1 .......................................................................................................................................

...................................................................................................................................................

Step 2 .......................................................................................................................................

...................................................................................................................................................

Step 3 .......................................................................................................................................

...................................................................................................................................................

Step 4 .......................................................................................................................................

...................................................................................................................................................

Step 5 .......................................................................................................................................

...................................................................................................................................................
[5]

(b) Sequence is one programming construct.

Identify two other programming constructs that will be required when the algorithm is
converted into pseudocode.

Construct 1 ...............................................................................................................................

...................................................................................................................................................

Construct 2 ...............................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2023 9618/21/O/N/23 [Turn over


PAGE 1308

3 The diagram represents an Abstract Data Type (ADT).

The operation of this stack may be summarised as follows:

• The TopOfStack pointer points to the last item added to the stack.
• The BottomOfStack pointer points to the first item on the stack.

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]

© UCLES 2023 9618/21/O/N/23


MUHAMMAD ALI KHAN
PAGE 1309

(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.

The algorithm is expressed in five steps.

Complete the steps.

1. If ........................................................ then return FALSE

2. Otherwise .......................................... TopOfStack

3. Use TopOfStack as an ................................... to the array.

4. Set the element at this ...................................... to the .............................. being added.

5. Return .............................. .

[5]

© UCLES 2023 9618/21/O/N/23 [Turn over


PAGE 1310

4 A global array is declared in pseudocode as follows:

DECLARE Data : ARRAY[1:150] OF STRING

A function TooMany() will:

1. take two parameters:


• a string (the search string)
• an integer (the maximum value)
2. count the number of strings in the array that exactly match the search string
3. return TRUE if the count is greater than the maximum value, otherwise will return FALSE

(a) Write pseudocode for the function TooMany().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2023 9618/21/O/N/23


MUHAMMAD ALI KHAN
PAGE 1311

(b) The global array is changed to a 2D array, organised as 150 rows by 2 columns. It is declared
in pseudocode as follows:

DECLARE Data : ARRAY[1:150, 1:2] OF STRING

The algorithm for the function in part (a) is changed. Strings will only be counted if both of
the following conditions are true:

• The current row is an even number.


• The search string exactly matches the value in either column.

Write pseudocode to check these conditions.

Assume that the row index is contained in variable Row and the search string in variable
Search.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2023 9618/21/O/N/23 [Turn over


PAGE 1312

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:

23, AB56, 17, 23ZW, 4, 10, END

Numeric input values are all integers and non-numeric input is ignored, except for the string "END"
which is used to terminate the sequence.

The algorithm is expressed in pseudocode as shown:

DECLARE NextInput : STRING


DECLARE Min, Count, Num : INTEGER

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.

Identify each error and state the correction required.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................

3 ................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2023 9618/21/O/N/23


MUHAMMAD ALI KHAN
PAGE 1313

(b) The operator errors are corrected and the algorithm is tested as follows:

The input sequence:

18, 4, ONE, 27, 189, ERIC, 3, 65, END

produces the output:

The minimum value is 3 and the count was 6

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.

(i) Explain the problem with the algorithm.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [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]

© UCLES 2023 9618/21/O/N/23 [Turn over


PAGE 1314

10

6 The pseudocode OUTPUT command starts each output on a new line.

(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.

MyString will be output in either of these two cases:

1. The Boolean parameter value is TRUE


2. The resulting string (after concatenation) would be longer than 255 characters.

If MyString is not output, the string is concatenated with MyString.

For example, the calls to MyOutput() given below would result in the output as shown:

MyOutput("Hello ", FALSE)


MyOutput("ginger ", FALSE)
MyOutput("cat", TRUE)
MyOutput("How are you?", TRUE)

Resulting output:

Hello ginger cat


How are you?

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.

© UCLES 2023 9618/21/O/N/23


MUHAMMAD ALI KHAN
PAGE 1315

11

Write pseudocode for MyOutput().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [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.

Explain why it does not work as expected.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2023 9618/21/O/N/23 [Turn over


PAGE 1316

12

7 An algorithm is represented by a state-transition diagram.

The table shows the inputs, outputs and states for the algorithm:

Current state Input Output Next state


S1 A1 X1 S2
S2 A3 none S1
S2 A2 X4 S5
S5 A1 X1 S5
S5 A4 X2 S2
S5 A3 none S3
S1 A9 X9 S3
S3 A9 X9 S4

Complete the state-transition diagram to represent the information given in the table.

A1 | X1

START
S1
A3

[5]

© UCLES 2023 9618/21/O/N/23


MUHAMMAD ALI KHAN
PAGE 1317

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:

• is assigned a unique three-digit ID


• has three ports, each identified by an integer value
• is connected to between one and three other computers.

Messages are sent between computers as a string of characters organised into fields as shown:

<STX><DestinationID><SourceID><Data><ETX>

Field
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

2 SourceID three numeric characters that identify the source computer


a variable length string containing the data being sent
3 Data
(Minimum length is 1 character)
a single character marking the end of the message
n/a ETX
(ASCII value 03)

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 "****"

© UCLES 2023 9618/21/O/N/23


PAGE 1318

15

(a) Write pseudocode for module SendFile().

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]

© UCLES 2023 9618/21/O/N/23 [Turn over


MUHAMMAD ALI KHAN
PAGE 1319

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).

(i) Explain why this is a problem.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(ii) Explain how the message format could be changed to allow a blank line to be sent.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2023 9618/21/O/N/23


PAGE 1320

18

(d) A new module has been defined:

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.

As a reminder, a message is defined as follows:

<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

2 SourceID three numeric characters that identify the source computer


a variable length string containing the data being sent
3 Data
(Minimum length is 1 character)
a single character marking the end of the message
Not applicable ETX
(ASCII value 03)

© UCLES 2023 9618/21/O/N/23


MUHAMMAD ALI KHAN
PAGE 1321

19

Write pseudocode for module GetField().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2023 9618/21/O/N/23


PAGE 1322
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

1(a) One mark per row: 4

Answer

The value assigned to Level when ThisValue is 40 "Medium"

The value assigned to Check when ThisValue is 36 12

The value assigned to Level when ThisValue is 18 "Low"

The number of elements in array Data that may be 11


incremented

1(b) One mark for identifying assignment: 3

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

1(d) One mark per point: 3

x ThisValue: INTEGER
x Check: REAL
x Level: STRING

© UCLES 2023 Page 4 of 10


MUHAMMAD ALI KHAN
PAGE 1323
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

2(a) Max 5 marks 5

MP1 Set total to zero


MP2 Input a number
MP3 Check if number greater than 29 and less than 71
MP4 … if check is true - add number to total
MP5 Repeat from step 2 99 times // for a total of 100 iterations
MP6 Output the total

2(b) MP1 An iterative construct // a (count-controlled) loop 2


MP2 A selection construct // an IF statement

Question Answer Marks

3(a) 3

MP1 all values in the order and location shown


MP2 TopOfStack value is index of element containing D1
MP3 BottomOfStack value is index of element containing D2

3(b) MP1 If TopOfStack = 8 // (stack) full then return FALSE 5

MP2 Otherwise, increment TopOfStack

MP3 Use TopOfStack as an index to the Array

MP4 Set the element at this index / location / position to the value / data /
item being added
MP5 Return TRUE

© UCLES 2023 Page 5 of 10


PAGE 1324
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

4(a) FUNCTION TooMany(Search : STRING, Max : INTEGER) RETURNS 6


BOOLEAN
DECLARE Count, Index : INTEGER

Count m 0

FOR Index m 1 TO 150


IF Data[Index] = Search THEN
Count m Count + 1
ENDIF
NEXT Index

IF Count > Max THEN


RETURN TRUE
ELSE
RETURN FALSE
ENDIF

ENDFUNCTION

MP1 Function heading, ending and return type


MP2 Declare Count and Index as integers
MP3 Initialise Count
MP4 Loop (any type) for 150 iterations
MP5 Compare Data element with parameter - if equal, increment Count in a
loop
MP6 Compare Count with Max and return Boolean in both cases outside the
loop

4(b) MP1 Test for row being even number 3


MP2 Test for either column value equal to Search

IF Row MOD 2 = 0 AND __

(Data[Row, 1] = Search OR Data[Row, 2] = Search) THEN

ALTERNATIVE using nested IFs:

IF Row MOD 2 = 0 THEN

IF Data[Row, 1] = Search OR Data[Row, 2] = Search THEN

MP3 Selection structure is either:


x Single IF statement using AND, or
x Two nested IFs using AND, or
x Single IF and the use of a two-iteration loop
Either of these structures correctly formed scores the mark

ALTERNATIVE SOLUTION: A FOR loop using ‘STEP 2’

FOR Row m 2 TO 150 / NEXT Row STEP 2

Data[Row, 1] = Search OR Data[Row, 2] = Search) THEN

© UCLES 2023 Page 6 of 10


MUHAMMAD ALI KHAN
PAGE 1325
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

5(a) MP1 Num > Min should be Num < Min 3


MP2 Count & 1 should be Count + 1
MP3 NextInput m "END" should be NextInput = "END"

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)

5(b)(ii) Many possible correct answers, for example: 2

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

MP2 Final value: END

Question Answer Marks

6(a) PROCEDURE MyOutput(NewString : STRING, EOL : BOOLEAN) 7

IF LENGTH(MyString) + LENGTH(NewString) > 255 THEN


OUTPUT MyString // Resulting string would be too
long
MyString m NewString
ELSE
MyString m MyString & NewString // Concat with
MyString

IF EOL = TRUE THEN


OUTPUT MyString
MyString m ""
ENDIF
ENDIF

ENDPROCEDURE

MP1 Procedure heading, including parameters, and ending


MP2 Produce concatenated string
MP3 … Check whether resulting string would be too long

MP4 If so, then output old MyString


MP5 … and assign NewString to MyString
MP6 Else concatenate NewString to MyString

MP7 (test for length < 255) Test EOL – If TRUE then Output
MP8 … and reset MyString to empty string

© UCLES 2023 Page 7 of 10


PAGE 1326
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

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

Question Answer Marks

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

© UCLES 2023 Page 8 of 10


MUHAMMAD ALI KHAN
PAGE 1327
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

8(a) PROCEDURE SendFile(FileName, DestID : STRING, Port : 7


INTEGER)
DECLARE FileData : STRING

CONSTANT STX = CHR(02)


CONSTANT ETX = CHR(03)

OPENFILE FileName FOR READ

WHILE NOT EOF(FileName)


READFILE FileName, FileData
FileData m STX & DestID & MyID & FileData & ETX
CALL Transmit(FileData, Port)
ENDWHILE

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

8(b) Max 2 marks 2

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)(i) MP1 A message cannot contain a zero-length data field 2


MP2 … so a blank line cannot be sent // there is no way to send a blank line

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

© UCLES 2023 Page 9 of 10


PAGE 1328
9618/21 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

8(d) FUNCTION GetField(Msg : STRING, FieldNo : INTEGER) 6


RETURNS STRING
DECLARE RetString : STRING

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

MP1 Use of CASE ... ENDCASE or IF ... THEN ... ENDIF


MP2 Field 1 and Field 2 extracted correctly
MP3 Calculate a length of field 3
MP4 Field 3 extracted correctly
MP5 Return empty string in case of invalid parameter (via OTHERWISE or
initialisation)
MP6 Final RETURN, after a reasonable attempt

© UCLES 2023 Page 10 of 10


MUHAMMAD ALI KHAN
PAGE 1329

Cambridge International AS & A Level


* 4 0 2 6 5 6 3 1 4 8 *

COMPUTER SCIENCE 9618/22


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2023

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (LK/SG) 315868/1
© UCLES 2023 [Turn over
PAGE 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

"Mr Khan" The name of the customer

3 The number of items in the order

TRUE To indicate whether this is a new customer

15.75 The deposit paid by the customer

[4]

(b) Other variables in the program have example values as shown:

Variable Example value


Total 124.00
DepRate 2.00
Description "AB12345:Cleaning Brush (small)"

Complete the table by evaluating each expression using the example values.

Expression Evaluates to

(Total * DepRate) + 1.5

RIGHT(Description, 7)

(LENGTH(Description) - 8) > 16

NUM_TO_STR(INT(DepRate * 10)) & '%'


[4]

© UCLES 2023 9618/22/O/N/23


MUHAMMAD ALI KHAN
PAGE 1331

(c) The data that needs to be stored for each customer order in part (a) is not all of the same
type.

Describe an effective way of storing this data for many customer orders while the program is
running.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2023 9618/22/O/N/23 [Turn over


PAGE 1332

2 An algorithm will:

1. input a sequence of integer values, one at a time


2. ignore all values until the value 27 is input, then sum the remaining values in the sequence
3. stop summing values when the value 0 is input and then output the sum of the values.

(a) Draw a program flowchart to represent the algorithm.

START

END

[5]

© UCLES 2023 9618/22/O/N/23


MUHAMMAD ALI KHAN
PAGE 1333

(b) The solution to the algorithm includes iteration.

Give the name of a suitable loop structure that could be used.

Justify your answer.

Name ........................................................................................................................................

Justification ...............................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2023 9618/22/O/N/23 [Turn over


PAGE 1334

3 The diagram represents a linked list Abstract Data Type (ADT).

• Ptr1 is the start pointer. Ptr2 is the free list pointer.


• Labels D40, D32, D11 and D100 represent the data items of nodes in the list.
• Labels F1, F2, F3 and F4 represent the data items of nodes in the free list.
• The symbol Ø represents a null pointer.

Ptr1
D40 D32 D11 D100 Ø

Ptr2
F1 F2 F3 F4 Ø

(a) The linked list is implemented using two variables and two 1D arrays as shown.

The pointer variables and the elements of the Pointer array store the indices (index numbers)
of elements in the Data array.

Complete the diagram to show how the linked list as shown above may be represented using
the variables and arrays.

Variable Value
Start_Pointer

Free_List_Pointer 5

Index Data array Pointer array


1 D32 2

2 3

4 D40

6 F2 7

8
[5]

© UCLES 2023 9618/22/O/N/23


MUHAMMAD ALI KHAN
PAGE 1335

(b) The original linked list is to be modified. A new node D6 is inserted between nodes D32 and
D11.

Ptr1
D40 D32 D11 D100 Ø

Ptr2
F1 F2 F3 F4 Ø

The algorithm required is expressed in four steps as shown.

Complete the steps.

1. Assign the data item .................................. to .................................. .

2. Set the .................................. of this node to point to .................................. .

3. Set Ptr2 to point to .................................. .

4. Set pointer of .................................. to point to .................................. .


[4]

© UCLES 2023 9618/22/O/N/23 [Turn over


PAGE 1336

4 A procedure Count() will:

1. input a value (all values will be positive integers)


2. count the number of odd values and count the number of even values
3. repeat from step 1 until the value input is 99
4. output the two count values, with a suitable message.

The value 99 must not be counted.

(a) Write pseudocode for the procedure Count().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2023 9618/22/O/N/23


MUHAMMAD ALI KHAN
PAGE 1337

(b) The procedure Count() is to be tested.

Typical test data would consist of odd and even values, for example:

23, 5, 64, 100, 2002, 1, 8, 900, 99

The purpose of this test would be to test a typical mix of even and odd values and check the
totals.

Give three test data sequences that may be used to test different aspects of the procedure.

Do not include invalid data.

Sequence 1:

Test data ...................................................................................................................................

Purpose of test. ........................................................................................................................

...................................................................................................................................................

Sequence 2:

Test data ...................................................................................................................................

Purpose of test. ........................................................................................................................

...................................................................................................................................................

Sequence 3:

Test data ...................................................................................................................................

Purpose of test. ........................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2023 9618/22/O/N/23 [Turn over


PAGE 1338

10

5 A global 1D array of integers contains four elements, which are assigned values as shown:

Mix[1] ĸ1
Mix[2] ĸ3
Mix[3] ĸ4
Mix[4] ĸ2
A procedure Process() manipulates the values in the array.

The procedure is written in pseudocode:

PROCEDURE Process(Start : INTEGER)


DECLARE Value, Index, Count : INTEGER

Index ĸ Start
Count ĸ0
REPEAT
Value ĸMix[Index]
Mix[Index]ĸ Mix[Index] - 1
Index ĸValue
Count ĸCount + 1
UNTIL Count = 5

Mix[4] ĸ Count * Index


ENDPROCEDURE

Complete the trace table on the opposite page by dry running the procedure when it is called as
follows:

CALL Process(3)

© UCLES 2023 9618/22/O/N/23


MUHAMMAD ALI KHAN
PAGE 1339

11

Index Value Count Mix[1] Mix[2] Mix[3] Mix[4]

[6]

© UCLES 2023 9618/22/O/N/23 [Turn over


PAGE 1340

12

6 (a) A procedure CreateFiles() will take two parameters:

• a string representing a file name


• an integer representing the number of files to be created.

The procedure will create the number of text files specified.

Each file is given a different name. Each file name is formed by concatenating the file name
with a suffix based on the file number. The suffix is always three characters.

For example, the call CreateFiles("TestData", 3) would result in the creation of the
three files, TestData.001, TestData.002 and TestData.003.

Each file will contain a single line. For example, file TestData.002 would contain the string:

This is File TestData.002

Write pseudocode for CreateFiles().

Assume both parameters are valid and that the integer value is between 1 and 999, inclusive.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]
© UCLES 2023 9618/22/O/N/23
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]

(ii) Write the module header for CheckFiles().

...........................................................................................................................................

..................................................................................................................................... [1]

(iii) State the file mode that should be used in CheckFiles().

..................................................................................................................................... [1]

© UCLES 2023 9618/22/O/N/23 [Turn over


PAGE 1342

14

7 A program contains six modules:

Pseudocode module header


PROCEDURE Module-A()
PROCEDURE Module-X(T1 : INTEGER, S2 : REAL)
PROCEDURE Reset(BYREF Code : INTEGER)
FUNCTION Restore(OldCode : INTEGER) RETURNS BOOLEAN
FUNCTION Module-Y(RA : INTEGER, RB : BOOLEAN) RETURNS BOOLEAN
FUNCTION Module-Z(SA : INTEGER) RETURNS INTEGER

Module-X() calls Reset()


Module-Y() calls Restore()

(a) Complete the structure chart for these modules.

Module-A()

[4]

(b) Explain the meaning of the diamond symbol as used in the diagram in part (a).

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2023 9618/22/O/N/23


MUHAMMAD ALI KHAN
PAGE 1343

16

8 A class of students are developing a program to send data between computers. Many computers
are connected together to form a wired network. Serial ports are used to connect one computer to
another.

Each computer:

• is assigned a unique three-digit ID


• has three ports, each identified by an integer value
• is connected to between one and three other computers.

Data is sent as individual message strings.


Each string contains the destination ID (the ID of the computer that is to receive the message)
followed by the data:

<DestinationID><Data>

Messages may pass through several computers on the way to their destination.
When a message arrives at a computer, that is not the destination, the program needs to forward
it on to another computer using one of its serial ports.

The port to use is obtained from information that is stored in an array RouteTable.

RouteTable is a global 2D array of integers. It is declared in pseudocode as follows:

DECLARE RouteTable : ARRAY[1:6,1:3] OF INTEGER

The values in the first two columns of RouteTable define a range of ID values.
Column 3 gives the corresponding port number to use when forwarding the message to a computer
with an ID within this range.

For example, the contents of RouteTable could be:

Column 1 Column 2 Column 3


Row 1 100 199 1
Row 2 200 259 2
Row 3 í <undefined> <undefined>
Row 4 260 399 2
Row 5 400 599 3
Row 6 600 999 1

In this example, a message that arrives with a DestinationID of "283" will be forwarded using
port 2.

Row 3 in the example shows an unused row. These may occur anywhere. Unused rows have the
FROXPQHOHPHQWVHWWRí7KHYDOXHRIXQXVHGHOHPHQWVLQWKHRWKHUWZRFROXPQVLVXQGHILQHG

© UCLES 2023 9618/22/O/N/23


PAGE 1344

17

The programmer has defined the first program module as follows:

Module Description
• takes a DestinationID as a parameter of type string
• searches for the range corresponding to the DestinationID
GetPort() in the array
• UHWXUQVWKHSRUWQXPEHURUUHWXUQVíLIQRFRUUHVSRQGLQJ
range is found

(a) Write pseudocode for module GetPort().

Assume DestinationID contains a valid three-digit string.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]
© UCLES 2023 9618/22/O/N/23 [Turn over
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.

Additional modules are defined:

Module Description
• takes two parameters:
ż a string representing a message
StackMsg() ż an integer representing the stack number
(already written) • adds the message to the required stack
• returns TRUE if the message is added to the required stack,
otherwise returns FALSE
• takes a message as a parameter of type string
• ignores any message with a zero-length data field
• extract the DestinationID from the message
• checks whether the DestinationID is this computer or
ProcessMsg() whether the message is to be forwarded
• uses StackMsg() to add the message to the appropriate
stack
• outputs an error if the message could not be added to the
stack

© UCLES 2023 9618/22/O/N/23


PAGE 1346

19

Write pseudocode for module ProcessMsg().

Module StackMsg() must be used.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2023 9618/22/O/N/23 [Turn over


MUHAMMAD ALI KHAN
PAGE 1347

20

(c) The program contains a module GetFile() which receives text files sent from another
computer.

Lines from the file are sent one at a time. Each message contains one line and ProcessMsg()
from part (b) adds each message as it is received onto stack 1.

Module GetFile() removes messages from stack 1 and writes the data to a text file.

There is a problem. Under certain circumstances, the received file does not appear as
expected.

Assume that while a file is being received ProcessMsg() receives only messages containing
lines from the file.

(i) Describe the circumstances and explain the problem.

Circumstances ..................................................................................................................

...........................................................................................................................................

Explanation .......................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[3]

(ii) Suggest a more appropriate Abstract Data Type that could be used to store the messages
that would not have the same problem.

..................................................................................................................................... [1]

Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the
publisher will be pleased to make amends at the earliest possible opportunity.

To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.

Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge
Local Examinations Syndicate (UCLES), which is a department of the University of Cambridge.

© UCLES 2023 9618/22/O/N/23


PAGE 1348
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

1(a) 4
One mark for each row with appropriate variable name and data type

Example Explanation Variable name Data


value type

"Mr Khan" The name of the customer CustomerName STRING

3 The number of items in the NumItems INTEGER


order

TRUE A value to indicate NewCustomer BOOLEAN


whether this is a new
customer

15.75 The deposit paid by the Deposit REAL


customer

1(b) One mark per row 4

Expression Evaluates to

(Total * DepRate) + 1.5 249.50

RIGHT(Description, 7) "(small)"

(LENGTH(Description) - 8) > 16 TRUE

NUM_TO_STR(INT(DepRate * 10)) & '%' "20%"

1(c) One mark per point Max 3 marks 3

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)

© UCLES 2023 Page 4 of 14


MUHAMMAD ALI KHAN
PAGE 1349
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

2(a) Example Solution 5

One mark per point:


1 Initialise Total to zero
2 Check for only first input of 27 in a loop then attempt to sum values
3 Loop until 0 input
4 Sum values input (after input of first 27) in a loop
5 Output Total after a reasonable attempt

2(b) One mark per point: 2

1 Name: (pre / post) conditional loop


2 Justification: the number of iterations is not known // loop ends following a
specific input (in the loop)

© UCLES 2023 Page 5 of 14


PAGE 1350
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

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

3(b) One mark per step: 4

1 Assign the data item D6 to F1


2 Set the pointer of this node to point to D11
3 Set Ptr2 to point to F2
4 Set pointer of D32 to point to D6

© UCLES 2023 Page 6 of 14


MUHAMMAD ALI KHAN
PAGE 1351
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

4(a) Example Solution 6

PROCEDURE Count()
DECLARE COdd, CEven, ThisNum : INTEGER

COdd m 0
CEven m 0

INPUT ThisNum

WHILE ThisNum <> 99


IF ThisNum MOD 2 = 1 THEN
COdd m COdd + 1
ELSE
CEven m CEven + 1
ENDIF
INPUT ThisNum
ENDWHILE

OUTPUT "Count of odd and even numbers: ", COdd, CEven

ENDPROCEDURE

Mark as follows Max 6 marks:

1 Procedure heading and ending


2 Local COdd, CEven and ThisNum declared as integers
3 Conditional loop while ThisNum <> 99
4 Input ThisNum in a loop
5 Check ThisNum is odd or even in a loop
6 Increment appropriate count in a loop, both counts must have been
initialised before loop
7 After the loop output COdd and CEven with a suitable message following
a reasonable attempt at counting

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

© UCLES 2023 Page 7 of 14


PAGE 1352
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

5 6

One mark for:


x Initialisation row
x Each iteration of Count 1 to 4 with correct Index, Count and array Mix
as shown
x Final iteration, Count = 5, correct Index, Count and array Mix as shown
plus Mix[4] assignment

© UCLES 2023 Page 8 of 14


MUHAMMAD ALI KHAN
PAGE 1353
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

6(a) Example Solution 6

PROCEDURE CreateFiles(NameRoot : STRING, NumFiles :


INTEGER)
DECLARE FileName, Suffix : STRING
DECLARE Count : INTEGER

FOR Count m 1 TO NumFiles

Suffix m NUM_TO_STR(Count)
WHILE LENGTH(Suffix) <> 3
Suffix m '0' & Suffix
ENDWHILE

FileName m NameRoot & '.' & Suffix


OPENFILE FileName FOR WRITE
WRITEFILE FileName, "This is File " & FileName
CLOSEFILE FileName

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)(ii) FUNCTION CheckFiles(NameRoot : STRING) RETURNS INTEGER 1

6(b)(iii) Read 1

© UCLES 2023 Page 9 of 14


PAGE 1354
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

7(a) 4

One mark per point:


1 Module names
2 Parameters with labels to Module-X and between Module-X and Reset
3 Parameter (with label) to Module-Z and return from Module-Z
4 Parameters with labels to Module-Y and Restore and return values from
Module-Y

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).

One mark for reference to selection


One mark for naming all four modules correctly

© UCLES 2023 Page 10 of 14


MUHAMMAD ALI KHAN
PAGE 1355
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

8(a) Solution using a loop 7

Example solution – using a loop

FUNCTION GetPort(ThisDest : STRING) RETURNS INTEGER


DECLARE Index, DNum, Port : INTEGER

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

Mark as follows Max 7:


1.Function heading and ending including parameter and return type
2 Convert parameter to a number
3 (Conditional) loop through array
4 Skip unused element in a loop
5 Attempt to check one range with destination in a loop
6 Test all ranges correctly with destination in a loop
7 Store port value if destination matched in a loop (and exit loop)
8 Return port value including -1 if no match found

Solution using selection statement(s)

Example solution

FUNCTION GetPort(ThisDest : STRING) RETURNS INTEGER


DECLARE Index, DNum, Port : INTEGER

DNum m STR_TO_NUM(ThisDest)
Port m -1

IF RouteTable[1, 1] <> -1 AND RouteTable[1, 1] >= DNum


AND RouteTable[1, 2] <= DNum THEN

© UCLES 2023 Page 11 of 14


PAGE 1356
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

8(a) Port m RouteTable[1, 3]


END IF
IF RouteTable[2, 1] <> -1 AND RouteTable[2, 1] >= DNum
AND __ RouteTable[2, 2] <= DNum THEN
Port m RouteTable[2, 3]
END IF
IF RouteTable[3, 1] <> -1 AND RouteTable[3, 1] >= DNum
AND __ RouteTable[3, 2] <= DNum THEN
Port m RouteTable[3, 3]
END IF
IF RouteTable[4, 1] <> -1 AND RouteTable[4, 1] >= DNum
AND __ RouteTable[4, 2] <= DNum THEN
Port m RouteTable[4, 3]
END IF
IF RouteTable[5, 1] <> -1 AND RouteTable[5, 1] >= DNum
AND __ RouteTable[5, 2] <= DNum THEN
Port m RouteTable[5, 3]
END IF
IF RouteTable[6, 1] <> -1 AND RouteTable[6, 1] >= DNum
AND __ RouteTable[6, 2] <= DNum THEN
Port m RouteTable[6, 3]
END IF

RETURN Port

ENDFUNCTION

Mark as follows Max 7:


1 Function heading and ending including parameter and return type
2 Convert parameter to a number
3 Skip all unused elements
4 Attempt to check one range
5 Check two ranges with destination correctly
6 Check all ranges with destination correctly
7 Store port value if destination matched
8 Return port value including -1 if no match found

© UCLES 2023 Page 12 of 14


MUHAMMAD ALI KHAN
PAGE 1357
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

8(b) Example solution 7

PROCEDURE ProcessMsg(ThisMsg : STRING)


DECLARE ThisDest : STRING
DECLARE Response : BOOLEAN
DECLARE StackNum : INTEGER

IF LENGTH(ThisMsg) >= 4 THEN

ThisDest m LEFT(ThisMsg, 3)

IF ThisDest = MyID THEN // It's for this computer


StackNum m 1
ELSE
StackNum m 2
ENDIF

Response m StackMsg(ThisMsg, StackNum)

IF Response = FALSE THEN


OUTPUT "Message discarded - no room on stack"
ENDIF

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

© UCLES 2023 Page 13 of 14


PAGE 1358
9618/22 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

8(c)(i) One mark per point Max 3 marks: 3

Decide on scenario and mark accordingly.


Scenario one:
x If more than one line is / all lines are stored on the stack (before line(s)
are removed)
x The stack operates as a FILO device // Last item added to stack will be in
first item out
x So lines in the file appear out of sequence

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

© UCLES 2023 Page 14 of 14


MUHAMMAD ALI KHAN
PAGE 1359

Cambridge International AS & A Level


* 1 7 9 0 6 9 5 1 7 2 *

COMPUTER SCIENCE 9618/23


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2023

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
Ɣ Answer all questions.
Ɣ Use a black or dark blue pen.
Ɣ Write your name, centre number and candidate number in the boxes at the top of the page.
Ɣ Write your answer to each question in the space provided.
Ɣ Do not use an erasable pen or correction fluid.
Ɣ Do not write on any bar codes.
Ɣ You may use an HB pencil for any diagrams, graphs or rough working.
Ɣ Calculators must not be used in this paper.

INFORMATION
Ɣ The total mark for this paper is 75.
Ɣ The number of marks for each question or part question is shown in brackets [ ].
Ɣ No marks will be awarded for using brand names of software packages or hardware.
Ɣ The insert contains all the resources referred to in the questions.

This document has 20 pages.

DC (LK/CT) 315870/2
© UCLES 2023 [Turn over
PAGE 1360

Refer to the insert for the list of pseudocode functions and operators.

1 A program is being developed in pseudocode before being converted into a programming


language.

(a) The following table shows four valid pseudocode assignment statements.

Complete the table by giving the data type that should be used to declare the variable
underlined in each assignment statement.

Assignment statement Data type

MyVar1 ĸ Total1 / Total2


MyVar2 ĸ 27/10/2023

MyVar3 ĸ "Sum1 / Sum2"

MyVar4 ĸ Result1 AND Result2


[4]

(b) Other variables in the program have example values as shown:

Variable Value
Active TRUE
Fraction 0.2
Code "Ab12345"

Complete the table by evaluating each expression using the example values.

Expression Evaluates to

Fraction >= 0.2 AND NOT Active

INT((Fraction * 100) + 13.3)

STR_TO_NUM(MID(Code, 4, 2)) + 5

LENGTH("TRUE" & Code)


[4]

© UCLES 2023 9618/23/O/N/23


MUHAMMAD ALI KHAN
PAGE 1361

(c) The program makes use of complex statistical functions. The required functions are not
built-in to the programming language and are too complicated for the programmer to write.

One solution would be to employ another programmer who has experience of writing these
functions, as there is no time to train the existing programmer.

State one other way that these functions may be provided for inclusion in the program.

...................................................................................................................................................

............................................................................................................................................. [1]

(d) The hardware that runs the program is changed and the program needs to be modified so
that it works with the new hardware.

Identify the type of maintenance that this represents and give one other reason why this type
of maintenance may be needed.

Type ..........................................................................................................................................

Reason .....................................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2023 9618/23/O/N/23 [Turn over


PAGE 1362

2 Data is a 1D array of integers, containing 30 elements. All element values are unique.

(a) An algorithm will output the index of the element with the smallest value.

Draw a program flowchart to represent the algorithm.

START

END

[5]

© UCLES 2023 9618/23/O/N/23


MUHAMMAD ALI KHAN
PAGE 1363

(b) The 30 data values could have been stored in separate variables rather than in an array.

Explain the benefits of using an array when designing a solution to part (a).

...................................................................................................................................................

............................................................................................................................................. [2]

(c) The requirement changes. Array Data needs to hold 120 elements and each value may
include a decimal place.

Write a pseudocode statement to declare the modified array.

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2023 9618/23/O/N/23 [Turn over


PAGE 1364

3 The diagram represents a queue Abstract Data Type (ADT).

The organisation of this queue may be summarised as follows:

• The FrontOfQueue pointer points to the next data item to be removed.


• The EndOfQueue pointer points to the last data item added.

Queue

D3 ĸ FrontOfQueue
D4

D1

D2

D5 ĸ EndOfQueue

The queue is implemented using three variables and a 1D array of eight elements as shown. The
variable NumItems stores the number of items in the queue.

The pointer variables store indices (index numbers) of the array.

(a) Complete the diagram to represent the state of the queue as shown above.

Index Array

4 Variable

5 FrontOfQueue

6 EndOfQueue

7 NumItems 5

8
[3]

© UCLES 2023 9618/23/O/N/23


MUHAMMAD ALI KHAN
PAGE 1365

(b) A module AddTo() will add a value to the queue by manipulating the array and variables in
part (a).

The queue implementation is circular. When pointers reach the end of the queue, they will
‘wrap around’ to the beginning.

Before a value can be added to the queue, it is necessary to check the queue is not full.

The algorithm to add a value to the queue is expressed in six steps.

Complete the steps.

1. If NumItems .............................. then jump to step 6.

2. Increment ................................... .

3. If ................................................. then set EndOfQueue to .............................. .

4. Increment ................................... .

5. Set the ............................ at the index stored in ........................... to the ............................


being added.

6. Stop.

[6]

© UCLES 2023 9618/23/O/N/23 [Turn over


PAGE 1366

4 A procedure RandList() will output a sequence of 25 random integers, where each integer is
larger than the previous one.

(a) Write pseudocode for procedure RandList().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2023 9618/23/O/N/23


MUHAMMAD ALI KHAN
PAGE 1367

(b) Procedure RandList() is modified so that the random numbers are also written into a
1D array Result.

A new module is written to confirm that the numbers in the array are in ascending order.

This module contains an IF statement that performs a comparison between elements:

IF (Result[x + 1] = Result[x]) OR (Result[x] > Result[x + 1]) THEN


Sequence FALSE ĸ
ENDIF

Write a simplified version of the conditional clause.

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [1]

© UCLES 2023 9618/23/O/N/23 [Turn over


PAGE 1368

10

5 A global 1D array of integers contains four elements, which are assigned values as shown:

Mix[1] ĸ4
Mix[2] ĸ2
Mix[3] ĸ3
Mix[4] ĸ5
A procedure Process() manipulates the values in the array.

The procedure is written in pseudocode as follows:

PROCEDURE Process(Start : INTEGER)


DECLARE Value, Index, Total : INTEGER

Index ĸ Start
Total ĸ0
WHILE Total < 20
Value ĸMix[Index]
Total ĸTotal + Value

IF Index < 4 THEN


Mix[Index] ĸ
Mix[Index] + Mix[Index+1]
ELSE
Mix[Index] ĸ
Mix[Index] + Mix[1]
ENDIF
Index ĸ
(Value MOD 4) + 1

ENDWHILE

Mix[1] ĸ Total * Index


ENDPROCEDURE

Complete the trace table on the opposite page by dry running the procedure when it is called as
follows:

CALL Process(2)

© UCLES 2023 9618/23/O/N/23


MUHAMMAD ALI KHAN
PAGE 1369

11

Index Value Total Mix[1] Mix[2] Mix[3] Mix[4]

[6]

© UCLES 2023 9618/23/O/N/23 [Turn over


PAGE 1370

12

6 A function TestNum() will take a six-digit string as a parameter.

The function will test whether the string meets certain conditions and will return an integer value
as follows:

Return value Condition Example


1 The last three digits are the same but non-zero. "253444"
2 The last three digits are zero. "253000"
3 The first three and last three digits are the same. "410410"

The function will return the highest possible value for the given string.

If the string does not meet any of the conditions, zero is returned.

© UCLES 2023 9618/23/O/N/23


MUHAMMAD ALI KHAN
PAGE 1371

13

Write pseudocode for function TestNum().

Assume that the parameter is valid.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [6]

© UCLES 2023 9618/23/O/N/23 [Turn over


PAGE 1372

14

7 A structure chart shows the modular structure of a program:

Module-A()

T1 RA
SA

RB

Sub-Y1() Sub-Y2() Sub-9()

(a) Explain the meaning of the curved arrow symbol which begins and ends at Module-A().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2023 9618/23/O/N/23


MUHAMMAD ALI KHAN
PAGE 1373

15

(b) The structure chart shows that Sub-9() is a function.

A Boolean value is returned by Sub-9() for processing by Module-A().

The original parameter RA is of type integer and RB is of type string.

A record type MyType will be defined with three fields to store the values passed between the
two modules.

(i) Write pseudocode to define MyType.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

(ii) The design is modified and Sub-9() is changed to a procedure.

The procedure will be called with a single parameter of type MyType.

Write the pseudocode header for procedure Sub-9().

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2023 9618/23/O/N/23 [Turn over


PAGE 1374

16

8 A class of students are developing a program to send data between computers. Many computers
are connected together to form a wired network. Serial ports are used to connect one computer to
another.

Each computer:
• is assigned a unique three-digit ID
• has three ports, each identified by an integer value
• is connected to between one and three other computers.

Messages are sent between computers as a string of characters organised into fields as shown:

<STX><DestinationID><SourceID><Data><ETX>

Field name Description

a single character marking the start of the message


STX
(ASCII value 02)

DestinationID three numeric characters identifying the destination computer

SourceID three numeric characters identifying the source computer

a variable length string containing the data being sent


Data
(Minimum length is 1 character)
a single character marking the end of the message
ETX
(ASCII value 03)

For example, the following message contains the data "Hello Jack" being sent from computer
"202" to computer "454":

<STX>"454202Hello Jack"<ETX>

Each computer will run a copy of the same program. Each program will contain a global variable
MyID of type string which contains the unique ID of the computer in which the program is running.

The first two program modules are defined as follows:

Module Description

GetData()
• returns the data field from a message that has been received
(already written)
• If no message is available, the module waits until one has been
received.
• takes a file name as a parameter of type string
• creates a text file with the given file name (no checking required)
ReceiveFile()
• writes the data field returned by GetData() to the file
• repeats until the data field is "****", which is not written to the file
• outputs a final message giving the total number of characters
written to the file, for example:
132456 characters were written to newfile.txt

© UCLES 2023 9618/23/O/N/23


MUHAMMAD ALI KHAN
PAGE 1375

17

(a) Write pseudocode for module ReceiveFile().

Module GetData() has already been written and must be used.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2023 9618/23/O/N/23 [Turn over


PAGE 1376

18

(b) The use of the string "****" as explained in the module description for ReceiveFile() may
cause a problem.

Explain the problem and suggest a solution.

Problem ....................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Solution .....................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

(c) Two new modules are defined, which will allow two users to exchange messages.

Module Description

• takes two parameters:


Transmit() ż a string representing a message
(already written) ż an integer representing a port number
• transmits the message using the given port
• takes two parameters:
ż a string representing a Destination ID
ż an integer representing a port number
Chat()
• extracts data from a received message using GetData() and
outputs it
• forms a message using data input by the user and sends it
using Transmit()
• repeats until either the output string or the sent string is "Bye"

Reminders:

• Each program contains a global variable MyID of type string which contains the unique ID of
the computer in which the program is running.
• Messages are sent between computers as a string of characters organised into fields as
shown:

<STX><DestinationID><SourceID><Data><ETX>

© UCLES 2023 9618/23/O/N/23


MUHAMMAD ALI KHAN
PAGE 1377

19

Write pseudocode for module Chat().

Modules GetData() and Transmit() must be used.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [7]

© UCLES 2023 9618/23/O/N/23 [Turn over


PAGE 1378

20

(d) Module GetData() returns the data field from a message that has been received. If no
message is available, the module waits until one has been received.

Explain the limitation of this on module Chat() from part (c).

Describe a modification to GetData() to address this limitation.

Limitation ..................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Modification ..............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the
publisher will be pleased to make amends at the earliest possible opportunity.

To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.

Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge
Local Examinations Syndicate (UCLES), which is a department of the University of Cambridge.

© UCLES 2023 9618/23/O/N/23


MUHAMMAD ALI KHAN
PAGE 1379
9618/23 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

1(a) 4
Assignment statement Data type

MyVar1 m Total1 / Total2 REAL

MyVar2 m 27/10/2023 DATE

MyVar3 m "Sum1 / Sum2" STRING

MyVar4 m Result1 AND Result2 BOOLEAN

1(b) 4
Expression Evaluates to

Fraction >= 0.2 AND NOT Active FALSE


INT((Fraction1 * 100) + 13.3) 33

STR_TO_NUM(MID(Code, 4, 2)) + 5 28
LENGTH("TRUE" & Code) 11

1(c) The use of a program library (routines) 1

1(d) MP1 Type: Adaptive 2


MP2 Reason: The (user) requirement(s) changes // to accommodate
legislative changes

© UCLES 2023 Page 4 of 11


PAGE 1380
9618/23 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

2(a) 5

MP1 Initialise Min to first value in Data and MinIndex to 1


MP2 Loop through 29 more values (or 30 values in total)
MP3 Compare element from Data[] with Min
MP4 Set new Min AND save MinIndex when element value < Min in a loop
MP5 Output MinIndex

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

2(c) One mark per underlined section 2

DECLARE Data : ARRAY[1:120] OF REAL

© UCLES 2023 Page 5 of 11


MUHAMMAD ALI KHAN
PAGE 1381
9618/23 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

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

3(b) MP1 If NumItems is / = 8 // (queue) full then jump to step 6 6


MP2 Increment EndOfQueue
MP3 If EndOfQueue = 9 then set EndOfQueue to 1
MP4 Increment NumItems

MP5 Set the Element at the index …


MP6 stored in EndOfQueue to value/data/item being added

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

© UCLES 2023 Page 6 of 11


PAGE 1382
9618/23 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

4(a) PROCEDURE RandList() 6


DECLARE Count, BaseNum, ThisNum : INTEGER
CONSTANT StepVal = 10
BaseNum m 0

FOR Count m 1 TO 25
ThisNum m BaseNum + INT(RAND(StepVal))
OUTPUT ThisNum
BaseNum m BaseNum + StepVal
NEXT Count

ENDPROCEDURE

MP1 Procedure heading and ending


MP2 Local loop counter Count as integer
MP3 Loop to iterate 25 times or more for each unique number
MP4 ‘Attempt’ to generate a random number including use of INT() in a
loop
MP5 Ensure that number generated is greater than previous and change
‘previous’
MP6 Output random number after an attempt at MP5 in a loop

4(b) One mark for simplified logical expression: 1

MP1 Result[x + 1] <= Result[x]

ALTERNATIVE SOLUTION:

Result[x] >= Result[x + 1]

© UCLES 2023 Page 7 of 11


MUHAMMAD ALI KHAN
PAGE 1383
9618/23 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

5 6

MP1 Row 1 (initialisation)

Each iteration (1 – 5):


MP2 1 – Total 2
MP3 2 – Total 5
MP4 3 – Total 10
MP5 4 – Total 15
MP6 5 – Total 28 and final Mix[1] = 56

© UCLES 2023 Page 8 of 11


PAGE 1384
9618/23 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

6 6
FUNCTION TestNum(ThisNum : STRING) RETURNS INTEGER

IF LEFT(ThisNum,3) = RIGHT(ThisNum 3) THEN


RETURN 3
ENDIF

IF RIGHT(ThisNum, 3) = "000" THEN


RETURN 2
ENDIF

IF MID(ThisNum, 4, 1) = MID(ThisNum, 5, 1)__


AND MID(ThisNum, 5, 1) = MID(ThisNum, 6, 1) THEN
RETURN 1
ENDIF

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

Question Answer Marks

7(a) MP1 iteration / looping 2


MP2 naming all four modules correctly in the correct sequence // e.g.
Module-A repeatedly calls Sub-Y1,then SubY2 then Sub-9

7(b)(i) TYPE MyType 3


DECLARE RA : INTEGER
DECLARE RB : STRING
DECLARE RC : BOOLEAN
ENDTYPE

MP1 TYPE MyType... ENDTYPE


MP2 RA as integer and RB3 as string
MP3 RC as Boolean

7(b)(ii) PROCEDURE Sub-9(BYREF Param : MyType) 2

MP 1 One mark for BYREF


MP 2 One mark for the rest of the statement

© UCLES 2023 Page 9 of 11


MUHAMMAD ALI KHAN
PAGE 1385
9618/23 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

8(a) PROCEDURE ReceiveFile(FileName : STRING) 7


DECLARE FileData : STRING
DECLARE CharCount : INTEGER
CONSTANT Terminator = "****"

OPENFILE FileName FOR WRITE


FileData m GetData()
CharCount m 0

WHILE FileData <> Terminator


WRITEFILE FileName, FileData
CharCount m CharCount + LENGTH(FileData)
FileData m GetData()
ENDWHILE

CLOSEFILE FileName

OUTPUT CharCount (, " characters were written to ",


FileName)

ENDPROCEDURE

MP1 OPEN file in WRITE mode and subsequently CLOSE


MP2 Conditional loop until terminator received
MP3 ‘Attempted’ use of GetData() – Ignore CALL …
MP4 Fully correct use GetData()to return the data in a loop
MP5 Maintain CharCount in a loop
MP6 Write each line to the file - except the terminator in a loop
MP7 Final output of message giving number of characters written outside
loop

8(b) Max 3 marks 3

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:

x (Transmitter program) chooses a different terminator string / character


that doesn't occur in the file
x Transmitter program sends the terminator string / character before first
line of file / before the transfer begins

© UCLES 2023 Page 10 of 11


PAGE 1386
9618/23 Cambridge International AS & A Level – Mark Scheme October/November
PUBLISHED 2023

Question Answer Marks

8(c) PROCEDURE Chat(Destination : STRING, Port : INTEGER) 7


DECLARE Data : STRING
DECLARE Finished : BOOLEAN
CONSTANT Terminator = "Bye"
CONSTANT STX = CHR(2)
CONSTANT ETX = CHR(3)

Finished m FALSE

REPEAT
Data m GetData()
OUTPUT Data
IF Data = Terminator THEN
Finished m TRUE
ENDIF

IF NOT Finished THEN //about to reply


INPUT Data
Transmit(STX & Destination & MyID & Data & ETX,
Port)
IF Data = Terminator THEN
Finished m TRUE
ENDIF
ENDIF

UNTIL Finished = TRUE

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()

8(d) Note: Max 3 marks (from either limitation or modification list) 3

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

© UCLES 2023 Page 11 of 11

You might also like