Computer Science (9618) · May/June 2024 · Question paper 21
Cambridge Computer Science (9618) question paper for paper 21, May/June 2024 — 9618/21/M/J/24, file 9618_s24_qp_21.pdf.
Text of this paper
www.dynamicpapers.com
Cambridge International AS & A Level
* 8 4 1 6 1 0 0 9 4 2 *
COMPUTER SCIENCE
Paper 2 Fundamental Problem-solving and Programming Skills
9618/21
May/June 2024
2 hours
You must answer on the question paper.
You will need:
Insert (enclosed)
INSTRUCTIONS
●
Answer all questions.
●
Use a black or dark blue pen.
●
Write your name, centre number and candidate number in the boxes at the top of the page.
●
Write your answer to each question in the space provided.
●
Do not use an erasable pen or correction fluid.
●
Do not write on any bar codes.
●
You may use an HB pencil for any diagrams, graphs or rough working.
●
Calculators must not be used in this paper.
INFORMATION
●
The total mark for this paper is 75.
●
The number of marks for each question or part question is shown in brackets [ ].
●
No marks will be awarded for using brand names of software packages or hardware.
●
The insert contains all the resources referred to in the questions.
This document has 24 pages. Any blank pages are indicated.
DC (PQ/CGW) 329348/4
© UCLES 2024
[Turn over
www.dynamicpapers.com
2
Refer to the insert for the list of pseudocode functions and operators.
1
An algorithm is developed in pseudocode before being coded in a programming language.
(a) The following table shows four valid pseudocode assignment statements.
Complete the table by giving an appropriate data type to declare each of the variables A, B, C
and D.
Assignment statement
A
LEFT(MyName, 1)
B
Total * 2
C
INT(ItemCost) / 3
D
"Odd OR Even"
Data type
[4]
(b) Other variables in the program have example values as shown:
Variable
Value
Sorted
False
Tries
9
ID
"ZGAC001"
Complete the table by evaluating each expression, using the example values.
Expression
Evaluates to
Tries < 10 AND NOT Sorted
Tries MOD 4
TO_LOWER(MID(ID, 3, 1))
LENGTH(ID & "xx") >= Tries
© UCLES 2024
9618/21/M/J/24
[4]
3
www.dynamicpapers.com
(c) The variable names A, B, C and D in part (a) are not good programming practice.
(i)
State why these variable names are not suitable.
[1]
(ii)
Identify one problem that these variable names might cause.
[1]
(iii)
The choice of suitable variable names is one example of good programming practice.
Give one other example.
[1]
© UCLES 2024
9618/21/M/J/24
[Turn over
www.dynamicpapers.com
4
2
An algorithm has three steps. It will:
1.
2.
3.
repeatedly input a pair of numeric values A and B
count the number of pairs that are input until A has been greater than B 10 times
output the number of pairs that were input.
(a) Complete the program flowchart.
START
INPUT A, B
Yes
No
END
[5]
© UCLES 2024
9618/21/M/J/24
5
www.dynamicpapers.com
(b) Step 1 of the algorithm is changed.
A variable ThisSequence is used to enter a sequence of 10 pairs of numeric values, using
a single input statement.
Following the input of ThisSequence the revised algorithm will extract the pairs of numbers.
Describe the variable ThisSequence and how the numbers are extracted.
[2]
© UCLES 2024
9618/21/M/J/24
[Turn over
6
3
www.dynamicpapers.com
The diagram shows an Abstract Data Type (ADT) representation of a linked list after data items
have been added.
•
•
•
•
•
PS is the start pointer.
PF is the free list pointer.
Labels Df, Dc, Db and Dy represent the data items of nodes in the list.
Labels Fg, Fh, Fm and Fw represent the data items of nodes in the free list.
The symbol Ø represents a null pointer.
PS
Df
Dc
Db
Dy
Ø
Fg
Fh
Fm
Fw
Ø
PF
(a) Describe the linked list immediately after initialisation, before any data items are added.
[3]
© UCLES 2024
9618/21/M/J/24
7
www.dynamicpapers.com
(b) A program will be written to include a linked list to store alphanumeric user IDs.
The design uses two variables and two 1D arrays to implement the linked list.
Each array element contains data of a single data type and not a record.
The statements below describe the design.
Complete the statements.
The two variables will be of type .
The two variables will be used as to the arrays.
The values stored in the two variables will indicate
.
The first 1D array will be of type .
The first 1D array will be used to .
The second 1D array will be of type .
The second 1D array will be used to .
[5]
© UCLES 2024
9618/21/M/J/24
[Turn over
8
4
www.dynamicpapers.com
A global 1D array Data contains 100 elements of type integer.
A function Check() will:
•
•
•
total the element values in odd index locations (1, 3, 5 ... 97, 99)
total the element values in even index locations (2, 4, 6 ... 98, 100)
return one of three strings ‘Odd’, ‘Even’ or ‘Same’ to indicate which total is the greater, or
whether the totals are the same.
Write pseudocode for the function Check().
[6]
© UCLES 2024
9618/21/M/J/24
9
www.dynamicpapers.com
BLANK PAGE
© UCLES 2024
9618/21/M/J/24
[Turn over
10
5
www.dynamicpapers.com
A global 1D array of strings contains three elements which are assigned values as shown:
Data[1]
Data[2]
Data[3]
"aaaaaa"
"bbbbbb"
"cccccc"
Procedure Process() manipulates the values in the array.
The procedure is written in pseudocode as follows:
PROCEDURE Process(Format : STRING)
DECLARE Count, Index, L : INTEGER
DECLARE Result : STRING
DECLARE C : CHAR
Result
"****"
1 TO LENGTH(Format) STEP 2
FOR Count
MID(Format, Count, 1)
C
STR_TO_NUM(MID(Format, Count + 1, 1))
L
Index
(Count + 1) DIV 2
CASE OF C
'X' : Result
'Y' : Result
'Z' : Result
ENDCASE
Data[Index]
NEXT Count
TO_UPPER(Data[Index])
TO_LOWER(Data[Index])
"**" & Data[Index]
LEFT(Result, L)
ENDPROCEDURE
© UCLES 2024
9618/21/M/J/24
www.dynamicpapers.com
11
(a) Complete the trace table by dry running the procedure when it is called as follows:
CALL Process("X3Y2W4")
Count
C
L
Index
Result
Data[1]
Data[2]
Data[3]
[6]
(b) The procedure is to be modified. If variable C is assigned a value other than 'X', 'Y' or 'Z',
then procedure Error() is called and passed the value of variable C as a parameter.
This modification can be implemented by adding a single line of pseudocode.
(i)
Write the single line of pseudocode.
[1]
(ii)
State where this new line should be placed.
[1]
© UCLES 2024
9618/21/M/J/24
[Turn over
12
6
www.dynamicpapers.com
Three points on a grid form a triangle with sides of length A, B and C as shown in the example:
y
10
9
8
7
6
5
4
3
2
1
C
B
A
0
1
2
3
4
5
6
7
8
x
9 10
A triangle is said to be right-angled if the following test is true (where A is the length of the longest
side):
A2 = B2 + C2
A2 means A multiplied by A, for example 32 means 3 × 3 which evaluates to 9
You can calculate A2, B2 and C2 by using the coordinates of the endpoints of each line.
For example, B2 is calculated as follows:
y
10
9
8
7
6
5
4
3
2
1
0
P2
B
P1
1
2
(x2, y2)
(x1, y1)
3
4
5
6
7
8
9 10
x
The endpoints, P1 and P2, have the coordinates (3, 2) and (6, 6).
The value B2 is given by the formula:
B2 = (x1 − x2)2 + (y1 − y2)2
In this example:
B2 = (3 − 6)2 + (2 − 6)2
B2 = (–3)2 + (–4)2
B2 = 9 + 16
B2 = 25
© UCLES 2024
9618/21/M/J/24
13
www.dynamicpapers.com
(a) A function IsRA() will:
•
•
take three sets of integers as parameters representing the coordinates of the three
endpoints that form a triangle
return TRUE if the endpoints form a right-angled triangle, otherwise return FALSE.
In pseudocode, the operator ‘^’ represents an exponent, which is the number of times a value
is multiplied by itself. For example, the expression Value2 may be written in pseudocode as
Value ^ 2
Complete the pseudocode for the function IsRA().
FUNCTION IsRA(x1, y1, x2, y2, x3, y3 : INTEGER) RETURNS BOOLEAN
ENDFUNCTION
© UCLES 2024
[6]
9618/21/M/J/24
[Turn over
14
www.dynamicpapers.com
(b) The test used to check if a triangle is right-angled can be written in two ways:
A2 = B2 + C2
or
A = √(B2 + C2)
The symbol √ represents the square root operation. For example, √81 = 9
A new function SQRT() is written to perform the square root operation. The function takes an
integer number as a parameter and returns a positive real value representing the square root
of the number.
During testing it is found that the SQRT() function returns a value that is only accurate to
4 decimal places.
For example, SQRT(25) returns 5.0000125 rather than the correct value of 5.0
The function IsRA() from part (a) is modified to use the new SQRT() function to test if a
triangle is right-angled.
Describe a problem that might occur when using the modified IsRA() function and suggest
a solution that still allows the SQRT() function to be used.
Problem
Solution
[2]
© UCLES 2024
9618/21/M/J/24
15
www.dynamicpapers.com
BLANK PAGE
© UCLES 2024
9618/21/M/J/24
[Turn over
16
7
www.dynamicpapers.com
A fitness club has a computerised membership system. The fitness club offers a number of
different exercise classes.
The following information is stored for each club member: name, home address, email address,
mobile phone number, date of birth and the exercise(s) they are interested in.
(a) When an exercise class is planned, a new module will send personalised text messages to
each member who has expressed an interest in that exercise. Members wishing to join the
class send a text message back. Members may decide not to receive future text messages
by replying with the message ‘STOP’.
The process of abstraction is used to filter out unnecessary information.
(i)
State one advantage of applying abstraction to this problem.
[1]
(ii)
Identify three items of information that will be required by the new module.
Justify your choices with reference to the given scenario.
Item 1 required
Justification
Item 2 required
Justification
Item 3 required
Justification
[3]
(iii)
Identify two operations that would be required to process data when the new module
receives a text message back from a member.
Operation 1
Operation 2
[2]
© UCLES 2024
9618/21/M/J/24
www.dynamicpapers.com
17
(b) The structure chart illustrates part of the membership program:
Update
A
P2
Name
Sub-A
T1
P1
Sub-B
Sub-C
Data item notes:
•
•
Name contains the name of a club member
P1 and T1 are of type real.
(i)
Explain the meaning of the diamond symbol (labelled with the letter A) in the chart.
[2]
(ii)
Write the pseudocode module headers for Sub-A and Sub-B.
Sub-A
Sub-B
[4]
© UCLES 2024
9618/21/M/J/24
[Turn over
www.dynamicpapers.com
18
8
A teacher is designing a program to process pseudocode projects written by her students.
Each student project is stored in a text file.
The process is split into a number of stages. Each stage performs a different task and creates a
new file named as shown:
File name
Comment
MichaelAday_src.txt
student project file produced by student Michael Aday
MichaelAday_S1.txt
file produced by stage 1
MichaelAday_S2.txt
file produced by stage 2
The teacher has defined the first program module as follows:
Module
DeleteComment()
Description
• called with a parameter of type string representing a line of
pseudocode from a student’s project file
• returns the line after removing any comments
Note on comments:
A comment starts with two forward slash characters and includes all the
remaining characters on the line.
The following example shows a string before and after the comment has
been removed:
Before: IF X2 > 13 THEN
After: IF X2 > 13 THEN
© UCLES 2024
9618/21/M/J/24
//check if limit exceeded
19
www.dynamicpapers.com
(a) Complete the pseudocode for module DeleteComment().
FUNCTION DeleteComment(Line : STRING) RETURNS STRING
ENDFUNCTION
© UCLES 2024
[8]
9618/21/M/J/24
[Turn over
20
www.dynamicpapers.com
(b) A second module is defined:
Module
Stage_1()
Description
• called with a parameter of type string representing a student name
• creates a new stage 1 file
• copies each line from the student’s project file to the stage 1 file after
removing any comment from each line
• does not write blank lines to the stage 1 file
• returns the number of lines written to the stage 1 file
Write pseudocode for module Stage_1().
Module DeleteComment() must be used in your solution.
© UCLES 2024
9618/21/M/J/24
21
www.dynamicpapers.com
[7]
© UCLES 2024
9618/21/M/J/24
22
BLANK PAGE
© UCLES 2024
9618/21/M/J/24
www.dynamicpapers.com
23
BLANK PAGE
© UCLES 2024
9618/21/M/J/24
www.dynamicpapers.com
24
www.dynamicpapers.com
BLANK PAGE
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge
Local Examinations Syndicate (UCLES), which is a department of the University of Cambridge.
© UCLES 2024
9618/21/M/J/24