Past paper – A Level Computer Science (9618)

Cambridge International AS & A Level · 9618

Computer Science · Paper 23

May/June 2024 · 9618/23/M/J/24

Questions8
Marks75
TypeWritten

Answer on paper, open each mark scheme and give yourself marks, then open the Summary.

0 / 0Answer a question to start your score.
Saved 0
Advertisement
1
9618/23/M/J/24 · Question 1May/June 2024Paper 239 marks
Loading question…
Question text

1
A program uses many complex algorithms.
One algorithm is repeated in several places. The code for the algorithm is the same wherever it is
used, but the calculations within the algorithm may operate on different data.
The result of each calculation is used by the code that follows it.
It is decided to modify the program and implement the algorithm as a separate module.
(a) (i)
State two benefits of this modification to the existing program.
1 …
…
2 …
…
[2]
(ii)
Describe how the modification would be implemented.
…
…
…
…
…
…
…
… [3]
,
,
(b) Four of the expressions used in the program are represented by pseudocode in the table.
Complete each pseudocode expression with a function or operator so that it evaluates to the
value shown.
Any functions and operators used must be defined in the insert.
Pseudocode expression
Evaluates to
"and"
… ("Random", 2, 3)
15
5 + … (10/11/2023)
TRUE
… ("45000")
3
(20 … 3) + 1
[4]

2
9618/23/M/J/24 · Question 2May/June 2024Paper 237 marks
Loading question…
Question text

2
(a) A program uses a global 1D array of type string and a text file.
An algorithm that forms part of the program is expressed as follows:
•
copy the first line from the file into the first element of the array
•
copy the second line from the file into the second element of the array
•
continue until all lines in the file have been copied into the array.
Stepwise refinement is applied to the algorithm.
Outline five steps for this algorithm that could be used to produce pseudocode.
Assume there are more elements in the array than lines in the file.
Do not use pseudocode statements in your answer.
Step 1 …
…
Step 2 …
…
Step 3 …
…
Step 4 …
…
Step 5 …
…
[5]
(b) Sequence is one programming construct.
Identify one other programming construct that will be required when the algorithm from
part (a) is converted into pseudocode and explain its use.
Construct …
…
Use …
…
[2]

3
9618/23/M/J/24 · Question 3May/June 2024Paper 239 marks
Loading question…
Question text

3
A record structure is declared to hold data relating to components being produced in a factory:
TYPE Component
DECLARE Item_ID : STRING
DECLARE Reject : BOOLEAN
DECLARE Weight : REAL
ENDTYPE
The factory normally produces a batch (or set) of 1000 components at a time. A global array is
declared to store 1000 records for a batch:
DECLARE Batch : ARRAY [1:1000] OF Component
Two global variables contain the minimum and maximum acceptable weight for each component.
The values represent an inclusive range and are declared as:
DECLARE Min, Max : REAL
(a) (i)
A program uses a variable ThisIndex as the array index to access a record.
Write a pseudocode clause to check whether or not the weight of an individual component
is within the acceptable range.
…
…
… [3]
(ii)
When batches of less than 1000 components are processed, it is necessary to indicate
that certain elements in the array are unused.
Suggest how an unused array element could be indicated.
…
… [1]
(b) A module InRange() will:
•
be called with an integer parameter representing an index value of a record in the Batch
array
•
check if the weight of the indexed component is within the acceptable range
•
return TRUE if the weight is in the range and FALSE if it is not.
A module BatchCheck() will:
•
iterate through a batch of 1000 component records
•
call module InRange() to check each individual component record
•
keep a count of the number of components that fail
•
output a suitable warning message and immediately stop if the number of failed
components exceeds 5.
,
,
Complete the program flowchart to represent the algorithm for module BatchCheck().
START
Is
Index = 1001 ?
Yes
No
END
[5]

Advertisement
4
9618/23/M/J/24 · Question 4May/June 2024Paper 2311 marks
Loading question…
Question text

4
A procedure TwoParts() will input a sequence of real values, one at a time.
The procedure will:
•
process the sequence in two parts
•
form a first total by adding the values until the first zero
•
form a second total by adding the values after the first zero until the second zero
•
output the average of the two totals, together with a suitable message.
Values input in the first part are totalled using global variable TotalA and those input in the
second part are totalled using global variable TotalB.
(a) Write pseudocode for the procedure TwoParts().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]
,
,
(b) The value zero denotes the split between the two parts of the sequence.
The requirement changes and now there may be up to 20 parts.
(i)
Identify a suitable data structure that could be used to store the different total values.
…

5
9618/23/M/J/24 · Question 5May/June 2024Paper 236 marks
Loading question…
Question text

5
A program is being designed in pseudocode.
The program contains the following declaration:
DECLARE Data : ARRAY[1:1000] OF STRING
A procedure ArrayInitialise() is written to initialise the values in the array:
PROCEDURE ArrayInitialise(Label : STRING)
DECLARE Index : INTEGER
1
Index
WHILE Index <= 1000
CASE OF (Index MOD 2)
FormatA(Label)
0 : Data[Index]
Index + 1
Index
FormatB(Label)
1 : Data[Index]
Index + 1
Index
ENDCASE
ENDWHILE
ENDPROCEDURE
Functions FormatA() and FormatB() apply fixed format case changes to the parameter string.
(a) The design of the procedure does not use the most appropriate loop construct.
Suggest a more appropriate construct that could be used and explain your choice.
Construct …
Explanation …
…
[2]
(b) The algorithm calls one of the functions FormatA() and FormatB() each time within the
loop.
Explain why this is not efficient and suggest a more efficient solution.
…
…
…
…
…
…
…
… [4]

6
9618/23/M/J/24 · Question 6May/June 2024Paper 239 marks
Loading question…
Question text

6
A program displays a progress bar to inform the user of the progress of tasks that take a significant
time to complete, such as those involving file transfer operations.
Task progress is divided into 11 steps. Each step represents the amount of progress as a
percentage. An image is associated with each step and each image is stored in a different file.
Different progress bar images may be selected. For a given image, files all have the same filename
root, with a different suffix.
The table illustrates the process for using the image with filename root BargraphA
Percentage
Step
Image filename
Image
progress
1
< 10
BargraphA-1.bmp
BargraphA-2.bmp
2
>= 10 and < 20
3
>= 20 and < 30
BargraphA-3.bmp
BargraphA-9.bmp
9
>= 80 and < 90
10
>= 90 and < 100
BargraphA-10.bmp
11
100
BargraphA-11.bmp
A procedure Progress() will:
•
be called with two parameters:
○ an integer representing the percentage progress (0 to 100 inclusive)
○ a string representing the image filename root
•
generate the full image filename
•
call a procedure Display() using the full image filename as the parameter.
,
,
(a) Write pseudocode for procedure Progress().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

7
9618/23/M/J/24 · Question 7May/June 2024Paper 239 marks
Loading question…
Question text

7
Seven program modules form part of a program. A description of the relationship between the
modules is summarised below. Any return values are stated in the description.
Module name
Description
Mod-A
calls Mod-B followed by Mod-C
•
called with parameters Par1 and Par2
•
Mod-B
calls either Mod-D or Mod-E, determined when the program runs
•
returns a Boolean value
•
called with parameters Par1 and Par3
•
Mod-C
Par3 is passed by reference
•
repeatedly calls Mod-F followed by Mod-G
Mod-D
called with parameter Par2
•
called with parameter Par3
Mod-E
•
returns an integer value
Mod-F
called with parameter Par3
•
called with parameter Par3
Mod-G
•
Par3 is passed by reference
Parameters in the table are as follows:
•
Par1 and Par3 are of type string.
•
Par2 is of type integer.
(a) (i)
Identify the modules that would be implemented as functions.
… [1]
(ii)
Modules Mod-F and Mod-G are both called with Par3 as a parameter.
In the case of Mod-F, the parameter is passed by value.
In the case of Mod-G, the parameter is passed by reference.
Explain the effect of the two different ways of passing the parameter Par3.
…
…
…
… [2]
,
,
(b) Draw a structure chart to show the relationship between the seven modules and the
parameters passed between them.
[6]

8
9618/23/M/J/24 · Question 8May/June 2024Paper 2315 marks
Loading question…
Question text

8
A teacher is designing a program to process pseudocode projects written by her students.
The program analyses a student project and extracts information about each module that is
defined (each procedure or function). This information is stored in a global 2D array ModInfo of
type string.
A module header is the first line of a module definition and starts with either of the keywords
PROCEDURE or FUNCTION.
An example of part of the array is given below. Row 10 of the array shows that a procedure header
occurs on line 27 and row 11 shows that a function header occurs on line 35. "P" represents a
procedure and "F" represents a function:
x = 1
x = 2
x = 3
ModInfo[10, x]
"27"
"P"
"MyProc(Z : CHAR)"
ModInfo[11, x]
"35"
"F"
"MyFun(Y : CHAR) RETURNS BOOLEAN"
The string stored in column 3 is called the module description. This is the module header without
the keyword.
A valid module header will:
•
be at least 13 characters long
•
start with the keyword PROCEDURE or FUNCTION. The keyword may appear in either upper or
lower case (or a mix of both) and must be followed by a space character.
The teacher has defined the first program module as follows:
Module
Description
Header()
•
called with a parameter of type string representing a line of
pseudocode
•
if the line is a valid procedure header, returns a string:
"P<Module description>"
•
if the line is a valid function header, returns a string:
"F<Module description>"
•
otherwise, returns an empty string
For example, given the string:
"FUNCTION Zap(X : INTEGER) RETURNS CHAR"
Header()returns the string:
"FZap(X : INTEGER) RETURNS CHAR"
,
,
(a) Write pseudocode for module Header().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

Advertisement