Download as pdf or txt
Download as pdf or txt
You are on page 1of 136

Cambridge A Level Computer Science

June 2020 - 9608/22 Pre-release material


IMPORTANT NOTICE

For the attention of the Exams Officer and the Computer Science
teacher.

IMPORTANT: This Cambridge A Level Computer Science 9608/22 pre-release


material is for candidates entered for Paper 22 examination in June 2020 only.

To maintain the security of our exams, we allocate all Cambridge schools to one of six
administrative zones. Different components are offered in the different administrative
zones. The Cambridge Guide to Making Entries (available from the ‘Support Materials’
section of CIE Direct) contains details of the components that are offered in your
administrative zone. You can find out which administrative zone you are in at
www.cambridgeinternational.org/preparation.

It is your responsibility to prepare candidates for their A Level Computer Science


examination using the pre-release material for the correct component. If you are
unsure of the component that your candidates will be entered for, and therefore the
pre-release material to download, please contact info@cambridgeinternational.org

Please note section 5.5.4 (h) of the Cambridge Handbook 2020.

If you discover that you have prepared candidates for the examination using an
incorrect version of the pre-release material please contact Cambridge International
immediately.

1
Cambridge International AS & A Level

COMPUTER SCIENCE 9608/22


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

PRE-RELEASE MATERIAL
* 6 4 8 7 7 3 5 4 3 2 *

No additional materials are needed.

This material should be given to the relevant teachers and candidates as soon as it has been
received at the centre.

INSTRUCTIONS
● You should use this material in preparation for the examination.
● You should attempt the practical programming tasks using your chosen high-level, procedural
programming language.

This document has 8 pages. Blank pages are indicated.

DC (KS) 198989
© UCLES 2020 [Turn over
2

Teachers and candidates should read this material prior to the June 2020 examination for 9608 Paper 2.

Reminders

The syllabus states:

• there will be questions on the examination paper which do not relate to this pre-release material.
• you must choose a high-level programming language from this list:

o Visual Basic (console mode)


o Python
o Pascal / Delphi (console mode)

Note: A mark of zero will be awarded if a programming language other than those listed is used.

Questions on the examination paper may ask the candidate to write:

• structured English
• pseudocode
• program code

A program flowchart should be considered as an alternative to pseudocode for documenting an


algorithm design.

Candidates should be confident with:

• the presentation of an algorithm using either a program flowchart or pseudocode


• the production of a program flowchart from given pseudocode and vice versa.

Some tasks may need one or more of the built-in function or operators listed in the Appendix at the
end of this document. There will also be a similar appendix at the end of the question paper.

Declaration of variables

The syllabus document shows the syntax expected for a declaration statement in pseudocode.

DECLARE <identifier> : <data type>

If Python is the chosen language, each variable’s identifier (name) and its intended data type must be
documented using a comment statement.

Structured English – Variables

An algorithm in pseudocode uses variables, which should be declared. An algorithm in structured


English does not always use variables. In this case, the candidate needs to use the information given
in the question to complete an identifier table. The table needs to contain an identifier, data type and
description for each variable.

© UCLES 2020 9608/22/PRE/M/J/20


3

TASK 1 – Structure charts

Describe a processing activity that can be represented by one main task with two or more sub-tasks.
The activity can relate to any scenario, but should include aspects of selection and iteration.

Activity examples may be taken from different areas, such as:

• school or college
• factory or workplace
• clubs or hobbies.

TASK 1.1

Consider how a problem is decomposed by splitting it into smaller parts.

Discuss the advantages of this approach.

TASK 1.2

Design a modular program to implement the activity described in TASK 1.

Produce a structure chart to represent the modular structure of the solution.

The structure chart should address:

• the sequence of module execution


• any module selection or iteration
• the parameters that are passed between the modules.

TASK 1.3

For each module, decide whether the solution should be implemented as a procedure or a function.

Justify your choices.

Produce pseudocode headers for each module.

© UCLES 2020 9608/22/PRE/M/J/20 [Turn over


4

TASK 2 – Algorithms, arrays and pseudocode

Declare an array to store multiple pieces of data for your activity in TASK 1. For example, a 1D array of
STRING could store the names of students in a class.

TASK 2.1

Design an algorithm to search for a specific value in the array and output the array index where the
value is found.

Consider the differences between algorithms that search for a single rather than multiple instances of
the value.

Document the algorithm using:

• structured English
• a program flowchart
• pseudocode.

TASK 2.2

Design an algorithm to manipulate data in the array, for example by sorting.

Document the algorithm as in TASK 2.1.

TASK 3 – Programs containing several components

A library maintains a list of books. The list is saved in a text file, where each line of the file represents
one book.

TASK 3.1

Consider the information that should be included in the text file other than the title and the author.

TASK 3.2

Consider that this is a text file, which means that all information will be saved in STRING format.

Consider the implications of storing numeric information, such as the number of copies of each book.

Define the format of each line of the file so that each piece of information may be easily extracted.

© UCLES 2020 9608/22/PRE/M/J/20


5

TASK 3.3

Design a program in pseudocode that has a menu-driven interface and will perform the following
tasks:

1. Add a new book to the text file. Include validation of the different pieces of information as
appropriate.

2. Search for books written by a given author. Output the title of any books found, or a suitable
message if no books by the given author are found.

3. End the program.

TASK 3.4 – Writing program code

Convert your pseudocode into program code.

TASK 3.5 – Testing

Consider how the program produced in TASK 3.4 may be tested.

TASK 4 – Algorithm modification

Additional information needs to be saved for each book, such as a publication date.

An additional task is needed to create a new file from the original file. The task will prompt the user to
input the additional information for each book.

Consider possible validation of the additional information.

Write program code for the additional task.

© UCLES 2020 9608/22/PRE/M/J/20 [Turn over


6

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", 4) returns "EFGH"

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

BLANK PAGE

© UCLES 2020 9608/22/PRE/M/J/20


8

BLANK PAGE

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

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

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

© UCLES 2020 9608/22/PRE/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
2

BLANK PAGE

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


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:hsharma99@stlmail.com"

A function, GetName(), is part of the program that processes the array. A data item string will be
passed to the function as a parameter. The function will return the Name part. Validation is not
necessary.

(a) Use structured English to describe the algorithm for the function GetName().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© 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


13

Question 6 begins on the next page.

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


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


18

BLANK PAGE

© 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


20

BLANK PAGE

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

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

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

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


Cambridge International AS & A Level

COMPUTER SCIENCE 9608/22


Paper 2 Written Paper May/June 2020
MARK SCHEME
Maximum Mark: 75

Published

Students did not sit exam papers in the June 2020 series due to the Covid-19 global pandemic.

This mark scheme is published to support teachers and students and should be read together with the
question paper. It shows the requirements of the exam. The answer column of the mark scheme shows the
proposed basis on which Examiners would award marks for this exam. Where appropriate, this column also
provides the most likely acceptable alternative responses expected from students. Examiners usually review
the mark scheme after they have seen student responses and update the mark scheme if appropriate. In the
June series, Examiners were unable to consider the acceptability of alternative responses, as there were no
student responses to consider.

Mark schemes should usually be read together with the Principal Examiner Report for Teachers. However,
because students did not sit exam papers, there is no Principal Examiner Report for Teachers for the June
2020 series.

Cambridge International will not enter into discussions about these mark schemes.

Cambridge International is publishing the mark schemes for the June 2020 series for most Cambridge
IGCSE™ and Cambridge International A & AS Level components, and some Cambridge O Level
components.

This document consists of 15 printed pages.

© UCLES 2020 [Turn over


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Generic Marking Principles

These general marking principles must be applied by all examiners when marking candidate answers.
They should be applied alongside the specific content of the mark scheme or generic level descriptors
for a question. Each question paper and mark scheme will also comply with these marking principles.

GENERIC MARKING PRINCIPLE 1:

Marks must be awarded in line with:

• the specific content of the mark scheme or the generic level descriptors for the question
• the specific skills defined in the mark scheme or in the generic level descriptors for the question
• the standard of response required by a candidate as exemplified by the standardisation scripts.

GENERIC MARKING PRINCIPLE 2:

Marks awarded are always whole marks (not half marks, or other fractions).

GENERIC MARKING PRINCIPLE 3:

Marks must be awarded positively:

• marks are awarded for correct/valid answers, as defined in the mark scheme. However, credit
is given for valid answers which go beyond the scope of the syllabus and mark scheme,
referring to your Team Leader as appropriate
• marks are awarded when candidates clearly demonstrate what they know and can do
• marks are not deducted for errors
• marks are not deducted for omissions
• answers should only be judged on the quality of spelling, punctuation and grammar when these
features are specifically assessed by the question as indicated by the mark scheme. The
meaning, however, should be unambiguous.

GENERIC MARKING PRINCIPLE 4:

Rules must be applied consistently e.g. in situations where candidates have not followed
instructions or in the application of generic level descriptors.

GENERIC MARKING PRINCIPLE 5:

Marks should be awarded using the full range of marks defined in the mark scheme for the question
(however; the use of the full mark range may be limited according to the quality of the candidate
responses seen).

GENERIC MARKING PRINCIPLE 6:

Marks awarded are based solely on the requirements as defined in the mark scheme. Marks should
not be awarded with grade thresholds or grade descriptors in mind.

© UCLES 2020 Page 2 of 15


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

1(a) One mark for name 3


Max two marks for description: one for each underlined word or phrase (or
equivalent)

Name: Sequence
Description: Instructions / lines of code are executed in a fixed order

OR

Name: Assignment
Description: A value is given to a variable

1(b) One mark per bullet point: 2

• Knowledge / experience of one programming language...

• ... can be applied to an unknown language // will help recognise control


structures (accept by example) in an unknown language

1(c) One mark per bullet point: 2

• Count controlled – the number of iterations is known / fixed

• Post condition – the number of iterations depends on some condition


being tested at the end / before the loop is repeated // at least one
iteration is always executed

For conditional: reject answer that also applies to pre-conditional

1(d) Examples include: 3

• context sensitive prompts


• (dynamic) syntax checking
• use of colours to highlight key words / pretty printing / highlighting unused
variables (etc)
• Formatting (incl. collapsing and expanding blocks)
• (UML) modelling
• Text editor (or by reference to a function such as copy & paste)
• Built-in (library) functions

Do not accept answers relating to debugging features

Max 3

© UCLES 2020 Page 3 of 15


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

2(a) One mark per bullet point: 2

• Parameters passed between modules // the interface between modules


• Module Iteration
• Module selection

Max 2

2(b)(i) Advantages include: 3

• Easier to solve / implement / program the solution as online shopping is


a complex task

• Easier to debug / maintain as each module can be tested separately e.g.


test FillBasket() first then test Checkout()

• Tasks may be shared among a team of programmer. e.g. Checkout()


and Search() modules could be developed in parallel / by teams with
different expertise

Note:
Must include reference to given scenario to achieve all 3 marks - Max 2 if no
reference.

© UCLES 2020 Page 4 of 15


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

2(b)(ii) 6

One Mark for


1 Three middle row boxes correctly labelled and connected to Shop()
2 Two bottom row boxes correctly labelled and connected to
FillBasket()
3 Iteration arrow on FillBasket()
4 Return parameters from ChooseSlot() and Checkout()
5 Return parameters from Search()
6 Two input parameters to Add()

Notes:
Parameter types must be as shown but ignore parameter names (if given)

© UCLES 2020 Page 5 of 15


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

3 FUNCTION CheckCourse(Course : REAL) RETURNS INTEGER 7


DECLARE Adjust, Check : INTEGER

Check ← INT(Deviate(Course))
Adjust ← 255

CASE OF Check
-20 to -1: Adjust ← 10
0 : Adjust ← 0
1 to 20 : Adjust ← -10
OTHERWISE CALL Alert()
ENDCASE

RETURN Adjust

ENDFUNCTION

1 mark for each of the following:

1 FUNCTION heading and ending including parameter as given above


2 Assign value to Check using integer conversion and intialise Adjust to
255
3 CASE ... ENDCASE
4 Conditions −20 to −1 and 1 to 20 (and corresponding assignments)
5 Condition 0 (and corresponding assignment)
6 OTHERWISE
7 Return Adjust

© UCLES 2020 Page 6 of 15


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

4(a) DECLARE Random : ARRAY [1:10] OF INTEGER 6


DECLARE NextNum, Index, Rnum : INTEGER
DECLARE Exists : BOOLEAN

NextNum ← 1 // index position for the next random number

REPEAT
Rnum ← INT(RAND(100)) + 1 // from original question
Exists ← FALSE
FOR Index ← 1 to NextNum - 1 // search for Rnum
IF Random[Index] = Rnum
THEN
Exists ← TRUE
ENDIF
ENDFOR

IF Exists = FALSE
THEN
Random[NextNum] ← Rnum // store Rnum
NextNum ← NextNum + 1 // increment index
ENDIF
UNTIL NextNum > 10

1 mark for each of the following:

1 Conditional (outer) loop to generate 10 values


2 Inner loop to search array for duplicate number
3 Check for duplicate by comparing number generated with array element
in a loop
4 Avoid checking uninitialised elements // array initialisation to rogue value
at start of algorithm
5 If Rnum is a duplicate then repeat outer loop
6 If Rnum not a duplicate then assign to array element and Increment
index

Notes:
Max 5 if statement to generate random number (as given in Q) not present or
incorrectly placed.

4(b) Adaptive Maintenance 1

© UCLES 2020 Page 7 of 15


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

5(a) Mark as follows: 7


1 SET Name to ""
2 SET Index to 1
3 SELECT the character from input parameter string at Index position
4 IF character is not colon then concatenate character with Name
5 …INCREMENT Index
6 …REPEAT from step 3
7 RETURN Name

Alternative Solution:

Mark as follows:
1 SET Index to 1
2 SELECT the character from input parameter string at Index position
3 IF character is colon then go to 5
4 Else INCREMENT Index and repeat from 2
5 Extract a substring from the left of the parameter string (and assign this to
variable Name)
6 ...Using Index -1 for the length
7 RETURN Name

Note:
Mark points may be combined for equivalent marks
e.g a suitable structured English description of the pseudocode statement
below satisfies MP 5, 6 and 7:

RETURN LEFT(ParamString, Index – 1)

5(b)(i) Description: 4

• Reduce the number of items to be checked by one after each pass

• Use a flag variable to stop the outer loop


• ... after no more swaps made on a single pass of the inner loop
• ... resetting before the inner loop starts, and setting it whenever a swap is
made

© UCLES 2020 Page 8 of 15


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

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

PROCEDURE BubbleSort()
DECLARE Temp : STRING
DECLARE NoSwaps : BOOLEAN
DECLARE Boundary, J : INTEGER

Boundary ← 999
REPEAT
NoSwaps ← TRUE
FOR J ← 1 TO Boundary
IF Contact[J] > Contact[J+1]
THEN
Temp ← Contact[J]
Contact[J] ← Contact[J+1]
Contact[J+1] ← Temp
NoSwaps ← FALSE
ENDIF
ENDFOR
Boundary ← Boundary - 1
UNTIL NoSwaps = TRUE

ENDPROCEDURE

Mark as follows:

1 Procedure heading and ending


2 Outer loop
3 Inner loop
4 Correct comparison in a loop
5 Correct swap of array elements in a loop
6 'NoSwap' mechanism: Post-conditional outer loop including flag reset
7 'NoSwap' mechanism: Set flag in inner loop to indicate swap
8 Reducing Boundary in the outer loop

© UCLES 2020 Page 9 of 15


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

6(a)(i) FUNCTION AddTime(StartTime : STRING, Duration : INTEGER)_ 8


RETURNS STRING

DECLARE NewTime : STRING


DECLARE StartMinutes, StartHours : INTEGER
DECLARE Total, NewMinutes, NewHours : INTEGER

StartHours ← STRING_TO_NUM(LEFT(StartTime,2))
StartMinutes ← STRING_TO_NUM(RIGHT(StartTime, 2))
Total ← (StartHours * 60) + StartMinutes + Duration
NewHours ← DIV(Total, 60)
NewMinutes ← MOD(Total, 60)

NewTime ← ""

IF NewHours < 10
THEN
NewTime ← '0' // add leading zero to hours
ENDIF

NewTime ← NewTime & NUM_TO_STRING(NewHours) & ':'

IF NewMinutes < 10
THEN
NewTime ← NewTime & '0'// add leading zero
ENDIF

NewTime ← NewTime & NUM_TO_STRING(NewMinutes)

RETURN NewTime

ENDFUNCTION

1 mark for each of the following:

1 Function heading and ending including parameters


2 Extract StartHours and convert to integer
3 Extract StartMinutes and convert to integer
4 Add Duration to StartTime in minutes
5 Use DIV() to extract NewHours
6 Use MOD() to extract NewMinutes
7 Adding leading zeros when necessary to hours and minutes eg “09:05”
8 Return concatentated string

Note:
Accept alternative methods for calculation of NewHours and NewMinutes

6(a)(ii) To test every path through the algorithm 1

6(a)(iii) • Logical error 2


• Algorithm is incorrect // program produces unexpected result / incorrect
calculation is performed

© UCLES 2020 Page 10 of 15


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Question Answer Marks

6(b) Test data: 2


Any string value where hours are > “24” or minutes > “59”

Explanation:
Suitable explanation

Note:
Accept times that would also be invalid for the given scenario.

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

PROCEDURE GetTotals()

DECLARE BoatNum : INTEGER


DECLARE Paid : REAL
DECLARE FileLine : STRING

FOR BoatNum ← 1 TO 17
Total[BoatNum] ← 0
ENDFOR

OPENFILE "Hirelog.txt" FOR READ

WHILE NOT EOF("Hirelog.txt")


READFILE "Hirelog.txt", FileLine
BoatNum ← STRING_TO_NUM(LEFT(FileLine, 2))
Paid ← STRING_TO_NUM (RIGHT(FileLine,__
LENGTH(Fileline) – 8))
Total[BoatNum] ← Total[BoatNum] + Paid

ENDWHILE

CLOSEFILE "Hirelog.txt"

ENDPROCEDURE

One mark for each of the following:

1 Procedure heading and ending (where appropriate) with no parameters


2 Initialisation of elements in Total array
3 OPEN "Hirelog.txt" in read mode and CLOSE after use
4 Loop until EOF()
5 Read line from file in a loop
6 Extract and convert BoatNum
7 Extract and convert Paid
8 Update appropriate array total in a loop

© UCLES 2020 Page 11 of 15


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Program Code Example Solutions


To be reviewed at STM

Q5(b)(i): Visual Basic

Sub BubbleSort()
Dim Temp As String
Dim NoSwaps As Boolean
Dim Boundary, J As Integer

Boundary = 999
Do
NoSwaps = TRUE
For J = 1 To Boundary
If Contact(J) > Contact(J+1) Then
Temp = Contact(J)
Contact(J) = Contact(J+1)
Contact(J+1) = Temp
NoSwaps = FALSE
End If
Next
Boundary = Boundary - 1
Loop Until NoSwaps = TRUE

End Sub

Q5(b)(i): Pascal

procuedre BubbleSort()
var
Temp : String;
NoSwaps : Boolean;
Boundary, J : Integer;

Boundary := 999
repeat
begin
NoSwaps := TRUE
for J := 1 to Boundary do
begin
if Contact[J] > Contact[J+1]then
begin
Temp := Contact[J];
Contact[J] := Contact[J+1];
Contact[J+1] := Temp;
NoSwaps := FALSE;
end;
end;

Boundary := Boundary – 1
end;
until NoSwaps = TRUE;

End Sub

© UCLES 2020 Page 12 of 15


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Q5(b)(i): Python

def BubbleSort()
# Temp : String
# NoSwaps : Boolean
# Boundary, J : Integer

Boundary = 999
NoSwaps = TRUE

while NoSwaps == TRUE:


NoSwaps = TRUE
For J in range(Boundary + 1)
If Contact[J] > Contact[J+1]:
Temp = Contact[J]
Contact[J] = Contact[J+1]
Contact[J+1] = Temp
NoSwaps = FALSE

Boundary = Boundary - 1

End Sub

Q6(c): Visual Basic

Sub GetTotals()

Dim BoatNum As Integer


Dim Paid As Real
Dim File As StreamReader("Hirelog.txt")

For BoatNum = 1 To 17
Total(BoatNum) = 0
Next

Do While File.Peek >= 0


FileLine = File.ReadLine()
BoatNum = CInt(Left(FileLine, 2))
Paid = CSng(Right(FileLine, Len(Fileline) – 8))
Total(boatnumber) = Total(boatbnumber) + Paid
Loop

File.Close()

End Sub

© UCLES 2020 Page 13 of 15


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Q6(c): Pascal

procedure GetTotals()

var
BoatNum : Integer;
Paid : Real;
MyFile : testfile;

for BoatNum := 1 to 17 do
Total[BoatNum] := 0;

assignFile(MyFile, "Hirelog.txt");
reset(MyFile);

while not eof(MyFile) do


begin
readln(MyFile, FileLine);
BoatNum = StrToInt(copy(FileLine, 1, 2));
Paid = StrToFloat(copy(FileLine, 9, length(Fileline) – 8));
Total(boatnumber) = Total(boatbnumber) + Paid;
end;

close(MyFile)

end;

Alternative FreePascal string functions) :

BoatNum := LeftStr(FileLine, 2);

Paid := StrToFloat(RightStr(FileLine, length(Fileline) – 8));

© UCLES 2020 Page 14 of 15


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2020
PUBLISHED

Q6(c): Python

def GetTotals()

# BoatNum : Integer
# Paid : Real
# File : File Handle
# FileData : String

For BoatNum in range (1, 18)


Total[BoatNum] = 0
Next

File = open("Hirelog.txt", "r")


FileData = File.readline()
while FileData != "":
FileLine = File.ReadLine()
BoatNum = int(FileLine[1, 3])
Paid = float(FileLine[8, len(Fileline) – 7))
Total[boatnumber] = Total[boatbnumber] + Paid
FileData = File.readline()

File.Close()

© UCLES 2020 Page 15 of 15


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


9

[7]
© UCLES 2020 9608/22/O/N/20 [Turn over
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


13

Question 5 begins on the next page.

© UCLES 2020 9608/22/O/N/20 [Turn over


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


20

BLANK PAGE

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

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

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

© UCLES 2020 9608/22/O/N/20


Cambridge International AS & A Level

COMPUTER SCIENCE 9608/22


Paper 2 Written Paper October/November 2020
MARK SCHEME
Maximum Mark: 75

Published

This mark scheme is published as an aid to teachers and candidates, to indicate the requirements of the
examination. It shows the basis on which Examiners were instructed to award marks. It does not indicate the
details of the discussions that took place at an Examiners’ meeting before marking began, which would have
considered the acceptability of alternative answers.

Mark schemes should be read in conjunction with the question paper and the Principal Examiner Report for
Teachers.

Cambridge International will not enter into discussions about these mark schemes.

Cambridge International is publishing the mark schemes for the October/November 2020 series for most
Cambridge IGCSE™, Cambridge International A and AS Level and Cambridge Pre-U components, and some
Cambridge O Level components.

This document consists of 24 printed pages.

© UCLES 2020 [Turn over


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Generic Marking Principles

These general marking principles must be applied by all examiners when marking candidate answers. They should be applied alongside the
specific content of the mark scheme or generic level descriptors for a question. Each question paper and mark scheme will also comply with these
marking principles.

GENERIC MARKING PRINCIPLE 1:

Marks must be awarded in line with:

• the specific content of the mark scheme or the generic level descriptors for the question
• the specific skills defined in the mark scheme or in the generic level descriptors for the question
• the standard of response required by a candidate as exemplified by the standardisation scripts.

GENERIC MARKING PRINCIPLE 2:

Marks awarded are always whole marks (not half marks, or other fractions).

GENERIC MARKING PRINCIPLE 3:

Marks must be awarded positively:

• marks are awarded for correct/valid answers, as defined in the mark scheme. However, credit is given for valid answers which go beyond the
scope of the syllabus and mark scheme, referring to your Team Leader as appropriate
• marks are awarded when candidates clearly demonstrate what they know and can do
• marks are not deducted for errors
• marks are not deducted for omissions
• answers should only be judged on the quality of spelling, punctuation and grammar when these features are specifically assessed by the
question as indicated by the mark scheme. The meaning, however, should be unambiguous.

GENERIC MARKING PRINCIPLE 4:

Rules must be applied consistently, e.g. in situations where candidates have not followed instructions or in the application of generic level
descriptors.

© UCLES 2020 Page 2 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
GENERIC MARKING PRINCIPLE 5:

Marks should be awarded using the full range of marks defined in the mark scheme for the question (however; the use of the full mark range may
be limited according to the quality of the candidate responses seen).

GENERIC MARKING PRINCIPLE 6:

Marks awarded are based solely on the requirements as defined in the mark scheme. Marks should not be awarded with grade thresholds or
grade descriptors in mind.

© UCLES 2020 Page 3 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED

Question Answer Marks

1(a) One mark for both answers: 1

• Process
• Output

Order not important.

1(b) One mark per bullet point (or equivalent) 2

They all represent:

• A solution to a problem / a way to perform a task


• Expressed as a sequence / series of steps / stages / instructions

1(c) 1 mark per row to max 4 marks 4

Example answers:
Data type Example data value

BOOLEAN FALSE

STRING "Happy"

INTEGER 18

REAL 31234.56

CHAR 'H'

DATE 10/01/2019

Each row must be a different data type together with an appropriate value

© UCLES 2020 Page 4 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

1(d) Max 3 marks, one mark for each correct line 3

© UCLES 2020 Page 5 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

1(e) 1 mark for two rows correct, 2 marks for all rows correct. 2

Expression Evaluates to

NOT FlagB AND FlagC TRUE

NOT (FlagB OR FlagC) FALSE

(FlagA AND FlagB) OR FlagC TRUE

NOT (FlagA AND FlagB) OR NOT FlagC TRUE

© UCLES 2020 Page 6 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

2(a) DECLARE A, B, C : INTEGER 6


DECLARE Average : REAL

INPUT A
REPEAT
INPUT B
UNTIL B <> A

REPEAT
INPUT C
UNTIL C <> A AND C <> B

Average ← (A + B + C) / 3
OUTPUT Average

IF A > B AND A > C


THEN
OUTPUT A
ELSE
IF B > A AND B > C
THEN
OUTPUT B
ELSE
OUTPUT C
ENDIF
ENDIF

Mark as follows:
1 Declaration of all variables used (at least A, B and C)
2 Uniqueness test on A, B and C
3 Loop(s) to repeat until three unique values have been entered
4 Calculation of average value
5 Determine the largest value
6 Output of average value and largest value

© UCLES 2020 Page 7 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

2(b) One mark per correct row 5


(Completed parts shown in bold)

Expression Evaluates to

"ALARM: " & RIGHT("Time: 1202",4) "ALARM: 1202"

MID("Stepwise.",5, 4) "wise"

1.5 * LENGTH("OnePointFive") 18

NUM_TO_STRING(27.5) "27.5"

DIV(9, 4) 2

2(c) One mark per point, example points: 3

1 Subtasks make the solution more manageable // make the algorithm easier to follow
2 A subtask makes the problem easier to solve / design / program than the whole task
3 A subtask is useful when a part of the algorithm is repeated

© UCLES 2020 Page 8 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

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

FUNCTION CheckSkid() RETURNS BOOLEAN


DECLARE Rot : ARRAY[1:4] OF INTEGER
DECLARE Average : REAL
DECLARE ThisRot : INTEGER
DECLARE Danger : BOOLEAN

FOR Index ← 1 TO 4
REPEAT
OUTPUT "Input Rotation speed for wheel ",Index
INPUT ThisRot
UNTIL ThisRot >= 0 AND ThisRot <= 1000
Rot[Index] ← ThisRot
ENDFOR

Average ← (Rot[1] + Rot[2] + Rot[3] + Rot[4]) / 4

Danger ← FALSE
FOR Index ← 1 TO 4
IF Rot[Index] > (Average * 1.1) OR Rot[Index] < (Average * 0.9)
THEN
Danger ← TRUE
ENDIF
ENDFOR

IF Danger = TRUE
THEN
OUTPUT "Skid Danger"
ENDIF

RETURN Danger

ENDFUNCTION

© UCLES 2020 Page 9 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

3(a) 1 mark for each of the following:

1 Function heading and ending


2 Declare local integers for 4 rotation values and a real for the average / tolerance
3 Prompt and input four rotation values
4 Validate each input value in a loop
5 Calculate average rotation AND calculate acceptable max and min (or single tolerance, or alternative method)
6 Compare rotational value of each wheel
7 Test if rotational value of (each) wheel is within the acceptable range
8 Output a warning message and return the correct value in all cases

3(b) Example answers: 2

Test1 – No Skid detected

Value 1 Value2 Value 3 Value 4

100 100 100 100

One of:

Test2 – Skid detected (one wheel too fast)

Value 1 Value2 Value 3 Value 4

100 100 100 160

Test2 – Skid detected (one wheel too slow)

Value 1 Value2 Value 3 Value 4

100 100 100 40

Independent marks: one mark each for Test1 and Test 2

© UCLES 2020 Page 10 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

4(a) 7

Mark as follows:
• One mark for START and END
• One mark per area outlined

Outputs from conditional diamond must have at least one label

© UCLES 2020 Page 11 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

4(b)(i) One mark per region as indicated. 5

Strin String RetFl Len NextCh


Len1 X New y
g1 2 ag 2 ar
"SUB" "BUS" 3 TRUE 1
3 'S' ""
"B" 1
"BU" 2
3

"BU" 2
2 'U' ""
1
"B" 2

"B" 3
1 'B' ""
1

""

© UCLES 2020 Page 12 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

4(b)(ii) TRUE 1

4(b)(iii) One mark for explanation of problem, one mark for test strings 2

Problem:

• The inner FOR loop removes ALL characters from String2 that match the current character from String1 and not just
one instance

Test Strings:

• ‘SAME’ and ‘MASS’ (for example)

4(b)(iv) The inner FOR loop should only remove one instance of the character from String2 1

4(b)(v) • Dry run // White-box testing 1

4(b)(vi) Max 2 marks, features include: 2

• Single stepping
• Breakpoints
• Variable and expressions report window
• Syntax error highlighting

© UCLES 2020 Page 13 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

5(a) PROCEDURE InitArrays() 4

DECLARE Index : INTEGER

FOR Index ← 1 TO 10000


TagString[Index] ← ""
TagCount[Index] ← 0
ENDFOR

ENDPROCEDURE

1 mark for each of the following:

1 Procedure heading and ending (as shown)


2 Declaration of Index (e.g.) as integer
3 Loop for 10000 iterations
4 Initialise TagString element to ""

© UCLES 2020 Page 14 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

5(b) FUNCTION SaveArrays() RETURNS INTEGER 8

DECLARE Index, NumUnused : INTEGER


DECLARE FileString : STRING
CONSTANT COMMA = ','

NumUnused ← 0

OPEN "Backup.txt" FOR WRITE


FOR Index ← 1 to 10000
IF TagString[Index] <> ""
THEN
FileString ← TagString[Index] & COMMA & NUM_TO_STRING(TagCount[Index])
WRITEFILE "Backup.txt", FileString
ELSE
NumUnused ← NumUnused + 1
ENDIF
ENDFOR
CLOSEFILE "Backup.txt"

RETURN NumUnused
ENDFUNCTION

1 mark for each of the following:

1 Function heading and ending


2 Open the file Backup.txt in write mode and close file
3 Loop through 10000 elements
4 Test if TagString[Index] is "" in a loop
5 If not then form FileString from array elements with separator and using NUM_TO_STRING()in a loop
6 Write string to file in a loop
7 Count the number of unused elements
8 Return NumUnused not in a loop

© UCLES 2020 Page 15 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

5(c) ‘Pseudocode’ solution included here for development and clarification of mark scheme. 8
Programming language example solutions appear in the Appendix.
Max 8 marks from 9 available mark points

FUNCTION LoadArrrays() RETURNS INTEGER

DECLARE ArrayIndex, Index, CountLen, Count : INTEGER


DECLARE FileString, HashTag : STRING
CONSTANT COMMA = ','

ArrayIndex ← 0 // first element

OPEN "Backup.txt" FOR READ


WHILE NOT EOF("Backup.txt")
READFILE "Backup.txt", FileString
Index ← 1
HashTag ← ""
WHILE MID(FileString, Index, 1) <> COMMA // hashtag
HashTag ← HashTag & MID(FileString, Index, 1)
Index ← Index + 1
ENDWHILE
TagString[ArrayIndex] ← HashTag
CountLen ← LENGTH(FileString) - LENGTH(HashTag) - 1
Count ← STR_TO_NUM(RIGHT(FileString, CountLen)) // count
TagCount[ArrayIndex] ← Count
ArrayIndex ← ArrayIndex + 1
ENDWHILE

CLOSE "Backup.txt"

RETURN ArrayIndex
ENDFUNCTION

© UCLES 2020 Page 16 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Question Answer Marks

5(c) 1 mark for each of the following:

1 Function heading and ending


2 Declare and initialise ArrayIndex (or equivalent name)
3 Open the file Backup.txt in read mode and close the file
4 Loop until end of the Backup.txt file // string read is null
5 Read a line from the file in a loop
6 Extract hashtag and count in a loop
7 Store hashtag in TagString array and count in TagCount array after type conversion
8 Increment ArrayIndex in a loop
9 Return number of array elements

*** End of Mark Scheme – example program code solutions follow ***

© UCLES 2020 Page 17 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Appendix: Program Code Example Solutions

Q3 (a): Visual Basic

Function CheckSkid() As Boolean

Dim Rot(3) As Integer


Dim Average As Double
Dim ThisRot As Integer
Dim Danger As Boolean

For Index = 0 To 3
Do
Console.Writeline("Enter Wheel Rotation Speed: "
ThisRot = Console.Readline()
Loop Until ThisRot >= 0 And ThisRot <= 1000
Rot(Index) = ThisRot
Next

Average = (Rot(0) + Rot(1) + Rot(2) + Rot(3)) / 4

Danger = FALSE
For Index = 0 TO 3
If Rot(Index) > (Average * 1.1) OR Rot(Index) < (Average * 0.9) Then
Danger = TRUE
End If
Next

If Danger = TRUE Then


Console.Writeline("Skid Danger")
Else
Console.Writeline("No Skid Danger")
End if

RETURN Danger

End Function

© UCLES 2020 Page 18 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q3 (a): Pascal

Function CheckSkid() : Boolean;

var
Rot : array [1..4] of integer;
Average : Real;
ThisRot : Integer;
Index : Integer;
Danger : Boolean;

For Index := 1 to 4 do
begin
repeat
write('Enter rotation speed : ');
readln(ThisRot);
until (ThisRot >= 0) And (ThisRot <= 1000);
Rot[Index] := ThisRot;
end;

Average := (Rot[1] + Rot[2] + Rot[3] + Rot[4]) / 4;

Danger := FALSE;
For Index := 1 to 4 do
begin
If (Rot[Index] > (Average * 1.1)) OR (Rot[Index] < (Average * 0.9)) then
Danger := TRUE;
end;

If Danger = TRUE then


writeln('Skid Danger')
Else
writeln('No Skid Danger');

CheckSkid := Danger;

end;

© UCLES 2020 Page 19 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q3 (a): Python

def CheckSkid():

# Rot[3] As Integer
# Average As Real
# ThisRot As Integer
# Danger As Boolean

Rot = [0, 0, 0, 0]
for Index in range(0, 4):
while True:
ThisRot = float(input("Enter the rotation speed of the wheel: "))
if ThisRot >= 0 and ThisRot <= 1000:
break
Rot[Index] = ThisRot
Next

Average = (Rot[0] + Rot[1] + Rot[2] + Rot[3]) / 4

Danger = False
for Index in range(0, 4):
if Rot[Index] > (Average * 1.1) or Rot[Index] < (Average * 0.9):
Danger = True

If Danger == True:
print("Skid Danger")
else:
print("No Skid Danger")

return Danger

© UCLES 2020 Page 20 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q5 (c): Visual Basic

Function LoadArrrays () As Integer

Dim ArrayIndex, Index, CountLen, Count As Integer


Dim FileString, HashTag As String
Dim File As New StreamReader("Backup.txt")

Const COMMA = ','

ArrayIndex = 0 ' First element

Do While File.Peek <> -1


FileString = File.ReadLine()
Index = 1
HashTag = ""
Do While Mid(FileString, Index, 1) <> COMMA ' the hashtag
HashTag = HashTag & MID(FileString, Index, 1)
Index = Index + 1
Loop

TagString(arrayIndex) = HashTag
CountLen = Len(fileString) – Len(HashTag) – 1
Count = CInt(Right(FileString, CountLen)) ' the count
TagCount(ArrayIndex) = Count
ArrayIndex = ArrayIndex + 1
Loop

File.Close

Return ArrayIndex
End Function

© UCLES 2020 Page 21 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q5 (c): Pascal

Function LoadArrrays () : Integer;

var
ArrayIndex, Index, CountLen, Count : Integer;
FileData, HashTag : String;
Backup : Textfile;

const
COMMA = ',';

begin
assignfile(Backup, 'Backup.txt');
reset(File);

ArrayIndex := 0; //First element

while not EOF(File) do


begin
readln(Backup, FileData);
Index := 1;
HashTag := "";
while midstr(FileData, Index, 1) <> COMMA do // the hashtag
begin
HashTag := HashTag + midstr(FileData, Index, 1);
Index := Index + 1;
end;

TagString[ArrayIndex] := HashTag;
CountLen := length(FileData) – length(HashTag) – 1;
Count := strtoint(RightStr(FileData, CountLen)); // the count
TagCount[ArrayIndex] := Count;
ArrayIndex := ArrayIndex + 1;
end;

closefile(File);

© UCLES 2020 Page 22 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
LoadArrays := ArrayIndex;

end;

© UCLES 2020 Page 23 of 24


9608/22 Cambridge International AS & A Level – Mark Scheme October/November 2020
PUBLISHED
Q5 (c): Python

def LoadArrays ():

# ArrayIndex, Index, CountLen, Count As Integer


# FileString, HashTag As String
# File As StreamReader("Backup.txt")

COMMA = ','

File = open("Backup.txt", "r")


ArrayIndex = 0 #First element

for FileString in File:


Index = 0
HashTag = ""
while FileString[Index] != COMMA: # the hashtag
HashTag = HashTag + FileString[Index]
Index = Index + 1

TagString[ArrayIndex] = HashTag
Count = int(FileString[Index+1:]) # the count
TagCount[ArrayIndex] = Count
ArrayIndex = ArrayIndex + 1

File.close()

return ArrayIndex

© UCLES 2020 Page 24 of 24


Cambridge International AS & A Level

COMPUTER SCIENCE 9608/22


Paper 2 Fundamental Problem-solving and Programming Skills October/November 2021

PRE-RELEASE MATERIAL
* 4 5 0 9 9 2 8 9 8 7 *

No additional materials are needed.

This material should be given to the relevant teachers and candidates as soon as it has been
received at the centre.

INSTRUCTIONS
● You should use this material in preparation for the examination.
● You should attempt the practical programming tasks using your chosen high-level, procedural
programming language.

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

DC (SLM) 220516
© UCLES 2021 [Turn over
2

Candidates and teachers should read this material prior to the November 2021 examination for 9608
Paper 2.

Reminders

The syllabus states:

• there will be questions on the examination paper which do not relate to this pre-release material.
• you must choose a high-level programming language from this list:
• Visual Basic (console mode)
• Python
• Pascal / Delphi (console mode).

Note: A mark of zero will be awarded if a programming language other than those listed is used.

Questions on the examination paper may ask the candidate to write:

• structured English
• pseudocode
• program code.

A program flowchart should be considered as an alternative to pseudocode for documenting an


algorithm design.

Candidates should be confident with:

• the presentation of an algorithm using either a program flowchart or pseudocode


• the production of a program flowchart from given pseudocode and vice versa.

Some tasks may need one or more of the built-in functions or operators listed in the Appendix at the
end of this document. There will also be a similar appendix at the end of the question paper.

Declaration of variables

The syllabus document shows the syntax expected for a declaration statement in pseudocode.

DECLARE <identifier> : <data type>

If Python is the chosen language, each variable’s identifier (name) and its intended data type must be
documented using a comment statement.

Structured English – Variables

An algorithm in pseudocode uses variables, which should be declared. An algorithm in structured


English does not always use variables. In this case, the candidate needs to use the information given
in the question to complete an identifier table. The table needs to contain an identifier, data type and
description for each variable.

© UCLES 2021 9608/22/PRE/O/N/21


3

TASK 1 – Structured programming

TASK 1.1

Describe a process using an algorithm written using structured English.

Use examples from:

• sports or leisure clubs


• college or school
• hotels.

TASK 1.2

Split the process into sub-tasks and consider the advantages of this approach.

TASK 1.3

Produce a structure chart for the design of this modular program.

TASK 1.4

Convert each of the sub-tasks into a program flowchart.

TASK 1.5

Convert the program flowcharts into pseudocode algorithms and then into a high-level language
program.

TASK 1.6

Research the different types of errors that can occur at different stages of the program development
cycle.

TASK 1.7

Consider the advantages of modular programming using both built-in and user-defined functions.

TASK 1.8

Consider ways of testing the complete program both with and without knowledge of the underlying
program code.

Consider ways of testing the main program before all the user-defined functions have been completed.

© UCLES 2021 9608/22/PRE/O/N/21 [Turn over


4

TASK 2 – Good programming practice

TASK 2.1

Discuss what is meant by good programming practice.

TASK 2.2

Design and write program code to declare, initialise and output the contents of a 1D array.

Implement different initialisation methods such as:

• Fill the complete array with a single value.


• Fill the array with an incrementing or decrementing sequence of values.
• Fill the array with values obtained using a programmed function, for example, a Fibonacci sequence.

Add a simple menu interface to allow the user to repeatedly select any of the previous stages and to
output the array elements.

Use good programming practice throughout.

TASK 2.3

Swap your program with one of your peers.

Amend this program so that it processes the elements in the array. An example of a process is to add
up all the elements in a range and find the average value.

TASK 2.4

Modify the program to work with a 2D array.

TASK 2.5

Describe in detail the purpose of a section of code you have not written yourself.

© UCLES 2021 9608/22/PRE/O/N/21


5

TASK 3 – File handling

The computer system at a sports club maintains a log of visits by each member.

Each time a member visits the club, an entry is added to a file as follows:

• Membership number (6 characters, for example "123456")


• Date of visit (8 characters, for example "28/09/20")

The system concatenates these data items and stores them as a single line in the file.

TASK 3.1

Write pseudocode to create a text file containing log data for several visits by the sports club members.

The user will input the two strings described above and these will be concatenated and added to the
file.

TASK 3.2

Write pseudocode to append a new data line to the existing file.

The process will repeat until a rogue value is input.

TASK 3.3

Write pseudocode to output a list of visits made by a sports club member.

Prompt the user to input the membership number and output the date of each visit by that member.

If the membership number is not found, output a suitable message.

TASK 3.4

Write program code for TASK 3.1 to TASK 3.3.

TASK 3.5

Extend the program from TASK 3.4 to present a menu to allow the user to repeatedly add a new visit
(TASK 3.2) or print the visits (TASK 3.3).

Use a suitable input value to terminate the program.

© UCLES 2021 9608/22/PRE/O/N/21 [Turn over


6

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

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 2021 9608/22/PRE/O/N/21


7

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 2021 9608/22/PRE/O/N/21


8

BLANK PAGE

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

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

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

© UCLES 2021 9608/22/PRE/O/N/21


Cambridge International AS & A Level
* 8 3 0 3 8 3 5 5 8 0 *

COMPUTER SCIENCE 9608/22


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

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. Any blank pages are indicated.

DC (CJ) 205021/2
© UCLES 2021 [Turn over
2

BLANK PAGE

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


3

1 (a) Maintenance of programs may be needed for a number of different reasons.

State two types of maintenance and give a reason why each may be needed.

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

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

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

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

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

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

(b) State why characters need to be represented in ASCII or Unicode before they can be
processed.

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

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

(c) Each line of a text file contains several data items. A special character is inserted between
data items before the line is written to the file.

Explain why a special character is used in this way.

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

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

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

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

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

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

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

Statement Error

Code RIGHT("Cap" & "art", 4)

Status MID("Computer", 7, 5)

Size LENGTH("Password") * 2

NextChar CHR('A')

Index Index & 3


[5]

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


4

2 Study the following pseudocode.

DECLARE Overload : BOOLEAN

PROCEDURE LEM()

DECLARE Status : BOOLEAN


DECLARE Landed : INTEGER

Overload FALSE
Landed FALSE

WHILE Landed = FALSE


Status Sample()
IF Status = TRUE
THEN
Landed SubA(42)
ELSE
Overload SubB(37)
IF Overload = TRUE
THEN
CALL Display("Alarm 1202")
ENDIF
ENDIF
ENDWHILE

ENDPROCEDURE

(a) Examine the pseudocode and complete the following table:

Answer

The identifier name of a global variable

The name of the loop structure

The identifier involved in a data type mismatch

The name of a procedure that takes a parameter

The name of a function

[5]

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


5

(b) Draw a program flowchart to represent the pseudocode algorithm.

Variable declarations are not required in program flowcharts.

[5]
© UCLES 2021 9608/22/M/J/21 [Turn over
6

3 (a) (i) Module names and parameters are features that may be represented on a structure
chart.

State two other features than can be represented on a structure chart.

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

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

(ii) The headers for three modules in a program are defined in pseudocode as follows:

Pseudocode module header


PROCEDURE Create(S2 : INTEGER, P3 : STRING)
PROCEDURE Modify(S2 : INTEGER, BYREF P4 : STRING)
FUNCTION Delete(P4 : INTEGER, M4 : STRING) RETURNS INTEGER

A fourth module, Membership(), may call any one of the three modules.

Draw a structure chart to represent the information given about the four modules.

[5]

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


7

(b) Draw a diagram to show the stages of the program development cycle. Use arrows to indicate
how the stages are linked.

[2]

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


8

4 (a) Using pseudocode, write a post-condition loop to output every odd number between 100
and 200.

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

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

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

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

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

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

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

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

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

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

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

(b) A program contains a global 2D array XRef. The array consists of 100 rows and 3 columns.
The array is of data type STRING.

A function, Search(), takes two parameters Par1 and Par2 as string values and returns an
integer value.

The function returns:

• the index number of the first row where:

• the element in column 1 of that row matches Par1 and


• either of the other two elements in that row match Par2

• –1 if no match found in any row.

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


9

Write program code for the function Search().

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 2021 9608/22/M/J/21 [Turn over
10

5 (a) An Integrated Development Environment (IDE) will be used to develop a program.

(i) An IDE includes features for program presentation.

State two of these presentation features.

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

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

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

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

(ii) Name two IDE features that can help with initial error detection.

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

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

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

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

(b) (i) A function, Verify(), is written in pseudocode.

Write the two missing lines to complete the pseudocode.

FUNCTION Verify(UserID : STRING) RETURNS BOOLEAN

..............................................
DECLARE Password : STRING
OUTPUT "Please Input your password: "
INPUT Password
Response Validate(UserID, Password) AND Today()

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

ENDFUNCTION
[2]

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


11

(ii) The function, Verify(), is to be amended as follows:

• if the UserID is "Guest", a password is not required and TRUE should be returned
• output a message to try again if the password entered is not valid
• return FALSE if the number of attempts to enter a valid password exceeds three.

Write program code for the amended function Verify().

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 2021 9608/22/M/J/21 [Turn over
12

6 A program stores data about stock items in four global 1D arrays as follows:

Example Initial data


Array Data type Description
data value value
the stock item ID
StockID STRING "JBCD0002" ""
(eight alpha-numeric characters)
a description of the item
Description STRING "soap" ""
(alphabetic characters only)
Quantity INTEGER the number in stock 9 0
Cost REAL the cost of the item 1.45 0.0

• Each array contains 10 000 elements.


• Elements with the same index relate to the same stock item. For example, StockID[3]
contains the ID for the product whose description is in Description[3].
• The StockID array is not sorted.

The program will be modified so that the data from the arrays can be stored in a text file for
backup. You may assume that a backup file contains only valid stock data.

The programmer has started to define program modules as follows:

Module Description
• called with two parameters:
• an array index
Unpack()
• a string value read from one line of the backup file
• extracts the four data values from the string and assigns each
to the appropriate array
• called with a string representing the name of a backup file
• returns FALSE if the file is empty
• sets all elements of each array to the initial data value as given
in the table
Restore() • reads the backup file line by line
calls Unpack() to extract data from each line and assign
values to the corresponding arrays
• returns FALSE if the arrays are full but there are still lines in the
file, otherwise returns TRUE
For all items where StockID does not contain the initial value:
• counts the number of stock entries in the StockID array
StockSummary() • outputs the overall value of all items in stock (cost multiplied by
the quantity)
• outputs the number of stock entries

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


13

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

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 2021 9608/22/M/J/21 [Turn over


14

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


15

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

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

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

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

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

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

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

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

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

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


16

(c) The module description of GetValidFilename() is as follows:

Module Description
• prompts and inputs a filename
• validates the filename by checking that it:
• is between 4 and 10 characters in length (inclusive)
GetValidFilename() • contains only alphanumeric characters
• if the filename is invalid, outputs a warning message and
asks the user to try again
• otherwise returns the valid filename

Write program code for the module GetValidFilename().

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


17

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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'

ASC(ThisChar : CHAR) RETURNS INTEGER


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

CHR(x : INTEGER) RETURNS CHAR


returns the character whose ASCII value is x
Example: CHR(87) returns 'W'

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


19

BLANK PAGE

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


20

BLANK PAGE

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

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

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

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


Cambridge International AS & A Level

COMPUTER SCIENCE 9608/22


Paper 2 Fundamental Problem-solving and Programming Skills May/June 2021
MARK SCHEME
Maximum Mark: 75

Published

This mark scheme is published as an aid to teachers and candidates, to indicate the requirements of the
examination. It shows the basis on which Examiners were instructed to award marks. It does not indicate the
details of the discussions that took place at an Examiners’ meeting before marking began, which would have
considered the acceptability of alternative answers.

Mark schemes should be read in conjunction with the question paper and the Principal Examiner Report for
Teachers.

Cambridge International will not enter into discussions about these mark schemes.

Cambridge International is publishing the mark schemes for the May/June 2021 series for most Cambridge
IGCSE™, Cambridge International A and AS Level components and some Cambridge O Level components.

This document consists of 20 printed pages.

© UCLES 2021 [Turn over


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Generic Marking Principles

These general marking principles must be applied by all examiners when marking candidate answers.
They should be applied alongside the specific content of the mark scheme or generic level descriptors
for a question. Each question paper and mark scheme will also comply with these marking principles.

GENERIC MARKING PRINCIPLE 1:

Marks must be awarded in line with:

• the specific content of the mark scheme or the generic level descriptors for the question
• the specific skills defined in the mark scheme or in the generic level descriptors for the question
• the standard of response required by a candidate as exemplified by the standardisation scripts.

GENERIC MARKING PRINCIPLE 2:

Marks awarded are always whole marks (not half marks, or other fractions).

GENERIC MARKING PRINCIPLE 3:

Marks must be awarded positively:

• marks are awarded for correct/valid answers, as defined in the mark scheme. However, credit
is given for valid answers which go beyond the scope of the syllabus and mark scheme,
referring to your Team Leader as appropriate
• marks are awarded when candidates clearly demonstrate what they know and can do
• marks are not deducted for errors
• marks are not deducted for omissions
• answers should only be judged on the quality of spelling, punctuation and grammar when these
features are specifically assessed by the question as indicated by the mark scheme. The
meaning, however, should be unambiguous.

GENERIC MARKING PRINCIPLE 4:

Rules must be applied consistently, e.g. in situations where candidates have not followed
instructions or in the application of generic level descriptors.

GENERIC MARKING PRINCIPLE 5:

Marks should be awarded using the full range of marks defined in the mark scheme for the question
(however; the use of the full mark range may be limited according to the quality of the candidate
responses seen).

GENERIC MARKING PRINCIPLE 6:

Marks awarded are based solely on the requirements as defined in the mark scheme. Marks should
not be awarded with grade thresholds or grade descriptors in mind.

© UCLES 2021 Page 2 of 20


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Mechanics of Marking:
Every mark given should have a corresponding tick on the script.

Every part question must be annotated to show that it has been read.

There are four pages that appear at the start of the script (including the Appendix page) that
must be annotated with the SEEN icon. The easiest way to do this is to go the first question
and select Zoom > ‘fit height’ then all six can be annotated at the same time without scrolling.

Do not put comments on the scripts. When scripts are returned to centres all the annotations
including comments, are visible.

If work has been crossed out and something written in its place, the replacement work is marked even
if the crossed-out work is correct. If the crossed-out work has not been replaced, mark the crossed-
out answer.

For single mark answers, mark the first answer on the line, unless there is a note to the contrary on
the mark scheme.

If a candidate writes something that is not enough (NE) for a mark, but is not actually incorrect,
continue reading, even if the mark scheme says, for example, mark first two answers.

The use of NR (No Response) is described in this extract from the RM Assessor guide:

For questions requiring program code, if the only thing that is written is the name of the program
language then award NE.

Annotation requirement for multi-page responses:

Question 6(b) and Question 6(c)

In each case, if the second page of the response (page 15 and page 17 respectively) is blank then
add the annotation ‘SEEN’ to the second page.

© UCLES 2021 Page 3 of 20


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

1(a) One mark for each type and one mark for corresponding reason (not 4
dependant)

Type: Corrective
Reason: Because the program does not function as intended / contains a
bug

Type: Adaptive
Reason: Change the program due to a requirement / specification /
legislative change

Type: Perfective
Reason: Improve the performance of the program / to enhance the program

Type: Preventive
Reason: Improve maintainability or reliability

1(b) One mark for: 1

• Program / computer / CPU can only process / store binary values.

• Standard encoding recognised by all programs / used to exchange


information

Note: Max 1 mark

1(c) One mark per bullet point: 2

• To provide a separator (or implied) between the data items


• Algorithm to extract / locate individual items from a line of text is
simplified
• The special character does not appear in the data

Note: Max 2 marks

© UCLES 2021 Page 4 of 20


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

1(d) 5
Statement Error

Code ← RIGHT("Cap" &


NO ERROR
"art", 4)

Status ← MID("Computer",
Not enough characters
7, 5)

Size ← LENGTH("Password")
NO ERROR
* 2

CHR() param should be integer //


NextChar ← CHR('A')
CHR() should be ASC()

3 is not character (should be ‘3’) //


Index ← Index & 3
and is not an arithmetic operator

One mark for each line

Question Answer Marks

2(a) 5
Answer

The identifier name of a global variable Overload

The name of the loop structure Pre-condition loop

The identifier involved in a type mismatch Landed

The name of a procedure that takes a Display()


parameter

Sample() //
The name of a function
SubA() // SubB()

One mark per row

© UCLES 2021 Page 5 of 20


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

2(b) 5

© UCLES 2021 Page 6 of 20


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

3(a)(i) One mark for each: 2

Module...

• Hierarchy / relationships
• Selection
• Repetition / Iteration
• Sequence

Note: Max 2 marks

3(a)(ii) 5

One mark for each of:


1 Diagram with all boxes correctly labelled, positioned as shown
2 Selection diamond as shown
3 (P3 and S2) and (P4 and M4) (Parameters to Create and Delete)
4 S2 and P4 (double arrow) (Parameters to Modify)
5 Return parameter from Delete()

© UCLES 2021 Page 7 of 20


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

3(b) 2
Design

Coding

Testing

One mark for:


• Design, Coding and Testing (in sequence)
• Arrows as shown // Alternative 'waterfall model' where each stage loops
back to the previous stage

Question Answer Marks

4(a) DECLARE Num : INTEGER 4


Num ← 101

REPEAT
OUTPUT Num
Num ← Num + 2
UNTIL Num > 199

Mark as follows:
1 Counter declaration and initialisation to sensible value before the loop
2 REPEAT ... UNTIL <condition>
3 Correct selection of number to be output (use of MOD() or +2 or other)
4 Correct range of numbers output

© UCLES 2021 Page 8 of 20


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

4(b) 'Pseudocode' solution included here for development and clarification of 7


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

FUNCTION Search(Par1, Par2 : STRING) RETURNS INTEGER

DECLARE Index, RetVal : INTEGER

Index ← 1
RetVal ← -1

WHILE Index <= 100 AND RetVal = -1


IF XRef[Index, 1] = Par1 _
AND (XRef[Index, 2] = Par2 OR XRef[Index, 3] = Par2)
THEN
RetVal ← Index
ENDIF
Index ← Index + 1
ENDWHILE

RETURN RetVal
ENDFUNCTION

Mark as follows:
1 Function heading and ending including parameters
2 Declaration of local variable for array index (Index) but not of global
XRef array
3 Any loop for 100 elements
4 Use of correct XRef 2D array syntax in a loop
5 Logical test of array elements in a loop
6 Exit loop if match found (following attempt at MP5)
Return index number or −1 if not found

Question Answer Marks

5(a)(i) One mark per point: 2

• Pretty print / Colour-coding of keywords / variables


• (Auto) indentation
• (Auto) Expansion / collapsing of data structures / code blocks //
thumbnail overview

Max 2 marks

5(a)(ii) One mark per point: 2

• Dynamic syntax checking / highlighting syntax errors as code is typed


• Type checking
• Checking for used variables not declared / unused variables which are
declared

Max 2 marks

© UCLES 2021 Page 9 of 20


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

5(b)(i) DECLARE Response : BOOLEAN 2


DECLARE Password : STRING
OUTPUT "Please Input your password: "
INPUT Password
Response ←Validate(UserID, Password) AND Today()
RETURN Response

One mark per line in bold

5(b)(ii) 'Pseudocode' solution included here for development and clarification of 6


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

FUNCTION Verify(UserID : STRING) RETURNS BOOLEAN


DECLARE Count : INTEGER
DECLARE Response : BOOLEAN
DECLARE Password : STRING

Count ← 1
Response ← FALSE

IF UserID = "Guest" THEN


Response ← TRUE
ENDIF

WHILE Response = FALSE AND Count < 4


OUTPUT "Please input your password: "
INPUT Password
Response ← Validate(UserID, Password) AND TODAY()
IF Response = FALSE THEN
IF Count < 3 THEN
OUTPUT "Incorrect password – please try again"
ENDIF
Count ← Count + 1
ENDIF
ENDWHILE

RETURN Response
ENDFUNCTION

1 mark for each of the following:

1 If parameter matches "Guest" then skip to Return (MP7)


2 Loop for max 3 attempts and terminate if valid password input
3 Prompt and Input first password attempt
4 Evaluate result of Validate() AND TODAY() in a loop...
5 Test result and increment count for incorrect password in a loop...
6 ...output 'try again' message and re-input password in a loop...
7 Return Boolean (correctly in all 3 cases)

Note: Max 6 marks

© UCLES 2021 Page 10 of 20


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

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


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

PROCEDURE StockSummary()
DECLARE Index, Count : INTEGER
DECLARE Total : REAL

Count ← 0
Total ← 0.0

FOR Index ← 1 TO 10000


IF StockID[Index]) <> "" THEN
Count ← Count + 1
Total ← Total + (Quantity[Index] * Cost[Index])
ENDIF
ENDFOR
OUTPUT "Total Value is ", Total
OUTPUT "Number of Stock Entries is ", Count

ENDPROCEDURE

One mark for each of the following:

1 Declaration and initialisation of Count and Total (by comment in


Python)
2 Loop for 10000 elements
3 Skip row when StockID element = "" in a loop
4 Increment Count and sum Total in a loop
5 OUTPUT the total and the count after the loop (following a reasonable
attempt at MP4)

© UCLES 2021 Page 11 of 20


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

6(b) FUNCTION Restore(Filename : STRING) RETURNS BOOLEAN 8

DECLARE Index : INTEGER


DECLARE FileLine : STRING
DECLARE Success : BOOLEAN

Success ← TRUE
OPENFILE Filename FOR READ
READFILE Filename, FileLine
IF FileLine = "" THEN //alt: IF EOF(filename)
CLOSEFILE Filename
RETURN FALSE //file is empty
ENDIF

FOR Index ← 1 TO 10000 //first initialise arrays


StockID[Index] ← ""
Description[Index] ← ""
Quantity[Index] ← 0
Cost[Index] ← 0.0 // 0
ENDFOR

Index ← 1 //starts loop with first FileLine


WHILE NOT EOF(Filename) AND Index <= 10000
CALL Unpack(Index, FileLine)
Index ← Index + 1
READFILE Filename, FileLine
ENDWHILE

IF Index = 10001 AND NOT EOF(Filename) THEN


Success ← FALSE
ENDIF
CLOSEFILE Filename

RETURN Success

ENDFUNCTION

1 mark for each of the following:

1 Function heading including input parameter and function End


2 Declare local variable for line read from file
3 OPEN file in READ mode and CLOSE
4 Check whether file is empty and return FALSE if it is (no restore
5 Loop through all 10 000 elements initialising arrays
6 Loop until EOF(Filename) OR Index > 10000
7 Call Unpack() correctly for each line from the file in a loop
8 Return FALSE if more than 10000 lines in file, otherwise returns TRUE

© UCLES 2021 Page 12 of 20


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question Answer Marks

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


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

FUNCTION GetValidFilename() RETURNS STRING


DECLARE Filename : STRING
DECLARE Valid : BOOLEAN
DECLARE Index : INTEGER
DECLARE NextChar : CHAR

REPEAT
Valid ← TRUE
OUTPUT "Please input the name for the backup file "
INPUT Filename
IF LENGTH(Filename) < 4 OR LENGTH(Filename) > 10
THEN
Valid ← FALSE
ELSE
Index ← 1
WHILE Index <= LENGTH(Filename) AND Valid = TRUE
NextChar ← MID(Filename, Index, 1)
IF NOT ((NextChar >='a' AND NextChar <='z')
OR (NextChar >='A' AND NextChar <='Z')
OR (NextChar >='0' AND NextChar <='9'))
THEN
Valid ← FALSE //not alphanumeric
ENDIF
Index ← Index + 1
ENDWHILE
ENDIF

IF Valid = FALSE THEN


OUTPUT "Invalid filename – please try again"
ENDIF

UNTIL Valid = TRUE


RETURN Filename
ENDFUNCTION

One mark for each of the following:


1 Conditional loop until valid filename input
2 Prompt and Input of filename in a loop
3 Test length is within range
4 Loop through filename:
5 Extract a single character
6 Test that character is numeric in a loop
7 Test that character is alphabetic in a loop
8 If filename invalid, output warning and repeat, if valid then return
filename
*** End of Mark Scheme – example program code solutions follow ***

Program Code Example Solutions

© UCLES 2021 Page 13 of 20


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question 4(b): Visual Basic

Function Search(Par1, Par2 As STRING) As INTEGER

Dim Index, RetVal As INTEGER

Index = 1
RetVal = -1

While Index <= 100 And RetVal = -1


If XRef(Index, 1) = Par1 _
AND (XRef(Index, 2) = Par2 OR XRef(Index, 3) = Par2) Then
RetVal = Index
End If
Index = Index + 1
End While

Return RetVal
End Function

Question 4(b): Pascal

function Search(Par1, Par2 : string) : integer;

var
Index : integer;
RetVal : integer;

begin

Index := 1;
RetVal := -1;

While Index <= 100 And RetVal = -1 do


begin
if XRef[Index, 1] = Par1
and (XRef[Index, 2] = Par2 or XRef[Index, 3] = Par2) then
RetVal := Index;

Index := Index + 1;
end;

Search := RetVal // result := RetVal


end;

© UCLES 2021 Page 14 of 20


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question 4(b): Python

def Search(Par1, Par2):

## Index, RetVal As INTEGER

Index = 1
RetVal = -1

while Index <= 100 and RetVal = -1:


if XRef[Index][1] == Par1 \
and XRef[Index][2] == Par2 or XRef[Index][3] == Par2:
RetVal = Index
Index = Index + 1

return RetVal

Question 5(b)(ii): Visual Basic

Function Verify(UserID As String) As Boolean


Dim Count As INTEGER
Dim Response As BOOLEAN
Dim Password As STRING

Count = 1
Response = FALSE

If UserID = "Guest" Then


Return TRUE
End If

While Response = FALSE And Count < 4


Console.Writeline("Please input your password: ")
Password = Console.Readline()
Response = Validate(UserID, Password) AND TODAY()
If Response = FALSE Then
Count = Count + 1
If Count < 4 Then
Console.Writeline("Incorrect password – please try again")
End If
End If
End While

Return Response

End Function

© UCLES 2021 Page 15 of 20


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question 5(b)(ii): Pascal

function Verify(UserID : string) : boolean;


var
Count : integer;
Response : boolean;
Password : string;

begin
Count := 1;

if UserID = "Guest" then


Verify := TRUE // result := TRUE;

while Response = FALSE And Count < 4


begin
writeln('Please input your password: ');
readln(Password);
Response := Validate(UserID, Password) and TODAY();
if Response = FALSE then
begin
Count := Count + 1;
if Count < 4 then
writeln('Incorrect password – please try again');
end;
end;

Verify := Response // result := Response

end;

Question 5(b)(ii): Python

def Verify(UserID):
## Count As INTEGER
## Response As BOOLEAN
## Password As STRING

Count = 1

if UserID == "Guest":
return TRUE

while Response == FALSE and Count < 4:


Password = input("Please input your password: ")
Response = Validate(UserID, Password) and TODAY()
if Response == FALSE:
Count = Count + 1
if Count < 4:
print("Incorrect password – please try again")

return Response

© UCLES 2021 Page 16 of 20


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question 6(a): Visual Basic

Sub StockSummary()
Dim Index, Count As Integer
Dim Total As Real

Count = 0
Total = 0.0

For Index = 1 To 10000


If StockID(Index) <> "" then
Count = Count + 1
Total = Total + (Quantity(Index)) * Cost(Index))
End If
Next Index

Console.writeline("Total Value is " & Total.toString)


Console.writeline("Number of Stock Entries is " & Count.toString)

End Sub

Question 6(a): Pascal

procedure StockSummary();

var
Index, Count : Integer;
Total : Real;

begin
Count := 0;
Total := 0.0;

for Index := 1 TO 10000 do


begin
if StockID[Index] <> "" then
begin
Count := Count + 1;
Total := Total + (Quantity[Index]) * Cost[Index]);
end;
end;

writeln('Total Value is ', Total);


writeln('Number of Stock Entries is ', Count);

end;

© UCLES 2021 Page 17 of 20


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question 6(a): Python

def StockSummary():

## Index, Count : Integer


## Total : Real

Count = 0
Total = 0.0

for Index in range(1, 10001):


if StockID[Index] <> "":
Count = Count + 1
Total = Total + (Quantity[Index]) * Cost[Index])

print("Total Value is ", Total)


print("Number of Stock Entries is ", Count)

Question 6(c): Visual Basic

Function GetValidFilename() As String


Dim Filename As String
Dim Valid As Boolean
Dim Index As Integer
Dim NextChar as Char

Valid = FALSE

Do
Valid = TRUE
Console.writeline("Please input the name for the backup file ")
Filename = Console.readline()
If Len(Filename) < 4 Or Len(Filename) > 10 Then
Valid = FALSE
Else
Index = 1
While Index <= Len(Filename) And Valid = TRUE
NextChar = MID(Filename, Index, 1)
If Not ((NextChar >='a' AND NextChar <='z') _
Or (NextChar >='A' AND NextChar <='Z')_
Or (NextChar >='0' AND NextChar <='9')) Then
Valid = FALSE //not alphanumeric
End If
Index = Index + 1
End While

End If

If Valid = FALSE Then


Console.writeline("Invalid filename – please try again")
End If

Loop Until Valid = TRUE


Return Filename
End Function

© UCLES 2021 Page 18 of 20


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Question 6(c): Pascal

function GetValidFilename() : String;


var
Filename : String;
Valid : Boolean;
Index : Integer;
NextChar : Char;

begin
Valid := FALSE;

repeat
Valid := TRUE;
writeln('Please input the name for the backup file ');
readln(Filename);
if length(Filename) < 4 Or length(Filename) > 10 then
Valid := FALSE
else
begin
Index := 1;
while Index <= length(Filename) And Valid = TRUE do
begin
NextChar := MidStr(Filename, Index, 1);
if Not ((NextChar >='a' AND NextChar <='z')
Or (NextChar >='A' AND NextChar <='Z'
Or (NextChar >='0' AND NextChar <='9')) then
Valid := FALSE; //not alphanumeric

Index := Index + 1;
end;
end;

If Valid = FALSE then


writeln('Invalid filename – please try again');

until Valid = TRUE;


result := Filename; // GetValidFilename := Filename
end;

Question 6(c): Python

def GetValidFilename():
## Filename As String
## Valid As Boolean
## Index As Integer
## NextChar As Char

Valid = FALSE

while not Valid:


Valid = TRUE
Filename = input("Please input the name for the backup file ")
if Len(Filename) < 4 or Len(Filename) > 10:
Valid = FALSE
else:
Index = 0
while Index <= Len(Filename) and Valid = TRUE:
NextChar = FileName[Index]
if not ((NextChar >= '0' and NextChar <= '9'
or (NextChar >= 'a' and NextChar <= 'z')
or (NextChar >= 'A' and NextChar <= 'Z'):

© UCLES 2021 Page 19 of 20


9608/22 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED

Valid = FALSE

Index = Index + 1

if Valid == FALSE:
print("Invalid filename – please try again")

return Filename

© UCLES 2021 Page 20 of 20

You might also like