Computer Science (9618) · Oct/Nov 2023 · Question paper 23

Cambridge Computer Science (9618) question paper for paper 23, Oct/Nov 2023 — 9618/23/O/N/23, file 9618_w23_qp_23.pdf.

Advertisement
Loading the paper…
Text of this paper

www.dynamicpapers.com

Cambridge International AS & A Level

* 1 7 9 0 6 9 5 1 7 2 *

COMPUTER SCIENCE

9618/23

Paper 2 Fundamental Problem-solving and Programming Skills

October/November 2023
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.
DC (LK/CT) 315870/2
© UCLES 2023

[Turn over

2

www.dynamicpapers.com

Refer to the insert for the list of pseudocode functions and operators.
1

A program is being developed in pseudocode before being converted into a programming
language.
(a) The following table shows four valid pseudocode assignment statements.
Complete the table by giving the data type that should be used to declare the variable
underlined in each assignment statement.
Assignment statement

Data type

← Total1 / Total2
MyVar2 ← 27/10/2023
MyVar3 ← "Sum1 / Sum2"
MyVar4 ← Result1 AND Result2
MyVar1

[4]

(b) Other variables in the program have example values as shown:
Variable

Value

Active

TRUE

Fraction

0.2

Code

"Ab12345"

Complete the table by evaluating each expression using the example values.
Expression

Evaluates to

Fraction >= 0.2 AND NOT Active
INT((Fraction * 100) + 13.3)
STR_TO_NUM(MID(Code, 4, 2)) + 5
LENGTH("TRUE" & Code)

© UCLES 2023

[4]

9618/23/O/N/23

3

www.dynamicpapers.com

(c) The program makes use of complex statistical functions. The required functions are not
built-in to the programming language and are too complicated for the programmer to write.
One solution would be to employ another programmer who has experience of writing these
functions, as there is no time to train the existing programmer.
State one other way that these functions may be provided for inclusion in the program.

[1]
(d) The hardware that runs the program is changed and the program needs to be modified so
that it works with the new hardware.
Identify the type of maintenance that this represents and give one other reason why this type
of maintenance may be needed.
Type
Reason

[2]

© UCLES 2023

9618/23/O/N/23

[Turn over

4
2

www.dynamicpapers.com

Data is a 1D array of integers, containing 30 elements. All element values are unique.
(a) An algorithm will output the index of the element with the smallest value.
Draw a program flowchart to represent the algorithm.

START

END
[5]
© UCLES 2023

9618/23/O/N/23

5

www.dynamicpapers.com

(b) The 30 data values could have been stored in separate variables rather than in an array.
Explain the benefits of using an array when designing a solution to part (a).

[2]
(c) The requirement changes. Array Data needs to hold 120 elements and each value may
include a decimal place.
Write a pseudocode statement to declare the modified array.

[2]

© UCLES 2023

9618/23/O/N/23

[Turn over

www.dynamicpapers.com

6
3

The diagram represents a queue Abstract Data Type (ADT).
The organisation of this queue may be summarised as follows:

•
•

The FrontOfQueue pointer points to the next data item to be removed.
The EndOfQueue pointer points to the last data item added.
Queue

D3
D4

← FrontOfQueue

D1
D2
D5

← EndOfQueue

The queue is implemented using three variables and a 1D array of eight elements as shown. The
variable NumItems stores the number of items in the queue.
The pointer variables store indices (index numbers) of the array.
(a) Complete the diagram to represent the state of the queue as shown above.
Index

Array

1
2
3
4

Variable

5

FrontOfQueue

6

EndOfQueue

7

NumItems

5

8
[3]

© UCLES 2023

9618/23/O/N/23

7

www.dynamicpapers.com

(b) A module AddTo() will add a value to the queue by manipulating the array and variables in
part (a).
The queue implementation is circular. When pointers reach the end of the queue, they will
‘wrap around’ to the beginning.
Before a value can be added to the queue, it is necessary to check the queue is not full.
The algorithm to add a value to the queue is expressed in six steps.
Complete the steps.
1.

If NumItems then jump to step 6.

2.

Increment .

3.

If then set EndOfQueue to .

4.

Increment .

5.

Set the at the index stored in to the
being added.

6.

Stop.
[6]

© UCLES 2023

9618/23/O/N/23

[Turn over

8
4

www.dynamicpapers.com

A procedure RandList() will output a sequence of 25 random integers, where each integer is
larger than the previous one.
(a) Write pseudocode for procedure RandList().

[6]

© UCLES 2023

9618/23/O/N/23

9

www.dynamicpapers.com

(b) Procedure RandList() is modified so that the random numbers are also written into a
1D array Result.
A new module is written to confirm that the numbers in the array are in ascending order.
This module contains an IF statement that performs a comparison between elements:
IF (Result[x + 1] = Result[x]) OR (Result[x] > Result[x + 1]) THEN
FALSE
Sequence
ENDIF

←

Write a simplified version of the conditional clause.

[1]

© UCLES 2023

9618/23/O/N/23

[Turn over

10
5

www.dynamicpapers.com

A global 1D array of integers contains four elements, which are assigned values as shown:
Mix[1]
Mix[2]
Mix[3]
Mix[4]

←4
←2
←3
←5

A procedure Process() manipulates the values in the array.
The procedure is written in pseudocode as follows:
PROCEDURE Process(Start : INTEGER)
DECLARE Value, Index, Total : INTEGER
Index
Total

← Start
←0

WHILE Total < 20
Mix[Index]
Value
Total + Value
Total

←
←

IF Index < 4 THEN
Mix[Index] + Mix[Index+1]
Mix[Index]
ELSE
Mix[Index] + Mix[1]
Mix[Index]
ENDIF
(Value MOD 4) + 1
Index
ENDWHILE
Mix[1]

←

←
←

← Total * Index

ENDPROCEDURE

Complete the trace table on the opposite page by dry running the procedure when it is called as
follows:
CALL Process(2)

© UCLES 2023

9618/23/O/N/23

11
Index

Value

Total

Mix[1]

www.dynamicpapers.com
Mix[2]

Mix[3]

Mix[4]

[6]

© UCLES 2023

9618/23/O/N/23

[Turn over

12
6

www.dynamicpapers.com

A function TestNum() will take a six-digit string as a parameter.
The function will test whether the string meets certain conditions and will return an integer value
as follows:
Return value

Condition

1

The last three digits are the same but non-zero.

"253444"

2

The last three digits are zero.

"253000"

3

The first three and last three digits are the same.

"410410"

The function will return the highest possible value for the given string.
If the string does not meet any of the conditions, zero is returned.

© UCLES 2023

Example

9618/23/O/N/23

13

www.dynamicpapers.com

Write pseudocode for function TestNum().
Assume that the parameter is valid.

[6]

© UCLES 2023

9618/23/O/N/23

[Turn over

www.dynamicpapers.com

14
7

A structure chart shows the modular structure of a program:

Module-A()

T1
SA

RA
RB

Sub-Y1()

Sub-Y2()

Sub-9()

(a) Explain the meaning of the curved arrow symbol which begins and ends at Module-A().

[2]

© UCLES 2023

9618/23/O/N/23

15

www.dynamicpapers.com

(b) The structure chart shows that Sub-9() is a function.
A Boolean value is returned by Sub-9() for processing by Module-A().
The original parameter RA is of type integer and RB is of type string.
A record type MyType will be defined with three fields to store the values passed between the
two modules.
(i)

Write pseudocode to define MyType.

[3]

(ii)

The design is modified and Sub-9() is changed to a procedure.
The procedure will be called with a single parameter of type MyType.
Write the pseudocode header for procedure Sub-9().

[2]

© UCLES 2023

9618/23/O/N/23

[Turn over

www.dynamicpapers.com

16
8

A class of students are developing a program to send data between computers. Many computers
are connected together to form a wired network. Serial ports are used to connect one computer to
another.
Each computer:
is assigned a unique three-digit ID
has three ports, each identified by an integer value
is connected to between one and three other computers.

•
•
•

Messages are sent between computers as a string of characters organised into fields as shown:
<STX><DestinationID><SourceID><Data><ETX>
Field name

Description

STX

a single character marking the start of the message
(ASCII value 02)

DestinationID

three numeric characters identifying the destination computer

SourceID

three numeric characters identifying the source computer

Data

a variable length string containing the data being sent
(Minimum length is 1 character)

ETX

a single character marking the end of the message
(ASCII value 03)

For example, the following message contains the data "Hello Jack" being sent from computer
"202" to computer "454":
<STX>"454202Hello Jack"<ETX>
Each computer will run a copy of the same program. Each program will contain a global variable
MyID of type string which contains the unique ID of the computer in which the program is running.
The first two program modules are defined as follows:
Module
GetData()
(already written)

ReceiveFile()

© UCLES 2023

Description

•
•

returns the data field from a message that has been received
If no message is available, the module waits until one has been
received.

•
•
•
•
•

takes a file name as a parameter of type string
creates a text file with the given file name (no checking required)
writes the data field returned by GetData() to the file
repeats until the data field is "****", which is not written to the file
outputs a final message giving the total number of characters
written to the file, for example:
132456 characters were written to newfile.txt

9618/23/O/N/23

17

www.dynamicpapers.com

(a) Write pseudocode for module ReceiveFile().
Module GetData() has already been written and must be used.

[7]

© UCLES 2023

9618/23/O/N/23

[Turn over

www.dynamicpapers.com

18

(b) The use of the string "****" as explained in the module description for ReceiveFile() may
cause a problem.
Explain the problem and suggest a solution.
Problem

Solution

[3]
(c) Two new modules are defined, which will allow two users to exchange messages.
Module
Transmit()
(already written)

Description

•
•
•

Chat()

•
•
•

takes two parameters:
○ a string representing a message
○ an integer representing a port number
transmits the message using the given port
takes two parameters:
○ a string representing a Destination ID
○ an integer representing a port number
extracts data from a received message using GetData() and
outputs it
forms a message using data input by the user and sends it
using Transmit()
repeats until either the output string or the sent string is "Bye"

Reminders:

•
•

Each program contains a global variable MyID of type string which contains the unique ID of
the computer in which the program is running.
Messages are sent between computers as a string of characters organised into fields as
shown:
<STX><DestinationID><SourceID><Data><ETX>

© UCLES 2023

9618/23/O/N/23

19

www.dynamicpapers.com

Write pseudocode for module Chat().
Modules GetData() and Transmit() must be used.

[7]

© UCLES 2023

9618/23/O/N/23

[Turn over

20

www.dynamicpapers.com

(d) Module GetData() returns the data field from a message that has been received. If no
message is available, the module waits until one has been received.
Explain the limitation of this on module Chat() from part (c).
Describe a modification to GetData() to address this limitation.
Limitation

Modification

[3]

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 2023

9618/23/O/N/23

Advertisement