Computer Science (9618) · Oct/Nov 2024 · Question paper 21
Cambridge Computer Science (9618) question paper for paper 21, Oct/Nov 2024 — 9618/21/O/N/24, file 9618_w24_qp_21.pdf.
Text of this paper
www.dynamicpapers.com
* 0000800000001 *
,
,
Cambridge International AS & A Level
¬W. 4mHuOªE_z5W
¬i9|R£^sI=ty§
¥u Uu5e5¥5EEE5¥UU
* 0 2 8 5 5 0 0 1 8 0 *
COMPUTER SCIENCE
Paper 2 Fundamental Problem-solving and Programming Skills
9618/21
October/November 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 20 pages. Any blank pages are indicated.
DC (DE/FC) 336146/4
© UCLES 2024
[Turn over
,
Refer to the insert for the list of pseudocode functions and operators.
A program will calculate the tax payable based on the cost of an item.
Calculations will occur at many places in the program and these involve the use of one of three tax
rates.
Tax rate values represent a percentage. For example, a tax rate value of 5.23 represents 5.23%.
In this case, the tax payable on an item costing $100 would be $5.23.
Tax rate values are used at several places within the program. One example is given in pseudocode
as follows:
← 3.75
← 5.23
← 6.25
← TRUE
←
// tax rate of 3.75%
// tax rate of 5.23%
// tax rate of 6.25%
* TaxRate // tax payable
(a) The pseudocode contains a logical error.
Identify the error and suggest a correction.
Error
Correction
[2]
(b) During the design of the program, tax rate values have been used wherever they are needed
as shown in the pseudocode example above. Tax rates do not change while the program runs.
(i)
Identify a more appropriate way of representing the tax rate values in the final program.
[1]
(ii)
Describe the benefits of your answer to part (b)(i) with reference to this program.
DO NOT WRITE IN THIS MARGIN
←
HighRate
FALSE
CASE OF ItemCost
<= 50 : TaxRate
<= 200 : TaxRate
> 200 : TaxRate
HighRate
ENDCASE
TaxPayable
ItemCost
DO NOT WRITE IN THIS MARGIN
1
DO NOT WRITE IN THIS MARGIN
2
,
DO NOT WRITE IN THIS MARGIN
www.dynamicpapers.com
* 0000800000002 *
[3]
© UCLES 2024
ĬÕĊ®Ġ´íÈõÏĪÅĊÞü·þ×
Ĭé»ûÓĩĚąÕîąæõĊëÁğĂ
ĥåĕÕµÕĥÕÕõĕąÅõąÕõÕ
9618/21/O/N/24
DO NOT WRITE IN THIS MARGIN
www.dynamicpapers.com
DO NOT WRITE IN THIS MARGIN
* 0000800000003 *
3
,
,
(c) Give the appropriate data type for the variables in the following table, as used in the
pseudocode:
Variable name
Data type
HighRate
[2]
(d) The final CASE condition (> 200) in the pseudocode example could be replaced with a
keyword.
Give the keyword.
[1]
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
TaxPayable
© UCLES 2024
Ĭ×Ċ®Ġ´íÈõÏĪÅĊÞú·þ×
Ĭé¼üÛğĖõäČüģáòïÁďĂ
ĥåĥĕõµąµÅąÅąÅĕĥĕĥÕ
9618/21/O/N/24
[Turn over
2
,
A program uses three global integer variables HH, MM and SS to represent the current time in
hours, minutes and seconds using the 24-hour clock notation.
Midnight would be represented as 00:00:00 (HH:MM:SS). If the variables HH, MM and SS contained
the values 16, 30 and 10 respectively, then the time would be 16:30:10 or just after 4.30 in the
afternoon.
A procedure Tick() will be called every second.
The procedure Tick() will:
•
update the value in SS each time it is called
•
update the values in HH and MM as appropriate
•
call a procedure CheckAlarm() at the start of each minute
•
call a procedure NewDay() whenever the time reaches midnight.
Complete the pseudocode for procedure Tick().
PROCEDURE Tick()
DO NOT WRITE IN THIS MARGIN
4
,
DO NOT WRITE IN THIS MARGIN
www.dynamicpapers.com
* 0000800000004 *
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
ENDPROCEDURE
© UCLES 2024
[6]
ĬÕĊ®Ġ´íÈõÏĪÅĊàü·Ā×
Ĭé¼ùÛĥĨô×ĆóĬăÎÍÑħĂ
ĥĕµĕµµąĕååµąąĕÅĕõÕ
9618/21/O/N/24
DO NOT WRITE IN THIS MARGIN
www.dynamicpapers.com
5
,
,
BLANK PAGE
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
* 0000800000005 *
© UCLES 2024
Ĭ×Ċ®Ġ´íÈõÏĪÅĊàú·Ā×
Ĭé»úÓģĬĄâôþÝ׿ĉÑėĂ
ĥĕÅÕõÕĥõµÕĥąąõåÕĥÕ
9618/21/O/N/24
[Turn over
6
3
,
An algorithm will output the last three lines from a text file Result.txt
The lines need to be output in the same order as they appear in the file.
Assume:
•
•
Three variables LineX, LineY and LineZ will store the three lines. These are of type string
and all three variables have been initialised to an empty string.
The file exists and contains at least three lines.
DO NOT WRITE IN THIS MARGIN
(a) The algorithm to output the lines is expressed in eight steps.
Complete the steps.
1.
Open the file
2.
Loop until
3.
and store in ThisLine
4.
Assign LineY to LineX
5.
Assign LineZ to LineY
6.
Assign ThisLine to LineZ
7.
After the loop,
8.
Output LineX, LineY, LineZ
[4]
(b) Explain the purpose of steps 4, 5 and 6 in the algorithm from part (a).
DO NOT WRITE IN THIS MARGIN
,
DO NOT WRITE IN THIS MARGIN
www.dynamicpapers.com
* 0000800000006 *
[1]
© UCLES 2024
ĬÙĊ®Ġ´íÈõÏĪÅĊÝú¶þ×
Ĭé¼úÐĩĄĊê÷ïØ·ÎĬùħĂ
ĥÅĥÕõõĥÕõµÅąÅõąĕµÕ
9618/21/O/N/24
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
www.dynamicpapers.com
DO NOT WRITE IN THIS MARGIN
* 0000800000007 *
7
,
,
(c) The requirement changes, and the algorithm will now output three lines from the file, starting
from a given line number.
The modified algorithm will be implemented as a function which will:
•
•
•
be called with an integer parameter representing the given line number
output three lines, starting at the given line
return TRUE if the 3 lines are output, or FALSE if it was not possible to output the 3 lines.
DO NOT WRITE IN THIS MARGIN
Describe the changes that need to be made to steps 2 to 8 of the algorithm given in part (a).
[4]
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
© UCLES 2024
ĬÛĊ®Ġ´íÈõÏĪÅĊÝü¶þ×
Ĭé»ùØğĀúÏāĂđģæ°ùėĂ
ĥÅĕĕµĕąµĥÅĕąÅĕĥÕåÕ
9618/21/O/N/24
[Turn over
8
,
4
,
A program includes the following assignment statement:
Result
← STR_TO_NUM(x) / STR_TO_NUM(y)
When the program evaluates the expression in the statement, it performs a calculation.
Variable Result is of type real and variables x and y are of type string.
DO NOT WRITE IN THIS MARGIN
www.dynamicpapers.com
* 0000800000008 *
1.
2.
The two strings represent valid numeric values.
The numeric value of string y is not zero.
(a) Identify the type of error that could occur if these checks are not carried out and state a
cause of this error.
Type
DO NOT WRITE IN THIS MARGIN
Two checks are required before the calculation is performed:
[2]
(b) The designer considers implementing the checks and calculation as a module (a procedure
or a function). One reason for this is that the same checks and calculations are performed at
several places in the program.
Give another reason why this is a suitable approach and state what is avoided by this
approach.
Reason
DO NOT WRITE IN THIS MARGIN
Cause
[2]
© UCLES 2024
ĬÙĊ®Ġ´íÈõÏĪÅĊßú¶Ā×
Ĭé»üØĥîïìÿĉĚÁĊĎĩğĂ
ĥõÅĕõĕąĕąĥĥąąĕÅÕµÕ
9618/21/O/N/24
DO NOT WRITE IN THIS MARGIN
Avoided
DO NOT WRITE IN THIS MARGIN
www.dynamicpapers.com
DO NOT WRITE IN THIS MARGIN
* 0000800000009 *
9
,
,
(c) The module to perform the checks and calculation will be implemented as a function. The
function will need to return both a real and a Boolean value. To achieve this a record type is
defined in pseudocode as follows:
TYPE Result
DECLARE Done : BOOLEAN
DECLARE Value : REAL
ENDTYPE
DO NOT WRITE IN THIS MARGIN
The function Evaluate() will:
•
•
•
take two parameters of type string representing the two numeric values
return a variable of type Result with the Done field set to FALSE if either of the following
applies:
◦
at least one of the strings does not represent a valid numeric value
◦
the numeric value of the string representing value y is zero
otherwise return a variable of type Result with the Done field set to TRUE and the
Value field assigned the result of the formula (based on the numeric value of the two
parameters).
DO NOT WRITE IN THIS MARGIN
Write pseudocode for the function Evaluate().
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
[6]
© UCLES 2024
ĬÛĊ®Ġ´íÈõÏĪÅĊßü¶Ā×
Ĭé¼ûÐģòÿÍùøÏĕòÊĩďĂ
ĥõµÕµõĥõĕĕµąąõåĕåÕ
9618/21/O/N/24
[Turn over
10
,
5
,
A software developer follows a program development life cycle. The life cycle divides the
development process into various stages.
(a) The following table lists some development activities.
Complete the table by writing the name of the life cycle stage for each activity.
Activity
Name of life cycle stage
DO NOT WRITE IN THIS MARGIN
www.dynamicpapers.com
* 0000800000010 *
DO NOT WRITE IN THIS MARGIN
The walkthrough method is used.
An algorithm is implemented in a programming language.
The client is interviewed about problems with the current system.
The program is modified to run on new hardware.
Records and file structures are defined.
(b) The program contains a validation function.
The function will:
•
•
•
take an integer value as a parameter
return TRUE if the value is within the range 24 to 37, inclusive
otherwise return FALSE.
Type of test data
Test data value
Expected result
Normal
30
TRUE
DO NOT WRITE IN THIS MARGIN
Complete the table to define a test plan to thoroughly test the operation of the function.
[4]
(ii)
The function is to be tested on its own. When it is shown to work correctly the function
will be combined with other modules and testing will continue.
Identify the type of testing that this represents.
[1]
© UCLES 2024
ĬÙĊ®Ġ´íÈõÏĪÅĊÞú¸þ×
ĬéºüÍħöĩæĈĂ´ÝČúÑėĂ
ĥååÕõĕåĕåÕĥÅąµÅÕąÕ
9618/21/O/N/24
DO NOT WRITE IN THIS MARGIN
(i)
DO NOT WRITE IN THIS MARGIN
[5]
www.dynamicpapers.com
11
,
,
BLANK PAGE
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
* 0000800000011 *
© UCLES 2024
ĬÛĊ®Ġ´íÈõÏĪÅĊÞü¸þ×
Ĭé¹ûÕġúęÓòïõùôÞÑħĂ
ĥåÕĕµõÅõµåµÅąÕåĕĕÕ
9618/21/O/N/24
[Turn over
12
,
6
,
A factory produces food items. The items must be used within a certain number of days after their
production date. The number of days is known as the shelf life. It is different for each type of item
but is always a whole number in the range 1 to 21 (inclusive).
The latest date that an item can be used is called the ‘use-by’ date.
A program is needed to produce labels which show the ‘use-by’ date.
DO NOT WRITE IN THIS MARGIN
www.dynamicpapers.com
* 0000800000012 *
•
•
take two parameters: a production date and a value representing the shelf life
return the corresponding ‘use-by’ date.
The program contains a global 1D array DaysInMonth of type integer which stores the number of
days in each month (index 1 is January):
Index
Value
1
31
2
28
3
31
4
30
11
30
12
31
DO NOT WRITE IN THIS MARGIN
Note: Leap years are not considered
DO NOT WRITE IN THIS MARGIN
Part of the program is a function GetDate() which will:
An array-based technique is often used when there is a large number of different values to
check and where no pattern exists.
One advantage of using an array-based technique is the speed of execution compared to the
use of multiple selection statements.
Give two other advantages of using an array for this type of operation rather than a solution
based on multiple selection statements.
1
DO NOT WRITE IN THIS MARGIN
(a) An algorithm uses the array DaysInMonth to calculate a ‘use-by’ date. An alternative design
would involve the use of multiple selection statements.
2
[2]
© UCLES 2024
ĬÙĊ®Ġ´íÈõÏĪÅĊàú¸Ā×
Ĭé¹úÕīČĐèðøîÛÐĀÁďĂ
ĥĕąĕõõÅÕÕąÅÅÅÕąĕąÕ
9618/21/O/N/24
DO NOT WRITE IN THIS MARGIN
www.dynamicpapers.com
DO NOT WRITE IN THIS MARGIN
* 0000800000013 *
13
,
,
(b) Complete the pseudocode for the function GetDate().
Date functions from the insert should be used in your solution.
FUNCTION GetDate(ProductionDate : DATE, ShelfLife : INTEGER) RETURNS DATE
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
ENDFUNCTION
© UCLES 2024
[7]
ĬÛĊ®Ġ´íÈõÏĪÅĊàü¸Ā×
ĬéºùÍĝĈĠÑĊĉ»ÿèÜÁğĂ
ĥĕõÕµĕåµÅõĕÅŵĥÕĕÕ
9618/21/O/N/24
[Turn over
DO NOT WRITE IN THIS MARGIN
www.dynamicpapers.com
* 0000800000014 *
14
,
7
,
A program contains six modules with headers as follows:
Pseudocode module header
PROCEDURE Connect()
FUNCTION Activate(H1 : STRING, Code : INTEGER) RETURNS BOOLEAN
FUNCTION Sync(T1 : BOOLEAN, S2 : REAL) RETURNS INTEGER
PROCEDURE Initialise(BYREF ID : INTEGER, BYVAL CC : INTEGER)
DO NOT WRITE IN THIS MARGIN
FUNCTION Reset(RA : STRING) RETURNS INTEGER
FUNCTION Enable(SA : INTEGER) RETURNS BOOLEAN
Module Connect() will call either Activate() or Sync(). This is decided at run-time.
(a) Complete the structure chart for these modules.
DO NOT WRITE IN THIS MARGIN
Connect
DO NOT WRITE IN THIS MARGIN
T1
(b) Explain the meaning of the curved arrow symbol used in the diagram in part (a).
[2]
© UCLES 2024
ĬÕĊ®Ġ´íÈõÏĪÅĊßûµĂ×
Ĭé¹ûÐģûĘãĀþĘãíÐñħĂ
ĥµõĕõõĥĕåĥĕąąõÅĕÅÕ
9618/21/O/N/24
DO NOT WRITE IN THIS MARGIN
[5]
www.dynamicpapers.com
15
,
,
BLANK PAGE
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
* 0000800000015 *
© UCLES 2024
Ĭ×Ċ®Ġ´íÈõÏĪÅĊßùµĂ×
ĬéºüØĥ÷ĨÖúóÑ÷ąČñėĂ
ĥµąÕµĕąõµĕÅąąĕåÕÕÕ
9618/21/O/N/24
[Turn over
16
,
8
,
An exam paper has a maximum of 75 marks. One of five pass grades (A to E) is assigned,
depending on the mark obtained. The lowest mark for a given grade is known as the grade
boundary. For example, if the grade boundary for an A grade is 65 marks, then any candidate who
achieves a mark of 65 or above will be awarded an A. A grade of U is awarded for marks below the
E grade boundary.
The five grade boundaries are stored in a global 1D array GradeBoundary of type integer.
DO NOT WRITE IN THIS MARGIN
www.dynamicpapers.com
* 0000800000016 *
GradeBoundary[1]
65
The minimum mark for an A grade.
GradeBoundary[2]
57
The minimum mark for a B grade.
GradeBoundary[3]
43
The minimum mark for a C grade.
GradeBoundary[4]
35
The minimum mark for a D grade.
GradeBoundary[5]
27
The minimum mark for an E grade.
A global 2D array Result of type integer contains candidate marks for the exam. Each row
relates to one candidate. Column 1 contains the candidate mark and column 2 contains the unique
candidate ID.
For example, for the fourth and fifth candidates:
Element
Mark
Element
ID
Result[4, 1]
56
Result[4, 2]
1074832
Result[5, 1]
54
Result[5, 2]
2573839
There are more rows in the array than candidates who sit the exam. Any unused rows will be at
the end of the array.
Candidate papers that are given a mark within two marks of any grade boundary must be checked.
For example, given the values in the example grade boundaries above, any paper that was
awarded between 41 and 45 marks (inclusive) would need to be checked.
A program is being written to identify papers that need to be checked.
The programmer has defined the first program module as follows:
Module
Description
CheckMark()
© UCLES 2024
•
called with a parameter of type integer representing a
candidate mark
•
returns TRUE if the mark is within 2 of any of the five grade
boundaries, otherwise returns FALSE
ĬÕĊ®Ġ´íÈõÏĪÅĊÝûµĄ×
ĬéºùØğąġáøüÚÕéêġğĂ
ĥąÕÕõĕąÕÕµµąÅĕąÕÅÕ
9618/21/O/N/24
DO NOT WRITE IN THIS MARGIN
Comment
DO NOT WRITE IN THIS MARGIN
Value
DO NOT WRITE IN THIS MARGIN
Element
DO NOT WRITE IN THIS MARGIN
For example:
www.dynamicpapers.com
DO NOT WRITE IN THIS MARGIN
* 0000800000017 *
17
,
,
(a) Write pseudocode for module CheckMark().
DO NOT WRITE IN THIS MARGIN
[6]
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
© UCLES 2024
Ĭ×Ċ®Ġ´íÈõÏĪÅĊÝùµĄ×
Ĭé¹úÐĩĉđØĂąďāÑîġďĂ
ĥąåĕµõĥµÅÅĥąÅõĥĕÕÕ
9618/21/O/N/24
[Turn over
,
(b) A second module is defined:
Module
CheckAll()
Description
•
called with a parameter of type integer representing the
number of candidate marks in the Result array
•
uses CheckMark() to check each candidate mark
•
for each paper that needs to be checked, write the
corresponding candidate ID on a separate line in a new file
named GRList.txt
•
outputs a message with a count of how many papers need
to be checked
Write pseudocode for module CheckAll().
CheckMark() must be used to check each individual mark.
DO NOT WRITE IN THIS MARGIN
18
,
DO NOT WRITE IN THIS MARGIN
www.dynamicpapers.com
* 0000800000018 *
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
© UCLES 2024
ĬÕĊ®Ġ´íÈõÏĪÅĊàû·Ă×
Ĭé»ùÍĝý÷ßïóô¹ë¾ÙėĂ
ĥÕµĕõĕåÕõąµÅŵąÕõÕ
9618/21/O/N/24
DO NOT WRITE IN THIS MARGIN
www.dynamicpapers.com
DO NOT WRITE IN THIS MARGIN
* 0000800000019 *
19
,
,
DO NOT WRITE IN THIS MARGIN
[8]
(c) The requirement changes. Instead of a new file, the module described in part (b) needs to
add the corresponding candidate ID for each paper that needs to be checked to an existing
file.
[1]
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
Explain the change that will need to be made to CheckAll().
© UCLES 2024
Ĭ×Ċ®Ġ´íÈõÏĪÅĊàù·Ă×
Ĭé¼úÕīāćÚĉþµĝÓĚÙħĂ
ĥÕÅÕµõŵĥõĥÅÅÕĥĕĥÕ
9618/21/O/N/24
20
,
,
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/O/N/24
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
DO NOT WRITE IN THIS MARGIN
BLANK PAGE
DO NOT WRITE IN THIS MARGIN
www.dynamicpapers.com
* 0000800000020 *