Cambridge International AS & A Level: Computer Science 9608/23
Cambridge International AS & A Level: Computer Science 9608/23
Cambridge International AS & A Level: Computer Science 9608/23
* 3 6 5 9 0 7 9 7 1 3 *
2 hours
INSTRUCTIONS
● Answer all questions.
● Use a black or dark blue pen.
● Write your name, centre number and candidate number in the boxes at the top of the page.
● Write your answer to each question in the space provided.
● Do not use an erasable pen or correction fluid.
● Do not write on any bar codes.
● You may use an HB pencil for any diagrams, graphs or rough working.
● Calculators must not be used in this paper.
INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].
● No marks will be awarded for using brand names of software packages or hardware.
DC (PQ/FC) 205019/2
© UCLES 2021 [Turn over
2
Write each example statement in program code and state the programming language used.
Programming
Activity Example statement in program code
language
OUTPUT
[5]
(b) An algorithm searches a 1D array to find the first index of an element that contains a given
value. If the value is found, the index of that element is returned.
(i) State an appropriate loop structure for this algorithm. Justify your choice.
Justification .......................................................................................................................
...........................................................................................................................................
[2]
(ii) Give two possible reasons why the search for the value in part (b)(i) would end.
1 ........................................................................................................................................
...........................................................................................................................................
2 ........................................................................................................................................
...........................................................................................................................................
[2]
(c) 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 pages 22 and 23 for the list of built-in pseudocode functions and
operators.
Statement Error
Code RIGHT("Cap" * 3, 2)
Valid IS_NUM(3.14159)
[3]
2 (a) After using a program for some time, a user notices a fault in the program.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(b) Good programming practice may help to avoid faults. The use of sensible identifier names is
one example of good practice.
...........................................................................................................................................
..................................................................................................................................... [1]
1 ........................................................................................................................................
2 ........................................................................................................................................
3 ........................................................................................................................................
[3]
(c) A programmer chooses data to test each path through her program.
Identify the type of testing that the programmer has decided to perform.
............................................................................................................................................. [1]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
Draw a program flowchart for an algorithm that will output each element in the array.
[4]
© UCLES 2021 9608/23/M/J/21 [Turn over
6
(c) The program flowchart for part of an algorithm from a mobile phone program is shown.
Identifier Active is a global variable of type BOOLEAN.
START
Is Online = NO
FALSE ?
YES END
Is Active = NO
TRUE ?
YES
CALL Reset()
CALL Sync()
Is Active = YES
FALSE ?
NO
CALL Error("No
Signal")
CALL ReCheck()
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
Refer to the Appendix on pages 22 and 23 for the list of built-in pseudocode functions and
operators.
Result 0
Count 1
IF Count < 3
THEN
RETURN -1
ELSE
RETURN Result
ENDIF
ENDFUNCTION
(a) (i) Complete the trace table by performing a dry run of the function when it is called as
follows:
Answer Check("74.0,4.6,3x2")
[5]
(ii) State the value returned by the function when it is called as shown in part (a)(i).
................................................ [1]
(b) A number group is a string of characters that represents an integer or decimal value. A comma
separates number groups.
The function Check() is intended to analyse the number groups in the parameter passed.
or
• −1 if there are less than three number groups in the string or if any non-numeric
characters occur in the string (other than decimal point and comma).
There is an error in the algorithm causing an incorrect value to be returned by the function.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(ii) Describe how the algorithm could be amended to correct the error.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [1]
(c) A dry run of a pseudocode algorithm may help to locate logic errors.
Give another type of program error and describe how it can occur.
Description ................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[2]
BLANK PAGE
5 A program stores a contact list of telephone numbers. Each telephone number is stored as a
string of six or more numeric characters.
Before they are displayed, number strings are formatted to make them easier to read. This involves
forming the characters into groups, separated by the space character.
Different numbers may have different groupings. A template string is used to define the grouping.
For example:
For the first row, template "53" results in a formatted string comprising:
(a) Write pseudocode for a function GroupNum(), which takes a telephone number and a
template as parameter strings and returns a formatted string.
You may assume that the template and telephone number are valid.
Refer to the Appendix on pages 22 and 23 for the list of built-in pseudocode functions and
operators.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
© UCLES 2021 9608/23/M/J/21
13
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
© UCLES 2021 9608/23/M/J/21 [Turn over
14
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
BLANK PAGE
6 A program stores data about stock items in four global 1D arrays as follows:
• Elements with the same index relate to the same stock item. For example, StockID[5]
contains the ID for the product whose description is in Description[5].
• The StockID array is not sorted and unused elements may occur at any index position.
• Unused elements are assigned the initial data value shown in the table above.
• The first four characters of the StockID represent a product group. The last four characters
represent the item within the group.
• data from the arrays are stored in a text file for backup purposes. Data from unused elements
are not stored in the file.
• a Summary array is added. This will be a global 1D array of 500 elements of type STRING.
Each product group will occur once in the array, for example "ABLK" for the item in the table
above.
Module Description
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
© UCLES 2021 9608/23/M/J/21 [Turn over
18
(b) Write program code for a module GroupReport(), which will summarise the stock data for
a given product group.
The product group will be passed to the module as a string. The total value of items is
calculated by multiplying the cost by the quantity.
Group: ABLK
Number of items in Group: 11
Total value of items in Group: 387.89
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
© UCLES 2021 9608/23/M/J/21
19
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
Module Description
• called with a STRING representing a product group
(for example, "ABLK")
Lookup()
• searches the Summary array for the group
• returns the index position or returns −1 if not found
• stores each product group name (found in the
StockID array) into the Summary array, if not there
already
GroupSummary() • calls Lookup() to check whether the name is
already in the Summary array
• returns the number of product groups added to the
Summary array
• all elements of the Summary array have been initialised to the value "" before
GroupSummary() is called
• there will be no more than 500 product groups.
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
© UCLES 2021 9608/23/M/J/21
21
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.
Operators (pseudocode)
Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE
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.