0% found this document useful (0 votes)
27 views540 pages

Computer Science Unit 2 Jan19 - Oct 23

Uploaded by

KRISHAY Sanghani
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)
27 views540 pages

Computer Science Unit 2 Jan19 - Oct 23

Uploaded by

KRISHAY Sanghani
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/ 540

Cambridge Assessment International Education

Cambridge International Advanced Subsidiary and Advanced Level


* 3 0 2 5 5 8 8 3 4 7 *

COMPUTER SCIENCE 9608/21


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

READ THESE INSTRUCTIONS FIRST

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

Answer all questions.


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

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

The maximum number of marks is 75.

This document consists of 16 printed pages.

DC (ST) 163545/2
© UCLES 2019 [Turn over
2

1 (a) (i) Algorithms may be expressed using four basic constructs. One construct is sequence.

Complete the following table for two other constructs.

Construct Pseudocode example

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

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

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

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

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

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

[4]

(ii) Simple algorithms usually consist of input, process and output.

Complete the table by placing ticks (‘3’) in the relevant boxes.

Pseudocode statement Input Process Output


Temp SensorValue * Factor
WRITEFILE "LogFile.txt", TextLine
WRITEFILE "LogFile.txt", MyName & MyIDNumber
READFILE "AddressBook.txt", NextLine

[4]

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


3

(b) Program variables have values as follows:

Variable Value
Title "101 tricks with spaghetti"
Version 'C'
Author "Eric Peapod"
PackSize 4
WeightEach 6.2
Paperback TRUE

(i) Evaluate each expression in the following table.


If an expression is invalid, write ERROR.

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

Expression Evaluates to
MID(Title, 5, 3) & RIGHT(Author, 3)
INT(WeightEach * PackSize)
PackSize >= 4 AND WeightEach < 6.2
LEFT(Author, ASC(Version) - 65)
RIGHT(Title, (LENGTH(Author) – 6))
[5]

(ii) Programming languages support different data types.

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

Variable Data type


Title
Version
PackSize
WeightEach
Paperback
[5]

(c) White-box and black-box are two types of testing. In white-box testing, data are chosen to
test every possible path through the program.

Explain how data are chosen in black-box testing.

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

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

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


4

2 (a) One type of loop that may be found in an algorithm is a count-controlled loop.

State one other type and explain when it should be used.

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

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

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

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

(b) Chris is asked to work on a program that has been coded in a language he is not familiar
with.

He has identified that the program contains the constructs: sequence, iteration and selection.

Identify three other features of the program that he should expect to recognise.

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

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

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

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

ON x {
15: Call ProcA
20: y := 0
25: y := 99
NONE: Call ProcError
}

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

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

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

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

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

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

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


5

3 (a) A student is developing an algorithm to search through a 1D array of 100 elements. Each
element of the array, Result, contains a REAL value.

The algorithm will output:

• the average value of all the elements


• the number of elements with a value of zero.

The structured English description of the algorithm is:

1. SET Total value to 0


2. SET Zero count to 0
3. SELECT the first element
4. ADD value of element to Total value
5. IF element value is 0 then INCREMENT Zero count
6. REPEAT from step 4 for next element, until element is last element
7. SET Average to Total / 100
8. OUTPUT a suitable message and Average
9. OUTPUT a suitable message and Zero count

Write pseudocode for this algorithm.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


6

(b) The student decides to change the algorithm and implement it as a procedure, ScanArray(),
which will be called with three parameters.

ScanArray(AverageValue, ZeroCount, ArrayName)

ScanArray() will modify the first two parameters so that the new values are available to the
calling program or module.

Write the pseudocode procedure header for ScanArray().

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

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

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

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

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


8

4 The following pseudocode is a string handling function.

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

FUNCTION Clean(InString : STRING) RETURNS STRING

DECLARE NewString : STRING


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

AfterSpace FALSE
NewString ""

FOR Index 1 TO LENGTH(InString)


NextChar MID(InString, Index, 1)
IF AfterSpace = TRUE
THEN
IF NextChar <> Space
THEN
NewString NewString & NextChar
AfterSpace FALSE
ENDIF
ELSE
NewString NewString & NextChar
IF NextChar = Space
THEN
AfterSpace TRUE
ENDIF
ENDIF
ENDFOR

RETURN NewString

ENDFUNCTION

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


9

(a) (i) Complete the trace table by performing a dry run of the function when it is called as
follows:

Result Clean("X∇∇∇Y∇and∇∇Z")

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

Index AfterSpace NextChar NewString

[6]

(ii) State the effect of the function Clean().

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

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

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


10

(iii) The pseudocode is changed so that the variable AfterSpace is initialised to TRUE.

Explain what will happen if the function is called as follows:

Result Clean("∇∇X∇∇∇Y∇and∇∇Z")

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

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

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

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

(b) The following pseudocode declares and initialises an array.

DECLARE Code : ARRAY[1:100] OF STRING


DECLARE Index : INTEGER

FOR Index 1 TO 100


Code[Index] ""
ENDFOR

The design of the program is changed as follows:

• the array needs to be two dimensional, with 500 rows and 4 columns
• the elements of the array need to be initialised to the string "Empty"

Re-write the pseudocode to implement the new design.

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

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

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

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

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

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

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

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

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

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

(c) State the term used for changes that are made to a program in response to a specification
change.

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

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


12

5 (a) Programming languages usually contain a range of built-in functions, such as a random
number generator.

State three advantages of using built-in functions.

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

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

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

(b) A student is learning about random number generation.

She is investigating how many times the random function needs to be called before every
number in a given series is generated.

She is using pseudocode to develop a procedure, TestRand(), which will:

• use the random number function to generate an integer value in the range 1 to 50
inclusive
• count how many times the random function needs to be called before all 50 values have
been generated
• output a message giving the number of times the random function was called.

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


13

Write pseudocode for the procedure TestRand().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


14

6 A text file, MyCDs.txt, stores information relating to a Compact Disc (CD) collection. Information
about each CD is stored on three separate lines in the file as follows:

Line 1: <Artist Name>


Line 2: <CD Title>
Line 3: <Storage Location>

Information is stored as data strings.

A section of the file is shown:

File line Data


100 "Green Floyd"
101 "Bowlful of Cereal"
102 "Shelf 4"
103 "Strolling Bones"
104 "Exile on Station Road"
105 "Box 12"

(a) A program, CDOrganiser, will be written to manage the stored information. The program will
consist of three modules: AddCD, FindCD and RemoveCD.

Give three reasons why it is good practice to construct the program using modules.

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

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

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

(b) The module, FindCD(), will check whether a given CD exists in the collection. The module
will be implemented as a function.

The function will:

• be called with two strings as parameters, representing the artist name and CD title
• return a string that gives the storage location, or an empty string if the given CD has not
been found.

Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the
publisher will be pleased to make amends at the earliest possible opportunity.

To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.

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

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


15

Write program code for the function FindCD().

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

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

Program code

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

............................................................................................................................................. [8]
© UCLES 2019 9608/21/M/J/19 [Turn over
16

Appendix

Built-in functions (pseudocode)

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

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


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

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

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 10

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


returns leftmost x characters from ThisString

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

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


returns rightmost x characters from ThisString

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

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: INT(27.5415) returns 27

ASC(ThisChar : CHAR) RETURNS INTEGER


returns the ASCII value of character ThisChar

Example: ASC('A') returns 65

RAND(x : INTEGER) RETURNS REAL


returns a real number in the range 0 to x (x not inclusive).

Example: RAND(87) could return 35.43

Operators (pseudocode)

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

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


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

COMPUTER SCIENCE 9608/22


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

READ THESE INSTRUCTIONS FIRST

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

Answer all questions.


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

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

The maximum number of marks is 75.

This document consists of 16 printed pages.

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

1 (a) Algorithms are used in computer programming.

(i) Explain the term algorithm.

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

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

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

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

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

Complete the table below.

The third activity type is given.

Activity type Pseudocode example

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

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

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

[5]

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


3

(b) Program variables have values as follows:

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

(i) Evaluate each expression in the following table.

If an expression is invalid, write ERROR.

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

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

(ii) Programming languages support different data types.

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

Variable Data type


Married
ID
MiddleInitial
Height
IsMarried
[5]

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


4

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

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

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

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

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

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

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

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

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

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

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

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

Answer 23 + DoSomething("Yellow")

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

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

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

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

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

Describe these activities with reference to each of the following:

• editor
• translator
• debugger

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

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

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

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

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

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

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

WHEN Result < 20


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

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

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

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

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

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

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

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

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

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


6

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

TopLevel

B
D

A C
E

SubA SubB

Parameters A to E have the following data types:

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

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

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

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

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

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

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

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

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

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

State two other features than can be represented.

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

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

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


8

4 The following is pseudocode for a string handling function.

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

FUNCTION Search(InString : STRING) RETURNS INTEGER

DECLARE NewString : STRING


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

NewString '0'
Selected 0

FOR Index 1 TO LENGTH(InString)

NextChar MID(InString, Index, 1)


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

ENDFOR

RETURN Selected

ENDFUNCTION

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


9

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

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

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

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

Index NextChar Selected NewValue NewString

[5]

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

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

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


10

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


11

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

• take a filename as a string parameter


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

Write pseudocode for the procedure CountLines().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


12

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

The program will:

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


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

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

Nadine has defined the modules as follows:

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

A valid user ID:

• is five characters in length


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

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

Nadine wants all inputs to have suitable prompts.

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


13

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

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

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

Program code

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Program code

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the
publisher will be pleased to make amends at the earliest possible opportunity.

To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.

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

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


16

Appendix

Built-in functions (pseudocode)


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

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


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

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

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 10

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


returns leftmost x characters from ThisString

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

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


returns rightmost x characters from ThisString

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

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: INT(27.5415) returns 27

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.

Example: NUM_TO_STRING(87.5) returns "87.5"


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

STRING_TO_NUM(x : STRING) RETURNS REAL


returns a numeric representation of a string.

Example: STRING_TO_NUM("23.45") returns 23.45


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

Operators (pseudocode)

Operator Description

Concatenates (joins) two strings


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

Performs a logical AND on two Boolean values


AND
Example: TRUE AND FALSE produces FALSE

Performs a logical OR on two Boolean values


OR
Example: TRUE OR FALSE produces TRUE

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


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

COMPUTER SCIENCE 9608/23


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

READ THESE INSTRUCTIONS FIRST

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

Answer all questions.


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

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

The maximum number of marks is 75.

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

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

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

DECLARE Message : ARRAY[1:100] OF CHAR

PROCEDURE Search()

DECLARE Index : INTEGER


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

ThisChar Message[1]
ThisRun 1
LongRun 1

FOR Index 2 TO 100

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

ENDFOR

OUTPUT "The longest run was " , LongRun

ENDPROCEDURE

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


3

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

Variable and array declarations are not required in program flowcharts.

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

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

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

Evaluate each expression in the following table.

If an expression is invalid, write ERROR.

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

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

(ii) Programming languages support different data types.

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

Variable Data type


MeltingPoint

Soluble

Attempt

Version

ProductID
[5]

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


5

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

• search through a 1D array of 100 elements


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

Use structured English to describe the algorithm she could use.

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

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

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

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

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

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

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

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

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

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

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

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

Explain this process.

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

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

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

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

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

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

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


6

(c) The student is learning about file handling.

She has been told that there are different file modes that can be used when opening a text
file. She wants to make sure that the existing contents are not deleted when the file is opened.

Identify two file modes she could use and describe their use.

Mode .........................................

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

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

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

Mode .........................................

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

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

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

(d) The student has completed the design of her program and is ready to use an Integrated
Development Environment (IDE).

Describe the features of an IDE that she can use to write, translate and test her program.

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

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

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

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

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

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

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


8

3 The following pseudocode represents three separate modules from an algorithm design. The
module contents are not shown.

FUNCTION Search(AA : INTEGER, BB : STRING) RETURNS INTEGER

ENDFUNCTION

FUNCTION Allocate() RETURNS BOOLEAN

ENDFUNCTION

PROCEDURE Enable(CC : INTEGER, BYREF DD : INTEGER)

ENDPROCEDURE

A fourth module, Setup(), refers to the previous three modules as follows:

PROCEDURE Setup()

WHILE Authorised = TRUE

ThisValue Search(27, "Thursday")

Authorised Allocate()

CALL Enable(ThisValue, 4)

ENDWHILE

ENDPROCEDURE

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


9

(a) Draw a structure chart to show the four modules and the parameters that these pass between
them.

[6]

(b) The algorithm is implemented in a high-level language. Changes are required and the
program is given to Albert, who is an experienced programmer. He is not familiar with the
language that has been used.

Explain why Albert would be able to understand the program.

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

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

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

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

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


10

4 A program is being written to process student information. One task involves inputting the names
of all students in a class.

A first attempt at the pseudocode for this task is as follows:

DECLARE Name1 : STRING


DECLARE Name2 : STRING
DECLARE Name3 : STRING

DECLARE Name40 : STRING

OUTPUT "Input the name for student 1"


INPUT Name1
OUTPUT "Input the name for student 2"
INPUT Name2
OUTPUT "Input the name for student 3"
INPUT Name3

OUTPUT "Input the name for student 40"


INPUT Name40

(a) Re-write the pseudocode to perform this task in a more efficient way, to allow for the class of
40 students.

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

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

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

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

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

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

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

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

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

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

(b) Give one advantage of your solution.

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

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


12

5 Nigel is learning about string handling. He wants to write code to count the number of words in a
given string. A word is defined as a sequence of alphabetic characters that is separated by one or
more space characters.

His first attempt at writing an algorithm in pseudocode is as follows:

PROCEDURE CountWords(Message : STRING)

DECLARE NumWords : INTEGER


DECLARE Index : INTEGER
CONSTANT Space = ' '

NumWords 0

FOR Index 1 TO LENGTH(Message)


IF MID(Message, Index, 1) = Space
THEN
NumWords NumWords + 1
ENDIF
ENDFOR

OUTPUT "Number of words : " , NumWords

ENDPROCEDURE

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

His first attempt is incorrect. He will use white-box testing to help him to identify the problem.

(a) (i) State the purpose of white-box testing.

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

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

(ii) Dry running the code is often used in white-box testing. In this method, the programmer
records the values of variables as they change.

Identify what the programmer would normally use to record the changes.

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

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


13

(b) (i) Write a test string containing two words that gives the output:

Number of words : 2

Use the symbol '∇' to represent each space character in your test string.

Explain why the algorithm gives the output shown above.

String .................................................................................................................................

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

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

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

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

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

(ii) Nigel tested the procedure with the strings:

String 1: "Red∇and∇Yellow"
String 2: "Green∇∇and∇∇Pink∇"

Give the output that is produced for each of the strings.

Describe the changes that would need to be made to the algorithm to give the correct
output in each case.

Do not write pseudocode or program code.

String 1 ..............................................................................................................................

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

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

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

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

String 2 ..............................................................................................................................

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

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

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

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

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


14

6 A text file, StudentContact.txt, contains a list of names and telephone numbers of students
in a school. Not all students in the school have provided a contact telephone number. In this case,
their name will not be in the file.

Each line of the file is stored as a string that contains a name and telephone number, separated by
the asterisk character ('*') as follows:

<Name>'*'<TelNumber>, for example:

"Bill Smith*081234567"

A 1D array, ClassList, contains the names of students in a particular class. The array consists
of 40 elements of string data type. You can assume that student names are unique.
Unused elements contain the empty string "".

A program is to be written to produce a new text file, ClassContact.txt, containing student


names and numbers for all students in a particular class.

For each name contained in the ClassList array, the program will:

• search the StudentContact.txt file


• copy the matching string into ClassContact.txt if the name is found
• write the name together with “*No number” into ClassContact.txt if the name is not found.

The program will be implemented as three modules. The description of these is as follows:

Module Description
ProcessArray() • Check each element of the array:
○ Read the student name from the array
○ Ignore unused elements
○ Call SearchFile() with the student name
○ If the student name is found, call AddToFile() to
write the student details to the class file
○ If the student name is not found, call AddToFile()
to write a new string to the class file, formed as
follows:
<Name>“*No number”
• Return the number of students who have not provided a
telephone number
SearchFile() • Search for a given student name at the start of each line
in the file StudentContact.txt:
○ If the search string is found, return the text line from
StudentContact.txt
○ If the search string is not found, return an empty
string
AddToFile() • Append the given string to a specified file, for example,
AddToFile(StringName, FileName)

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


15

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

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

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

Program code

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

............................................................................................................................................. [8]
© UCLES 2019 9608/23/M/J/19 [Turn over
16

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

............................................................................................................................................. [9]

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


17

(c) ProcessArray() is modified to make it general purpose. It will now be called with two
parameters as follows:

• an array
• a string representing the name of a class contact file

It will still return the number of students who have not provided a contact telephone number.

Write program code for the header (declaration) of the modified ProcessArray().

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

Program code

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

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

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

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

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


18

Appendix

Built-in functions (pseudocode)

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

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


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

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

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 10

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


returns leftmost x characters from ThisString

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

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


returns rightmost x characters from ThisString

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

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: INT(27.5415) returns 27

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.

Example: NUM_TO_STRING(x) returns "87.5" if x has the value 87.5


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

STRING_TO_NUM(x : STRING) RETURNS REAL


returns a numeric representation of a string.

Example: STRING_TO_NUM(x) returns 23.45 if x has the value "23.45"


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

Operators (pseudocode)

Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE
© UCLES 2019 9608/23/M/J/19
Cambridge Assessment International Education
Cambridge International Advanced Subsidiary and Advanced Level
* 9 7 4 4 6 8 1 1 6 1 *

COMPUTER SCIENCE 9608/21


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

READ THESE INSTRUCTIONS FIRST

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

Answer all questions.


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

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

The maximum number of marks is 75.

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

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

1 Study the following pseudocode.

FUNCTION Search() RETURNS INTEGER


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

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

State three such features.

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

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

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

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


3

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

[5]

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


4

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

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

Example value Data type

"NOT TRUE"

− 4.5

NOT FALSE

132

[4]

(ii) Evaluate each expression in the following table.

If an expression is invalid then write ‘ERROR’.

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

Expression Evaluates to

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

MID("sample", 3, 5)

NUM_TO_STRING(12.3 * 2)

INT(STRING_TO_NUM("53.4")) + 7

[4]

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


5

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

State four other features that may be shown.

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

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

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

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

Feature 3 ..................................................................................................................................

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

Feature 4 ..................................................................................................................................

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

(b) Identify and describe one feature of an Integrated Development Environment (IDE) that can
help with program presentation.

Feature .....................................................................................................................................

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

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

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

Identify and describe the other method.

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

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

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

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

(d) Explain the term adaptive maintenance.

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

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

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

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

3 The following is a function design in pseudocode.

Line numbers are given for reference only.

10 FUNCTION Check(InString : STRING) RETURNS BOOLEAN


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

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


7

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

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

Feature Answer

The number of the line containing a variable being incremented

The range of line numbers containing a pre-condition loop

The number of initialisation statements

The number of the line containing a logical operator

The range of line numbers containing a selection statement

The name of a built-in function

The name of a parameter

[7]

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


8

4 A student is developing a program to count how many times each character of the alphabet (A to Z)
occurs in a given string. Upper case and lower case characters will be counted as the same. The
string may contain non-alphabetic characters, which should be ignored.

The program will:

• check each character in the string to count how many times each alphabetic character occurs
• store the count for each alphabetic character in a 1D array
• output each count together with the corresponding character.

(a) The student has written a structured English description of the algorithm:

1. START at the beginning of the string


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

Step 4 above is not described in sufficient detail.

The student decides to apply a process to increase the level of detail given in step 4.

State the name of the process and use this process to write step 4 in more detail. Use
structured English for your answer.

Process .....................................................................................................................................

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

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

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

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

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

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

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


9

(b) Write pseudocode to implement the program.

You should note the following:

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


• The elements of the array Result have all been initialised to zero.
• The ASCII value of letter ‘A’ is 65.

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

DECLARE InString : STRING


DECLARE Result : ARRAY [1:26] OF INTEGER

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


10

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

FUNCTION CheckPassword(InString : STRING) RETURNS BOOLEAN

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


DECLARE NextChar : CHAR

Upper 0
Lower 0
Digit 0
Other 0

FOR Index 1 TO LENGTH(InString)

NextChar MID(InString, Index, 1)


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

ENDFOR

IF Upper > 1 AND Lower >= 5 AND (Digit - Other) > 0


THEN
RETURN TRUE
ELSE
RETURN FALSE
ENDIF

ENDFUNCTION

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

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

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

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

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

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

............................................................................................................................................. [3]
© UCLES 2019 9608/21/O/N/19
11

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

Result CheckPassword("Jim+Smith*99")

Index NextChar Upper Lower Digit Other

[5]

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

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

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

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

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

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


12

6 Account information for users of a library is held in one of two text files; UserListAtoM.txt and
UserListNtoZ.txt

The format of the data held in the two files is identical. Each line of the file is stored as a string that
contains an account number, name and telephone number separated by the asterisk character
('*') as follows:

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

An example of one line from the file is:

"GB1234*Kevin Mapunga*07789123456"

The account number string may be six or nine characters in length and is unique for each
person. It is made up of alphabetic and numeric characters only.

An error has occurred and the same account number has been given to different users in the two
files. There is no duplication of account numbers within each individual file.

A program is to be written to search the two files and to identify duplicate entries. The account
number of any duplicate found is to be written to an array, Duplicates, which is a 1D array of
100 elements of data type STRING.

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

Module Outline description

ClearArray()
• Initialise the global array Duplicates. Set all elements to the
empty string.
• Read each line from the file UserListAtoM.txt
• Check whether the account number appears in file
UserListNtoZ.txt using SearchFileNtoZ()
FindDuplicates() • If the account number does appear then add the account
number to the array.
• Output an error message and exit the module if there are more
duplicates than can be written to the array.
• Search for a given account number in file UserListNtoZ.txt
SearchFileNtoZ()
• If found, return TRUE, otherwise return FALSE

(a) State one reason for storing data in a file rather than in an array.

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

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

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


13

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

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

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

Program code

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


15

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

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

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

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

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

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

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

(d) ClearArray() is to be modified to make it general purpose. It will be used to initialise any
1D array of data type STRING to any value.

It will now be called with three parameters as follows:

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

You should assume that the lower bound is 1.

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

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

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

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

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

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

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

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

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

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

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

Program code

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

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

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


16

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

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


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

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

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 10

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


returns leftmost x characters from ThisString

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

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


returns rightmost x characters from ThisString

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

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: INT(27.5415) returns 27

NUM_TO_STRING(x : REAL) RETURNS STRING


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

Example: NUM_TO_STRING(87.5) returns "87.5"

STRING_TO_NUM(x : STRING) RETURNS REAL


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

Example: STRING_TO_NUM("23.45") returns 23.45

ASC(ThisChar : CHAR) RETURNS INTEGER


returns the ASCII value of ThisChar

Example: ASC('A') returns 65

CHR(x : INTEGER) RETURNS CHAR


returns the character whose ASCII value is x

Example: CHR(87) returns 'W'

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


17

UCASE(ThisChar : CHAR) RETURNS CHAR


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

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

Operators (pseudocode)

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

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


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

COMPUTER SCIENCE 9608/22


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

READ THESE INSTRUCTIONS FIRST

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

Answer all questions.


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

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

The maximum number of marks is 75.

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

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

1 Study the following pseudocode.

PROCEDURE FillTank()

DECLARE Tries : INTEGER


DECLARE Full : BOOLEAN

Tries 1

Full ReadSensor("F1")

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

ENDPROCEDURE

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

State three such features.

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

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

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

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


3

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

[5]

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


4

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

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

Example value Data type

43

TRUE

− 273.16

"− 273.16"

[4]

(ii) Evaluate each expression in the following table.

If an expression is invalid then write ‘ERROR’.

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

Expression Evaluates to

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

MID(NUM_TO_STRING(2019), 3, 1)

INT(NUM_TO_STRING(-273.16))

INT(13/2)

[4]

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


5

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

• source code
• object code
• corrective maintenance.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


6

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

The program will:

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

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

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

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

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

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

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

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

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

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


7

(b) Write the pseudocode for the program.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


8

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

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

Button Parameter value

Volume increase 10

Volume decrease 20

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

CALL Button(10) // VolLevel increased by 1


CALL Button(10) // VolLevel increased by 1
CALL Button(10) // VolLevel increased by 1
CALL Button(20) // VolLevel decreased by 1

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

Variable Description
VolLevel The current volume setting. This must be in the range 0 to 49.
A value that can be set to limit the maximum value of VolLevel,
in order to protect the user’s hearing.
MaxVol
A value in the range 1 to 49 indicates the volume limit.
A value of zero indicates that no volume limit has been set.

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

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


9

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

The value of MaxVol should not be changed within the procedure.

Parameter validation is not necessary.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]
© UCLES 2019 9608/22/O/N/19 [Turn over
10

(b) The procedure Button() is to be tested using black-box testing.

Fill in the gaps below to define three tests that could be carried out.

TEST 1 – VolLevel is changed

Parameter value: 10

MaxVol: ..................

VolLevel value before call to Button(): 48

VolLevel expected value after call to Button(): ..................

TEST 2 – VolLevel is not changed

Parameter value: 10

MaxVol: 34

VolLevel value before call to Button(): ..................

VolLevel expected value after call to Button(): ..................

TEST 3 – VolLevel is not changed

Parameter value: ..................

MaxVol: 40

VolLevel value before call to Button(): 0

VolLevel expected value after call to Button(): ..................

[6]

© UCLES 2019 9608/22/O/N/19


11

(c) The testing stage is part of the program development cycle.

(i) The program for the music player has been completed. The program does not contain
any syntax errors, but testing could reveal further errors.

Identify and describe one different type of error that testing could reveal.

Type ..................................................................................................................................

Description ........................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[2]

(ii) Stub testing is a technique often used in the development of modular programs.

Describe the technique.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

© UCLES 2019 9608/22/O/N/19 [Turn over


12

5 The module headers for three modules in a program are defined in pseudocode as follows:

Pseudocode module header


PROCEDURE Lookup(P4 : INTEGER, BYREF M4 : STRING)
FUNCTION Update(T4 : INTEGER) RETURNS INTEGER
FUNCTION Validate(S2 : INTEGER, P3 : STRING) RETURNS BOOLEAN

A fourth module, Renew(), calls the three modules in the following sequence.

Validate()
Lookup()
Update()

Draw a structure chart to show the relationship between the four modules and the parameters
passed between them.

[7]

© UCLES 2019 9608/22/O/N/19


14

6 A text file, StudentList.txt, contains a list of information about students in a school.

Each line of the file contains a reference, name and date of birth for one student. All the information
is held as strings and separated by the asterisk character ('*') as follows:

<Reference>'*'<Name>'*'<Date Of Birth>

An example of one line from the file is:

"G1234*Aleza Hilton*05062001"

The reference string may be five or eight characters in length and is unique for each student. It is
made up of alphabetic and numeric characters only.

A global 1D array, Leavers, contains the references of all students who have recently left the
school. The array consists of 500 elements of data type STRING. Unused elements contain the
empty string "".

A program is to be written to produce a new text file, UpdatedList.txt, containing information


only for students who are still attending the school.

The program is to be implemented as several modules. The outline description of three of these is
as follows:

Module Outline description


• Read each line from the file StudentList.txt
• Check whether the Reference appears in the
array using SearchLeavers()
ProcessStudentList()
• If the Reference does not appear then write the
line to the file UpdatedList.txt
• Return the number of lines not copied.
• Search for a given Reference in the array Leavers
SearchLeavers() • If the Reference is found, return TRUE, otherwise
return FALSE
• Take two parameters: the name of an array and a
string.
CountTimes()
• Count the number of elements that are the same as
the string. Return the count value.

© UCLES 2019 9608/22/O/N/19


15

(a) Write program code for the module SearchLeavers(). Declare any additional variables
you use.

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2019 9608/22/O/N/19 [Turn over


16

(b) Write pseudocode for the module ProcessStudentList().

The module description is repeated here for reference.

Module Outline description


• Read each line from the file StudentList.txt
• Check whether the Reference appears in the
array using SearchLeavers()
ProcessStudentList()
• If the Reference does not appear then write the
line to the file UpdatedList.txt
• Return the number of lines not copied.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2019 9608/22/O/N/19
17

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [9]

(c) CountTimes() is to be used to count how many unused elements there are in the Leavers
array. An unused element is one that contains an empty string.

The module description is repeated here for reference.

Module Outline description


• Take two parameters: the name of an array and a
string.
CountTimes()
• Count the number of elements that are the same as
the string. Return the count value.

Write a statement in program code that uses CountTimes() to assign the count of unused
elements to the variable Result.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2019 9608/22/O/N/19 [Turn over


18

Appendix
Built-in functions (pseudocode)

Each function returns an error if the function call is not properly formed.

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString

Example: MID("ABCDEFGH", 2, 3) returns "BCD"

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString

Example: LEFT("ABCDEFGH", 3) returns "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString

Example: RIGHT("ABCDEFGH", 3) returns "FGH"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: INT(27.5415) returns 27

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.
Note: This function will also work if x is of type INTEGER

Example: NUM_TO_STRING(87.5) returns "87.5"

STRING_TO_NUM(x : STRING) RETURNS REAL


returns a numeric representation of a string.
Note: This function will also work if x is of type CHAR

Example: STRING_TO_NUM("23.45") returns 23.45

Operators (pseudocode)

Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE

© UCLES 2019 9608/22/O/N/19


Cambridge Assessment International Education
Cambridge International Advanced Subsidiary and Advanced Level
* 9 5 3 4 4 8 1 8 7 2 *

COMPUTER SCIENCE 9608/23


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2019
2 hours
Candidates answer on the Question Paper.
No Additional Materials are required.
No calculators allowed.

READ THESE INSTRUCTIONS FIRST

Write your centre number, candidate number and name in the spaces at the top of this page.
Write in dark blue or black pen.
You may use an HB pencil for any diagrams, graphs or rough working.
Do not use staples, paper clips, glue or correction fluid.
DO NOT WRITE IN ANY BARCODES.

Answer all questions.


No marks will be awarded for using brand names of software packages or hardware.

At the end of the examination, fasten all your work securely together.
The number of marks is given in brackets [ ] at the end of each question or part question.

The maximum number of marks is 75.

This document consists of 16 printed pages.

DC (ST/SG) 171122/4
© UCLES 2019 [Turn over
3

1 (a) (i) Programming languages can support different data types.

Complete the table by naming three different data types together with an example data
value for each.

Data type Example data value

[6]

(ii) Identify the type of programming statement that assigns a data type to a variable.

..................................................................................................................................... [1]

(b) As part of the development of an algorithm, a programmer may construct an identifier table.

Describe what an identifier table contains.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

(c) (i) Simple algorithms usually consist of three different stages.

Complete the table below. Write each example statement in program code.

The second stage has already been given.

Stage Example statement

Process

[5]

(ii) Write a single statement in program code that contains two of the stages. Do not
repeat any of the statements from part (c)(i).

..................................................................................................................................... [1]

© UCLES 2019 9608/23/O/N/19 [Turn over


4

(d) A software developer is writing a program and includes several features to make it easier to
read and understand. One of these features is the use of indentation.

State three other features.

Feature 1 ..................................................................................................................................

Feature 2 ..................................................................................................................................

Feature 3 ..................................................................................................................................
[3]

(e) A trace table is often used during program testing.

Identify the type of testing that includes the use of a trace table.

............................................................................................................................................. [1]

© UCLES 2019 9608/23/O/N/19


5

2 (a) (i) Two types of loop that may be found in an algorithm are the ‘pre-condition’ and ‘post-
condition’ loop.

Identify one other type of loop. Explain when it should be used.

Type ..................................................................................................................................

Explanation .......................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[2]

(ii) Part of a program flowchart is shown.

LOOP

AlarmReset()

Set Status1 to
GetStatus(Sys_A)

Set Status2 to
GetStatus(Sys_B)

Are Status1
NO
and Status2
both TRUE?

YES

Implement the flowchart in pseudocode using a post-condition loop.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [4]

© UCLES 2019 9608/23/O/N/19 [Turn over


6

(b) The following lines of code are taken from a high-level language program.

100 setvar(Count, Integer)


110 setvar(Gross[0-20], Real)
120 setvar(Posn, Real)
130 setvar(Length, Integer)
140 setvar(Rate, Real)
150 Length := 7
160 Rate := 1.175
170
180 For (Count, 0, 20, 2)
190 {
200 Echo "Input next cost"
210 Posn := Read()
220 Gross[Count] := Mult(Posn, Rate) %Apply current tax rate
230 }

Study the code. Identify the relevant features in the following table.

Feature Answer

The symbol used to indicate an assignment

The line numbers for the start and end of a count-controlled loop

The step value of the count-controlled loop

The character that indicates a comment

The name of a function


[5]

(c) A program written in a high-level language cannot be run directly.

Identify one type of translator that can be used to translate the program.

............................................................................................................................................. [1]

© UCLES 2019 9608/23/O/N/19


7

3 Three program modules process updating of passwords in a file. A description of the relationship
between the modules is summarised as follows:

Module name Description

GetPassword()
• Takes two parameters: AccountID and OldPassword
• Returns a string containing the new password
• Takes two parameters: AccountID and NewPassword
UpdateFile() • Returns a Boolean value to indicate whether or not the
update was successful

ChangePassword()
• Calls GetPassword() to obtain the new password then
calls UpdateFile() to write the new password to the file

Draw a structure chart to show the relationship between the three modules and the parameters
passed between them.

[5]

© UCLES 2019 9608/23/O/N/19 [Turn over


8

4 The following pseudocode algorithm checks whether a string is a valid email address.

FUNCTION Check(InString : STRING) RETURNS BOOLEAN

DECLARE Index : INTEGER


DECLARE NumDots : INTEGER
DECLARE NumAts : INTEGER
DECLARE NextChar : CHAR
DECLARE NumOthers : INTEGER

NumDots 0
NumAts 0
NumOthers 0

FOR Index 1 TO LENGTH(InString)

NextChar MID(InString, Index, 1)


CASE OF NextChar
'.': NumDots NumDots + 1
'@': NumAts NumAts + 1
OTHERWISE NumOthers NumOthers + 1
ENDCASE

ENDFOR

IF (NumDots >= 1 AND NumAts = 1 AND NumOthers > 5)


THEN
RETURN TRUE
ELSE
RETURN FALSE
ENDIF

ENDFUNCTION

(a) Describe the validation rules that are implemented by this pseudocode. Refer only to the
contents of the string and not to features of the pseudocode.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2019 9608/23/O/N/19


9

(b) (i) Complete the trace table by dry running the function when it is called as follows:

Result Check("[email protected]")

Index NextChar NumDots NumAts NumOthers

[5]

(ii) State the value returned when function Check is called as shown in part (b)(i).

..................................................................................................................................... [1]

© UCLES 2019 9608/23/O/N/19 [Turn over


10

(c) The function Check() is to be tested.

State two different invalid string values that could be used to test the algorithm. Each string
should test a different rule.

Justify your choices.

Value .........................................................................................................................................

Justification ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Value .........................................................................................................................................

Justification ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[4]

5 Abbreviations are often used in place of a full name. Concatenating the first letter of each word in
the name makes an abbreviation.

For example:

Name Abbreviation

United Nations UN

World Wide Web WWW

British Computer Society BCS

A function, Abbreviate(), will take a string representing the full name and return a string
containing the abbreviated form.

You should assume that:

• names only contain alphabetic characters and space characters


• names always start with an alphabetic character
• each word in the name always starts with an uppercase character
• only a single space separates words in the name.

© UCLES 2019 9608/23/O/N/19


11

Write pseudocode to implement the function Abbreviate().

Refer to the Appendix on page 16 for the list of built-in functions and operators.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [8]

© UCLES 2019 9608/23/O/N/19 [Turn over


12

6 A text file, Library.txt, stores information relating to a book collection. The file stores four
pieces of information about each book on separate lines of the file, as follows:

Line n: <Book Title>


Line n + 1: <Author Name>
Line n + 2: <ISBN>
Line n + 3: <Location>

Information is stored as data strings.

Information relating to two books is shown:

File line Data


100 "Learning Python"

101 "Brian Smith"

102 "978-14-56543-21-8"

103 "BD345"

104 "Surviving in the mountains"

105 "C T Snow"

106 "978-35-17635-43-9"

107 "ZX001"

(a) (i) A function, FindBooksBy(), will search Library.txt for all books by a given author.

The function will store the Book Title and Location in the array Result, and will
return a count of the number of books found.

Array Result is a global 2D array of type STRING. It has 100 rows and 2 columns.

Write pseudocode to declare the array Result.

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

(ii) Function FindBooksBy() will:

• receive the Author Name as a parameter


• search Library.txt for matching entries
• store the Book Title and Location of matching entries in the Result array
• return an integer value giving the number of books by the author that were found.

© UCLES 2019 9608/23/O/N/19


13

Write program code for the function FindBooksBy().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language .....................................................................................................

Program code

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
© UCLES 2019 9608/23/O/N/19 [Turn over
14

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [8]

(b) The function FindBooksBy() has already been called and has stored values in the array
Result.

The procedure, DisplayResults(), will output the information from the array.

The procedure receives the following two parameters:

• a string containing the author name


• an integer value representing the number of books found

The output should be formatted as in the following example:

Books written by: Brian Smith

Title Location
Learning Python BD345
Arrays are not lists CZ562
Learning Java CZ589

Number of titles found: 3

If no books by the author are found, the following should be output:

Search found no books by: Brian Smith

© UCLES 2019 9608/23/O/N/19


15

Write pseudocode for the procedure DisplayResults().

Refer to the Appendix on page 16 for the list of built-in functions and operators.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2019 9608/23/O/N/19 [Turn over


16

Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString
Example: MID("ABCDEFGH", 2, 3) returns "BCD"

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString
Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString
Example: LEFT("ABCDEFGH", 3) returns "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString
Example: RIGHT("ABCDEFGH", 3) returns "FGH"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x
Example: INT(27.5415) returns 27

ASC(ThisChar : CHAR) RETURNS INTEGER


returns the ASCII value of ThisChar
Example: ASC('A') returns 65

MOD(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the remainder when ThisNum is divided by ThisDiv
Example: MOD(10,3) returns 1

Operators (pseudocode)

Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE
© UCLES 2019 9608/23/O/N/19
Cambridge International AS & A Level
* 0 6 3 8 5 6 1 5 3 5 *

COMPUTER SCIENCE 9608/21


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2020

2 hours

You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
● Answer all questions.
● Use a black or dark blue pen.
● Write your name, centre number and candidate number in the boxes at the top of the page.
● Write your answer to each question in the space provided.
● Do not use an erasable pen or correction fluid.
● Do not write on any bar codes.
● You may use an HB pencil for any diagrams, graphs or rough working.
● Calculators must not be used in this paper.

INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].
● No marks will be awarded for using brand names of software packages or hardware.

This document has 24 pages. Blank pages are indicated.

DC (CE/CB) 180782/4
© UCLES 2020 [Turn over
2

1 (a) Complete this definition of the term algorithm.

An algorithm is a solution to a problem expressed as ..............................................................

...................................................................................................................................................

............................................................................................................................................. [2]

(b) A program design includes the use of subroutines (functions and procedures).

Give three advantages of using subroutines in a program.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................

3 ................................................................................................................................................

...................................................................................................................................................
[3]

(c) Draw lines on the following diagram to connect each computing term with the appropriate
description.

Term Description

Checking that a program


Selection performs as expected

A method for increasing the


Black-box testing level of detail of an algorithm

To test a condition to determine


Stepwise refinement the path of program execution

A method of executing certain


Iteration lines of code more than once

[3]

© UCLES 2020 9608/21/M/J/20


3

2 (a) Three modules form part of a program for a car rental company. A description of the
relationship between the modules is summarised as follows:

Module name Description


A customer will pay for each car rental either by bank card or by using their
RentCar()
account with the rental company.
Called with parameter HireCost, representing the cost of the rental.
PayByCard() Returns a BOOLEAN value to indicate whether or not the card payment was
successful.
Called with parameters HireCost, AccountNumber, CurrentBalance
and AccountLimit.
• Checks whether HireCost plus the CurrentBalance would exceed
PayByAccount() the AccountLimit. If so, then the rental is not authorised.
• If the rental is authorised, then the CurrentBalance is updated.
• Returns a BOOLEAN value to indicate whether or not the rental was
authorised.

Draw a structure chart to show the relationship between the three modules and the
parameters passed between them.

[5]
© UCLES 2020 9608/21/M/J/20 [Turn over
4

(b) The following pseudocode algorithm has been developed to check whether a string contains
a valid password.

To be a valid password, a string must:

• be longer than 6 characters


• contain at least one lower case letter
• contain at least one upper case letter
• contain at least one non-alphabetic character.

10 FUNCTION Check(InString : STRING) RETURNS BOOLEAN


11
12 DECLARE Index : INTEGER
13 DECLARE StrLen : INTEGER
14 DECLARE NumUpper, NumLower : INTEGER
15 DECLARE NumNonAlpha : INTEGER
16 DECLARE NextChar : CHAR
17
18 NumUpper 0
19 NumLower 0
20 NumNonAlpha 0
21
22 StrLen LENGTH(InString)
23 IF StrLen < 7
24 THEN
25 RETURN FALSE
26 ELSE
27 FOR Index 1 TO StrLen
28 NextChar MID(InString, Index, 1)
29 IF NextChar >= 'a' AND NextChar <= 'z'
30 THEN
31 NumLower NumLower + 1
32 ELSE
33 IF NextChar > 'A' AND NextChar <= 'Z'
34 THEN
35 NumUpper NumUpper + 1
36 ELSE
37 NumNonAlpha NumNonAlpha + 1
38 ENDIF
39 ENDIF
40 ENDFOR
41 ENDIF
42
43 IF (NumUpper >= 1) AND (NumLower >= 1) AND (NumNonAlpha >= 1)
44 THEN
45 RETURN TRUE
46 ELSE
47 RETURN FALSE
48 ENDIF
49
50 ENDFUNCTION

Refer to the Appendix on page 21 for a list of built-in pseudocode functions and operators.

© UCLES 2020 9608/21/M/J/20


5

The pseudocode does not work under all circumstances.

A dry run performed on the function Check(), with the string "crAsh99", produced the
following trace table.

The string is a valid password, but the pseudocode would return the value FALSE.

Trace
StrLen Index NextChar NumUpper NumLower NumNonAlpha
table row
1 7 0 0 0
2 1 'c'
3 1
4 2 'r'
5 2
6 3 'A'
7 1
8 4 's'
9 3
10 5 'h'
11 4
12 6 '9'
13 2
14 7 '9'
15 3

(i) Describe how the completed trace table may be used to identify the error in the
pseudocode. In your answer, refer to the trace table row number(s).

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(ii) State the pseudocode line number that has to be changed to correct the error and write
the correct pseudocode for the complete line.

Line number ......................................................................................................................

Correct pseudocode ..........................................................................................................

...........................................................................................................................................
[2]

© UCLES 2020 9608/21/M/J/20 [Turn over


6

(iii) Rewrite lines 29 to 39 of the original pseudocode using a CASE structure.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [4]

© UCLES 2020 9608/21/M/J/20


8

3 (a) A mobile phone provider has developed an account management program. The program
includes a procedure, AddCredit(). The procedure is called with two parameters, TopUp
and PhoneNum.

The relevant part of the identifier table and the program flowchart for the procedure are as
shown:

Identifier Type Description


TopUp REAL The amount of credit to be added
PhoneNum STRING The unique customer phone number
Balance REAL The current amount of credit
Multiple REAL The amount of credit bonus
Takes the phone number as a parameter and returns the current
GetBalance() FUNCTION
balance
Takes the phone number and the new balance as parameters and
SetBalance() PROCEDURE
updates the account with the new balance

START

Set Multiple
to 1

Set Balance to
GetBalance(PhoneNum)

Is YES Set Multiple to


Balance > 10 ? 1.25

NO

Is YES Set Multiple to


Balance > 5 ? 1.1

NO

Set TopUp to
TopUp * Multiple

SetBalance(PhoneNum, Balance + TopUp)

END

© UCLES 2020 9608/21/M/J/20


9

Write pseudocode to implement the procedure AddCredit(). The pseudocode must follow
the algorithm represented by the flowchart. Declare any local variables used.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2020 9608/21/M/J/20 [Turn over


10

(b) The following pseudocode searches for a string "Chris" in a 1D array and outputs the index
positions where the string is found.

DECLARE NameList : ARRAY [1:100] OF STRING


DECLARE n : INTEGER

FOR n 1 TO 100
IF NameList[n] = "Chris"
THEN
OUTPUT "Found at: " & NUM_TO_STRING(n)
ENDIF
ENDFOR

The pseudocode needs to be modified as follows:

• Write the search as a procedure, Search(), that takes the search string as a parameter.
• Change the array to a 2D array. The first dimension contains names and the second
dimension contains the corresponding status.

For example:
NameList[23, 1] "Chris" // name
NameList[23, 2] "On Holiday" // status
• Detect a match only when the name contains the search string and the status contains
"Active".
• If a match has been detected, the procedure will output a single message giving all of
the index positions where a match occurred. For example, "Found at: 3 6 22".
• If no match has been detected, the procedure will output a suitable message.

Refer to the Appendix on page 21 for a list of built-in pseudocode functions and operators.

© UCLES 2020 9608/21/M/J/20


11

Write the pseudocode for the procedure Search(). Assume the array has been declared
globally.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2020 9608/21/M/J/20 [Turn over


12

4 (a) An inexperienced user buys a games program. A program fault occurs while the user is
playing the game.

Explain what is meant by a program fault.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

(b) Give three ways to minimise the risk of faults when writing programs.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................

3 ................................................................................................................................................

............................................................................................................................................. [3]

(c) Three types of program error are syntax, logic and run-time.

Define these three types.

Syntax error ..............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Logic error ................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Run-time error ..........................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2020 9608/21/M/J/20


14

5 (a) A 1D array, Directory, of type STRING is used to store a list of school internal telephone
numbers. There are 1000 elements in the array. Each element stores a single data item. The
format of each data item is as follows:

<Number><Name>

Number is a four-digit numeric string.


Name is a variable-length string.

For example:

"1024Collins Robbie"

The following pseudocode is an initial attempt at defining a procedure SortContacts()


that will perform a bubble sort on Directory. The array is to be sorted in ascending order of
Name.

Fill in the gaps to complete the pseudocode.

Refer to the Appendix on page 21 for a list of built-in pseudocode functions and operators.

PROCEDURE SortContacts ()
DECLARE Temp : STRING
DECLARE FirstName, SecondName : STRING
DECLARE NoSwaps : ……………………………………
DECLARE Boundary, J : INTEGER
Boundary ……………………
REPEAT
NoSwaps TRUE
FOR J 1 TO Boundary
FirstName …………………………(Directory[J], LENGTH(Directory[J]) – …………… )
SecondName RIGHT(Directory[J + 1], LENGTH(Directory[J + 1]) – 4)
IF FirstName ………………………………
THEN
Temp Directory[J]
Directory[J] Directory ……………………………
Directory[J + 1] Temp
NoSwaps ……………………………
ENDIF
ENDFOR
Boundary ……………………………
UNTIL NoSwaps = TRUE
ENDPROCEDURE
[8]

© UCLES 2020 9608/21/M/J/20


15

(b) The pseudocode contains a mechanism designed to make this an efficient bubble sort.

Describe the mechanism and explain why it may be considered to be efficient.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]

© UCLES 2020 9608/21/M/J/20 [Turn over


16

6 A company hires out rowing boats on a lake. The company has ten boats, numbered from 1 to 10.

The company is developing a program to help manage and record the hiring out process.

Hire information is stored in three global 1D arrays when a boat is hired out. Each array contains
10 elements representing each of the ten boats.

The three 1D arrays are summarised as follows:

Array Data type Description Example data value


HireTime STRING The time the boat was hired out "10:15"

Duration INTEGER The number of minutes of the hire 30

Cost REAL The cost of the hire 5.75

If an individual boat is not currently on hire, the corresponding element of the HireTime array will
be set to "Available".

The programmer has started to define program modules as follows:

Module Description
• Called with two parameters:
o a STRING value representing a time
AddTime() o an INTEGER value representing a duration in minutes
• Adds the duration to the time to give a new time
• Returns the new time as a STRING
• Called with a STRING value representing the time the
hire will start
• Outputs the boat numbers that will be available for hire at
the given start time. A boat will be available for hire if it is
either:
ListAvailable()
o currently not on hire, or
o due back before the given hire start time
• Outputs the number of each boat available
• Outputs the total number of boats available or a suitable
message if there are none
• Called with four parameters:
o an INTEGER value representing the boat number
o a STRING value representing the hire start time
o an INTEGER value representing the hire duration in
minutes
o a REAL value representing the cost of hire
RecordHire()
• Updates the appropriate element in each array
• Adds the cost of hire to the global variable DailyTakings
• Converts the four input parameters to strings,
concatenated using commas as separators, and writes
the resulting string to the end of the existing text file
HireLog.txt

© UCLES 2020 9608/21/M/J/20


17

(a) Write pseudocode for the module ListAvailable().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2020 9608/21/M/J/20 [Turn over


18

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2020 9608/21/M/J/20


19

(b) Write program code for the module RecordHire().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]
© UCLES 2020 9608/21/M/J/20 [Turn over
20

(c) The module description of AddTime()is repeated here for reference.

Module Description
• Called with two parameters:
o a STRING value representing a time
AddTime() o an INTEGER value representing a duration in minutes
• Adds the duration to the time to give a new time
• Returns the new time as a STRING

(i) Write program code for a statement that uses the AddTime() function to add a duration
of 60 minutes to a start time contained in variable BeginTime and to assign the new
time to variable EndTime.

Programming language .....................................................................................................

Program code

...........................................................................................................................................

..................................................................................................................................... [2]

(ii) The function AddTime() is to be tested using black-box testing.

Complete the following two tests that can be performed to check the operation of the
function. Note that test 1 and test 2 are different.

Test 1 – Boat is returned during the same hour as rental starts

Start time value ....................................... Duration value .......................................

Expected new time value .......................................

Test 2 – Boat is returned during the hour after the rental starts

Start time value ....................................... Duration value .......................................

Expected new time value .......................................


[2]

© UCLES 2020 9608/21/M/J/20


21

Appendix

Built-in functions (pseudocode)

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString

Example: MID("ABCDEFGH", 2, 3) returns "BCD"

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString

Example: LEFT("ABCDEFGH", 3) returns "ABC"

RIGHT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString

Example: RIGHT("ABCDEFGH", 3) returns "FGH"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: INT(27.5415) returns 27

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value
Note: This function will also work if x is of type INTEGER

Example: NUM_TO_STRING(87.5) returns "87.5"

Operators (pseudocode)

Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE

© UCLES 2020 9608/21/M/J/20


Cambridge International AS & A Level
* 4 8 6 0 2 0 4 7 9 7 *

COMPUTER SCIENCE 9608/22


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2020

2 hours

You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
● Answer all questions.
● Use a black or dark blue pen.
● Write your name, centre number and candidate number in the boxes at the top of the page.
● Write your answer to each question in the space provided.
● Do not use an erasable pen or correction fluid.
● Do not write on any bar codes.
● You may use an HB pencil for any diagrams, graphs or rough working.
● Calculators must not be used in this paper.

INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].
● No marks will be awarded for using brand names of software packages or hardware.

This document has 20 pages. Blank pages are indicated.

DC (RW/TP) 180777/4
© UCLES 2020 [Turn over
3

1 (a) Selection and repetition are basic constructs of an algorithm.

Name and describe one other construct.

Name ........................................................................................................................................

Description ................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

(b) Program coding is a transferable skill.

Explain the term transferable skill.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

(c) Count-controlled and post-condition are two types of loop.

Describe the characteristics of each of these types of loop.

Count-controlled .......................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Post-condition ...........................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[2]

(d) Name three features provided by an Integrated Development Environment (IDE) that assist
in the coding and initial error detection stages of the program development cycle.

1 ................................................................................................................................................

2 ................................................................................................................................................

3 ................................................................................................................................................
[3]

© UCLES 2020 9608/22/M/J/20 [Turn over


4

2 (a) A structure chart is often produced as part of a modular program design. The chart shows the
hierarchy of modules and the sequence of execution.

Give two other features the structure chart can show.

Feature 1 ..................................................................................................................................

...................................................................................................................................................

Feature 2 ..................................................................................................................................

...................................................................................................................................................
[2]

(b) Six program modules implement part of an online shopping program. The following table
gives the modules and a brief description of each module:

Module Description
Allows the user to choose a delivery slot, select items to be added to
Shop()
the basket and finally check out

ChooseSlot() Allows the user to select a delivery time. Returns a delivery slot number

FillBasket() Allows the user to select items and add them to the basket

Completes the order by allowing the user to pay for the items. Returns
Checkout()
a Boolean value to indicate whether or not payment was successful

Search() Allows the user to search for a specific item. Returns an item reference

Adds an item to the basket. Takes an item reference and a quantity as


Add()
parameters

(i) The online shopping program has been split into sub-tasks as part of the design process.

Explain the advantages of decomposing the program into modules. Your explanation
should refer to the scenario and modules described in part (b).

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

© UCLES 2020 9608/22/M/J/20


5

(ii) Complete the structure chart for the six modules described in part (b).

Shop()

[6]

© UCLES 2020 9608/22/M/J/20 [Turn over


6

3 A navigation program includes a function, CheckCourse(). This function is called with a real
value, Course, and returns an integer value.

The identifier table and the program flowchart for the function are shown as follows:

Identifier Type Description


Course REAL The value passed to CheckCourse()
Adjust INTEGER The value returned by CheckCourse()
Check INTEGER A local variable
A function that is passed a REAL value representing the
Deviate() FUNCTION course and returns a REAL value representing the current
deviation
Alert() PROCEDURE A procedure that generates a warning

START

Set Check to integer


value of
Deviate(Course)

Set Adjust to 255

CASE OF
Check
–20 to –1
OTHERWISE Set Adjust to 10

0
Set Adjust to 0

Alert()

1 to 20
Set Adjust to –10

RETURN Adjust

END

© UCLES 2020 9608/22/M/J/20


7

Write pseudocode to implement the function CheckCourse(). The pseudocode must follow the
algorithm represented by the flowchart. Declare any local variables used.

Refer to the Appendix on page 19 for a list of built-in pseudocode functions and operators.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [7]
© UCLES 2020 9608/22/M/J/20 [Turn over
8

4 (a) Mustafa has developed the following pseudocode to generate ten random integers in the
range 1 to 100.

DECLARE Random : ARRAY [1:10] OF INTEGER


DECLARE Count, RNum : INTEGER

FOR Count 1 TO 10
Rnum INT(RAND(100)) + 1
Random[Count] RNum
ENDFOR

Refer to the Appendix on page 19 for a list of built-in pseudocode functions and operators.

Rewrite the pseudocode so that there are no duplicated numbers in the list of random
numbers.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

..................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]
© UCLES 2020 9608/22/M/J/20
9

(b) The changes made to the pseudocode in part (a) were as a result of changes to the program
requirement.

Give the term used to describe changes made for this reason.

............................................................................................................................................. [1]

© UCLES 2020 9608/22/M/J/20 [Turn over


10

5 A global 1D array, Contact, of type STRING is used to store a list of names and email addresses.

There are 1000 elements in the array. Each element stores one data item. The format of each
data item is as follows:

<Name>':'<EmailAddress>

Name and EmailAddress are both variable-length strings.

For example:

"Sharma Himal:[email protected]"

A function, GetName(), is part of the program that processes the array. A data item string will be
passed to the function as a parameter. The function will return the Name part. Validation is not
necessary.

(a) Use structured English to describe the algorithm for the function GetName().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2020 9608/22/M/J/20


11

(b) (i) The array is to be sorted using an efficient bubble sort algorithm. An efficient bubble sort
reduces the number of unnecessary comparisons between elements.

Describe how this could be achieved.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [4]

© UCLES 2020 9608/22/M/J/20 [Turn over


12

(ii) A procedure, BubbleSort(), is needed to sort the 1D array Contact into ascending
order of Name using an efficient bubble sort algorithm.

Write program code for the procedure BubbleSort().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language .....................................................................................................

Program code ....................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [8]

© UCLES 2020 9608/22/M/J/20


14

6 A company hires out rowing boats on a lake. The company has 17 boats numbered from 1 to 17.

Boats may be hired between 9:00 and 18:00, with a maximum hire duration of 90 minutes.

The company is developing a program to help manage and record the boat hire process.

The programmer has decided to store all values relating to hire time as strings. The program will
use a 24-hour clock format. For example:

Time (in words) String value


Nine o’clock in the morning "09:00"
Five minutes past ten o’clock in the morning "10:05"
Ten minutes before three o’clock in the afternoon "14:50"

The programmer has defined the first module as follows:

Module Description
• Takes two parameters:
StartTime: a STRING value representing a time as described
AddTime() Duration: an INTEGER value representing a duration in minutes
• Adds the duration to the time to give a new time
• Returns the new time as a STRING

(a) (i) Write pseudocode for the module AddTime(). Assume both input parameters are valid.

Refer to the Appendix on page 19 for a built-in list of pseudocode functions and
operators.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

© UCLES 2020 9608/22/M/J/20


15

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [8]

(ii) AddTime() will be tested using white-box testing.

State the reason for using white-box testing.

...........................................................................................................................................

..................................................................................................................................... [1]

(iii) A run-time error is one type of error that black-box testing can reveal.

Describe one other type of error that black-box testing can reveal.

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2020 9608/22/M/J/20 [Turn over


16

(b) The user will input the desired start time of a hire. A new module will be written to validate the
input string as a valid time in 24-hour clock format.

The string is already confirmed as being in the format "NN:NN", where N is a numeric
character.

Give an example of suitable test data that is in this format but which is invalid. Explain your
answer.

Test data ...................................................................................................................................

Explanation ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[2]

(c) Each time a boat is hired out, details of the hire are added to a text file, Hirelog.txt. Each
line of the text file corresponds to information about one hire session.

The format of each line is as follows:

<BoatNumber><Date><AmountPaid>

• BoatNumber is a two-digit numeric string


• Date is a six-digit numeric string in the format DDMMYY
• AmountPaid is a variable-length string representing a numeric value, for example
"12.75"

The total hire amount from each boat is to be stored in a global array, Total. This array is
declared in pseudocode as follows:

DECLARE Total : ARRAY [1:17] OF REAL

The programmer has defined module GetTotals() as follows:

Module Description
• Search through the file Hirelog.txt
GetTotals() • Extract the AmountPaid each time a boat is hired
• Store the total of AmountPaid for each boat in the array

© UCLES 2020 9608/22/M/J/20


17

Write program code for the module GetTotals().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2020 9608/22/M/J/20


19

Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.
LENGTH(ThisString : STRING) RETURNS INTEGER
returns the integer value representing the length of ThisString
Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString
Example: LEFT("ABCDEFGH", 3) returns "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString
Example: RIGHT("ABCDEFGH", 3) returns "FGH"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x
Example: INT(27.5415) returns 27

RAND(x : INTEGER) RETURNS REAL


returns a real number in the range 0 to x (not inclusive of x)
Example: RAND(87) could return 35.43

MOD(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the remainder when ThisNum is divided by ThisDiv
Example: MOD(10,3) returns 1

DIV(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the whole number part of the result when ThisNum is divided
by ThisDiv
Example: DIV(10,3) returns 3

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.
Example: If x has the value 87.5 then NUM_TO_STRING(x) returns "87.5"
Note: This function will also work if x is of type INTEGER

STRING_TO_NUM(x : STRING) RETURNS REAL


returns a numeric representation of a string.
Example: If x has the value "23.45" then STRING_TO_NUM(x) returns 23.45
Note: This function will also work if x is of type CHAR

Operators (pseudocode)
Operator Description

& Concatenates (joins) two strings


Example: "Summer" & " " & "Pudding" produces "Summer Pudding"

AND Performs a logical AND on two Boolean values


Example: TRUE AND FALSE produces FALSE

OR Performs a logical OR on two Boolean values


Example: TRUE OR FALSE produces TRUE

© UCLES 2020 9608/22/M/J/20


Cambridge International AS & A Level
* 1 7 5 3 4 1 4 9 7 5 *

COMPUTER SCIENCE 9608/23


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2020

2 hours

You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
● Answer all questions.
● Use a black or dark blue pen.
● Write your name, centre number and candidate number in the boxes at the top of the page.
● Write your answer to each question in the space provided.
● Do not use an erasable pen or correction fluid.
● Do not write on any bar codes.
● You may use an HB pencil for any diagrams, graphs or rough working.
● Calculators must not be used in this paper.

INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].
● No marks will be awarded for using brand names of software packages or hardware.

This document has 20 pages. Blank pages are indicated.

DC (RW/TP) 180778/4
© UCLES 2020 [Turn over
3

1 (a) Algorithms are produced during program development.

State when you would produce an algorithm during program development and state its
purpose.

When ........................................................................................................................................

...................................................................................................................................................

Purpose ....................................................................................................................................

...................................................................................................................................................
[2]

(b) Selection is one of the basic constructs used in algorithms.

Explain the term selection.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

(c) Explain the process of problem decomposition. State one reason it may be used.

Explanation ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Reason .....................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[2]

(d) Name two features provided by a typical Integrated Development Environment (IDE) that
assist in the debugging stage of the program development cycle.

1 ................................................................................................................................................

2 ................................................................................................................................................
[2]

© UCLES 2020 9608/23/M/J/20 [Turn over


4

2 (a) A structure chart is often produced as part of a modular program design. The chart shows the
relationship between modules and the parameters that are passed between them.

Give two other features the structure chart can show.

Feature 1 ..................................................................................................................................

...................................................................................................................................................

Feature 2 ..................................................................................................................................

...................................................................................................................................................
[2]

(b) The following structure chart shows the relationship between three modules.

ModuleA()

ParW
ParX

ParZ

ModuleB() ModuleC()

Parameter data types are:

ParW : REAL
ParX : INTEGER
ParZ : STRING

(i) Write the pseudocode header for module ModuleB().

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

(ii) Write the pseudocode header for module ModuleC().

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

© UCLES 2020 9608/23/M/J/20


5

(c) A student is developing an algorithm to count the number of times a given string,
SearchString, appears in a 2D array. The array, Item, consists of 100 elements organised
as 50 rows of 2 columns. SearchString could appear in any row or column.

The array is declared in pseudocode as follows:

DECLARE Item : ARRAY [1:50, 1:2] OF STRING

The structured English description of the algorithm is:

1. SET Count to 0.
2. Examine the first row of the array.
3. IF column 1 element value is equal to SearchString, ADD 1 to Count.
4. IF column 2 element value is equal to SearchString, ADD 1 to Count.
5. REPEAT from step 3 for next row, UNTIL row is last row.
6. OUTPUT a suitable message and Count.

Write pseudocode for the algorithm.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

© UCLES 2020 9608/23/M/J/20 [Turn over


7

3 (a) Study the following pseudocode.

Error Delta(Plan, Actual)


CASE OF Error
> 10 : Steer Steer − 10
0 : ZCount ZCount + 1
< -10 : Steer Steer + 10
OTHERWISE OUTPUT "Unexpected Error"
ENDCASE

Draw a program flowchart to represent the pseudocode. Variable declarations are not
required in program flowcharts.

[5]
© UCLES 2020 9608/23/M/J/20 [Turn over
8

(b) The following pseudocode algorithm has been developed to check whether a string contains
a valid password.

To be a valid password, a string must:

• be longer than five characters


• contain at least one numeric digit
• contain at least one upper case letter
• contain at least one other character (not a numeric digit or an upper case letter).

10 FUNCTION Check(InString : STRING) RETURNS BOOLEAN


11
12 DECLARE Index : INTEGER
13 DECLARE StrLen : INTEGER
14 DECLARE NumUpper, NumDigit : INTEGER
15 DECLARE NextChar : CHAR
16 DECLARE NumOther : INTEGER
17
18 NumUpper 0
19 NumDigit 0
20
21 StrLen LENGTH(InString)
22 IF StrLen < 6
23 THEN
24 RETURN FALSE
25 ELSE
26 FOR Index 1 TO StrLen - 1
27 // loop for each character
28 NextChar MID(InString, Index, 1)
29 IF NextChar >= '0' AND NextChar <= '9'
30 THEN
31 NumDigit NumDigit + 1 // count digits
32 ELSE
33 IF NextChar >= 'A' AND NextChar <= 'Z'
34 THEN
35 NumUpper NumUpper + 1 // count upper case
36 ENDIF
37 ENDIF
38 ENDFOR
39 ENDIF
40
41 NumOther StrLen – (NumDigit – NumUpper)
42 IF NumDigit >= 1 AND NumUpper >= 1 AND NumOther >= 1
43 THEN
44 RETURN TRUE
45 ELSE
46 RETURN FALSE
47 ENDIF
48
49 ENDFUNCTION

© UCLES 2020 9608/23/M/J/20


9

The pseudocode does not work under all circumstances.

The function was dry run with the string "1234AP" and the following trace table was
produced. The string is an invalid password, but the pseudocode returned the value
TRUE.

Trace
StrLen Index NextChar NumUpper NumDigit NumOther
table row
1 6 0 0
2 1 '1'
3 1
4 2 '2'
5 2
6 3 '3'
7 3
8 4 '4'
9 4
10 5 'A'
11 1
12 3

(i) The pseudocode algorithm contains two errors.

State how the given trace table indicates the existence of each error.

Error 1 ...............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

Error 2 ...............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[2]

© UCLES 2020 9608/23/M/J/20 [Turn over


10

(ii) Give the line number of each error in the pseudocode algorithm and write the modified
pseudocode to correct each error.

Line number for error 1 .....................................................................................................

Correct pseudocode ..........................................................................................................

...........................................................................................................................................

Line number for error 2 .....................................................................................................

Correct pseudocode ..........................................................................................................

...........................................................................................................................................
[2]

(c) The term adaptive maintenance refers to amendments that are made in response to
changes to the program specification. These changes usually affect the program algorithm.

Name one other part of the design that can change as a result of adaptive maintenance.

............................................................................................................................................. [1]

4 A global 1D array, Contact, of type STRING is used to store a list of names and email addresses.
There are 1000 elements in the array. Each element stores one data item. The format of each
data item is as follows:

<Name>':'<EmailAddress>

Name and EmailAddress are both variable-length strings.

For example:

"Wan Zhu:[email protected]"

A function, Extract(), is part of the program that processes the array. A string data item is
passed to the function as a parameter. The function will return the Name part. Validation is not
necessary.

© UCLES 2020 9608/23/M/J/20


11

(a) Write program code for the function Extract().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

© UCLES 2020 9608/23/M/J/20 [Turn over


12

(b) The original function, Extract(), needs to be modified to separate the name from the email
address. The calling program can then use both of these values.

Write, in pseudocode, the header for the modified subroutine. Explain the changes you have
made.

Subroutine header ....................................................................................................................

...................................................................................................................................................

Explanation ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

5 A company hires out rowing boats on a lake. The company has 20 boats, numbered from 1 to 20.

For safety reasons, the boats have to be serviced (checked and any damage repaired) regularly.

The company is developing a program to help manage the servicing of the boats.

Every time a boat is serviced, details are added at the end of the text file, ServiceLog.txt, as a
single line of information. Each boat is serviced before it is hired out for the first time.

The format of each line is as follows:

<BoatNumber><Date>

BoatNumber and Date are as follows:

• BoatNumber is a two-digit numeric string in the range "01" to "20"


• Date is an 8-digit numeric string in the format YYYYMMDD

The programmer has defined the first module as follows:

Module Description
• Called with a string parameter representing the BoatNumber
GetLastService() • Searches through the file ServiceLog.txt
• Returns the date of the last service in the form "YYYYMMDD"

© UCLES 2020 9608/23/M/J/20


13

(a) Write pseudocode for the module GetLastService().

Refer to the Appendix on page 19 for a list of built-in pseudocode functions and operators.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2020 9608/23/M/J/20 [Turn over


14

(b) (i) Every time a boat is hired out, details of the hire are added at the end of a text file,
Hirelog.txt. Each line of the text file corresponds to information about the hire of one
boat.

The format of each line of information is as follows:

<Date><BoatNumber><HireDuration>

• Date is an 8-digit numeric string in the format YYYYMMDD


• BoatNumber is a two-digit numeric string in the range "01" to "20"
• HireDuration is a variable-length string representing a numeric value in hours.
For example, the string "1.5" would represent a hire duration of 1½ hours.

A module GetHours() is defined as follows:

Module Description
• Takes two parameters:
the BoatNumber as a string
the date of the last service for that boat ("YYYYMMDD")
as a string
GetHours()
• Searches through file Hirelog.txt and calculates the sum of
the hire durations for the given boat after the given date (hire
durations on or before the given date are ignored)

• Returns the total of the hire durations as a real

Note:

Standard comparison operators may be used with dates in this format.


For example:

"20200813" > "20200812" would evaluate to TRUE

Parameter validation is not required.

© UCLES 2020 9608/23/M/J/20


15

Write pseudocode for the module GetHours().

Refer to the Appendix on page 19 for a list of built-in pseudocode functions and
operators.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [8]

© UCLES 2020 9608/23/M/J/20 [Turn over


16

(ii) An additional module, Validate(), has been written to check that a given string
corresponds to a valid BoatNumber. A valid BoatNumber is a two-digit numeric string in
the range "01" to "20".

Give three test strings that are invalid for different reasons. Explain your choice in each
case.

String 1 ..............................................................................................................................

Reason ..............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

String 2 ..............................................................................................................................

Reason ..............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

String 3 ..............................................................................................................................

Reason ..............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[6]

(c) A new module is described as follows:

Module Description
• Takes an integer as a parameter that represents the maximum
number of hours before a boat must be serviced

• Uses GetLastService() and GetHours()

• Outputs:
a suitable heading
the BoatNumber of each boat hired for more than the
maximum number of hours since its last service
ServiceList() the total hire duration for each of these boats

An example output list is:


Boat Service List
4: 123
17: 117

If no boats are due to be serviced, the output is:


Boat Service List
No boats are due to be serviced

© UCLES 2020 9608/23/M/J/20


17

Write program code for the module ServiceList().

Python: You should show a comment statement for each variable used with its data type.
Visual Basic and Pascal: You should include the declaration statements for variables.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]
© UCLES 2020 9608/23/M/J/20 [Turn over
18

(d) (i) A team of programmers will work on the program. Before they begin, the team meet to
discuss ways in which the risk of program faults may be reduced during the design and
coding stages.

State two ways to minimise program faults during the design and coding stages.

1 ........................................................................................................................................

...........................................................................................................................................

2 ........................................................................................................................................

...........................................................................................................................................
[2]

(ii) During development, the team test the program using a process known as stub testing.

Explain this process.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(iii) Explain how single stepping may be used to help find a logic error in a program.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2020 9608/23/M/J/20


19

Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString

Example: LEFT("ABCDEFGH", 3) returns "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString

Example: RIGHT("ABCDEFGH", 3) returns "FGH"

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString

Example: MID("ABCDEFGH", 2, 3) returns "BCD"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: INT(27.5415) returns 27

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.
Note: This function will also work if x is of type INTEGER

Example: NUM_TO_STRING(87.5) returns "87.5"

STRING_TO_NUM(x : STRING) RETURNS REAL


returns a numeric representation of a string.
Note: This function will also work if x is of type CHAR

Example: STRING_TO_NUM("23.45") returns 23.45

Operators (pseudocode)

Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE

© UCLES 2020 9608/23/M/J/20


Cambridge International AS & A Level
* 6 3 4 1 3 6 2 7 4 2 *

COMPUTER SCIENCE 9608/21


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2020

2 hours

You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
● Answer all questions.
● Use a black or dark blue pen.
● Write your name, centre number and candidate number in the boxes at the top of the page.
● Write your answer to each question in the space provided.
● Do not use an erasable pen or correction fluid.
● Do not write on any bar codes.
● You may use an HB pencil for any diagrams, graphs or rough working.
● Calculators must not be used in this paper.

INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].
● No marks will be awarded for using brand names of software packages or hardware.

This document has 20 pages. Blank pages are indicated.

DC (LK) 188573/3
© UCLES 2020 [Turn over
2

1 (a) Translation is one stage of the program development cycle.

State three other stages.

1 ................................................................................................................................................

2 ................................................................................................................................................

3 ................................................................................................................................................
[3]

(b) Define the following types of maintenance.

Corrective maintenance ............................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Adaptive maintenance ..............................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[2]

(c) Experienced programmers have a transferable skill.

Explain how this skill might be useful for a programmer.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

(d) Jackie has written a program and has used the identifier names I1, I2, and I3.

Explain why this is not good practice.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2020 9608/21/O/N/20


3

(e) A pseudocode algorithm assigns values to three variables as follows:

GateOpen FALSE
Alarm TRUE
PowerFail TRUE

Evaluate the expressions given in the following table:

Expression Evaluates to

Alarm OR NOT PowerFail

NOT (Alarm AND PowerFail)

(GateOpen OR Alarm) AND PowerFail

(GateOpen AND Alarm) OR NOT PowerFail


[2]

© UCLES 2020 9608/21/O/N/20 [Turn over


4

2 (a) User names are stored in a text file. Each line of the file represents one name. Before a new
user name can be issued, a check has to be made to ensure that the new name is unique.

Use structured English to describe an algorithm that would prompt and input a new user
name and output a message to indicate whether or not it is unique.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

(b) Complete the pseudocode expressions in the following table.

Use only the functions and operators described in the Appendix on pages 18–19.

Expression Evaluates to

........................ ("Stepwise" , ........................) & "art" "Start"

........................ ("Concatenate" , ........................ , ........................) "ten"

2 * .......................... ("Kipper") 12

TRUE .......................... FALSE TRUE

.......................... (9, 2) 1

[5]
© UCLES 2020 9608/21/O/N/20
5

(c) Study the following pseudocode.

Line numbers are given for reference only.

01 PROCEDURE StringClean(InString : STRING)


02
03 DECLARE NextChar : CHAR
04 DECLARE OutString : STRING
05 DECLARE Index : INTEGER
06
07 OutString ""
08
09 FOR Index 1 TO LENGTH(InString)
10
11 NextChar MID(InString, Index, 1)
12 NextChar LCASE(NextChar)
13
14 IF NextChar >= 'a' AND NextChar <= 'z'
15 THEN
16 OutString OutString & NextChar
17 ENDIF
18
19 ENDFOR
20
21 OUTPUT OutString
22
23 ENDPROCEDURE

Complete the following table by entering an appropriate answer.

Answer

The name for the type of loop used

A line number of a selection statement

The scope of OutString

The name of a function that is called

A line number containing a logical operator


[5]

© UCLES 2020 9608/21/O/N/20 [Turn over


6

3 The procedure OutputLines() outputs a number of lines from a text file.

An example of the use of the procedure is given by the following pseudocode:

CALL OutputLines(FileName, StartLine, NumberLines)

Parameter Data type Description

FileName STRING The name of the text file

StartLine INTEGER The number of the first line to be output

NumberLines INTEGER The number of lines to be output

The procedure is tested using the file MyFile.txt that contains 100 lines of text.

The procedure gives the expected result when called as follows:

CALL OutputLines("MyFile.txt", 1, 10)

(a) The procedure is correctly called with three parameters of the appropriate data types, but the
procedure does not give the expected result.

Give three different reasons why this might happen.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................

3 ................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2020 9608/21/O/N/20


7

(b) Write program code for the procedure OutputLines().

Note: Parameter validation is not necessary.

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language .............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]
© UCLES 2020 9608/21/O/N/20 [Turn over
8

(c) A program is compiled without producing any errors.

(i) Describe one type of error that the program could still contain.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(ii) Give two techniques that may be used to identify an error of the type given in part (c)(i).

Technique 1 .......................................................................................................................

...........................................................................................................................................

Technique 2 .......................................................................................................................

...........................................................................................................................................
[2]

(d) State two reasons why the use of library subroutines can be a benefit in program development.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2020 9608/21/O/N/20


10

4 A function, FormOut(), takes an integer parameter in the range 0 to 999 999 and returns a
formatted string depending on two other parameter values.

Formatting may incorporate the use of:

• A prefix string to be added before the integer value (e.g. '$' or "Total: ")
• A comma as a thousand-separator (e.g. "1,000")

The function will be called as follows:

MyString FormOut(Number, Prefix, AddComma)

Parameter Data type Description

Number INTEGER The positive integer value to be formatted.


A string that will appear in front of the numeric value. Set to an
Prefix STRING
empty string if no prefix is required.
TRUE if a comma is required in the formatted string.
AddComma BOOLEAN
FALSE if a comma is not required in the formatted string.

(a) Fill in the tables to show two tests that could be carried out to test different aspects of the
function.

Give the expected result for each test.

TEST 1
Parameter Value
Expected return string:
Number

Prefix ...............................................................

AddComma

TEST 2
Parameter Value
Expected return string:
Number
Prefix ...............................................................
AddComma
[4]

© UCLES 2020 9608/21/O/N/20


11

(b) Write pseudocode for the function FormOut().

Refer to the Appendix on pages 18–19 for the list of built-in functions and operators.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2020 9608/21/O/N/20 [Turn over


12

5 A message may contain several hashtags.

A hashtag is a string consisting of a hash character ‘#’, followed by one or more alphanumeric
characters.

A hashtag may be terminated by a space character, the start of the next hashtag, any other
non-alphanumeric character, or by the end of the message.

For example, the following message contains three hashtags:

"#Error27 is the result of #PoorPlanning by the #Designer"

The hashtags in the message are "#Error27", "#PoorPlanning" and "#Designer".

A program is being developed to process a message and extract each hashtag.

A global 1D array of strings, TagString, will store each hashtag in a single element.
Unused array elements will contain an empty string. The array will contain 10 000 elements.

A developer has started to define the modules as follows:

Module Description
• Called with two parameters:
• a message string
• an integer giving the number of the required hashtag.
GetStart() For example, GetStart(Message, 3) would search
for the third hashtag in the string Message
• Returns an integer value representing the start position
of the hashtag in the message string, or value −1 if that
hashtag does not exist
• Called with two parameters:
• a message string
GetTag() • an integer giving the hashtag start position within the
message
• Returns the hashtag or an empty string if the character in
the message at the hashtag start position is not '#'
• Called with a hashtag as a parameter
• Returns the index position of the hashtag in array
GetIndex() TagString
• Returns the value −1 if the hashtag is not present in the
array

© UCLES 2020 9608/21/O/N/20


13

(a) Write pseudocode for the module GetIndex().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2020 9608/21/O/N/20 [Turn over


14

(b) Write pseudocode for the module GetStart().

The module description is repeated here for reference.

Module Description
• Called with two parameters:
• a message string
• an integer giving the number of the required hashtag. For
example, GetStart(Message, 3) would search for the
GetStart()
third hashtag in the string Message
• Returns an integer value representing the start position of the
hashtag in the message string, or value −1 if that hashtag does
not exist

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]
© UCLES 2020 9608/21/O/N/20
16

(c) Write program code for the module GetTag().

The module description is repeated here for reference.

Module Description
• Called with two parameters:
• a message string
• an integer giving the hashtag start position within the
GetTag()
message
• Returns the hashtag or an empty string if the character in the
message at the hashtag start position is not '#'

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2020 9608/21/O/N/20


17

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2020 9608/21/O/N/20 [Turn over


18

Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of string ThisString

Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString

Example: LEFT("ABCDEFGH", 3) returns string "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString

Example: RIGHT("ABCDEFGH", 3) returns string "FGH"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: INT(27.5415) returns 27

MOD(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the remainder when ThisNum is divided by ThisDiv

Example: MOD(10,3) returns 1

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString

Example: MID("ABCDEFGH", 2, 3) returns string "BCD"

LCASE(ThisChar : CHAR) RETURNS CHAR


returns the character value representing the lower case equivalent of ThisChar
If ThisChar is not an upper-case alphabetic character, it is returned unchanged.

Example: LCASE('W') returns 'w'

DIV(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the whole number part of the result when ThisNum is divided
by ThisDiv

Example: DIV(10,3) returns 3

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.
Note: This function will also work if x is of type INTEGER

Example: NUM_TO_STRING(87.5) returns "87.5"

© UCLES 2020 9608/21/O/N/20


19

Operators (pseudocode)

Operator Description

Concatenates (joins) two strings


&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"

Performs a logical AND on two Boolean values


AND
Example: TRUE AND FALSE produces FALSE

Performs a logical OR on two Boolean values


OR
Example: TRUE OR FALSE produces TRUE

© UCLES 2020 9608/21/O/N/20


Cambridge International AS & A Level
* 7 1 8 7 0 7 4 0 4 6 *

COMPUTER SCIENCE 9608/22


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2020

2 hours

You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
● Answer all questions.
● Use a black or dark blue pen.
● Write your name, centre number and candidate number in the boxes at the top of the page.
● Write your answer to each question in the space provided.
● Do not use an erasable pen or correction fluid.
● Do not write on any bar codes.
● You may use an HB pencil for any diagrams, graphs or rough working.
● Calculators must not be used in this paper.

INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].
● No marks will be awarded for using brand names of software packages or hardware.

This document has 20 pages. Blank pages are indicated.

DC (CJ) 188580/2
© UCLES 2020 [Turn over
2

1 (a) Algorithms usually consist of three different stages.

One stage is INPUT.

Name the other stages.

1 ................................................................................................................................................

2 ................................................................................................................................................
[1]

(b) An algorithm may be documented using different methods. These include structured English,
a program flowchart, and pseudocode.

State what a program designer represents using one or more of these methods.

...................................................................................................................................................

............................................................................................................................................. [2]

(c) Programming languages support different data types.

Complete the table by giving four different data types together with an example data value
for each.

Data type Example data value

[4]

© UCLES 2020 9608/22/O/N/20


3

(d) Draw lines to connect each of the following computing terms with the appropriate description.

Term Description

A structure for the


Black-box testing
temporary storage of data

A method used when the


File structure of the program is
unknown

A method of setting the


Assignment
value of a variable

A structure for the


Array
permanent storage of data

[3]

(e) A pseudocode algorithm assigns values to three variables as follows:

FlagA TRUE
FlagB FALSE
FlagC TRUE

Evaluate the expressions given in the following table:

Expression Evaluates to

NOT FlagB AND FlagC

NOT (FlagB OR FlagC)

(FlagA AND FlagB) OR FlagC

NOT (FlagA AND FlagB) OR NOT FlagC

[2]

© UCLES 2020 9608/22/O/N/20 [Turn over


4

2 (a) The following pseudocode is an attempt to define an algorithm that takes two numbers as
input and outputs the larger of the two numbers.

DECLARE A, B : INTEGER
INPUT A
INPUT B
IF A > B
THEN
OUTPUT A
ELSE
OUTPUT B
ENDIF

The algorithm needs to be amended to include the following changes:

1. Input three values, ensuring that each value input is unique.


2. Output the average.
3. Output the largest value.

Write the pseudocode for the amended algorithm.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2020 9608/22/O/N/20
5

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

(b) Complete the pseudocode expressions in the following table.

Use only functions and operators described in the Appendix on pages 18–19.

Expression Evaluates to

"ALARM: " & ...................... ("Time: 1202" , ......................) "ALARM: 1202"

...................... ("Stepwise." , ...................... , ......................) "wise"

1.5 * .......................... ("OnePointFive") 18

...................................... (27.5) "27.5"

.......................... (9, 4) 2
[5]

(c) A problem may be decomposed into sub-tasks when designing an algorithm.

Give three benefits of using sub-tasks.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................

3 ................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2020 9608/22/O/N/20 [Turn over


6

3 A car has the ability to detect a skid by monitoring the rate of rotation (the rotational speed) of
each wheel. If the rate of rotation of any wheel is not within 10% of the average of all four wheels,
the car skids.

A function, CheckSkid(), is being developed.

The function will:

• simulate real-time data acquisition, by prompting for the input of four integer values in the
range 0 to 1000 inclusive, representing the rate of rotation of each wheel
• calculate the average value
• check whether any individual value is more than 10% greater than the average or more than
10% less than the average
• return TRUE if any individual value is more than 10% greater than the average or more than
10% less than the average and FALSE otherwise
• output a suitable warning message.

(a) Write program code for the function CheckSkid().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2020 9608/22/O/N/20


7

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

(b) Give two sets of test data that could be used to test the function.

Test 1 – No skid detected

Value1 Value2 Value3 Value4

Test 2 – Skid detected

Value1 Value2 Value3 Value4

[2]

© UCLES 2020 9608/22/O/N/20 [Turn over


8

4 (a) The following structured English describes an algorithm used to count the number of odd and
even digits in an input sequence.

1. Initialise variables OddCount and EvenCount to zero.


2. Prompt and input an integer.
3. If the integer is not in the range 0 to 9 then go to step 7.
4. If the integer is an even number then add 1 to EvenCount.
5. Otherwise add 1 to OddCount.
6. Repeat from step 2.
7. Output "Same" if there are the same number of odd and even integers.
8. Output "Odd" if there are more odd than even integers.
9. Output "Even" if there are more even than odd integers.

Draw a flowchart on the following page to represent the algorithm.

© UCLES 2020 9608/22/O/N/20


10

(b) The following pseudocode is an attempt to check whether two equal-length strings consist of
identical characters.

Refer to the Appendix on pages 18–19 for the list of built-in functions and operators.

FUNCTION Compare(String1, String2 : STRING) RETURNS BOOLEAN


DECLARE x, y, Len1, Len2 : INTEGER
DECLARE RetFlag : BOOLEAN
DECLARE NextChar : CHAR
DECLARE New : STRING

Len1 LENGTH(String1)
RetFlag TRUE

FOR x 1 TO Len1 // for each char in String1


Len2 LENGTH(String2)
NextChar MID(String1, x, 1) // get NextChar from String1
New ""
FOR y 1 TO Len2 // for each char in String2
IF NextChar <> MID(String2, y, 1) // no match
THEN
New New & MID(String2, y, 1) // save this char from String2
ENDIF
ENDFOR
String2 New // replace String2 with New
ENDFOR

IF LENGTH(String2) <> 0 // anything left in String2 ?


THEN
RetFlag FALSE
ENDIF

RETURN RetFlag

ENDFUNCTION

© UCLES 2020 9608/22/O/N/20


11

(i) Complete the trace table below by performing a dry run of the function when it is called
as follows:

Result Compare("SUB", "BUS")

The first row has been completed for you.

String1 String2 Len1 RetFlag x Len2 NextChar New y


"SUB" "BUS" 3 TRUE 1

[5]

(ii) State the value returned.

..................................................................................................................................... [1]

© UCLES 2020 9608/22/O/N/20 [Turn over


12

(iii) There is an error in the algorithm, which means that under certain circumstances, the
function will return an incorrect value.

Describe the problem. Give two test strings that would demonstrate it.

Problem .............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

Test String1 .......................................................................................................................

Test String2 .......................................................................................................................


[2]

(iv) Describe the modification that needs to be made to the algorithm to correct the error.

Do not use pseudocode or program code in your answer.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [1]

(v) State the name given to the type of testing that makes use of a trace table.

..................................................................................................................................... [1]

(vi) State two features found in a typical Integrated Development Environment (IDE) that
may be used for debugging a program.

1 ........................................................................................................................................

2 ........................................................................................................................................
[2]

© UCLES 2020 9608/22/O/N/20


14

5 A hashtag is used on a social media network. A hashtag is a string consisting of a hash character
‘#’ followed by one or more alphanumeric characters.

A program is being developed to monitor the use of hashtags.

The program will include two global arrays each containing 10 000 elements:

• A 1D array, TagString, of type STRING stores each hashtag in a single element. All unused
array elements contain an empty string ("").

• A 1D array, TagCount, of type INTEGER stores a count of the number of times each hashtag
is used. The count value at a given index relates to the element stored at the corresponding
index in the TagString array.

The contents of the two arrays will be stored in a text file Backup.txt. The format of each line of
the file is:

<Hashtag><','><Count>

For example:

"#ComputerScienceClass,978"

A developer has started to define the modules as follows:

Module Description
InitArrays() • Initialise the arrays
• The contents of the two arrays are stored in the text file Backup.txt
Existing file contents will be overwritten
SaveArrays() • Each hashtag and count are stored in one line of the file, as in the example
above
• Unused TagString elements are not added to the file
• Returns the total number of unused TagString elements

LoadArrays()
• Values from the text file Backup.txt are stored in the two arrays
• The number of elements stored is returned

(a) Write pseudocode for the module InitArrays().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]
© UCLES 2020 9608/22/O/N/20
15

(b) Write pseudocode for the module SaveArrays().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]
© UCLES 2020 9608/22/O/N/20 [Turn over
16

(c) Write program code for the module LoadArrays().

The module description is repeated here for reference.

Module Description
• Values from the text file Backup.txt are stored in the
LoadArrays() two arrays
• The number of elements stored is returned

You should assume:

• each line of the file contains a string of the correct format and no validation checks are
required
• there are no more than 10 000 lines in the file.

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2020 9608/22/O/N/20
17

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2020 9608/22/O/N/20 [Turn over


18

Appendix
Built-in functions (pseudocode)

Each function returns an error if the function call is not properly formed.

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of string ThisString

Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString

Example: LEFT("ABCDEFGH", 3) returns string "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString

Example: RIGHT("ABCDEFGH", 3) returns string "FGH"

MOD(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the remainder when ThisNum is divided by ThisDiv

Example: MOD(10,3) returns 1

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString

Example: MID("ABCDEFGH", 2, 3) returns string "BCD"

DIV(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the whole number part of the result when ThisNum is
divided by ThisDiv

Example: DIV(10,3) returns 3

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.
Note: This function will also work if x is of type INTEGER

Example: NUM_TO_STRING(87.5) returns "87.5"

STRING_TO_NUM(x : STRING) RETURNS REAL


returns a numeric representation of a string.
Note: This function will also work if x is of type CHAR

Example: STRING_TO_NUM("23.45") returns 23.45

© UCLES 2020 9608/22/O/N/20


19

Operators (pseudocode)

Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE

© UCLES 2020 9608/22/O/N/20


Cambridge International AS & A Level
* 5 4 7 9 1 0 0 9 4 4 *

COMPUTER SCIENCE 9608/23


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2020

2 hours

You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
● Answer all questions.
● Use a black or dark blue pen.
● Write your name, centre number and candidate number in the boxes at the top of the page.
● Write your answer to each question in the space provided.
● Do not use an erasable pen or correction fluid.
● Do not write on any bar codes.
● You may use an HB pencil for any diagrams, graphs or rough working.
● Calculators must not be used in this paper.

INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].
● No marks will be awarded for using brand names of software packages or hardware.

This document has 16 pages. Blank pages are indicated.

DC (JC/CT) 188579/4
© UCLES 2020 [Turn over
2

1 (a) A programmer uses the process of stepwise refinement to break down a problem.

Explain the purpose of stepwise refinement.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

(b) Programming languages support different data types. These usually include STRING and
REAL.

Complete the table by giving four other data types and an example data value for each.

Data type Example data value

[4]

(c) An experienced programmer is working on a program that is written in a language she is not
familiar with.

(i) State one feature of the program that she should be able to recognise.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) State the type of skill that would allow her to recognise this feature.

...........................................................................................................................................

..................................................................................................................................... [1]

(d) Give three methods that may be used to identify and locate errors in a program after it has
been written.

You may include one feature found in a typical Integrated Development Environment (IDE).

1 ................................................................................................................................................

2 ................................................................................................................................................

3 ................................................................................................................................................
[3]
© UCLES 2020 9608/23/O/N/20
3

2 (a) An algorithm is needed to input a list of numbers representing test marks for a class of
30 students.
The algorithm will output the number of students who have a mark greater than 75. It will also
output the average mark for the class.

Document the algorithm using structured English.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

(b) Each pseudocode statement in the following table contains an error.

State the error in each case.

Refer to the Appendix on page 16 for the list of built-in functions and operators.

Statement Error

Code LEFT(3, "Europe")

Hour MID("ALARM:12:02", 7, 6)

Size LENGTH(27.5)

Num INT(27 / (Count + 3)

Result "Conditional" AND "Loop"

[5]
© UCLES 2020 9608/23/O/N/20 [Turn over
4

(c) Part of a program flowchart is shown.

Set Index to 0

Set Status to FALSE

LOOP

Is YES
Status = TRUE
?

NO
NO Is Index > 100
?
Set Status to TopUp()
YES

SetLevel("Super")
Set Index to Index + 1

Write program code to implement the flowchart shown. Variable declarations are not
required.

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]
© UCLES 2020 9608/23/O/N/20
5

3 A global 1D array, ProdNum, of type INTEGER contains 5 000 elements and is used to store
product numbers.

A procedure is needed to sort ProdNum into ascending order using a bubble sort algorithm.

Write program code for the procedure BubbleSort().

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language ....................................................................................................................

Program code

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................
© UCLES 2020 9608/23/O/N/20 [Turn over
6

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [7]

4 (a) The following pseudocode includes a procedure that searches for a value in a 1D array and
outputs each position in the array where the value is found.

Refer to the Appendix on page 16 for the list of built-in functions and operators.

DECLARE NameList : ARRAY [1:100] OF STRING


DECLARE SearchString : STRING

PROCEDURE Search()
DECLARE Index : INTEGER

FOR Index 1 TO 100


IF NameList[Index] = SearchString
THEN
OUTPUT "Found at " & NUM_TO_STRING(Index)
ENDIF
ENDFOR
ENDPROCEDURE

The specification of module Search() changes. The pseudocode needs to be amended to


meet a new requirement.

The procedure needs to be implemented as a function, Search(), which will:

• take the search value as a parameter


• return an integer which is:

• either the index value where the search value is first found
• or –1 if the search value is not found.

© UCLES 2020 9608/23/O/N/20


7

Write the pseudocode for the function Search().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

(b) A change to the specification in part (a) required a modification of the algorithm.

Give the term used for this type of modification.

............................................................................................................................................. [1]

(c) A change to the specification is only one reason to modify an algorithm.

Give another reason for the modification of an algorithm.

............................................................................................................................................. [1]

© UCLES 2020 9608/23/O/N/20 [Turn over


8

(d) Consider the following pseudocode:

10 DECLARE VarA : INTEGER


11 VarA 20
12
13 CALL ProcA(VarA)
14 OUTPUT VarA // first value output
15
16 CALL ProcB(VarA)
17 OUTPUT VarA // second value output
18
19
20 PROCEDURE ProcA(BYVALUE ThisValue : INTEGER)
21 ThisValue ThisValue + 5
22 ENDPROCEDURE
23
24 PROCEDURE ProcB(BYREF ThisValue : INTEGER)
25 ThisValue ThisValue + 5
26 ENDPROCEDURE

Procedures ProcA() and ProcB() use two methods of passing parameters.

Complete the following table.

Output Explanation

.........................................................................................................
First
value
..................... .........................................................................................................
(line 14)
.........................................................................................................

.........................................................................................................
Second
value
..................... .........................................................................................................
(line 17)
.........................................................................................................
[4]

© UCLES 2020 9608/23/O/N/20


9

(e) The procedures ProcA and ProcB in part (d) are examples of program modules.

Give two advantages of using program modules in program design.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2020 9608/23/O/N/20 [Turn over


10

5 A hashtag is used on a social media network to make it easier to find messages with a specific
theme or content. A hashtag is a string consisting of a hash character ‘#’ followed by a number of
alphanumeric characters.

A message may contain several hashtag strings. A hashtag may be terminated by a space
character, the start of the next hashtag, or by the end of the message.

For example, the following message contains three hashtags:

"#Alarm34 is the result of #BatteryFailure in the #PowerModule"

The hashtags in this message are "#Alarm34", "#BatteryFailure" and "#PowerModule".

A program is being developed to monitor their use.

The program will include two global arrays each containing 10 000 elements:

• A 1D array, TagString, of type STRING storing each hashtag in a single element of the
array. All unused array elements contain an empty string ("").

• A 1D array, TagCount, of type INTEGER storing a count of the number of times each hashtag
is used. The count value in a given element relates to the hashtag value stored in the element
in the TagString array with the corresponding index value.

A developer has started to define the modules. Module GetStart() has already been written.

Module Description

• Called with two parameters:


• a message of type STRING
• an integer giving the number of the required hashtag;
for example, GetStart(Message, 3) would search
GetStart()
for the third hashtag in the string Message
• Returns an integer value representing the start position of
the hashtag in the message, or value −1 if that hashtag
does not exist
• Called with a hashtag of type STRING
• Copies the hashtag to the next free element of the
TagString array, and sets the corresponding element of
AddHashtag()
the TagCount array to 1
• Returns FALSE if there are no unused elements in the
TagString array, otherwise returns TRUE
• Called with a message of type STRING
CountHashtag()
• Searches the message for hashtags using GetStart()
• Returns a value representing the number of hashtags in the
message
• Called with a hashtag of type STRING
• Increments the value of the appropriate element in the
IncrementHashtag() TagCount array if the hashtag is found
• Returns TRUE if the hashtag is found, or FALSE if the
hashtag is not found

© UCLES 2020 9608/23/O/N/20


11

(a) Write pseudocode for the module AddHashtag().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2020 9608/23/O/N/20 [Turn over


12

(b) Write program code for the module CountHashtag().

The module description is repeated here for reference.

Module Description

• Called with a message of type STRING


CountHashtag()
• Searches the message for hashtags using GetStart()
• Returns a value representing the number of hashtags in the
message

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language .............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]
© UCLES 2020 9608/23/O/N/20
13

(c) Write program code for the module IncrementHashtag().

The module description is repeated here for reference.

Module Description

• Called with a hashtag of type STRING


• Increments the value of the appropriate element in the
IncrementHashtag() TagCount array if the hashtag is found
• Returns TRUE if the hashtag is found, or FALSE if the
hashtag is not found

Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.

Programming language .............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]
© UCLES 2020 9608/23/O/N/20 [Turn over
14

(d) A procedure, OutputMostPop(), is needed to output the most popular hashtag. The most
popular hashtag is the one with the highest count value stored in the TagCount array.

As a reminder, the program includes two global arrays each containing 10 000 elements:

• A 1D array, TagString, of type STRING storing each hashtag in a single element of the
array. All unused array elements contain an empty string ("").

• A 1D array, TagCount, of type INTEGER storing a count of the number of times each
hashtag is used. The count value in a given element relates to the hashtag value stored
in the element in the TagString array with the corresponding index value.

If the maximum count value occurs once, the procedure will output the corresponding hashtag
and the count value.

It is possible for more than one hashtag to have the same highest count value. In this case,
the procedure will output the maximum count value together with the number of hashtags
with this maximum count value.

In both cases, the procedure must also output a suitable message.

You can assume that the arrays contain data for at least one hashtag.

Write pseudocode for the OutputMostPop() procedure.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2020 9608/23/O/N/20
15

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................ . [8]

© UCLES 2020 9608/23/O/N/20 [Turn over


16

Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of string ThisString
Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString
Example: LEFT("ABCDEFGH", 3) returns string "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString
Example: RIGHT("ABCDEFGH", 3) returns string "FGH"

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString
Example: MID("ABCDEFGH", 2, 3) returns string "BCD"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x
Example: INT(27.5415) returns 27

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.
Note: This function will also work if x is of type INTEGER
Example: NUM_TO_STRING(87.5) returns "87.5"

Operators (pseudocode)
Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE

Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the
publisher will be pleased to make amends at the earliest possible opportunity.

To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.

Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of
Cambridge Local Examinations Syndicate (UCLES), which itself is a department of the University of Cambridge.

© UCLES 2020 9608/23/O/N/20


Specimen Paper Answers
Paper 2
Cambridge International AS & A Level
Computer Science 9618
For examination from 2021

Version 1
In order to help us develop the highest quality resources, we are undertaking a continuous programme
of review; not only to measure the success of our resources but also to highlight areas for
improvement and to identify new development needs.

We invite you to complete our survey by visiting the website below. Your comments on the quality and
relevance of our resources are very important to us.

www.surveymonkey.co.uk/r/GL6ZNJB

Would you like to become a Cambridge International consultant and help us develop
support materials?

Please follow the link below to register your interest.

www.cambridgeinternational.org/cambridge-for/teachers/teacherconsultants/

Copyright © UCLES July 2019


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 retains the copyright on all its publications. Registered Centres are permitted to copy material from
this booklet for their own internal use. However, we cannot give permission to Centres to photocopy any
material that is acknowledged to a third party, even for internal use within a Centre.
Contents
Introduction ........................................................................................................................................................ 4
Assessment overview ........................................................................................................................................ 5
Question 1 ......................................................................................................................................................... 6
Question 2 ....................................................................................................................................................... 11
Question 3 ....................................................................................................................................................... 13
Question 4 ....................................................................................................................................................... 15
Question 5 ....................................................................................................................................................... 17
Question 6 ....................................................................................................................................................... 20
Question 7 ....................................................................................................................................................... 25
Specimen Paper Answers

Introduction
The main aim of this booklet is to exemplify standards for those teaching Cambridge International AS & A
Level Computer Science 9618, Paper 2: Fundamental Problem-solving and Programming Skills, and to show
examples of very good answers. The questions are from the published Specimen Paper, which contains
seven questions, each consisting of several parts. There are no optional questions. The format of the
Specimen Paper consists of questions and related sub-questions. This may be taken as a guide to actual
examination question papers, although the actual number of questions and sub-questions may alter from
series to series.

In this booklet, we have provided answers for all questions in the Specimen Paper.

Each question is followed by an example of a high-grade answer with an examiner comment on


performance. Comments are given to indicate where and why marks were awarded, and how additional
marks could have been obtained. In this way, it is possible to understand what candidates have done to gain
their marks and how they could improve.

The mark schemes for the Specimen Papers are available to download from the School Support Hub at
www.cambridgeinternational.org/support

2021 Specimen Paper 2 Mark Scheme

Past exam resources and other teacher support materials are available on the School Support Hub
www.cambridgeinternational.org/support

4 Cambridge International AS & A Level Computer Science 9618 Paper 2


Specimen Paper Answers

Assessment overview

Paper 2 – Fundamental Problem-solving and Programming Skills


Written paper, 2 hours, 75 marks

Externally assessed

Paper 2 will assess sections 9 to 12 of the syllabus content.

Candidates will need to write answers in pseudocode.

Candidates answer all questions.

50% of the AS Level

25% of the A Level

Many questions require a solution to a problem, which will require the application of problem-solving and
programming skills. Due to the nature of the subject it is likely that there will be several different solutions.
In these cases the mark schemes will reflect the essential components of the solution rather than reference
one specific method.

When writing pseudocode answers, candidates should limit themselves to the list of functions and operators
that are provided in the insert. Whilst it may be tempting to make use of functions or methods that are
available in a certain programming language to provide an easy solution to a given problem, this could
disadvantage those candidates who have not studied that particular language. By using only the defined set
of functions and operators all candidates are given an equal opportunity to provide a correct answer.

Centres are referred to the published pseudocode guide for further information.

Assessment objectives
The assessment objectives (AOs) are:

AO2: Apply knowledge and understanding of the principles and concepts of computer science, including to
analyse problems in computational terms.

AO3: Design, program and evaluate computer systems to solve problems, making reasoned judgements
about these.

Cambridge International AS & A Level Computer Science 9618 Paper 2 5


Specimen Paper Answers

Question 1

Question 1 (a) (i)

Specimen Paper Response

Variable Data type


Today STRING
WeekNumber INTEGER
Revision CHAR
MaxWeight REAL
LastBatch BOOLEAN

Examiner comment:
The given values in the table in part (a) are interpreted as follows:

• "Tuesday" is a literal string enclosed by quotation marks and so is of data type STRING

• 37 is a numeric value without decimal places so is of data type INTEGER

• 'C' is a single character enclosed by quotation marks so is of data type CHAR

• 60.5 is a numeric value with decimal places so is of data type REAL

• TRUE indicates a Boolean value so the data type is BOOLEAN

Total mark awarded = 5 out of 5

6 Cambridge International AS & A Level Computer Science 9618 Paper 2


Specimen Paper Answers

Question 1 (a) (ii)

Specimen Paper Response


Expression Evaluates to
MID(Today, 3, 2) & Revision & "ape" "esCape"
INT(MaxWeight + 4.2) 64
LENGTH(MaxWeight) ERROR
MOD(WeekNumber, 12) 1
(Revision <= 'D') AND (NOT LastBatch) FALSE

Examiner comment:
The expressions are evaluated as follows:

Row 1
Variable Today contains the string "Tuesday". The MID() function extracts 2 characters from this string
starting from position 3 (i.e. characters 3 and 4) which gives the string "es". Variable Revision contains
the character 'C', so the expression simplifies to:

"es" & 'C' & "ape"

The & represents the concatenation operator, so this expression evaluates to the string "esCape"
Quotation marks must be used to indicate that the value represents a literal string and not an identifier name.
A common mistake is for these to be omitted.

Row 2
Variable MaxWeight has the value 60.5. Adding this to 4.2 gives 64.7. The INT() function returns the
INTEGER value of the parameter (in this case 64.7) , which is 64.

Row 3
The LENGTH function expects a parameter of type STRING. In this expression a variable of type REAL has
been used, hence the expression is invalid and ERROR should be written, as directed in the question.

Row 4
Variable WeekNumber contains the value 37. The MOD() function returns an INTEGER value representing
the remainder when one number is divided by another using integer arithmetic. In this case 37 divided by 12
gives a remainder of 1.

Cambridge International AS & A Level Computer Science 9618 Paper 2 7


Specimen Paper Answers

Row 5
Variable Revision contains the character 'C' which is less than character 'D' so the contents of the first
bracket evaluates to TRUE. Variable LastBatch contains the value TRUE so the contents of the second
bracket evaluates to FALSE. This gives the simplified expression:

TRUE AND FALSE

This in turn evaluates to FALSE.

Total mark awarded = 5 out of 5

Question 1 (b)

Specimen Paper Response


Item Statement Input Process Output

1 SomeChars ← "Hello World" 

2 OUTPUT RIGHT(SomeChars,5)  
3 READFILE MyFile, MyChars  
4 WRITEFILE MyFile, "Data is " & MyChars  

Examiner comment:
The table has been completed correctly, as follows:

Row 1
The assignment of the literal string value to the identifier is an example of a Process

Row 2
The statement involves generating a sub-string by extracting 5 characters from the identifier SomeChars
(the Process) and outputting the resulting sub-string (the Output)

Row 3
The statement reads a line from the file MyFile (the Input) and assigns the value to the identifier Mychars
(the Process).

Row 4
The statement writes a line to the file MyFile (the Output) after first forming a string by concatenating (the
Process) the literal string "Data is " and the value of identifier MyChars.

Total mark awarded = 4 out of 4

8 Cambridge International AS & A Level Computer Science 9618 Paper 2


Specimen Paper Answers

Question 1 (c)

Specimen Paper Response


MyCount ← 101
REPEAT
OUTPUT MyCount
MyCount ← MyCount + 2
UNTIL MyCount = 199

Examiner comment:
The question specifies a post-condition loop, which implies a REPEAT ... UNTIL construct. The loop
termination condition should be based on the final value required (200). Prior to the loop, the start value
should be assigned to a variable and this variable will be increased by two each time around the loop. Note
that the start value given in the question is not an odd number and so should not be output.

The answer above could be considered to be an "optimised" solution in the sense that the learner has taken
into account the fact that the start value given in the question is not an odd number and modified the initial
value accordingly. They have also realised that adding 2 to an odd number will give the next odd number.

A mistake has been made with the terminating condition, meaning that the final value output would be 197
rather than 199, losing one mark.

An alternative solution could be as follows:

MyCount ← 100
REPEAT
IF MOD(MyCount, 2) = 1 // Check for a remainder of 1 when divided by 2 i.e. an
odd number
THEN
OUTPUT MyCount
ENDIF
MyCount ← MyCount + 1
UNTIL MyCount = 200

Cambridge International AS & A Level Computer Science 9618 Paper 2 9


Specimen Paper Answers

Note that this alternative solution includes a correct terminating condition and would gain full marks.

Total mark awarded = 3 out of 4

10 Cambridge International AS & A Level Computer Science 9618 Paper 2


Specimen Paper Answers

Question 2

Question 2 (a) (i)

Specimen Paper Response


1 The names of the modules

2 The relationship between the modules

3 The parameters passed between the modules

Examiner comment:
The labelled rectangles represent three program modules. The lines from module Checkout to the other two
modules at the lower level indicate that these two are sub-modules that are called from within Checkout.
The labelled arrows indicate the parameters that are passed between modules; the shaded circle of
parameter C indicates a Boolean value.

The answer correctly identifies three items of information.

In this case, an alternative mark could have been obtained by reference to the module sequence. For
example by answering:

"Module sequence – Checkout calls Card payment and then Account payment"

Cambridge International AS & A Level Computer Science 9618 Paper 2 11


Specimen Paper Answers

It is important that candidates read questions carefully to be clear about the scope of the question being
asked. In this case the question refers to the diagram given and not structure charts in general.
Consequently, only features that are present in the given diagram will be awarded a mark. For example,
"iteration" and "selection" are features that may be included in a structure chart but they would not be
acceptable answers as the symbols for these are not included in the given diagram.

Total mark awarded = 3 out of 3

Question 2 (b)

Specimen Paper Response


FUNCTION CardPayment (Amount : REAL, Name : STRING) RETURNS BOOLEAN

Examiner comment:
The example values given for the Data Items indicate the required data types for the parameters. The
single-headed arrows used in the diagram for parameters A and B indicate that these parameters are
passed by value and not by reference. This is the default mechanism and does not need to be explicitly
stated in the function declaration, but use of the BYVALUE keyword would obviously be correct.

The names given to parameters A and B are not important although they must be present and unique and
given the example data items it is expected that they would be given appropriate identifier names. The
parameter order for A and B in the function header is not important.

Total mark awarded = 3 out of 3

12 Cambridge International AS & A Level Computer Science 9618 Paper 2


Specimen Paper Answers

Question 3

Question 3 (a)

Specimen Paper Response


MyVar = POP

The value 'E' is removed from the stack


The TopofStack pointer is then incremented to point to location 102

PUSH('Z')

The TopOfStack pointer is decremented to point to location 101


Value 'Z' is loaded into location 101

Cambridge International AS & A Level Computer Science 9618 Paper 2 13


Specimen Paper Answers

Examiner comment:
There are several different possible ways in which stack operations can function. For clarity, this question
states that the TopOfStack pointer points to the last value added to the stack, in this case the value E in
location 101. Locations 102 to 105 are shown to contain values whereas locations 100 and 99 are shown
as 'empty'. This should be sufficient to indicate to learners that the stack in this case will grow 'upwards'
through decreasing address locations. In this case a 'Push' operation would be pre-decrement operation but
this terminology is not something learners would be expected to be familiar with.

The answer given fully describes the two operations.

It is intended that the two operations described in the question be applied in sequence to the stack as
shown. If the answer given to the first part is incorrect, then whatever value had been assigned to the
TopOfStack would be carried forward when marking the second part of the question.

Total mark awarded = 4 out of 4

Question 3 (b)

Specimen Paper Response

The strings are different because one is the reverse of the other. e.g. "CAT" becomes
"TAC"

This is because a stack operates as a First-In-Last-Out (FILO) mechanism

Examiner comment:
The answer describes the difference between the two strings - that is the strings are in reverse order. In this
case the answer also includes an example, which in itself would be sufficient to gain the first mark.

The answer explains that the reason for this is that a stack operates as a FILO (or LIFO) mechanism.

Total mark awarded = 2 out of 2

14 Cambridge International AS & A Level Computer Science 9618 Paper 2


Specimen Paper Answers

Question 4

Question 4 (a)

Specimen Paper Response


Name of parameter Value
Explanation
passing method Output
A pointer to the variable is passed.
Call by reference 5 Original variable is changed when parameter
changed in MyProc.
A copy of the variable is passed.
Call by value 4 Original variable not changed when parameter
changed in Myproc.

Cambridge International AS & A Level Computer Science 9618 Paper 2 15


Specimen Paper Answers

Examiner comment:
In the first two columns the answer correctly names the two possible methods and gives the corresponding
value output in each case. The explanation section requires a more in-depth answer and here the answer
describes the mechanism in each case and also the effect this has on the parameter that is passed.

For each method, a mark is awarded for the name plus the corresponding value output, and two marks for
the explanation.

It is important that the explanation is sufficiently detailed and unambiguous. For example, the statement
"the value is not changed" would not be given a mark as it is not clear which value is being referred to.

Total mark awarded = 6 out of 6

Question 4 (b)

Specimen Paper Response


Procedures
Local variables

Examiner comment:
The answer correctly identifies two features that are contained in the example. In this case the word
'subroutine' would have been an acceptable alternative to 'procedure'.

Total mark awarded = 2 out of 2

16 Cambridge International AS & A Level Computer Science 9618 Paper 2


Specimen Paper Answers

Question 5

Question 5 (a)

Specimen Paper Response


TYPE Stock
DECLARE ProductCode : STRING
DECLARE Price : REAL
DECLARE NumberInStock : INTEGER
END

Examiner comment:
The answer requires the definition of a user-defined record type named StockItem that includes the three
fields as required. In the answer above, the data type for each field have been correctly inferred from the
typical values given, but the record type has been named "Stock", rather than "StockItem"

Total mark awarded = 2 out of 3

Question 5 (b)

Specimen Paper Response


DECLARE StockItem : ARRAY [1:1000] OF StockItem

Cambridge International AS & A Level Computer Science 9618 Paper 2 17


Specimen Paper Answers

Examiner comment:
The array declaration includes the array size and the data type, but the name of the array has been given as
'StockItem" rather than "Stock".

Total mark awarded = 2 out of 3

Question 5 (c)

Specimen Paper Response


Stock[20].Price ← 105.99
Stock[20].NumberInStock ← Stock[20].NumberInStock + 12

Examiner comment:
The answer correctly demonstrates how individual data items are accessed using the dot notation.

Total mark awarded = 2 out of 2

Question 5 (d)

18 Cambridge International AS & A Level Computer Science 9618 Paper 2


Specimen Paper Answers

Specimen Paper Response


DECLARE n : INTEGER
FOR n ← 1 to 1000
IF Stock[n].Price >= 100
THEN
OUTPUT "ProductCode: " & Stock[n].ProductCode & Number in Stock: &
Stock[n].NumberInStock
ENDIF
NEXT

Examiner comment:
The answer contains one error, but otherwise correctly implements the simple algorithm, the essential
elements of which are as follows:

• A loop to process all the elements in the array

• A conditional statement to check the price, correctly translating the phrase 'at least' into the
comparison '>='. Note that the expression '> 99' would not be valid in this case as the numbers are
not integer values. For example, information would be output for a stock item with a price of 99.5,
which is not what is required.

• An output statement that includes the required field values and is formatted as required in the
question, but the necessary quotation marks around the literal string "Number in Stock: " have been
omitted.

The answer provides simple 'in-line' pseudocode as the question does not ask for the solution to be provided
as either a procedure or a function.

Total mark awarded = 3 out of 4

Cambridge International AS & A Level Computer Science 9618 Paper 2 19


Specimen Paper Answers

Question 6

Question 6 (a)

Specimen Paper Response


FUNCTION ValidatePassword(Pass : STRING) RETURNS BOOLEAN
DECLARE LCaseChar, UCaseChar, NumChar, n : INTEGER
DECLARE NextChar : CHAR
DECLARE ReturnFlag : BOOLEAN
ReturnFlag ← TRUE
LCaseChar ← 0
UCaseChar ← 0
NumChar ← 0
n ←1

20 Cambridge International AS & A Level Computer Science 9618 Paper 2


Specimen Paper Answers

WHILE n < LENGTH(Pass) AND ReturnFlag = TRUE


NextChar ← MID(Pass, n, 1)
IF NextChar >= 'a' AND NextChar <= 'z’
THEN
LCaseChar ← LCaseChar + 1
ELSE
IF NextChar >= 'A' AND NextChar <= 'Z’
THEN
UCaseChar ← UCaseChar + 1
ELSE
IF NextChar >= '0' AND NextChar <= '9’
THEN
NumChar ← NumChar + 1
ELSE
ReturnFlag ← False //illegal character
ENDIF
ENDIF
n←n +1
NEXT

IF NOT (LCaseChar > 1 AND UCaseChar > 1 AND NumChar > 2 AND ReturnFlag)
THEN
ReturnFlag ← FALSE
ENDIF
OUTPUT ReturnFlag
ENDFUNCTION

Examiner comment:
There are many ways of solving this problem – the answer given represents a typical 'straightforward'
solution. There are opportunities for simplification and a solution based on a CASE construct may provide a
more elegant solution but neither of these is a requirement. A functionally correct solution will gain full
marks.

Following the function header and local variable declarations and initialisation, the solution breaks down into
two parts:

A loop is used. Within this loop each character of the given password string is extracted in turn. The
character is compared with the three ranges described by each of the first three rules in the question, and a
separate count is made in the number of characters in each range. If the character is not one of the three
types specified then it is an illegal character and a flag is set. In the answer above, the loop is terminated as
soon as an illegal character is encountered. This is not essential to the solution but would be expected from
a top-grade answer.

Following the loop, the four rules given are tested via an IF statement. This assigns a Boolean value to the
variable, which is then returned.

The answer contains three errors as follows:

• The loop does not check the final character of the string. The condition should be:
n <= LENGTH(Pass)

Cambridge International AS & A Level Computer Science 9618 Paper 2 21


Specimen Paper Answers

• There is a missing ENDIF. (The first IF clause is unterminated.)

• The boolean value is output rather than returned

The available mark scheme points are shown below. For this answer, marks have been awarded for the
points that have not been crossed through. (Note that the question is for a maximum of 9 marks, but there
are 10 possible mark points)

1. Correct Function heading (including parameter) and ending


2. Declaration and initialisation of local counter integer variables
3. Correct loop
4. Loop terminates if illegal character found
5. Picking up NextChar from Pass
6. Correct check and increment for lower case
7. Correct check and increment for upper case
8. Correct check and increment for numeric
9. Correct check for invalid character
10. Correct final format check and returning correct Boolean value

Total mark awarded = 7 out of 9

Question 6 (b) (i)

Specimen Paper Response


PASSword123

Examiner comment:
The answer satisfies the three rules as it contains:
• 4 uppercase alphabetic characters
• 4 lowercase alphabetic characters
• 3 numeric characters
• no non-alphanumeric characters.

Note: The question asks simply for the password, rather than for a STRING value, so double quotation
marks are not required. These would be ignored if present.

Total mark awarded = 1 out of 1

22 Cambridge International AS & A Level Computer Science 9618 Paper 2


Specimen Paper Answers

Question 6 (b) (ii)

Specimen Paper Response


Password: PASSw123
Reason: only one lower-case alphabetic characters – should be at least two

Password: Pword123
Reason: only one upper-case alphabetic characters – should be at least two

Password: PASSword12
Reason: only two numeric characters – should be at least three

Password: PASSw-123
Reason: contains a non-alphanumeric character

Cambridge International AS & A Level Computer Science 9618 Paper 2 23


Specimen Paper Answers

Examiner comment:
Each password should break a different rule, and each password should break only one rule. A password
that breaks more than one rule would be of limited use for test purposes.

A mark is given for each password together with a suitable explanation.

The final password is incorrect. Although it contains an illegal character it also contains an incorrect number
of lowercase alphabetic characters.

Total mark awarded = 3 out of 4

Question 6 (b) (iii)

Specimen Paper Response


White-box

Examiner comment:
The correct term has been given.

Total mark awarded = 1 out of 1

Question 6 (b) (iv)

Specimen Paper Response


Stub testing is the process of testing a function before it has been fully written.

Examiner comment:
The answer addresses the first of the required two points, which are that the function can be tested before it
is fully written.

For the second mark, the answer would need to say how this could be achieved. For example:

The function contents are replaced with simple code to return a fixed value or to
output a message.

Total mark awarded = 1 out of 2

24 Cambridge International AS & A Level Computer Science 9618 Paper 2


Specimen Paper Answers

Question 7

Question 7

Cambridge International AS & A Level Computer Science 9618 Paper 2 25


Specimen Paper Answers

Specimen Paper Response


PROCEDURE LogEvents()

DECLARE FileData : STRING


DECLARE ArrayIndex : INTEGER
OPENFILE "LoginFile.txt" FOR WRITE
FOR ArrayIndex ← 1 TO 500
IF LogArray[ArrayIndex] <> ""
THEN
FileData ← LogArray[ArrayIndex]
WRITEFILE "LoginFile.txt", FileData
ENDIF
NEXT

CLOSEFILE "LoginFile.txt"

ENDPROCEDURE

Examiner comment:
The scenario description is straightforward and although different solutions may include minor variations, all
will require the following features:
• The pseudocode will be contained within a procedure named LogEvents, which has a header and
an end statement
• A loop is required to search through the array. A loop variable (ArrayIndex above), of type
INTEGER is necessary as this will be used to index individual element values within the array
• The file must be opened in APPEND mode in order to add data to the end of the existing file
• Within the loop, each array element needs to be checked to check whether it contains the string
"Empty"
• If an array element does not contain the value "Empty" then the value is written to the file
• After the loop ends, loop the file is closed

The answer contains two errors as follows:

• The file is opened in the wrong mode

• The check for an unused elements uses an empty string rather than te value "Empty"

The available mark scheme points are shown below. For this answer, marks have been awarded for the
points that have not been crossed through.

1. Procedure heading and ending


2. Declare ArrayIndex as integer
3. Open file LoginFile for append

26 Cambridge International AS & A Level Computer Science 9618 Paper 2


Specimen Paper Answers

4. Correct loop
5. Extract data from array in a loop
6. Check for unused element in a loop
7. Write data to file in a loop
8. Close the file outside the loop

Total mark awarded = 6 out of 8

Cambridge International AS & A Level Computer Science 9618 Paper 2 27


Cambridge International AS & A Level
*0123456789*

COMPUTER SCIENCE 9618/02


Paper 2 Fundamental Problem-solving and Programming Skills For examination from 2021
SPECIMEN PAPER 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 14 pages. Blank pages are indicated.

© UCLES 2018 [Turn over


2

1 (a) Program variables have values as follows:

Variable Value
Today "Tuesday"
WeekNumber 37
Revision 'C'
MaxWeight 60.5
LastBatch TRUE

(i) Give an appropriate data type for each variable.

Variable Data type


Today
WeekNumber
Revision
MaxWeight
LastBatch
[5]

(ii) Evaluate each expression in the following table.


If an expression is invalid then write ERROR.

Refer to the Insert for the list of pseudocode functions and operators.

Expression Evaluates to
MID(Today, 3, 2) & Revision & "ape"
INT(MaxWeight + 4.2)
LENGTH(MaxWeight)
MOD(WeekNumber, 12)
(Revision <= 'D') AND (NOT LastBatch)
[5]

(b) Simple algorithms usually consist of input, process and output.

Complete the table to show if each statement is an example of input, process or output.
Place one or more ticks (9) for each statement.

Item Statement Input Process Output


1 SomeChars ← "Hello World"
2 OUTPUT RIGHT(SomeChars, 5)
3 READFILE MyFile, MyChars
4 WRITEFILE MyFile, "Data is " & MyChars

[4]
© UCLES 2018 9618/02/SP/21
3

(c) Write in pseudocode a post-condition loop to output all the odd numbers between 100 and
200.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

.............................................................................................................................................. [4]

© UCLES 2018 9618/02/SP/21 [Turn over


4

2 Roberta downloads music from an online music store. The diagram shows part of a structure chart
for the online music store program.

Checkout

A
B

Card payment Account payment

(a) State three items of information that the diagram shows about the design of the program.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................

3 ................................................................................................................................................

...................................................................................................................................................
[3]

(b) Examples of the data items that correspond to the arrows are given in the table.

Arrow Data item


A 234.56
B "Ms Roberta Smith"
C TRUE

Use pseudocode to write the function header for the Card payment module.

...................................................................................................................................................

.............................................................................................................................................. [3]

© UCLES 2018 9618/02/SP/21


5

3 A stack is created using a high-level language. The following diagram represents the current state
of the stack. The Top of Stack pointer points to the last item added to the stack.

Address Value Pointer

99
100
101 E ⇐ TopOfStack
102 D
103 C
104 B
105 A

(a) Two operations associated with this stack are PUSH() and POP().

Describe these operations with reference to the diagram.

MyVar = POP()

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

PUSH('Z')

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[4]

(b) Two programs use a stack to exchange data. Program AddString pushes a string of
characters onto the stack one character at a time. Program RemoveString pops the same
number of characters off the stack, one character at a time. The string taken off the stack is
different from the string put on the stack.

Explain why the strings are different.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

.............................................................................................................................................. [2]

© UCLES 2018 9618/02/SP/21 [Turn over


6

4 (a) Parameter x is used to pass data to procedure MyProc in the following pseudocode:

x ← 4
CALL MyProc(x)
OUTPUT x

PROCEDURE MyProc(x : INTEGER)


DECLARE z : INTEGER
x ← x + 1
z ← x + 3
ENDPROCEDURE

There are two parameter passing methods that could be used.

Complete the following table for each of the two methods.

Name of parameter Value Explanation


passing method output

......................................................................................
.................................
............ ......................................................................................
.................................
......................................................................................

......................................................................................
.................................
............ ......................................................................................
.................................
......................................................................................

[6]

(b) The pseudocode includes the use of parameters.

State two other features in the pseudocode that support a modular approach to programming.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2018 9618/02/SP/21


8

5 A company keeps details of its product items in a 1D array, Stock. The array consists of 1000
elements of type StockItem.

The record fields of StockItem are:

Field Typical value


ProductCode "BGR24-C"
Price 102.76
NumberInStock 15

(a) Write pseudocode to declare the record structure StockItem.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

.............................................................................................................................................. [3]

(b) Write pseudocode to declare the Stock array.

...................................................................................................................................................

.............................................................................................................................................. [3]

(c) Write pseudocode to modify the values to element 20 as follows:

• set the price to 105.99


• increase the number in stock by 12

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

.............................................................................................................................................. [2]

© UCLES 2018 9618/02/SP/21


9

(d) A stock report program is developed.

Write pseudocode to output the information for each stock item that has a price of at least
100.

Output the information as follows:

Product Code: BGR24-C Number in Stock: 15

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

.............................................................................................................................................. [4]

© UCLES 2018 9618/02/SP/21 [Turn over


10

6 Members of a family use the same laptop computer. Each family member has their own password.

To be valid, a password must comply with the following rules:

1 At least two lower-case alphabetic characters


2 At least two upper-case alphabetic characters
3 At least three numeric characters
4 Alpha-numeric characters only

A function, ValidatePassword, is needed to check that a given password follows these rules.
This function takes a string, Pass, as a parameter and returns a boolean value:

• TRUE if it is a valid password


• FALSE otherwise

(a) Write pseudocode to implement the function ValidatePassword.

Refer to the Insert for the list of pseudocode functions and operators.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2018 9618/02/SP/21
11

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

.............................................................................................................................................. [9]
© UCLES 2018 9618/02/SP/21 [Turn over
12

(b) The ValidatePassword function will be tested.

(i) Give a valid password that can be used to check that the function returns TRUE under
the correct conditions.

Password1: .................................................................................................................. [1]

(ii) Password1 is modified to test each rule separately. Give four modified passwords and
justify your choice.

Password to test rule 1: .....................................................................................................

Reason: .............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

Password to test rule 2: .....................................................................................................

Reason: .............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

Password to test rule 3: .....................................................................................................

Reason: .............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

Password to test rule 4: .....................................................................................................

Reason: .............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[4]

(iii) When testing the ValidatePassword function a module it is necessary to test all
possible paths through the code.

State the name given to this type of validation testing.

...................................................................................................................................... [1]

© UCLES 2018 9618/02/SP/21


13

(iv) A program consisting of several functions can be tested using a process known as ‘stub
testing’

Explain this process.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...................................................................................................................................... [2]

© UCLES 2018 9618/02/SP/21


14

7 LogArray is a 1D array containing 500 elements of type STRING.

A procedure, LogEvents, is required to add data from the array to the end of the existing text file
LoginFile.txt

Unused array elements are assigned the value "Empty". These can occur anywhere in the array
and should not be added to the file.

Write pseudocode for the procedure LogEvents.

Refer to the Insert for the list of pseudocode functions and operators.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..................................................................................................................................................... [8]

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.

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 2018 9618/02/SP/21


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
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


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


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
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


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
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
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


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


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
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


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
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


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


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
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


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
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


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


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


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


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


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


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


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


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


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
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


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


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


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


Cambridge International AS & A Level
* 1 2 8 1 9 6 8 3 4 2 *

COMPUTER SCIENCE 9618/21


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2023

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
● Answer all questions.
● Use a black or dark blue pen.
● Write your name, centre number and candidate number in the boxes at the top of the page.
● Write your answer to each question in the space provided.
● Do not use an erasable pen or correction fluid.
● Do not write on any bar codes.
● You may use an HB pencil for any diagrams, graphs or rough working.
● Calculators must not be used in this paper.

INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].
● No marks will be awarded for using brand names of software packages or hardware.
● The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (EF/SG) 338525/4
© UCLES 2023 [Turn over
2

Refer to the insert for the list of pseudocode functions and operators.

1 A programmer has written a program which includes the function Calculate().


When the program is run, the function returns an unexpected value.

(a) Describe how a typical Integrated Development Environment (IDE) could be used to help
debug the program to find the errors in the function Calculate().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [4]

(b) The algorithm for function Calculate() contains the three pseudocode statements shown.

Describe the error in each statement or write ‘no error’ if the statement contains no error.

Assume any variables used are of the correct type for the given function.

Statement 1: Index STR_TO_NUM(("27") + 2)

Error ..........................................................................................................................................

...................................................................................................................................................

Statement 2: Index STR_TO_NUM(MID("CPE1704TKS", 4, 2))

Error ..........................................................................................................................................

...................................................................................................................................................

Statement 3: IF MONTH(ThisDate) > '6' THEN

Error ..........................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2023 9618/21/M/J/23


3

(c) The program contains variables with values as follows:

Variable Value
Active TRUE
Points 75
Exempt FALSE

(i) Complete the table by evaluating each expression.

Expression Evaluation

1 (Points > 99) OR Active

2 (Points MOD 2 = 0) OR Exempt

3 (Points <= 75) AND (Active OR Exempt)

4 (Active OR NOT Active) AND NOT Exempt

[2]

(ii) Write expression 4 from the table in part (c)(i) in its simplest form.

..................................................................................................................................... [1]

© UCLES 2023 9618/21/M/J/23 [Turn over


4

2 A program contains an algorithm to output a string of a specified length containing identical


characters.

(a) The algorithm is described as follows:


1. prompt and input a character and store in MyChar
2. prompt and input an integer and store in MyCount
3. generate a string consisting of MyChar repeated MyCount times
4. output the string.

Draw a program flowchart to represent the algorithm.

START

END

[4]
© UCLES 2023 9618/21/M/J/23
5

(b) A different part of the program uses the variable StartDate.

Write pseudocode statements to declare StartDate and assign to it the date corresponding
to 15/11/2005.

Declaration ...............................................................................................................................

Assignment ...............................................................................................................................
[3]

© UCLES 2023 9618/21/M/J/23 [Turn over


6

3 Customers collect points every time they make a purchase at a store.

A program is used to manage the points system and the table lists some of the information stored
for one customer.

Information Data type required


Name String
Number of points collected Integer
Date of birth Date

(a) (i) Identify a suitable structure for storing the information for one customer. Explain the
advantage of using this structure.

Structure ............................................................................................................................

Advantage .........................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[4]

(ii) Describe a data structure that could be used to store the information for all customers.

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2023 9618/21/M/J/23


7

(b) Customers receive points depending on the amount they spend. The number of points
depends on the band that the amount falls into:

Band Amount Points


1 Less than $10 5 per whole dollar ($)
2 Between $10 and $100 inclusive 7 per whole dollar ($)
3 Over $100 10 per whole dollar ($)

For example, if the amount is $99.77, this amount is in band 2 and therefore the number of
points is 7 × 99, which is 693 points.

The algorithm to calculate the points from a given amount is expressed as follows:
• work out the appropriate band
• calculate and output the number of points.

Apply the process of stepwise refinement to increase the detail of the algorithm. Structure
your algorithm into a sequence of five steps that could be used to produce pseudocode.

Write the five steps.

1 ................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

3 ................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

4 ................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

5 ................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[5]
© UCLES 2023 9618/21/M/J/23 [Turn over
8

4 Function Replace() will:


1. take three parameters:
• a string (the original string)
• a char (the original character)
• a char (the new character)

2. form a new string from the original string where all instances of the original character are
replaced by the new character

3. return the new string.

Write pseudocode for function Replace().

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [6]

© UCLES 2023 9618/21/M/J/23


9

5 Several companies are developing websites to market a new type of games console. The company
that is first to create a website that can demonstrate the interactive features of the games console
will have an advantage over the others. The requirements for the website are likely to change as
more information about the features of the console are made available.

One company has decided to develop their website using a program development life cycle based
on the waterfall model.

(a) (i) Give two reasons why this may not be the most appropriate model to use in this case.

Reason 1 ...........................................................................................................................

...........................................................................................................................................

Reason 2 ...........................................................................................................................

...........................................................................................................................................
[2]

(ii) Identify a more appropriate program development life cycle model for this scenario.

..................................................................................................................................... [1]

(b) The website has been running in test mode for several weeks.

Identify and describe a final stage of testing that should take place before the website is
made available to all customers.

Stage ........................................................................................................................................

Description ................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2023 9618/21/M/J/23 [Turn over


10

6 A video-conferencing program supports up to six users. Speech from each user is sampled and
digitised (converted from analogue to digital). Digitised values are stored in array Sample.

The array Sample consists of 6 rows by 128 columns and is of type integer. Each row contains
128 digitised sound samples from one user.

The digitised sound samples from each user are to be processed to produce a single value which
will be stored in a 1D array Result of type integer. This process will be implemented by procedure
Mix().

A procedure Mix() will:


• calculate the average of each of the 6 sound samples in a column
• ignore sound sample values of 10 or less
• store the average value in the corresponding position in Result
• repeat for each column in array Sample

The diagram uses example values to illustrate the process:

1 2 3 ... 126 127 128


1 20 20 20 30 30 2
2 20 20 30 50 30 3
3 20 20 40 40 40 4
Sample:
4 20 20 50 40 50 20
5 20 3 5 6 60 4
6 20 4 2 4 70 30

Result: 20 20 35 40 46 25

© UCLES 2023 9618/21/M/J/23


11

Write pseudocode for procedure Mix().

Assume Sample and Result are global.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [6]

© UCLES 2023 9618/21/M/J/23 [Turn over


12

7 A school has a computerised library system that allows students to borrow books for a fixed length
of time. The system uses text files to store details of students, books and loans.

A new module is to be written which will generate emails to each student who has an overdue
book.

(a) Decomposition will be used to break down the problem of designing the new module into
sub-problems.

Identify three program modules that could be used in the design and describe their use.

Module 1 ...................................................................................................................................

Use ...........................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Module 2 ...................................................................................................................................

Use ...........................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Module 3 ...................................................................................................................................

Use ...........................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2023 9618/21/M/J/23


13

(b) The program designer produces a structure chart for the new module. Part of the structure
chart is shown:

Module-A()

Module-B() Module-C() Module-D()

(i) Explain the relationship between the four modules shown.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(ii) Two new modules are added: Module‑X() and Module‑Y().


• Module‑X() has no parameters.
• Module‑Y() will take a string and a real number as parameters and return a
Boolean value.
• Module‑D() will call either Module‑X() or Module‑Y().

Draw only the part of the structure chart that represents the relationship between
Module‑X(), Module‑Y() and Module‑D().

[3]
© UCLES 2023 9618/21/M/J/23 [Turn over
14

8 A computer shop assembles computers using items bought from several suppliers. A text file
Stock.txt contains information about each item.

Information for each item is stored as a single line in the Stock.txt file in the format:
<ItemNum><SupplierCode><Description>

Item information is as follows:

Format Comment
unique for each item in the range
ItemNum 4 numeric characters
"0001" to "5999" inclusive

SupplierCode 5 alphabetic characters to identify the supplier of the item

Description a string a minimum of 12 characters

The file is organised in ascending order of ItemNum and does not contain all possible values in
the range.

A programmer has started to define program modules as follows:

Module Description
SuppExists() • called with a parameter of type string representing a supplier code
(already written)
• returns TRUE if the supplier code is already in use, otherwise returns
FALSE
IsNewSupp() • called with a parameter of type string representing a new supplier code
• returns TRUE if the string only contains alphabetic characters (either
upper or lower case) and the supplier code is not already in use,
otherwise returns FALSE

© UCLES 2023 9618/21/M/J/23


15

(a) Write pseudocode for module IsNewSupp().

Module SuppExists() has already been written and should be used as part of your solution.
Module SuppExists() will generate a run-time error if the given parameter is not
5 characters in length.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2023 9618/21/M/J/23 [Turn over


16

(b) A new module has been defined:

Module Description
CheckNewItem() • called with a parameter of type string representing a line of
item information
• checks to see whether an item with the same ItemNum already
exists in the file
• returns TRUE if the ItemNum is not already in the file, otherwise
returns FALSE

Write efficient pseudocode for module CheckNewItem().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2023 9618/21/M/J/23


17

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

(c) The program modules SuppExists(), IsNewSupp() and CheckNewItem() are part of a
group of modules that are combined to create a complete stock control program.

Each module in the program is tested individually during development and is debugged as
necessary. It is then added to the program and further testing performed.

(i) Identify this method of testing.

..................................................................................................................................... [1]

(ii) One of the modules does not work properly when it is added to the program.

Describe a testing method that can be used to address this problem so that testing can
continue and other modules can be added.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(d) A new module AddItem() will be used to add information to the Stock.txt file.

State the file mode that should be used for the algorithm within this module.

............................................................................................................................................. [1]

(e) A new module FindItem() searches for a given item in the Stock.txt file, which is already
organised in ascending order of ItemNum.

Describe how this organisation may improve the efficiency of the algorithm.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]
© UCLES 2023 9618/21/M/J/23
Cambridge International AS & A Level
* 3 0 3 3 2 5 1 8 2 6 *

COMPUTER SCIENCE 9618/22


Paper 2 Fundamental Problem‑solving and Programming Skills May/June 2023

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
● Answer all questions.
● Use a black or dark blue pen.
● Write your name, centre number and candidate number in the boxes at the top of the page.
● Write your answer to each question in the space provided.
● Do not use an erasable pen or correction fluid.
● Do not write on any bar codes.
● You may use an HB pencil for any diagrams, graphs or rough working.
● Calculators must not be used in this paper.

INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].
● No marks will be awarded for using brand names of software packages or hardware.
● The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (EF/SG) 312086/3
© UCLES 2023 [Turn over
2

Refer to the insert for the list of pseudocode functions and operators.

1 A program calculates the postal cost based on the weight of the item and its destination.
Calculations occur at various points in the program and these result in the choice of several
possible postal costs. The programmer has built these postal costs into the program.

For example, the postal cost of $3.75 is used in the following lines of pseudocode:

IF Weight < 250 AND ValidAddress = TRUE THEN


ItemPostalCost 3.75 // set postal cost for item to $3.75
ItemStatus "Valid" // item can be sent
ENDIF

(a) (i) Identify a more appropriate way of representing the postal costs.

..................................................................................................................................... [1]

(ii) Describe the advantages of your answer to part (a)(i) with reference to this program.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

(b) The lines of pseudocode contain features that make them easier to understand.

State three of these features.

1 ................................................................................................................................................

2 ................................................................................................................................................

3 ................................................................................................................................................
[3]

(c) Give the appropriate data types for the following variables:

ValidAddress ........................................................................................................................

ItemPostalCost ...................................................................................................................

ItemStatus ............................................................................................................................
[3]

© UCLES 2023 9618/22/M/J/23


3

2 A program stores a user’s date of birth using a variable MyDOB of type DATE.

(a) Write a pseudocode statement, using a function from the insert, to assign the value
corresponding to 17/11/2007 to MyDOB.

............................................................................................................................................. [1]

(b) MyDOB has been assigned a valid value representing the user’s date of birth.

Write a pseudocode statement to calculate the number of months from the month of the
user’s birth until the end of the year and to assign this to the variable NumMonths.

For example, if MyDOB contains a value representing 02/07/2008, the value 5 would be
assigned to NumMonths.

............................................................................................................................................. [2]

(c) The program will output the day of the week corresponding to MyDOB.

For example, given the date 22/06/2023, the program will output "Thursday".

An algorithm is required. An array will be used to store the names of the days of the week.

Define the array and describe the algorithm in four steps.

Do not use pseudocode statements in your answer.

Array definition ..........................................................................................................................

...................................................................................................................................................

Step 1 .......................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Step 2 .......................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Step 3 .......................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Step 4 .......................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[6]
© UCLES 2023 9618/22/M/J/23 [Turn over
4

3 A program stores data in a text file. When data is read from the file, it is placed in a queue.

(a) The diagram below represents an Abstract Data Type (ADT) implementation of the queue.
Each data item is stored in a separate location in the data structure. During initial design, the
queue is limited to holding a maximum of 10 data items.

The operation of this queue may be summarised as follows:


• The Front of Queue Pointer points to the next data item to be removed.
• The End of Queue Pointer points to the last data item added.
• The queue is circular so that locations can be reused.

0
1
2
3
4
5 Red Front of Queue Pointer
6 Green
7 Blue
8 Pink End of Queue Pointer
9

(i) Describe how the data items Orange and Yellow are added to the queue shown in the
diagram.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [4]

© UCLES 2023 9618/22/M/J/23


5

(ii) The following diagram shows the state of the queue after several operations have been
performed. All queue locations have been used at least once.

0 D4
1 D3 End of Queue Pointer
2 D27
3 D8
4 D33
5 D17 Front of Queue Pointer
6 D2
7 D1
8 D45
9 D60

State the number of data items in the queue.

..................................................................................................................................... [1]

(b) The design of the queue is completed and the number of locations is increased.

A function AddToQueue() has been written. It takes a string as a parameter and adds this to
the queue. The function will return TRUE if the string was added successfully.

A procedure FileToQueue() will add each line from the file to the queue. This procedure
will end when all lines have been added or when the queue is full.

Describe the algorithm for procedure FileToQueue().

Do not use pseudocode in your answer.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [5]

© UCLES 2023 9618/22/M/J/23 [Turn over


6

4 A function GetNum() will:


1. take two parameters: a string and a character
2. count the number of times that the character occurs in the string
3. return the count.

Any comparison between characters needs to be case sensitive. For example, character 'a' and
character 'A' are not identical.

Write pseudocode for function GetNum().

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [6]

© UCLES 2023 9618/22/M/J/23


8

5 A programmer has produced the following pseudocode to output the square root of the numbers
from 1 to 10.

Line numbers are for reference only.

10 DECLARE Num : REAL


11 Num 1.0
...

40 REPEAT
41 CALL DisplaySqrt(Num)
42 Num Num + 1.0
43 UNTIL Num > 10
...

50 PROCEDURE DisplaySqrt(BYREF ThisNum : REAL)


51 OUTPUT ThisNum
52 ThisNum SQRT(ThisNum) // SQRT returns the square root
53 OUTPUT " has a square root of ", ThisNum
54 ENDPROCEDURE

The pseudocode is correctly converted into program code.

Function SQRT() is a library function and contains no errors.

The program code compiles without errors, but the program gives unexpected results. These are
caused by a design error.

(a) Explain why the program gives unexpected results.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

(b) Explain why the compiler does not identify this error.

...................................................................................................................................................

............................................................................................................................................. [1]

© UCLES 2023 9618/22/M/J/23


9

(c) Describe how a typical Integrated Development Environment (IDE) could be used to identify
this error.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

(d) The pseudocode is converted into program code as part of a larger program.

During compilation, a complex statement generates an error.

The programmer does not want to delete the complex statement but wants to change the
statement so that it is ignored by the compiler.

State how this may be achieved.

...................................................................................................................................................

............................................................................................................................................. [1]

© UCLES 2023 9618/22/M/J/23 [Turn over


10

6 A procedure Square() will take an integer value in the range 1 to 9 as a parameter and output a
number square.

The boundary of a number square is made up of the character representing the parameter value.
The inside of the number square is made up of the asterisk character (*).

Parameter value 1 2 3 4 ... 9

1 22 333 4444 ... 99 9 9 99 9 9 9


22 3*3 4**4 9 * * * ** * * 9
333 4**4 9 ** * *** * 9
4444 9 *** **** 9
Output 9 * * * ** * * 9
9 * * * ** * * 9
9 ** * *** * 9
9 ******* 9
999999999

The pseudocode OUTPUT command starts each output on a new line. For example, the following
three OUTPUT statements would result in the outputs as shown:

OUTPUT "Hello"
OUTPUT "ginger"
OUTPUT "cat"

Resulting output:

Hello
ginger
cat

© UCLES 2023 9618/22/M/J/23


11

Write pseudocode for procedure Square().

Parameter validation is not required.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

© UCLES 2023 9618/22/M/J/23 [Turn over


12

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [6]

© UCLES 2023 9618/22/M/J/23


14

7 A computer system for a shop stores information about each customer. The items of information
include name and address (both postal and email) together with payment details and order history.
The system also stores the product categories they are interested in and how they would like to be
contacted.

(a) The shop wants to add a program module that will generate emails to be sent to customers
who may be interested in receiving details of new products.

(i) State three items of information that the new module would need. Justify your choice in
each case.

Information ........................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................

Information ........................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................

Information ........................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................
[3]

(ii) Identify two items of customer information that would not be required by the new module.
Justify your choice in each case.

Information ........................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................

Information ........................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................
[2]

© UCLES 2023 9618/22/M/J/23


15

(b) The program includes a module to validate a Personal Identification Number (PIN). This is
used when customers pay for goods using a bank card.

A state‑transition diagram has been produced for this module.

The table show the inputs, outputs and states for this part of the program:

Current state Input Output Next state


S1 Input PIN S2
S2 Re‑input PIN Display error S2
S2 Cancel Re‑prompt S1
S2 Valid PIN Enable payment S4
S2 Too many tries Block Account S3

Complete the state‑transition diagram to represent the information given in the table.

S2

START
S1

Cancel | Re-prompt

[4]
© UCLES 2023 9618/22/M/J/23 [Turn over
16

8 A computer shop assembles computers using items bought from several suppliers. A text file
Stock.txt contains information about each item.

Information for each item is stored as a single line in the Stock.txt file in the format:
<ItemNum><SupplierCode><Description>

Valid item information is as follows:

Format Comment
unique number for each item in the range
ItemNum 4 numeric characters
″0001″ to ″5999″ inclusive

SupplierCode 3 alphabetic characters to identify the supplier of the item

Description a string a minimum of 12 characters

The file is organised in ascending order of ItemNum and does not contain all possible values in
the range.

A programmer has started to define program modules as follows:

Module Description
OnlyAlpha() • called with a parameter of type string
(already written)
• returns TRUE if the string contains only alphabetic characters,
otherwise returns FALSE
CheckInfo() • called with a parameter of type string representing a line of item
information
• checks to see whether the item information in the string is valid
• returns TRUE if the item information is valid, otherwise returns
FALSE

© UCLES 2023 9618/22/M/J/23


17

(a) Write pseudocode for module CheckInfo().

Module OnlyAlpha() should be used as part of your solution.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2023 9618/22/M/J/23 [Turn over


18

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

(b) A new module is defined as follows:

Module Description
AddItem() • called with a parameter of type string representing valid information
for a new item that is not currently in the Stock.txt file
• creates a new file NewStock.txt from the contents of the file
Stock.txt and adds the new item information at the appropriate
place in the NewStock.txt file

As a reminder, the file Stock.txt is organised in ascending order of ItemNum and does not
contain all possible values in the range.

Write pseudocode for module AddItem().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
© UCLES 2023 9618/22/M/J/23
19

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

(c) The program contains modules SuppExists() and CheckSupplier(). These have been
written but contain errors. These modules are called from several places in the main program
and testing of the main program (integration testing) has had to stop.

Identify a method that can be used to continue testing the main program before the errors in
these modules have been corrected and describe how this would work.

Method ......................................................................................................................................

Description ................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2023 9618/22/M/J/23


Cambridge International AS & A Level
* 3 1 4 1 1 6 4 8 5 5 *

COMPUTER SCIENCE 9618/23


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2023

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
● Answer all questions.
● Use a black or dark blue pen.
● Write your name, centre number and candidate number in the boxes at the top of the page.
● Write your answer to each question in the space provided.
● Do not use an erasable pen or correction fluid.
● Do not write on any bar codes.
● You may use an HB pencil for any diagrams, graphs or rough working.
● Calculators must not be used in this paper.

INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].
● No marks will be awarded for using brand names of software packages or hardware.
● The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (PQ/CB) 312089/3
© UCLES 2023 [Turn over
2

Refer to the insert for the list of pseudocode functions and operators.

1 The following pseudocode represents part of the algorithm for a program.

Line numbers are for reference only.

10 DECLARE Sheet4 : ARRAY[1:2, 1:50] OF INTEGER

100 FOR PCount 0 TO 49


101 Sheet4[1, PCount] 0
102 Sheet4[2, PCount] 47
103 NEXT PCount

(a) The pseudocode contains references to an array.

Complete the table by writing the answer for each row.

Answer
The dimension of the array
The name of the variable used as an array index
The number of elements in the array
[3]

(b) The pseudocode contains two errors. One error is that variable PCount has not been
declared.

Identify the other error and state the line number where it occurs.

Error ..........................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Line number ..............................................................................................................................


[2]

(c) The pseudocode does not include a declaration for PCount.

State the data type that should be used in the declaration.

............................................................................................................................................. [1]

© UCLES 2023 9618/23/M/J/23


3

(d) The pseudocode statements given in the following table are used in other parts of the
algorithm.

Complete the table by placing one or more ticks (✓) in each row.

The first row has already been completed.

Pseudocode statement Input Process Output

INPUT MyChoice ✓
OUTPUT FirstName & LastName

WRITEFILE YourFile, TextLine

READFILE MyFile, TextLine

Result SQRT(NextNum)
[4]

© UCLES 2023 9618/23/M/J/23 [Turn over


4

2 A program stores a date of birth for a student using a variable, MyDOB, of type DATE.

(a) MyDOB has been assigned a valid value corresponding to Kevin’s date of birth.

Complete the pseudocode statement to test whether Kevin was born on a Thursday.

IF ........................................................................................................................ THEN [2]

(b) A function CheckDate()will take three integer parameters representing a day, month and
year of a given date.

The function will validate the date of birth for a student that the parameters passed to it
represent.
For a date to be valid, a student must be at least 18 in year 2020.

(i) Two of the parameter values can be checked without reference to the third parameter.

Describe these two checks.

Check 1 .............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

Check 2 .............................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[2]

(ii) Several values of the parameter representing the day can only be checked completely
by referring to the value of one other parameter.

Describe this check.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2023 9618/23/M/J/23


6

3 A program processes data using a stack. The data is copied to a text file before the program ends.

(a) The following diagram shows the current state of the stack.

The operation of this stack may be summarised as follows:

• The TopOfStack pointer points to the last item added to the stack.
• The BottomOfStack pointer points to the first item on the stack.
• The stack grows upwards when items are added.

Stack Pointer

Memory location Value

506

505 WWW TopOfStack

504 YYY

503 XXX

502 ZZZ

501 NNN

500 PPP BottomOfStack

(i) An error will be generated if an attempt is made to POP a value when the stack is empty.

State the maximum number of consecutive POP operations that could be performed on
the stack shown above before an error is generated.

..................................................................................................................................... [1]

(ii) The following operations are performed:

1. POP and store value in variable Data1


2. POP and store value in variable Data2
3. PUSH value AAA
4. PUSH value BBB
5. POP and discard value
6. POP and store value in variable Data2

© UCLES 2023 9618/23/M/J/23


7

Complete the diagram to show the state of the stack and the variables after the given
operations have been performed.

Stack Pointer

Memory location Value

506

505

504

503

502 Variable Value

501 Data1

500 Data2
[4]
(b) The data is copied to a text file before the program ends.

(i) State an advantage of writing the data from the stack to a text file before the program
ends.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) A module SaveStack() will write the data from the stack to a text file.

Express an algorithm for SaveStack() as five steps that could be used to produce
pseudocode.

Write the five steps.

Step 1 ................................................................................................................................

...........................................................................................................................................

Step 2 ................................................................................................................................

...........................................................................................................................................

Step 3 ................................................................................................................................

...........................................................................................................................................

Step 4 ................................................................................................................................

...........................................................................................................................................

Step 5 ................................................................................................................................

...........................................................................................................................................
[5]
© UCLES 2023 9618/23/M/J/23 [Turn over
8

4 A function MakeString() will:

1. take two parameters:


• a count as an integer
• a character
2. generate a string of length equal to the count, made up of the character
3. return the string generated, or return "ERROR" if the count is less than 1.

For example, the function call:

MakeString(3, 'Z') will return the string "ZZZ"

Write pseudocode for function MakeString().

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [6]

© UCLES 2023 9618/23/M/J/23


9

5 A program is designed, coded and compiled without errors. The compiled code is sent for testing.

(a) The program will be tested using the walkthrough method.

Additional information will be needed before this method can be used.

Identify this additional information and explain why it is needed.

Additional information ...............................................................................................................

...................................................................................................................................................

Explanation ...............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

(b) Testing is completed and the program is made available to users.

Some time later, changes are made to the program to improve the speed of response.

State the type of maintenance that has been applied to the program.

............................................................................................................................................. [1]

© UCLES 2023 9618/23/M/J/23 [Turn over


10

6 A procedure Select() will:

1. take two integer values as parameters representing start and end values where both values
are greater than 9 and the end value is greater than the start value
2. output each integer value between the start and the end value (not including the start and
end values), where the sum of the last two digits is 6, for example, 142.

(a) Write pseudocode for procedure Select().

Parameter validation is not required.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]
© UCLES 2023 9618/23/M/J/23
11

(b) The check performed by procedure Select() on the last two digits is needed at several
places in the program and will be implemented using a new function.

The new function CheckNum() will:

• allow the required sum to be specified (not just 6)


• check one number
• return an appropriate value.

Describe the function interface and two advantages of this modular approach.

Interface ....................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Advantage 1 .............................................................................................................................

...................................................................................................................................................

Advantage 2 .............................................................................................................................

...................................................................................................................................................
[4]

© UCLES 2023 9618/23/M/J/23 [Turn over


12

7 A school has a library system which allows students to borrow books for a length of time.
Information relating to students and books is stored in text files. Student information includes
name, home address, email address, date of birth, tutor and subject choices. Book information
includes author, title, subject category, library location and the date that the book was borrowed.

A program helps the staff to manage the borrowing of books.

(a) A new module needs to be written to generate emails to send to students who have an
overdue book. Students who are sent an email are prevented from borrowing any more books
until the overdue book is returned.

The process of abstraction has been used when designing the new module.

(i) State the purpose of applying abstraction to this problem.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) Identify one item of information that is required and one item that is not required in the
new module. Justify your choices.

Item required .....................................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

Item not required ...............................................................................................................

Justification .......................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[2]

(iii) Identify two operations that would be required to process data when an overdue book is
returned.

Operation 1 .......................................................................................................................

...........................................................................................................................................

Operation 2 .......................................................................................................................

...........................................................................................................................................
[2]

© UCLES 2023 9618/23/M/J/23


13

(b) Part of the library program contains program modules with headers as follows:

Pseudocode module header


PROCEDURE Module-X()
PROCEDURE Module-Y(BYREF RA : INTEGER, SA : REAL)
PROCEDURE Overlay()
FUNCTION Replace(RA : INTEGER, RB : BOOLEAN) RETURNS BOOLEAN
FUNCTION Reset(TA : STRING) RETURNS INTEGER

Module-X() and Module-Y() are both called from module Overlay().

Complete the structure chart.

[3]

© UCLES 2023 9618/23/M/J/23 [Turn over


14

8 A computer shop assembles desktop computers, using items bought from several suppliers. A text
file Stock.txt contains information about each item.

Information for each item is stored as a single line in the Stock.txt file in the format:

<ItemNum><SupplierCode><Description>

Item information is as follows:

Format Comment
unique number for each item in the range “0001”
ItemNum 4 numeric characters
to “5999” inclusive
SupplierCode 3 alphabetic characters code to identify the supplier of the item

Description a string a minimum of 12 characters

The file is organised in ascending order of ItemNum and does not contain all possible values in
the range.

The programmer has defined the first program module as follows:

Module Description
ChangeSupp() • called with two parameters Code1 and Code2 of type string that represent
valid supplier codes
• creates a new file NewStock.txt from the contents of the
file Stock.txt where any reference to Code1 is replaced by Code2
• returns a count of the number of items that have had their supplier code
changed

© UCLES 2023 9618/23/M/J/23


15

(a) Write pseudocode for module ChangeSupp().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [8]

© UCLES 2023 9618/23/M/J/23 [Turn over


16

(b) A new module is required:

Module Description
Report_1() • takes a parameter of type string that represents a SupplierCode
• searches the Stock.txt file for each line of item information that
contains the given SupplierCode
• produces a formatted report of items for the given SupplierCode,
for example, for supplier DRG, the output could be:

Report for Supplier: DRG

Item Description

1234 USB Printer Cable 3 m


1273 32GB USB Flash Drive
1350 Mouse Mat 320 x 240 mm

Number of items listed: 3

Write pseudocode for module Report_1().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

© UCLES 2023 9618/23/M/J/23


17

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2023 9618/23/M/J/23 [Turn over


18

(c) The format of the output from module Report_1() from part (b) is changed. The number of
items listed is moved to the top of the report as shown in the example:

Report for Supplier: DRG


Number of items listed: 3

Item Description

1234 USB Printer Cable 3 m


1273 32GB USB Flash Drive
1350 Mouse Mat 320 x 240 mm

(i) Explain why this new layout would increase the complexity of the algorithm.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(ii) The algorithm will be modified to produce the report in the new format. The modified
algorithm will be implemented so that the file Stock.txt is only read once.

Describe the modified algorithm.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

© UCLES 2023 9618/23/M/J/23


Cambridge International AS & A Level
* 0 1 1 3 5 2 0 5 9 2 *

COMPUTER SCIENCE 9618/21


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2023

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
● Answer all questions.
● Use a black or dark blue pen.
● Write your name, centre number and candidate number in the boxes at the top of the page.
● Write your answer to each question in the space provided.
● Do not use an erasable pen or correction fluid.
● Do not write on any bar codes.
● You may use an HB pencil for any diagrams, graphs or rough working.
● Calculators must not be used in this paper.

INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].
● No marks will be awarded for using brand names of software packages or hardware.
● The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (LK/SG) 315866/3
© UCLES 2023 [Turn over
2

Refer to the insert for the list of pseudocode functions and operators.

1 The following pseudocode represents part of the algorithm for a program:

CASE OF ThisValue
< 30 : Level "Low" ←
// less than 30
Check 1 ←
< 20 : Level "Very Low" ←
// less than 20
Check ThisValue / 2 ←
30 TO 40 : Level "Medium" ←
// between 30 and 40
Check ThisValue / 3 ←
Data[ThisValue] Data[ThisValue] + 1 ←
> 40 : Level "High" ←
ENDCASE

(a) Complete the table by writing the answer for each row:

Answer

The value assigned to Level when ThisValue is 40

The value assigned to Check when ThisValue is 36

The value assigned to Level when ThisValue is 18

The number of elements in array Data that may be incremented


[4]

(b) The pseudocode contains four assignments to variable Level. One of these assignments
will never be performed.

Identify this assignment and explain why this is the case.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

(c) The following line is added immediately before the ENDCASE statement:

OTHERWISE : Level ← "Undefined"


State why this assignment is never performed.

...................................................................................................................................................

............................................................................................................................................. [1]

© UCLES 2023 9618/21/O/N/23


3

(d) Give the appropriate data types for the variables ThisValue, Check and Level.

ThisValue ..............................................................................................................................

Check .......................................................................................................................................

Level ......................................................................................................................................
[3]

2 (a) An algorithm is expressed as follows:

• input 100 numbers, one at a time


• keep a total of all numbers input that have a value between 30 and 70 inclusive and
output this total after the last number has been input.

Outline, using stepwise refinement, the five steps for this algorithm which could be used to
produce pseudocode.

Do not use pseudocode statements in your answer.

Step 1 .......................................................................................................................................

...................................................................................................................................................

Step 2 .......................................................................................................................................

...................................................................................................................................................

Step 3 .......................................................................................................................................

...................................................................................................................................................

Step 4 .......................................................................................................................................

...................................................................................................................................................

Step 5 .......................................................................................................................................

...................................................................................................................................................
[5]

(b) Sequence is one programming construct.

Identify two other programming constructs that will be required when the algorithm is
converted into pseudocode.

Construct 1 ...............................................................................................................................

...................................................................................................................................................

Construct 2 ...............................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2023 9618/21/O/N/23 [Turn over


4

3 The diagram represents an Abstract Data Type (ADT).

The operation of this stack may be summarised as follows:

• The TopOfStack pointer points to the last item added to the stack.
• The BottomOfStack pointer points to the first item on the stack.

Stack

D1 ← TopOfStack
D3
D4
D5
D2 ← BottomOfStack
(a) The stack is implemented using two variables and a 1D array of 8 elements as shown.

The variables are used to reference individual elements of the array, in such a way that:

• the array is filled from the lowest indexed element towards the highest
• all the elements of the array are available for the stack.

Complete the diagram to represent the state of the stack as shown above.

Array Data
element
8

5 Variable

4 TopOfStack

3 BottomOfStack

1
[3]

© UCLES 2023 9618/21/O/N/23


5

(b) A function Push() will add a value onto the stack by manipulating the array and variables in
part (a).

Before adding a value onto the stack, the algorithm will check that space is available.

If the value is added to the stack, the function will return TRUE, otherwise it will return FALSE.

The algorithm is expressed in five steps.

Complete the steps.

1. If ........................................................ then return FALSE

2. Otherwise .......................................... TopOfStack

3. Use TopOfStack as an ................................... to the array.

4. Set the element at this ...................................... to the .............................. being added.

5. Return .............................. .

[5]

© UCLES 2023 9618/21/O/N/23 [Turn over


6

4 A global array is declared in pseudocode as follows:

DECLARE Data : ARRAY[1:150] OF STRING

A function TooMany() will:

1. take two parameters:


• a string (the search string)
• an integer (the maximum value)
2. count the number of strings in the array that exactly match the search string
3. return TRUE if the count is greater than the maximum value, otherwise will return FALSE

(a) Write pseudocode for the function TooMany().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2023 9618/21/O/N/23


7

(b) The global array is changed to a 2D array, organised as 150 rows by 2 columns. It is declared
in pseudocode as follows:

DECLARE Data : ARRAY[1:150, 1:2] OF STRING

The algorithm for the function in part (a) is changed. Strings will only be counted if both of
the following conditions are true:

• The current row is an even number.


• The search string exactly matches the value in either column.

Write pseudocode to check these conditions.

Assume that the row index is contained in variable Row and the search string in variable
Search.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2023 9618/21/O/N/23 [Turn over


8

5 An algorithm is designed to find the smallest numeric value from an input sequence and count
how many numeric values have been input.
An example of an input sequence is:

23, AB56, 17, 23ZW, 4, 10, END

Numeric input values are all integers and non-numeric input is ignored, except for the string "END"
which is used to terminate the sequence.

The algorithm is expressed in pseudocode as shown:

DECLARE NextInput : STRING


DECLARE Min, Count, Num : INTEGER

Min ← 999
Count ←0
REPEAT
INPUT NextInput
IF IS_NUM(NextInput) = TRUE THEN
Num ←
STR_TO_NUM(NextInput)
IF Num > Min THEN
Min Num ←
ENDIF
Count ←
Count & 1
ENDIF
UNTIL NextInput "END" ←
OUTPUT "The minimum value is ", Min, " and the count was ", Count

(a) The pseudocode contains three errors due to the incorrect use of operators.

Identify each error and state the correction required.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................

3 ................................................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2023 9618/21/O/N/23


9

(b) The operator errors are corrected and the algorithm is tested as follows:

The input sequence:

18, 4, ONE, 27, 189, ERIC, 3, 65, END

produces the output:

The minimum value is 3 and the count was 6

The algorithm is tested with a different test data sequence. The sequence contains a mix
of integer and non-numeric values. It is terminated correctly but the algorithm produces
unexpected results.

(i) Explain the problem with the algorithm.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(ii) Give a sequence of four test data values that could be input to demonstrate the problem.

Value 1 ..............................................................................................................................

Value 2 ..............................................................................................................................

Value 3 ..............................................................................................................................

Value 4 ..............................................................................................................................
[2]

© UCLES 2023 9618/21/O/N/23 [Turn over


10

6 The pseudocode OUTPUT command starts each output on a new line.

(a) A new procedure MyOutput() will take a string and a Boolean parameter.
MyOutput() may be called repeatedly and will use concatenation to build a string using a
global variable MyString, up to a maximum length of 255 characters.

MyString will be output in either of these two cases:

1. The Boolean parameter value is TRUE


2. The resulting string (after concatenation) would be longer than 255 characters.

If MyString is not output, the string is concatenated with MyString.

For example, the calls to MyOutput() given below would result in the output as shown:

MyOutput("Hello ", FALSE)


MyOutput("ginger ", FALSE)
MyOutput("cat", TRUE)
MyOutput("How are you?", TRUE)

Resulting output:

Hello ginger cat


How are you?

Notes:

• MyString is initialised to an empty string before MyOutput() is called for the first time.
• No string passed to MyOutput() will be longer than 255 characters.

© UCLES 2023 9618/21/O/N/23


11

Write pseudocode for MyOutput().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

(b) The design of the procedure given in part (a) is modified and MyString is changed from a
global to a local variable declared in MyOutput().

When the modified procedure is converted into program code, it does not work as expected.

Explain why it does not work as expected.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2023 9618/21/O/N/23 [Turn over


12

7 An algorithm is represented by a state-transition diagram.

The table shows the inputs, outputs and states for the algorithm:

Current state Input Output Next state


S1 A1 X1 S2
S2 A3 none S1
S2 A2 X4 S5
S5 A1 X1 S5
S5 A4 X2 S2
S5 A3 none S3
S1 A9 X9 S3
S3 A9 X9 S4

Complete the state-transition diagram to represent the information given in the table.

A1 | X1

START
S1
A3

[5]

© UCLES 2023 9618/21/O/N/23


14

8 A class of students are developing a program to send data between computers. Many computers
are connected together to form a wired network. Serial ports are used to connect one computer to
another.

Each computer:

• is assigned a unique three-digit ID


• has three ports, each identified by an integer value
• is connected to between one and three other computers.

Messages are sent between computers as a string of characters organised into fields as shown:

<STX><DestinationID><SourceID><Data><ETX>

Field
Field name Description
number
a single character marking the start of the message
n/a STX
(ASCII value 02)
1 DestinationID three numeric characters that identify the destination computer

2 SourceID three numeric characters that identify the source computer


a variable length string containing the data being sent
3 Data
(Minimum length is 1 character)
a single character marking the end of the message
n/a ETX
(ASCII value 03)

For example, the following message contains the data "Hello Kevin" being sent from computer
"101" to computer "232":

<STX>"232101Hello Kevin"<ETX>

Each computer will run a copy of the same program. Each program will contain a global variable,
MyID of type string, that contains the unique ID of the computer in which the program is running.

The programmer has defined the first two program modules as follows:

Module Description
• takes two parameters:
Transmit() o a string containing a message
(already written) o an integer containing a port number
• transmits the message using the given port
• takes three parameters:
o a string containing a text file name
SendFile() o a string containing a Destination ID
o an integer containing a Port number
• transmits the file one line at a time
• transmits a final message with data string "****"

© UCLES 2023 9618/21/O/N/23


15

(a) Write pseudocode for module SendFile().

Assume:

• module Transmit() has already been written and is used to transmit a message
• the value of MyID may be used as SourceID
• the file specified contains no blank lines
• the file specified does not contain the line "****"

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2023 9618/21/O/N/23 [Turn over


16

(b) Module SendFile() is used to copy a file from one computer to another.

A module within the program running on the destination computer will receive the data and
write it to a new file.

Explain why module SendFile() transmits the message with data string "****" after the
last line of the file.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

(c) One of the text files to be sent contains several blank lines (lines that do not contain any text).

(i) Explain why this is a problem.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

(ii) Explain how the message format could be changed to allow a blank line to be sent.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2023 9618/21/O/N/23


18

(d) A new module has been defined:

Module Description
• takes two parameters:
o a string containing a message
GetField() o an integer containing a field number
• If the field number is valid (in the range 1 to 3, inclusive), it
returns a string containing the required field, otherwise it returns
an empty string.

As a reminder, a message is defined as follows:

<STX><DestinationID><SourceID><Data><ETX>

Field
Field name Description
number
a single character marking the start of the message
Not applicable STX
(ASCII value 02)
1 DestinationID three numeric characters that identify the destination computer

2 SourceID three numeric characters that identify the source computer


a variable length string containing the data being sent
3 Data
(Minimum length is 1 character)
a single character marking the end of the message
Not applicable ETX
(ASCII value 03)

© UCLES 2023 9618/21/O/N/23


19

Write pseudocode for module GetField().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2023 9618/21/O/N/23


Cambridge International AS & A Level
* 4 0 2 6 5 6 3 1 4 8 *

COMPUTER SCIENCE 9618/22


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2023

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
● Answer all questions.
● Use a black or dark blue pen.
● Write your name, centre number and candidate number in the boxes at the top of the page.
● Write your answer to each question in the space provided.
● Do not use an erasable pen or correction fluid.
● Do not write on any bar codes.
● You may use an HB pencil for any diagrams, graphs or rough working.
● Calculators must not be used in this paper.

INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].
● No marks will be awarded for using brand names of software packages or hardware.
● The insert contains all the resources referred to in the questions.

This document has 20 pages. Any blank pages are indicated.

DC (LK/SG) 315868/1
© UCLES 2023 [Turn over
2

Refer to the insert for the list of pseudocode functions and operators.

1 A shop sells car accessories. A customer order is created if an item cannot be supplied from
current stock. A program is being developed to create and manage the customer orders.

(a) The following identifier table shows some of the data that will be stored for each order.

Complete the identifier table by adding meaningful variable names and appropriate data
types.

Example
Explanation Variable name Data type
value

"Mr Khan" The name of the customer

3 The number of items in the order

TRUE To indicate whether this is a new customer

15.75 The deposit paid by the customer

[4]

(b) Other variables in the program have example values as shown:

Variable Example value


Total 124.00
DepRate 2.00
Description "AB12345:Cleaning Brush (small)"

Complete the table by evaluating each expression using the example values.

Expression Evaluates to

(Total * DepRate) + 1.5

RIGHT(Description, 7)

(LENGTH(Description) - 8) > 16

NUM_TO_STR(INT(DepRate * 10)) & '%'


[4]

© UCLES 2023 9618/22/O/N/23


3

(c) The data that needs to be stored for each customer order in part (a) is not all of the same
type.

Describe an effective way of storing this data for many customer orders while the program is
running.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

© UCLES 2023 9618/22/O/N/23 [Turn over


4

2 An algorithm will:

1. input a sequence of integer values, one at a time


2. ignore all values until the value 27 is input, then sum the remaining values in the sequence
3. stop summing values when the value 0 is input and then output the sum of the values.

(a) Draw a program flowchart to represent the algorithm.

START

END

[5]

© UCLES 2023 9618/22/O/N/23


5

(b) The solution to the algorithm includes iteration.

Give the name of a suitable loop structure that could be used.

Justify your answer.

Name ........................................................................................................................................

Justification ...............................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2023 9618/22/O/N/23 [Turn over


6

3 The diagram represents a linked list Abstract Data Type (ADT).

• Ptr1 is the start pointer. Ptr2 is the free list pointer.


• Labels D40, D32, D11 and D100 represent the data items of nodes in the list.
• Labels F1, F2, F3 and F4 represent the data items of nodes in the free list.
• The symbol Ø represents a null pointer.

Ptr1
D40 D32 D11 D100 Ø

Ptr2
F1 F2 F3 F4 Ø

(a) The linked list is implemented using two variables and two 1D arrays as shown.

The pointer variables and the elements of the Pointer array store the indices (index numbers)
of elements in the Data array.

Complete the diagram to show how the linked list as shown above may be represented using
the variables and arrays.

Variable Value
Start_Pointer

Free_List_Pointer 5

Index Data array Pointer array


1 D32 2

2 3

4 D40

6 F2 7

8
[5]

© UCLES 2023 9618/22/O/N/23


7

(b) The original linked list is to be modified. A new node D6 is inserted between nodes D32 and
D11.

Ptr1
D40 D32 D11 D100 Ø

Ptr2
F1 F2 F3 F4 Ø

The algorithm required is expressed in four steps as shown.

Complete the steps.

1. Assign the data item .................................. to .................................. .

2. Set the .................................. of this node to point to .................................. .

3. Set Ptr2 to point to .................................. .

4. Set pointer of .................................. to point to .................................. .


[4]

© UCLES 2023 9618/22/O/N/23 [Turn over


8

4 A procedure Count() will:

1. input a value (all values will be positive integers)


2. count the number of odd values and count the number of even values
3. repeat from step 1 until the value input is 99
4. output the two count values, with a suitable message.

The value 99 must not be counted.

(a) Write pseudocode for the procedure Count().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2023 9618/22/O/N/23


9

(b) The procedure Count() is to be tested.

Typical test data would consist of odd and even values, for example:

23, 5, 64, 100, 2002, 1, 8, 900, 99

The purpose of this test would be to test a typical mix of even and odd values and check the
totals.

Give three test data sequences that may be used to test different aspects of the procedure.

Do not include invalid data.

Sequence 1:

Test data ...................................................................................................................................

Purpose of test. ........................................................................................................................

...................................................................................................................................................

Sequence 2:

Test data ...................................................................................................................................

Purpose of test. ........................................................................................................................

...................................................................................................................................................

Sequence 3:

Test data ...................................................................................................................................

Purpose of test. ........................................................................................................................

...................................................................................................................................................
[3]

© UCLES 2023 9618/22/O/N/23 [Turn over


10

5 A global 1D array of integers contains four elements, which are assigned values as shown:

Mix[1] ←1
Mix[2] ←3
Mix[3] ←4
Mix[4] ←2
A procedure Process() manipulates the values in the array.

The procedure is written in pseudocode:

PROCEDURE Process(Start : INTEGER)


DECLARE Value, Index, Count : INTEGER

Index ← Start
Count ←0
REPEAT
Value ←Mix[Index]
Mix[Index]← Mix[Index] - 1
Index ←Value
Count ←Count + 1
UNTIL Count = 5

Mix[4] ← Count * Index


ENDPROCEDURE

Complete the trace table on the opposite page by dry running the procedure when it is called as
follows:

CALL Process(3)

© UCLES 2023 9618/22/O/N/23


11

Index Value Count Mix[1] Mix[2] Mix[3] Mix[4]

[6]

© UCLES 2023 9618/22/O/N/23 [Turn over


12

6 (a) A procedure CreateFiles() will take two parameters:

• a string representing a file name


• an integer representing the number of files to be created.

The procedure will create the number of text files specified.

Each file is given a different name. Each file name is formed by concatenating the file name
with a suffix based on the file number. The suffix is always three characters.

For example, the call CreateFiles("TestData", 3) would result in the creation of the
three files, TestData.001, TestData.002 and TestData.003.

Each file will contain a single line. For example, file TestData.002 would contain the string:

This is File TestData.002

Write pseudocode for CreateFiles().

Assume both parameters are valid and that the integer value is between 1 and 999, inclusive.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]
© UCLES 2023 9618/22/O/N/23
13

(b) A module CheckFiles() will count the number of files produced by CreateFiles() in
part (a).

CheckFiles() will take a string representing a file name and return the number of files
found.

(i) Identify the type of module that should be used for CheckFiles().

..................................................................................................................................... [1]

(ii) Write the module header for CheckFiles().

...........................................................................................................................................

..................................................................................................................................... [1]

(iii) State the file mode that should be used in CheckFiles().

..................................................................................................................................... [1]

© UCLES 2023 9618/22/O/N/23 [Turn over


14

7 A program contains six modules:

Pseudocode module header


PROCEDURE Module-A()
PROCEDURE Module-X(T1 : INTEGER, S2 : REAL)
PROCEDURE Reset(BYREF Code : INTEGER)
FUNCTION Restore(OldCode : INTEGER) RETURNS BOOLEAN
FUNCTION Module-Y(RA : INTEGER, RB : BOOLEAN) RETURNS BOOLEAN
FUNCTION Module-Z(SA : INTEGER) RETURNS INTEGER

Module-X() calls Reset()


Module-Y() calls Restore()

(a) Complete the structure chart for these modules.

Module-A()

[4]

(b) Explain the meaning of the diamond symbol as used in the diagram in part (a).

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2023 9618/22/O/N/23


16

8 A class of students are developing a program to send data between computers. Many computers
are connected together to form a wired network. Serial ports are used to connect one computer to
another.

Each computer:

• is assigned a unique three-digit ID


• has three ports, each identified by an integer value
• is connected to between one and three other computers.

Data is sent as individual message strings.


Each string contains the destination ID (the ID of the computer that is to receive the message)
followed by the data:

<DestinationID><Data>

Messages may pass through several computers on the way to their destination.
When a message arrives at a computer, that is not the destination, the program needs to forward
it on to another computer using one of its serial ports.

The port to use is obtained from information that is stored in an array RouteTable.

RouteTable is a global 2D array of integers. It is declared in pseudocode as follows:

DECLARE RouteTable : ARRAY[1:6,1:3] OF INTEGER

The values in the first two columns of RouteTable define a range of ID values.
Column 3 gives the corresponding port number to use when forwarding the message to a computer
with an ID within this range.

For example, the contents of RouteTable could be:

Column 1 Column 2 Column 3


Row 1 100 199 1
Row 2 200 259 2
Row 3 −1 <undefined> <undefined>
Row 4 260 399 2
Row 5 400 599 3
Row 6 600 999 1

In this example, a message that arrives with a DestinationID of "283" will be forwarded using
port 2.

Row 3 in the example shows an unused row. These may occur anywhere. Unused rows have the
column 1 element set to −1. The value of unused elements in the other two columns is undefined.

© UCLES 2023 9618/22/O/N/23


17

The programmer has defined the first program module as follows:

Module Description
• takes a DestinationID as a parameter of type string
• searches for the range corresponding to the DestinationID
GetPort() in the array
• returns the port number, or returns −1 if no corresponding
range is found

(a) Write pseudocode for module GetPort().

Assume DestinationID contains a valid three-digit string.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]
© UCLES 2023 9618/22/O/N/23 [Turn over
18

(b) Copies of the same program will run on each computer. The program contains a global
variable MyID of type string, which contains the unique ID of the computer in which the
program is running.

When messages are received, they are placed on one of two stacks. Stack 1 is used for
messages that have reached their destination and stack 2 is used for messages that will be
forwarded on to another computer.

Additional modules are defined:

Module Description
• takes two parameters:
○ a string representing a message
StackMsg() ○ an integer representing the stack number
(already written) • adds the message to the required stack
• returns TRUE if the message is added to the required stack,
otherwise returns FALSE
• takes a message as a parameter of type string
• ignores any message with a zero-length data field
• extract the DestinationID from the message
• checks whether the DestinationID is this computer or
ProcessMsg() whether the message is to be forwarded
• uses StackMsg() to add the message to the appropriate
stack
• outputs an error if the message could not be added to the
stack

© UCLES 2023 9618/22/O/N/23


19

Write pseudocode for module ProcessMsg().

Module StackMsg() must be used.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2023 9618/22/O/N/23 [Turn over


20

(c) The program contains a module GetFile() which receives text files sent from another
computer.

Lines from the file are sent one at a time. Each message contains one line and ProcessMsg()
from part (b) adds each message as it is received onto stack 1.

Module GetFile() removes messages from stack 1 and writes the data to a text file.

There is a problem. Under certain circumstances, the received file does not appear as
expected.

Assume that while a file is being received ProcessMsg() receives only messages containing
lines from the file.

(i) Describe the circumstances and explain the problem.

Circumstances ..................................................................................................................

...........................................................................................................................................

Explanation .......................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................
[3]

(ii) Suggest a more appropriate Abstract Data Type that could be used to store the messages
that would not have the same problem.

..................................................................................................................................... [1]

Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the
publisher will be pleased to make amends at the earliest possible opportunity.

To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.

Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge
Local Examinations Syndicate (UCLES), which is a department of the University of Cambridge.

© UCLES 2023 9618/22/O/N/23


Cambridge International AS & A Level
* 1 7 9 0 6 9 5 1 7 2 *

COMPUTER SCIENCE 9618/23


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2023

2 hours

You must answer on the question paper.

You will need: Insert (enclosed)

INSTRUCTIONS
● Answer all questions.
● Use a black or dark blue pen.
● Write your name, centre number and candidate number in the boxes at the top of the page.
● Write your answer to each question in the space provided.
● Do not use an erasable pen or correction fluid.
● Do not write on any bar codes.
● You may use an HB pencil for any diagrams, graphs or rough working.
● Calculators must not be used in this paper.

INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].
● No marks will be awarded for using brand names of software packages or hardware.
● The insert contains all the resources referred to in the questions.

This document has 20 pages.

DC (LK/CT) 315870/2
© UCLES 2023 [Turn over
2

Refer to the insert for the list of pseudocode functions and operators.

1 A program is being developed in pseudocode before being converted into a programming


language.

(a) The following table shows four valid pseudocode assignment statements.

Complete the table by giving the data type that should be used to declare the variable
underlined in each assignment statement.

Assignment statement Data type

MyVar1 ← Total1 / Total2


MyVar2 ← 27/10/2023

MyVar3 ← "Sum1 / Sum2"

MyVar4 ← Result1 AND Result2


[4]

(b) Other variables in the program have example values as shown:

Variable Value
Active TRUE
Fraction 0.2
Code "Ab12345"

Complete the table by evaluating each expression using the example values.

Expression Evaluates to

Fraction >= 0.2 AND NOT Active

INT((Fraction * 100) + 13.3)

STR_TO_NUM(MID(Code, 4, 2)) + 5

LENGTH("TRUE" & Code)


[4]

© UCLES 2023 9618/23/O/N/23


3

(c) The program makes use of complex statistical functions. The required functions are not
built-in to the programming language and are too complicated for the programmer to write.

One solution would be to employ another programmer who has experience of writing these
functions, as there is no time to train the existing programmer.

State one other way that these functions may be provided for inclusion in the program.

...................................................................................................................................................

............................................................................................................................................. [1]

(d) The hardware that runs the program is changed and the program needs to be modified so
that it works with the new hardware.

Identify the type of maintenance that this represents and give one other reason why this type
of maintenance may be needed.

Type ..........................................................................................................................................

Reason .....................................................................................................................................

...................................................................................................................................................
[2]

© UCLES 2023 9618/23/O/N/23 [Turn over


4

2 Data is a 1D array of integers, containing 30 elements. All element values are unique.

(a) An algorithm will output the index of the element with the smallest value.

Draw a program flowchart to represent the algorithm.

START

END

[5]

© UCLES 2023 9618/23/O/N/23


5

(b) The 30 data values could have been stored in separate variables rather than in an array.

Explain the benefits of using an array when designing a solution to part (a).

...................................................................................................................................................

............................................................................................................................................. [2]

(c) The requirement changes. Array Data needs to hold 120 elements and each value may
include a decimal place.

Write a pseudocode statement to declare the modified array.

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2023 9618/23/O/N/23 [Turn over


6

3 The diagram represents a queue Abstract Data Type (ADT).

The organisation of this queue may be summarised as follows:

• The FrontOfQueue pointer points to the next data item to be removed.


• The EndOfQueue pointer points to the last data item added.

Queue

D3 ← FrontOfQueue
D4

D1

D2

D5 ← EndOfQueue

The queue is implemented using three variables and a 1D array of eight elements as shown. The
variable NumItems stores the number of items in the queue.

The pointer variables store indices (index numbers) of the array.

(a) Complete the diagram to represent the state of the queue as shown above.

Index Array

4 Variable

5 FrontOfQueue

6 EndOfQueue

7 NumItems 5

8
[3]

© UCLES 2023 9618/23/O/N/23


7

(b) A module AddTo() will add a value to the queue by manipulating the array and variables in
part (a).

The queue implementation is circular. When pointers reach the end of the queue, they will
‘wrap around’ to the beginning.

Before a value can be added to the queue, it is necessary to check the queue is not full.

The algorithm to add a value to the queue is expressed in six steps.

Complete the steps.

1. If NumItems .............................. then jump to step 6.

2. Increment ................................... .

3. If ................................................. then set EndOfQueue to .............................. .

4. Increment ................................... .

5. Set the ............................ at the index stored in ........................... to the ............................


being added.

6. Stop.

[6]

© UCLES 2023 9618/23/O/N/23 [Turn over


8

4 A procedure RandList() will output a sequence of 25 random integers, where each integer is
larger than the previous one.

(a) Write pseudocode for procedure RandList().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

© UCLES 2023 9618/23/O/N/23


9

(b) Procedure RandList() is modified so that the random numbers are also written into a
1D array Result.

A new module is written to confirm that the numbers in the array are in ascending order.

This module contains an IF statement that performs a comparison between elements:

IF (Result[x + 1] = Result[x]) OR (Result[x] > Result[x + 1]) THEN


Sequence FALSE ←
ENDIF

Write a simplified version of the conditional clause.

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [1]

© UCLES 2023 9618/23/O/N/23 [Turn over


10

5 A global 1D array of integers contains four elements, which are assigned values as shown:

Mix[1] ←4
Mix[2] ←2
Mix[3] ←3
Mix[4] ←5
A procedure Process() manipulates the values in the array.

The procedure is written in pseudocode as follows:

PROCEDURE Process(Start : INTEGER)


DECLARE Value, Index, Total : INTEGER

Index ← Start
Total ←0
WHILE Total < 20
Value ←Mix[Index]
Total ←Total + Value

IF Index < 4 THEN


Mix[Index] ←
Mix[Index] + Mix[Index+1]
ELSE
Mix[Index] ←
Mix[Index] + Mix[1]
ENDIF
Index ←
(Value MOD 4) + 1

ENDWHILE

Mix[1] ← Total * Index


ENDPROCEDURE

Complete the trace table on the opposite page by dry running the procedure when it is called as
follows:

CALL Process(2)

© UCLES 2023 9618/23/O/N/23


11

Index Value Total Mix[1] Mix[2] Mix[3] Mix[4]

[6]

© UCLES 2023 9618/23/O/N/23 [Turn over


12

6 A function TestNum() will take a six-digit string as a parameter.

The function will test whether the string meets certain conditions and will return an integer value
as follows:

Return value Condition Example


1 The last three digits are the same but non-zero. "253444"
2 The last three digits are zero. "253000"
3 The first three and last three digits are the same. "410410"

The function will return the highest possible value for the given string.

If the string does not meet any of the conditions, zero is returned.

© UCLES 2023 9618/23/O/N/23


13

Write pseudocode for function TestNum().

Assume that the parameter is valid.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [6]

© UCLES 2023 9618/23/O/N/23 [Turn over


14

7 A structure chart shows the modular structure of a program:

Module-A()

T1 RA
SA

RB

Sub-Y1() Sub-Y2() Sub-9()

(a) Explain the meaning of the curved arrow symbol which begins and ends at Module-A().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [2]

© UCLES 2023 9618/23/O/N/23


15

(b) The structure chart shows that Sub-9() is a function.

A Boolean value is returned by Sub-9() for processing by Module-A().

The original parameter RA is of type integer and RB is of type string.

A record type MyType will be defined with three fields to store the values passed between the
two modules.

(i) Write pseudocode to define MyType.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [3]

(ii) The design is modified and Sub-9() is changed to a procedure.

The procedure will be called with a single parameter of type MyType.

Write the pseudocode header for procedure Sub-9().

...........................................................................................................................................

..................................................................................................................................... [2]

© UCLES 2023 9618/23/O/N/23 [Turn over


16

8 A class of students are developing a program to send data between computers. Many computers
are connected together to form a wired network. Serial ports are used to connect one computer to
another.

Each computer:
• is assigned a unique three-digit ID
• has three ports, each identified by an integer value
• is connected to between one and three other computers.

Messages are sent between computers as a string of characters organised into fields as shown:

<STX><DestinationID><SourceID><Data><ETX>

Field name Description

a single character marking the start of the message


STX
(ASCII value 02)

DestinationID three numeric characters identifying the destination computer

SourceID three numeric characters identifying the source computer

a variable length string containing the data being sent


Data
(Minimum length is 1 character)
a single character marking the end of the message
ETX
(ASCII value 03)

For example, the following message contains the data "Hello Jack" being sent from computer
"202" to computer "454":

<STX>"454202Hello Jack"<ETX>

Each computer will run a copy of the same program. Each program will contain a global variable
MyID of type string which contains the unique ID of the computer in which the program is running.

The first two program modules are defined as follows:

Module Description

GetData()
• returns the data field from a message that has been received
(already written)
• If no message is available, the module waits until one has been
received.
• takes a file name as a parameter of type string
• creates a text file with the given file name (no checking required)
ReceiveFile()
• writes the data field returned by GetData() to the file
• repeats until the data field is "****", which is not written to the file
• outputs a final message giving the total number of characters
written to the file, for example:
132456 characters were written to newfile.txt

© UCLES 2023 9618/23/O/N/23


17

(a) Write pseudocode for module ReceiveFile().

Module GetData() has already been written and must be used.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

© UCLES 2023 9618/23/O/N/23 [Turn over


18

(b) The use of the string "****" as explained in the module description for ReceiveFile() may
cause a problem.

Explain the problem and suggest a solution.

Problem ....................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Solution .....................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

(c) Two new modules are defined, which will allow two users to exchange messages.

Module Description

• takes two parameters:


Transmit() ○ a string representing a message
(already written) ○ an integer representing a port number
• transmits the message using the given port
• takes two parameters:
○ a string representing a Destination ID
○ an integer representing a port number
Chat()
• extracts data from a received message using GetData() and
outputs it
• forms a message using data input by the user and sends it
using Transmit()
• repeats until either the output string or the sent string is "Bye"

Reminders:

• Each program contains a global variable MyID of type string which contains the unique ID of
the computer in which the program is running.
• Messages are sent between computers as a string of characters organised into fields as
shown:

<STX><DestinationID><SourceID><Data><ETX>

© UCLES 2023 9618/23/O/N/23


19

Write pseudocode for module Chat().

Modules GetData() and Transmit() must be used.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

.................................................................................................................................................... [7]

© UCLES 2023 9618/23/O/N/23 [Turn over


20

(d) Module GetData() returns the data field from a message that has been received. If no
message is available, the module waits until one has been received.

Explain the limitation of this on module Chat() from part (c).

Describe a modification to GetData() to address this limitation.

Limitation ..................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Modification ..............................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
[3]

Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the
publisher will be pleased to make amends at the earliest possible opportunity.

To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.

Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge
Local Examinations Syndicate (UCLES), which is a department of the University of Cambridge.

© UCLES 2023 9618/23/O/N/23

You might also like