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

Computer A Level Full Noneed To Search

This document contains instructions for a computer science exam. It provides information about the exam such as its duration, materials allowed, and rules for answering questions. The exam contains multiple choice and written response questions on topics like pseudocode, data structures, program flowcharts, and using text files. It directs students to refer to an included insert for resources and provides spaces for students to write their answers. The document is 24 pages long and includes sample exam questions.

Uploaded by

Sushank Giri
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)
234 views

Computer A Level Full Noneed To Search

This document contains instructions for a computer science exam. It provides information about the exam such as its duration, materials allowed, and rules for answering questions. The exam contains multiple choice and written response questions on topics like pseudocode, data structures, program flowcharts, and using text files. It directs students to refer to an included insert for resources and provides spaces for students to write their answers. The document is 24 pages long and includes sample exam questions.

Uploaded by

Sushank Giri
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/ 244

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
2

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


3

(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


4

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
5

(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


6

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

BLANK PAGE

© UCLES 2021 9618/21/M/J/21 [Turn over


8

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


9

(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


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


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


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


13

BLANK PAGE

© UCLES 2021 9618/21/M/J/21 [Turn over


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


15

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

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

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

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

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

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

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

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

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

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

© UCLES 2021 9618/21/M/J/21 [Turn over


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


17

BLANK PAGE

© UCLES 2021 9618/21/M/J/21 [Turn over


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


19

(a) Write pseudocode for the module GetStart().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2021 9618/21/M/J/21 [Turn over


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


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
22

BLANK PAGE

© UCLES 2021 9618/21/M/J/21


23

BLANK PAGE

© UCLES 2021 9618/21/M/J/21


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


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
2

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


3

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


4

(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


5

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


6

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


7

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


8

(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


9

BLANK PAGE

© UCLES 2021 9618/22/M/J/21 [Turn over


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


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


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


13

(a) Write pseudocode for the module IgnoreWord().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2021 9618/22/M/J/21 [Turn over


14

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

............................................................................................................................................. [8]
© UCLES 2021 9618/22/M/J/21
15

BLANK PAGE

© UCLES 2021 9618/22/M/J/21


16

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/22/M/J/21


Cambridge International AS & A Level
* 7 4 8 3 1 9 9 9 0 1 *

COMPUTER SCIENCE 9618/23


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

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

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

INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].
● No marks will be awarded for using brand names of software packages or hardware.
● The insert contains all the resources referred to in the questions.

This document has 24 pages. Any blank pages are indicated.

DC (PQ/FC) 200587/4
© UCLES 2021 [Turn over
2

Refer to the insert for the list of pseudocode functions and operators.

1 (a) A program is being developed to help manage the membership of a football club.

Complete the following identifier table.

Example
Explanation Variable name Data type
value

The preferred name of the member


"Wong"
joining the football club

A value to indicate whether an


FALSE existing member of the club lives at
the same address

When the member joined the football


19/02/1983
club

The number of points a member has


1345 earned. Members of the club earn
points for different activities.
[4]

(b) Each pseudocode statement in the following table may contain an error due to the incorrect
use of the function or operator.

Describe the error in each case, or write ‘NO ERROR’ if the statement contains no error.

You can assume that none of the variables referenced are of an incorrect type.

Statement Error

Result 2 & 4

SubString MID("pseudocode", 4, 1)

IF x = 3 OR 4 THEN

Result Status AND INT(x/2)

Message "Done" + LENGTH(MyString)

[5]

© UCLES 2021 9618/23/M/J/21


3

(c) The following data items need to be stored for each student in a group:

• student name (a string)


• test score (an integer).

State a suitable data structure and justify your answer.

Structure ...................................................................................................................................

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

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

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

© UCLES 2021 9618/23/M/J/21 [Turn over


4

2 (a) Four program modules form part of a program for a library.

A description of the relationship between the modules is summarised as follows:

Module name Description

UpdateLoan() • Calls either LoanExtend() or LoanReturn()


• Called with parameters LoanID and BookID
• Calls CheckReserve() to see whether the book has been
LoanExtend() reserved for another library user
• Returns TRUE if the loan has been extended, otherwise returns
FALSE
• Called with BookID
CheckReserve() • Returns TRUE if the book has been reserved, otherwise returns
FALSE
• Called with parameters LoanID and BookID
LoanReturn() • Returns a REAL (which is the value of the fine to be paid in the
case of an overdue loan)

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

[5]
© UCLES 2021 9618/23/M/J/21
5

(b) The definition for module LoanReturn() is amended as follows:

Module name Description


Called with parameters LoanID, BookID and Fine
LoanReturn() The module code checks whether the book has been returned on time
and then assigns a new value to Fine

• LoanID and BookID are of type STRING


• Fine is of type REAL

Write the pseudocode header for the amended module LoanReturn().

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

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

© UCLES 2021 9618/23/M/J/21 [Turn over


6

(c) A program will:

• input 50 unique integer values


• output the largest value
• output the average of the values excluding the largest value.

Draw a program flowchart to represent the algorithm.

Variable declarations are not required.

It is not necessary to check that each input value is unique.

[6]
© UCLES 2021 9618/23/M/J/21
7

BLANK PAGE

© UCLES 2021 9618/23/M/J/21 [Turn over


8

3 (a) A concert venue uses a program to calculate admission prices and store information about
ticket sales.

A number of arrays are used to store data. The computer is switched off overnight and data
has to be input again at the start of each day before any tickets can be sold. This process is
very time consuming.

(i) Explain how the program could use text files to speed up the process.

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

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

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

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

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

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

(ii) State the characteristic of text files that allow them to be used as explained in part (a)(i).

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

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

(iii) Information about ticket sales will be stored as a booking. The booking requires the
following data:

• name of person booking


• number of people in the group (for example a family ticket or a school party)
• event type.

Suggest how data relating to each booking may be stored in a text file.

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

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

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

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

© UCLES 2021 9618/23/M/J/21


9

(b) A procedure Preview() will:

• take the name of a text file as a parameter


• output a warning message if the file is empty
• otherwise output the first five lines from the file (or as many lines as there are in the file if
this number is less than five).

Write pseudocode for the procedure Preview().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2021 9618/23/M/J/21 [Turn over


10

4 Study the following pseudocode. Line numbers are for reference only.

10 FUNCTION Convert(Name : STRING) RETURNS STRING


11
12 DECLARE Flag: BOOLEAN
13 DECLARE Index : INTEGER
14 DECLARE ThisChar : CHAR
15 DECLARE NewName : STRING
16
17 CONSTANT SPACECHAR = ' '
18
19 Flag TRUE
20 Index 1
21 NewName "" // formatted name string
22
23 WHILE Index <= LENGTH(Name)
24 ThisChar MID(Name, Index, 1)
25 IF Flag = TRUE THEN
26 NewName NewName & UCASE(ThisChar)
27 IF ThisChar <> SPACECHAR THEN
28 Flag FALSE
29 ENDIF
30 ELSE
31 NewName NewName & ThisChar
32 ENDIF
33 IF ThisChar = SPACECHAR THEN
34 Flag TRUE
35 ENDIF
36 Index Index + 1
37 ENDWHILE
38
39 RETURN NewName
40
41 ENDFUNCTION

© UCLES 2021 9618/23/M/J/21


11

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

Result Convert("∇in∇a∇∇Cup")

Note: The symbol '∇' has been used to represent a space character.
Use this symbol for any space characters in the trace table.

The first row has been completed for you.

Name Flag Index NewName ThisChar

"∇in∇a∇∇Cup"

[5]

© UCLES 2021 9618/23/M/J/21 [Turn over


12

(b) The pseudocode for Convert() contains a conditional loop.

State a more appropriate loop structure.

Justify your answer.

Loop structure ...........................................................................................................................

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

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

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

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

(c) Two changes need to be made to the algorithm.

Change 1: Convert to lower case any character that is not the first character after a space.
Change 2: Replace multiple spaces with a single space.

(i) Change 1 may be implemented by modifying one line of the pseudocode.

Write the modified line.

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

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

(ii) Change 2 may be implemented by moving one line of the pseudocode.

Write the number of the line to be moved and state its new position.

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

New position ......................................................................................................................

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

© UCLES 2021 9618/23/M/J/21


13

BLANK PAGE

© UCLES 2021 9618/23/M/J/21 [Turn over


14

5 A global 2D array Result of type INTEGER is used to store a list of exam candidate numbers
together with their marks. The array contains 2000 elements, organised as 1000 rows and
2 columns.

Column 1 contains the candidate number and column 2 contains the mark for the corresponding
candidate. All elements contain valid exam result data.

A procedure Sort() is needed to sort Result into ascending order of mark using an efficient
bubble sort algorithm.

Write pseudocode for the procedure Sort().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2021 9618/23/M/J/21


15

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

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

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

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

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

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

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

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

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

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

© UCLES 2021 9618/23/M/J/21 [Turn over


16

6 The following diagram represents an Abstract Data Type (ADT) for a linked list.

A C D E Ø

The free list is as follows:

(a) Explain how a node containing data value B is added to the list in alphabetic sequence.

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

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

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

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

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

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

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

(b) Describe how the linked list in part (a) may be implemented using variables and arrays.

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

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

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

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

© UCLES 2021 9618/23/M/J/21


17

BLANK PAGE

© UCLES 2021 9618/23/M/J/21 [Turn over


18

7 A program is needed to take a string containing a full name and produce a new string of initials.

Some words in the full name will be ignored. For example, "the", "and", "of", "for" and "to" may all
be ignored.

Each letter of the abbreviated string must be upper case.

For example:

Full name Initials

Integrated Development Environment IDE

The American Standard Code for Information Interchange ASCII

The programmer has decided to use a global variable FNString of type STRING to store the full
name.

It is assumed that:

• words in the full name string are separated by a single space character
• space characters will not occur at the beginning or the end of the full name string
• the full name string contains at least one word.

The programmer has started to define program modules as follows:

Module Description
• Called with an INTEGER as a parameter, representing the number of a
word in FNString.
GetStart()
• Returns the character start position of that word in FNString or
returns –1 if that word does not exist
• For example: if FNString contains the string "hot and cold",
GetStart(3) returns 9
• Called with a parameter representing the position of the first character
of a word in FNString
GetWord() • Returns the word from FNString
• For example: if FNString contains the string "hot and cold",
GetWord(9) returns "cold"

© UCLES 2021 9618/23/M/J/21


19

(a) Write pseudocode for the module GetStart().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2021 9618/23/M/J/21 [Turn over


20

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

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

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

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

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

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

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

(b) The programmer has decided to use a global ten-element 1D array IgnoreList of type
STRING to store the ignored words. Unused elements contain the empty string ("") and may
occur anywhere in the array.

A new module AddWord() is needed as follows:

Module Description
• Called with a parameter representing a word
• Stores the word in an unused element of the IgnoreList array
AddWord() and returns TRUE
• Returns FALSE if the array was already full or if the word was
already in the array

Write a detailed description of the algorithm for AddWord(). Do not include pseudocode
statements in your answer.

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2021 9618/23/M/J/21


21

(c) As a reminder, the module description of GetWord() is repeated:

Module Description
• Called with a parameter representing the position of the first
character of a word in FNString
GetWord() • Returns the word from FNString
• For example: if FNString contains the string "hot and cold",
GetWord(9) returns "cold"

Write pseudocode for the module GetWord().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

............................................................................................................................................. [5]
© UCLES 2021 9618/23/M/J/21
22

BLANK PAGE

© UCLES 2021 9618/23/M/J/21


23

BLANK PAGE

© UCLES 2021 9618/23/M/J/21


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/23/M/J/21


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
2

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


3

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


4

3 The manager of a cinema wants a program to allow users to book seats. The cinema has several
screens. Each screen shows a different film.

(a) Decomposition will be used to break the problem down into sub-problems.

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


5

BLANK PAGE

© UCLES 2022 9618/21/M/J/22 [Turn over


6

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


7

(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


8

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


9

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


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


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


12

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

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

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

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

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

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

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

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

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

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

© UCLES 2022 9618/21/M/J/22


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
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] ""
Secret[28, 1] "www.thatwebsite.com"

Secret[28, 2] ""

Note:
• For security, passwords are stored in an encrypted form, shown as "" 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


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


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


18

BLANK PAGE

© UCLES 2022 9618/21/M/J/22


19

BLANK PAGE

© UCLES 2022 9618/21/M/J/22


20

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 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 2022 9618/21/M/J/22


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
2

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


3

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


4

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


5

(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


6

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


7

(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


8

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
9

(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


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


11

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

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

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

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

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

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

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

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

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

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

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

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

ENDPROCEDURE [7]

© UCLES 2022 9618/22/M/J/22 [Turn over


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


13

BLANK PAGE

© UCLES 2022 9618/22/M/J/22 [Turn over


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] ""
Secret[28, 1] "thatwebsite.com"
Secret[28, 2] ""

Note:
• For security, the passwords are stored in an encrypted form, shown as "" in the
example.
• The passwords cannot be used without being decrypted.
• You may assume that the encrypted form of a password will NOT be an empty string.

The programmer has started to define program modules as follows:

Module Description
• Takes two parameters:
○ a string
○ a character
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


15

(a) Write pseudocode for the module Exists().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2022 9618/22/M/J/22 [Turn over


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


17

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2022 9618/22/M/J/22 [Turn over


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:
○ a string
○ a character
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:
○ 'a' to 'z'
RandomChar()
○ 'A' to 'Z'
○ '0' to '9'
• Returns the character

Note: in a case-sensitive comparison, 'a' is not the same as 'A'.

© UCLES 2022 9618/22/M/J/22


19

Describe the algorithm for GeneratePassword().

Do not use pseudocode statements in your answer.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2022 9618/22/M/J/22


20

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 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 2022 9618/22/M/J/22


Cambridge International AS & A Level
* 0 8 3 2 9 1 8 0 8 6 *

COMPUTER SCIENCE 9618/23


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

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

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

INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].
● No marks will be awarded for using brand names of software packages or hardware.
● The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (PQ/CGW) 303773/3
© UCLES 2022 [Turn over
2

Refer to the insert for the list of pseudocode functions and operators.

1 (a) The following table contains pseudocode examples.

Each example may include all or part of:


• selection
• iteration (repetition)
• assignment.

Complete the table by placing one or more ticks (✓) in each row.

Pseudocode example Selection Iteration Assignment


FOR Index 1 TO 3
Safe[Index] GetResult()
NEXT Index
OTHERWISE : OUTPUT "ERROR 1202"

REPEAT UNTIL Index = 27

INPUT MyName
IF Mark > 74 THEN
Grade 'A'
ENDIF
[5]

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

Variable Value

AAA TRUE

BBB FALSE

Count 99

Complete the table by evaluating each expression.

Expression Evaluation

AAA AND (Count > 99)

AAA AND (NOT BBB)

(Count <= 99) AND (AAA OR BBB)

(BBB AND Count > 50) OR NOT AAA


[2]

(ii) Give an example of when a variable of type Boolean would be used.

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

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

© UCLES 2022 9618/23/M/J/22


3

2 A program has been written to implement a website browser and maintenance is now required.

One type of maintenance is called perfective.

Name two other types of maintenance that the program may require and give a reason for each.

Type 1 ..............................................................................................................................................

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

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

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

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

Type 2 ..............................................................................................................................................

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

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

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

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

© UCLES 2022 9618/23/M/J/22 [Turn over


4

3 Four program modules are defined as follows:

Pseudocode module header

PROCEDURE Sub1_A(XT : INTEGER, PB : STRING)

FUNCTION Sub1_B(RA : INTEGER) RETURNS BOOLEAN

PROCEDURE Sub1_C(SB : INTEGER, BYREF SA : STRING)

PROCEDURE Section_1()

(a) A structure chart will be produced as part of the development process.

Describe the purpose of a structure chart.

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

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

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

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

(b) Module Section_1() calls one of the other three modules. The module called will be
selected when the program runs.

Draw the structure chart.

[5]
© UCLES 2022 9618/23/M/J/22
5

4 Items in a factory are weighed automatically. The weight is stored as an integer value representing
the item weight to the nearest gram (g).

A function is written to validate the weight of each item. The function will return "PASS" if the
weight of the item is within the acceptable range, otherwise the function will return "FAIL".

The acceptable weight range for an item is 150 g to 155 g inclusive.

The validation function is to be properly tested. Black-box testing will be used and a test plan
needs to be produced.

Complete the table by writing additional tests to test this function.

Type of Example Expected


Explanation
test data test value return value

Normal 153 "PASS" Value within the acceptable range

[4]

© UCLES 2022 9618/23/M/J/22 [Turn over


6

5 A program will store attendance data about each employee of a company.

The data will be held in a record structure of type Employee. The fields that will be needed are as
shown:

Field Typical value Comment

EmployeeNumber 123 A numeric value starting from 1

Name "Smith,Eric" Format: <last name>','<first name>

Department "1B" May contain letters and numbers

Born 13/02/2006 Must not be before 04/02/1957

Attendance 97.40 Represents a percentage

(a) (i) Write pseudocode to declare the record structure for type Employee.

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

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

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

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

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

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

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

(ii) A 1D array Staff containing 500 elements will be used to store the employee records.

Write pseudocode to declare the Staff array.

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

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

(b) There may be more records in the array than there are employees in the company. In this
case, some records of the array will be unused.

(i) State why it is good practice to have a standard way to indicate unused array elements.

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

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

(ii) Give one way of indicating an unused record in the Staff array.

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

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

© UCLES 2022 9618/23/M/J/22


7

(c) A procedure Absentees() will output the EmployeeNumber and the Name of all employees
who have an Attendance value of 90.00 or less.

Write pseudocode for the procedure Absentees().

Assume that the Staff array is global.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2022 9618/23/M/J/22 [Turn over


8

6 (a) The factorial of a number is the product of all the integers from 1 to that number.

For example:
factorial of 5 is given by 1 × 2 × 3 × 4 × 5 = 120
factorial of 7 is given by 1 × 2 × 3 × 4 × 5 × 6 × 7 = 5040
factorial of 1 = 1

Note: factorial of 0 = 1

A function Factorial() will:


• be called with an integer number as a parameter
• calculate and return the factorial of the number
• return −1 if the number is negative.

Write pseudocode for the function Factorial().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2022 9618/23/M/J/22


9

(b) A procedure FirstTen() will output the factorial of the numbers from 0 to 9. The procedure
will use the function from part (a).

The required output is:

Factorial of 0 is 1
Factorial of 1 is 1
Factorial of 2 is 2

Factorial of 9 is 362880

The program flowchart represents an algorithm for FirstTen().

START

Set Num to 0

C
A
F
B
D

END

Complete the table by writing the text that should replace each label A to F.

Label Text

F
[4]
© UCLES 2022 9618/23/M/J/22 [Turn over
10

7 The following pseudocode represents an algorithm intended to output the last three lines as they
appear in a text file. Line numbers are provided for reference only.

10 PROCEDURE LastLines(ThisFile : STRING)


11 DECLARE ThisLine : STRING
12 DECLARE Buffer : ARRAY[1:3] OF STRING
13 DECLARE LineNum : INTEGER
14 LineNum 1
15 OPENFILE ThisFile FOR READ
16
17 WHILE NOT EOF(ThisFile)
18 READFILE Thisfile, ThisLine // read a line
19 Buffer[LineNum] ThisLine
20 LineNum LineNum + 1
21 IF LineNum = 4 THEN
22 LineNum 1
23 ENDIF
24 ENDWHILE
25
26 CLOSEFILE ThisFile
27 FOR LineNum 1 TO 3
28 OUTPUT Buffer[LineNum]
29 NEXT LineNum
30 ENDPROCEDURE

(a) There is an error in the algorithm. In certain cases, a text file will have at least three lines but
the output will be incorrect.

(i) State how the output may be incorrect.

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

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

(ii) Describe the error in the algorithm and explain how it may be corrected.

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

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

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

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

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

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

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

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

© UCLES 2022 9618/23/M/J/22


11

(b) The original algorithm is implemented and sometimes the last three lines of the text file are
output correctly.

State the condition that results in the correct output.

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

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

(c) Lines 20 to 23 inclusive could be replaced with a single pseudocode statement.

Write the pseudocode statement.

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

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

© UCLES 2022 9618/23/M/J/22 [Turn over


12

8 The following diagram shows the incomplete waterfall model of the program development life
cycle.

(a) Complete the diagram.

Analysis

Maintenance

[3]

(b) Explain the meaning of the downward and upward arrows.

Downward arrows .....................................................................................................................

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

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

Upward arrows .........................................................................................................................

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

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

(c) Identify another type of model for the program development life cycle.

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

© UCLES 2022 9618/23/M/J/22


13

BLANK PAGE

© UCLES 2022 9618/23/M/J/22 [Turn over


14

9 A program allows a user to save passwords used to log in to websites. A stored password is then
inserted automatically when the user logs in to the corresponding website.

A student is developing a program to generate a strong password. The password will be of a fixed
format, consisting of three groups of four alphanumeric characters, separated by the hyphen
character '-'.

An example of a password is: "FxAf-3hzV-Aq49"

A valid password:
• must be 14 characters long
• must be organised as three groups of four alphanumeric characters. The groups are
separated by hyphen characters
• may include duplicated characters, provided these appear in different groups.

The programmer has started to define program modules as follows:

Module Description
• Generates a single random character from within one of the following
ranges:
○ 'a' to 'z'
RandomChar()
○ 'A' to 'Z'
○ '0' to '9'
• Returns the character
• Takes two parameters:
  ○ a string
  ○ a character
Exists()
• Performs a case-sensitive search for the character in the string
• Returns TRUE if the character occurs in the string, otherwise returns
FALSE
• Generates a valid password
Generate() • Uses RandomChar() and Exists()
• Returns the password

Note: in a case-sensitive comparison, 'a' is not the same as 'A'.

© UCLES 2022 9618/23/M/J/22


15

(a) Write pseudocode for the module Generate().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2022 9618/23/M/J/22 [Turn over


16

(b) A global 2D array Secret of type STRING stores the passwords together with the website
domain name where they are used. Secret contains 1000 elements organised as 500 rows
by 2 columns.

Unused elements contain the empty string (""). These may occur anywhere in the array.

An example of part of the array is:

Array element Value

Secret[27, 1] "www.thiswebsite.com"

Secret[27, 2] "●●●●●●●●●●●●"

Secret[28, 1] "www.thatwebsite.com"

Secret[28, 2] "●●●●●●●●●●●●"

Note:
• For security, the passwords are stored in an encrypted form, shown as "●●●●●●●●●●●●"
in the example.
• The passwords cannot be used without being decrypted.
• You may assume that the encrypted form of a password will not be an empty string.

Additional modules are defined as follows:

Module Description
• Takes a password as a string
Encrypt()
• Returns the encrypted form of the password as a string
• Takes an encrypted password as a string
Decrypt()
• Returns the decrypted form of the password as a string
• Takes a website domain name as a string
• Searches for the website domain name in the array Secret
FindPassword() • If the website domain name is found, the decrypted password is
returned
• If the website domain name is not found, an empty string is
returned
• Takes two parameters as strings: a website domain name and a
password
• Searches for the website domain name in the array Secret and
AddPassword() if not found, adds the website domain name and the encrypted
password to the array
• Returns TRUE if the website domain name and encrypted
password are added to the array, otherwise returns FALSE

The first three modules have been written.

© UCLES 2022 9618/23/M/J/22


17

Write pseudocode for the module AddPassword().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2022 9618/23/M/J/22 [Turn over


18

(c) The content of the array Secret is to be stored in a text file for backup.

It must be possible to read the data back from the file and extract the website domain name
and the encrypted password.

Both the website domain name and encrypted password are stored in the array as strings of
characters.

The encrypted password may contain any character from the character set used and the
length of both the encrypted password and the website domain name is variable.

Explain how a single line of the text file can be used to store the website domain name and
the encrypted password.

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

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

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

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

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

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

© UCLES 2022 9618/23/M/J/22


19

BLANK PAGE

© UCLES 2022 9618/23/M/J/22


20

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 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 2022 9618/23/M/J/22


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
2

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


3

(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 (3) 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


4

BLANK PAGE

© UCLES 2021 9618/21/O/N/21


5

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


6

(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


7

Write pseudocode for the simple algorithm shown on page 6.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2021 9618/21/O/N/21 [Turn over


8

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


9

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


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


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


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
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
• Returns −1 if no element is set to 1
• 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
• Returns −1 if no element is set to 1

© UCLES 2021 9618/21/O/N/21


15

(a) Write pseudocode to implement the module SetRow().

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2021 9618/21/O/N/21 [Turn over


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
• Returns −1 if no element is set to 1

Write pseudocode to implement the module SearchInRow().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

...................................................................................................................................................
© UCLES 2021 9618/21/O/N/21
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
• Returns −1 if no element is set to 1

Write pseudocode to implement the module GetCentreCol().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

...............................................................................................................................................[6]
© UCLES 2021 9618/21/O/N/21
18

BLANK PAGE

© UCLES 2021 9618/21/O/N/21


19

BLANK PAGE

© UCLES 2021 9618/21/O/N/21


20

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


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
2

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


3

(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


4

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


5

[5]
© UCLES 2021 9618/22/O/N/21 [Turn over
6

(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


7

BLANK PAGE

© UCLES 2021 9618/22/O/N/21 [Turn over


8

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
9

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


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


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
13

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2021 9618/22/O/N/21 [Turn over


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


15

BLANK PAGE

© UCLES 2021 9618/22/O/N/21 [Turn over


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)
• Returns −1 if there are no elements set to 1
• Searches for the last row that has an array element set to 1
LastRowSet() • Returns the index of that row
• Returns −1 if there are no elements set to 1
• 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)
• Returns −1 if there are no elements set to 1
• Searches for the last column that has an array element set to 1
LastColSet() • Returns the index of that column
• Returns −1 if there are no elements set to 1

© UCLES 2021 9618/22/O/N/21


17

(a) Write efficient pseudocode for the module FirstRowSet().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

............................................................................................................................................. [7]
© UCLES 2021 9618/22/O/N/21 [Turn over
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


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 CentreRow to −1 if no screen touch is detected

Write pseudocode for the module GetCentre().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

............................................................................................................................................. [6]
© UCLES 2021 9618/22/O/N/21
20

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


Cambridge International AS & A Level
* 5 4 2 7 3 9 9 5 0 1 *

COMPUTER SCIENCE 9618/23


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2021

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

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

INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].
● No marks will be awarded for using brand names of software packages or hardware.
● The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (CE/CGW) 213696/3
© UCLES 2021 [Turn over
2

Refer to the insert for the list of pseudocode functions and operators.

1 Sylvia is testing a program that has been written by her colleague. Her colleague tells her that the
program does not contain any syntax errors.

(a) (i) State what her colleague means by “does not contain any syntax errors”.

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

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

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

(ii) Identify and describe one other type of error that the program may contain.

Type of error ......................................................................................................................

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

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

(b) Complete the following table by giving the appropriate data type in each case.

Use of variable Data type


The average mark in a class of 40 students
An email address
The number of students in the class
To indicate whether an email has been read
[4]

© UCLES 2021 9618/23/O/N/21


3

(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 (3) one box in each row of the table to indicate whether each item of information
would be essential for the customer when making the booking.

Information Essential Not essential


Departure time
Flight number
Departure airport
Aircraft type
Ticket price
Number of seats in aircraft
[3]

(ii) Identify the technique used to filter out information that is not essential when designing
the booking system and state one benefit of this technique.

Technique ..........................................................................................................................

Benefit ...............................................................................................................................

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

(iii) Identify two additional pieces of essential information that a passenger might need
when booking a flight.

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

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

© UCLES 2021 9618/23/O/N/21 [Turn over


4

BLANK PAGE

© UCLES 2021 9618/23/O/N/21


5

2 (a) An algorithm to sort a 1D array into ascending order is described as follows:

• move the largest value to the end


• keep repeating until the array is sorted.

Apply the process of stepwise refinement to this algorithm in order to produce a more detailed
description.

Write the more detailed description using structured English. Your explanation of the
algorithm should not include pseudocode statements.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2021 9618/23/O/N/21 [Turn over


6

(b) The program flowchart shown describes a simple algorithm.

START

Set Count to 1

Set Flag to FALSE

Is Flag = YES
FALSE AND
Count <= 5 ?

NO
ReBoot()

Set Count to Count + 1

Set Flag to Check()

Is Flag = YES
FALSE ?

NO
Alert(27)

END

© UCLES 2021 9618/23/O/N/21


7

Write pseudocode for the simple algorithm shown on page 6.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2021 9618/23/O/N/21 [Turn over


8

3 (a) The diagram below represents a queue Abstract Data Type (ADT) that can hold a maximum
of eight items.

The operation of this queue may be summarised as follows:

• The front of queue pointer points to the next item to be removed.


• The end of queue pointer points to the last item added.
• The queue is circular so that empty storage elements can be reused.

0 Frog Front of queue pointer


1 Cat
2 Fish
3 Elk End of queue pointer
4
5
6
7

(i) Describe how “Octopus” is added to the given queue.

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

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

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

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

(ii) Describe how the next item in the given queue is removed and stored in the variable
AnimalName.

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

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

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

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

(iii) Describe the state of the queue when the front of queue and the end of queue pointers
have the same value.

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

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

© UCLES 2021 9618/23/O/N/21


9

(b) Some operations are carried out on the original queue given in part (a).

(i) The current state of the queue is:

0 Frog
1 Cat
2 Fish
3 Elk
4
5
6
7

Complete the diagram to show the state of the queue after the following operations:

Add “Wasp”, “Bee” and “Mouse”, and then remove two data items.
[3]

(ii) The state of the queue after other operations are carried out is shown:

0 Frog
1 Cat
2 Fish
3 Elk Front of queue pointer
4 Wasp
5 Bee
6 Mouse End of queue pointer
7 Ant

Complete the following diagram to show the state of the queue after the following
operations:

Remove one item, and then add “Dolphin” and “Shark”.

0
1
2
3
4
5
6
7
[2]
© UCLES 2021 9618/23/O/N/21 [Turn over
10

(c) The queue is implemented using a 1D array.

Describe the algorithm that should be used to modify the end of queue pointer when adding
an item to the queue.

Your algorithm should detect any potential error conditions.

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

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

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

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

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

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

© UCLES 2021 9618/23/O/N/21


11

4 A program controls the heating system in a sports hall.

Part of the program involves reading a value from a sensor. The sensor produces a numeric value
that represents the temperature. The value is an integer, which should be in the range 0 to 40
inclusive.

A program function has been written to validate the values from the sensor.

(a) A test plan is needed to test the function.

Complete the table. The first line has been completed for you.

You can assume that the sensor will generate only integer data values.

Test Test data value Explanation Expected outcome


1 23 Normal data Data is accepted
2
3
4
5
[4]

(b) A program module controls the heaters. This module operates as follows:

• If the temperature is below 10, switch the heaters on.


• If the temperature is above 20, switch the heaters off.

Complete the following state-transition diagram for the heating system:

Start
Heaters Heaters
Off On

[3]

© UCLES 2021 9618/23/O/N/21 [Turn over


12

5 The following data items will be recorded each time a student successfully logs on to the school
network:

Data item Example data


Student ID "CJL404"
Host ID "Lib01"
Time and date "08:30, June 01, 2021"

The Student ID is six characters long. The other two data items are of variable length.

A single string will be formed by concatenating the three data items. A separator character will
need to be inserted between items two and three.

For example:

"CJL404Lib01<separator>08:30, June 01, 2021"

Each string represents one log entry.

A programmer decides to store the concatenated strings in a 1D array LogArray that contains
2000 elements. Unused array elements will contain an empty string.

(a) Suggest a suitable separator character and give a reason for your choice.

Character ..................................................................................................................................

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

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

(b) The choice of data structure was made during one stage of the program development life
cycle.

Identify this stage.

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

© UCLES 2021 9618/23/O/N/21


13

(c) A function LogEvents() will:

• take a Student ID as a parameter


• for each element in the array that matches the Student ID parameter:
◦ add the value of the array element to the existing text file LogFile
◦ assign an empty string to the array element
• count the number of lines added to the file
• return this count.

Write pseudocode for the function LogEvents().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

.................................................................................................................................................... [7]
© UCLES 2021 9618/23/O/N/21 [Turn over
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
• Returns −1 if no element is set to 1
• 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
• Returns −1 if no element is set to 1

© UCLES 2021 9618/23/O/N/21


15

(a) Write pseudocode to implement the module SetRow().

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2021 9618/23/O/N/21 [Turn over


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
• Returns −1 if no element is set to 1

Write pseudocode to implement the module SearchInRow().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

...................................................................................................................................................
© UCLES 2021 9618/23/O/N/21
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
• Returns −1 if no element is set to 1

Write pseudocode to implement the module GetCentreCol().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

...............................................................................................................................................[6]
© UCLES 2021 9618/23/O/N/21
18

BLANK PAGE

© UCLES 2021 9618/23/O/N/21


19

BLANK PAGE

© UCLES 2021 9618/23/O/N/21


20

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


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
2

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


3

(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


4

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


5

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


6

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
7

(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


8

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


9

BLANK PAGE

© UCLES 2022 9618/21/O/N/22 [Turn over


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


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


12

7 A simple arithmetic expression is stored as a string in the format:

<Value1><Operator><Value2>

An operator character is one of the following: '+' '−' '*' '/'

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
• Value1 and Value2 are unsigned (they will not be preceded by ' + ' or ' − ').

(i) Write pseudocode for the procedure Calculate().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2022 9618/21/O/N/22


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


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


15

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

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

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

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

© UCLES 2022 9618/21/O/N/22 [Turn over


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


18

BLANK PAGE

© UCLES 2022 9618/21/O/N/22


19

BLANK PAGE

© UCLES 2022 9618/21/O/N/22


20

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 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 2022 9618/21/O/N/22


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
2

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


3

(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


4

(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


5

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


6

(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


7

BLANK PAGE

© UCLES 2022 9618/22/O/N/22 [Turn over


8

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


9

(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


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
11

BLANK PAGE

© UCLES 2022 9618/22/O/N/22 [Turn over


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 × (n−1) × ... × 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
• return −1 if the parameter value is not a factorial.

For example:

Parameter value Value returned


120 5
12 −1
6 3
1 1

FindBaseNumber(12) will return −1 because 12 is not a factorial.

You may use the rest of this page for rough working.

© UCLES 2022 9618/22/O/N/22


13

Write pseudocode for the function FindBaseNumber().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2022 9618/22/O/N/22 [Turn over


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


15

BLANK PAGE

© UCLES 2022 9618/22/O/N/22 [Turn over


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


17

(a) Write efficient pseudocode for module OutputError().

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

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

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

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2022 9618/22/O/N/22 [Turn over


18

(b) Write an efficient bubble sort algorithm in pseudocode for module SortArrays().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2022 9618/22/O/N/22


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


20

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 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 2022 9618/22/O/N/22


Cambridge International AS & A Level
* 5 3 3 4 5 1 5 3 2 7 *

COMPUTER SCIENCE 9618/23


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2022

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
● Answer all questions.
● Use a black or dark blue pen.
● Write your name, centre number and candidate number in the boxes at the top of the page.
● Write your answer to each question in the space provided.
● Do not use an erasable pen or correction fluid.
● Do not write on any bar codes.
● You may use an HB pencil for any diagrams, graphs or rough working.
● Calculators must not be used in this paper.

INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].
● No marks will be awarded for using brand names of software packages or hardware.
● The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (NF/CB) 302729/4
© UCLES 2022 [Turn over
2

Refer to the insert for the list of pseudocode functions and operators.

1 A program is required for a shopping website.

(a) Part of the program requires four variables. The following table describes the use of each
variable.

Complete the table by adding the most appropriate data type for each variable.

Variable use Data type

Store the number of days in the current month

Store the first letter of the customer’s first name

Store an indication of whether a year is a leap year

Store the average amount spent per customer visit

[4]

(b) The designer considers the use of a development life cycle to split the development of the
website into several stages.

(i) State one benefit of a development life cycle when developing the website.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) Analysis is one stage of a development life cycle.

State one document that may be produced from the analysis stage of the website project.

...........................................................................................................................................

..................................................................................................................................... [1]

© UCLES 2022 9618/23/O/N/22


3

(c) The program will be developed using the Rapid Application Development (RAD) life cycle.

(i) State one principle of this life cycle.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) Give two benefits and one drawback of its use compared to the waterfall life cycle.

Benefit 1 ............................................................................................................................

...........................................................................................................................................

Benefit 2 ............................................................................................................................

...........................................................................................................................................

Drawback ..........................................................................................................................

...........................................................................................................................................
[3]

(d) Adaptive maintenance needs to be carried out on the website program.

Give two reasons why adaptive maintenance may be required.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2022 9618/23/O/N/22 [Turn over


4

2 A program is being designed for a smartphone to allow users to send money to the charity of their
choice.

Decomposition will be used to break the problem down into sub-problems.

Identify three program modules that could be used in the design and describe their use.

Module 1 ..........................................................................................................................................

Use ...................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

Module 2 ..........................................................................................................................................

Use ...................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

Module 3 ..........................................................................................................................................

Use ...................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................
[3]

© UCLES 2022 9618/23/O/N/22


5

3 An algorithm is needed to process a sequence of numbers. Numbers may be positive or negative


and may be integer or decimal.

The algorithm will:


• prompt and input one number at a time until the value zero is input
• sum the negative numbers
• sum the positive numbers
• when zero is input, output the two sum values and then end.

Describe the algorithm needed. Do not include pseudocode statements in your answer.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [5]

© UCLES 2022 9618/23/O/N/22 [Turn over


6

4 (a) A program contains a 1D array DataItem with 100 elements.

State the one additional piece of information required before the array can be declared.

...................................................................................................................................................

............................................................................................................................................. [1]

(b) A programmer decides to implement a queue Abstract Data Type (ADT) in order to store
characters received from the keyboard. The queue will need to store at least 10 characters
and will be implemented using an array.

(i) Describe two operations that are typically required when implementing a queue.
State the check that must be carried out before each operation can be completed.

Operation 1 .......................................................................................................................

...........................................................................................................................................

Check 1 .............................................................................................................................

...........................................................................................................................................

Operation 2 .......................................................................................................................

...........................................................................................................................................

Check 2 .............................................................................................................................

...........................................................................................................................................
[4]

(ii) Describe the declaration and initialisation of the variables and data structures used to
implement the queue.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [5]
© UCLES 2022 9618/23/O/N/22
7

5 (a) A text string contains three data items concatenated as shown:

<StockID><Description><Cost>

Item lengths are:

Item Length
StockID 5
Description 32
Cost the remainder of the string

A procedure Unpack() takes four parameters of type string. One parameter is the original
text string. The other three parameters are used to represent the three data items shown in
the table and are assigned values within the procedure. These values will be used by the
calling program after the procedure ends.

(i) Write pseudocode for the procedure Unpack().

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [6]

(ii) Explain the term procedure interface with reference to procedure Unpack().

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2022 9618/23/O/N/22 [Turn over


8

(b) The design changes and a record structure is defined to store the three data items.

A user-defined data type StockItem is created as shown:

TYPE StockItem
DECLARE StockID : STRING
DECLARE Description : STRING
DECLARE Cost : REAL
ENDTYPE

(i) A variable LineData of type StockItem is declared.

Write the pseudocode statement to assign the value 12.99 to the Cost field of
LineData.

..................................................................................................................................... [1]

(ii) Procedure Unpack() is modified and converted to a function which takes the original
text string as the only parameter.

Explain the other changes that need to be made to convert the procedure into a function.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2022 9618/23/O/N/22


9

(c) Unpack() is part of a program made up of several modules. During the design stage, it is
important to follow good programming practice. One example of good practice is the use of
meaningful identifier names.

Give the reason why this is good practice. Give two other examples of good practice.

Reason .....................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Example 1 .................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Example 2 .................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

(d) The program that includes Unpack() is tested using the walkthrough method.

Describe this method and explain how it can be used to identify an error.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2022 9618/23/O/N/22 [Turn over


10

6 Components are weighed during manufacture. Weights are measured to the nearest whole gram.

Components that weigh at least 3 grams more than the maximum weight, or at least 3 grams less
than the minimum weight, are rejected.

A component is rechecked if it weighs within 2 grams of either the maximum or minimum weight.

The final outcome of weighing each component is shown below:

Outcome Weight

Reject

Max + 2
Recheck Max Maximum weight
Max – 2

Accept

Min + 2
Recheck Min Minimum weight
Min – 2

Reject

A function Status() will be called with three parameters. These are integers representing the
weight of an individual component together with the minimum and maximum weights.

The value returned from the function will be as follows:

Outcome Return value


Accept 'A'
Reject 'R'
Recheck 'C'

(a) Complete the following test plan for five tests that could be performed on function Status().
The tests should address all possible outcomes.

Test number Component weight Min Max Expected return value


1 'A'

5
[5]
© UCLES 2022 9618/23/O/N/22
11

(b) Write pseudocode for Status().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2022 9618/23/O/N/22 [Turn over


12

7 A teacher is designing a program to perform simple syntax checks on programs written by


students.

Two global 1D arrays are used to store the syntax error data. Both arrays contain 500 elements.

• Array ErrCode contains integer values that represent an error number in the range 1 to 800.
• Array ErrText contains string values that represent an error description.

The following diagram shows an example of the arrays.

Index ErrCode ErrText


1 10 "Invalid identifier name"
2 20 "Bracket mismatch"
3 50 ""
4 60 "Type mismatch in assignment"

...

500 999 <Undefined>

Note:
• There are less than 500 error codes so corresponding elements in both arrays may be
unused. Unused elements in ErrCode have the value 999. These will occur at the end of the
array. The value of unused elements in ErrText is undefined.
• Values in the ErrCode array are stored in ascending order but not all values may be present.
For example, there may be no error code 31.
• Some error numbers are undefined. In these instances, the ErrCode array will contain a
valid error number but the corresponding ErrText element will contain an empty string.

The teacher has defined one program module as follows:

Module Description
• Prompts for input of two error numbers
• Outputs a list of error numbers between the two numbers input
(inclusive) together with the corresponding error description
• Outputs a warning message when the error description is
missing as for error number 50 in the example
• Outputs a suitable header and a final count of error numbers
found
OutputRange()
Output based on the example array data above:

List of error numbers from 1 to 60

10 : Invalid identifier name


20 : Bracket mismatch
50 : Error Text Missing
60 : Type mismatch in assignment

4 error numbers output


© UCLES 2022 9618/23/O/N/22
13

(a) Write pseudocode for module OutputRange(). Assume that the two numbers input
represent a valid error number range.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2022 9618/23/O/N/22 [Turn over
14

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2022 9618/23/O/N/22


15

Question 7 continues on the next page.

© UCLES 2022 9618/23/O/N/22 [Turn over


16

(b) (i) Two additional modules are defined:

Module Description
SortArrays() • Sorts the arrays into ascending order of ErrCode
• Takes two parameters:
• an error number as an integer
• an error description as a string
• Writes the error number and error description to the first
AddError() unused element of the two arrays. Ensures the ErrCode
array is still in ascending order
• Returns the number of unused elements after the new error
number has been added
• Returns −1 if the new error number could not be added

Write pseudocode for the module AddError(). Assume that the error code is not
already in the ErrCode array.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

© UCLES 2022 9618/23/O/N/22


17

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [6]

(ii) A new Module RemoveError() will remove a given error number from the array.

Describe the algorithm that would be required. Do not include pseudocode statements in
your answer.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

© UCLES 2022 9618/23/O/N/22


18

BLANK PAGE

© UCLES 2022 9618/23/O/N/22


19

BLANK PAGE

© UCLES 2022 9618/23/O/N/22


20

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 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 2022 9618/23/O/N/22

You might also like