Computer Science (2210) · May/June 2024 · Question paper 21

Cambridge Computer Science (2210) question paper for paper 21, May/June 2024 — 2210/21/M/J/24, file 2210_s24_qp_21.pdf.

Advertisement
Loading the paper…
Text of this paper

www.dynamicpapers.com

Cambridge O Level

* 4 2 2 9 9 3 6 4 9 3 *

COMPUTER SCIENCE
Paper 2 Algorithms, Programming and Logic

2210/21
May/June 2024
1 hour 45 minutes

You must answer on the question paper.
No additional materials are needed.
INSTRUCTIONS
●
Answer all questions.
●
Use a black or dark blue pen. You may use an HB pencil for any diagrams or graphs.
●
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.
●
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.

This document has 16 pages. Any blank pages are indicated.
DC (KS) 341262
© UCLES 2024

[Turn over

2
1

www.dynamicpapers.com

Tick (ü) one box to complete this sentence.
A validation check to make sure that an email address contains an ‘@’ sign is a

2

A

range check.

B

visual check.

C

presence check.

D

format check.

[1]

Four descriptions of programming concepts and five programming concepts are shown.
(a) Draw one line to link each description to the most appropriate programming concept.
Not all programming concepts will be used.
Description

Programming concept

a subroutine that may not return a value

a value that is declared and used within a
specific procedure

function

procedure

parameter
a value that a procedure expects you to
supply when it is called

a subroutine that will always return a value

global variable

local variable
[4]

(b) Write the pseudocode to use a procedure named Average that passes the values 25 and 50
to the procedure.

[2]

© UCLES 2024

2210/21/M/J/24

3

www.dynamicpapers.com

(c) Outline the role of procedures and functions in creating a program that is easier to maintain.

[3]
3

State what is meant by the data types integer and real.
Give an example of each.
Integer

Example
Real

Example
[4]

© UCLES 2024

2210/21/M/J/24

[Turn over

4
4

www.dynamicpapers.com

This pseudocode algorithm is intended to allow, at random, between 1 and 20 values to be entered
and totalled. The total and average of the entered values are output at the end of the algorithm.
01
02
03
04
05
06
07
08
09
10
11
12
13

DECLARE Loop : STRING
DECLARE Limit : INTEGER
DECLARE Value : REAL
DECLARE Total : REAL
0
Total
ROUND(RANDOM() * 19,0) + 1
Limit
1 TO Limit
IF Loop
OUTPUT "Enter a number"
INPUT Loop
Total * Value
Total
NEXT Loop
OUTPUT "The total of the numbers entered is ", Total
OUTPUT "The average of the numbers entered is ", Total / Limit

(a) Identify the line numbers of four errors in the pseudocode and suggest corrections.
Error 1 line number
Correction

Error 2 line number
Correction

Error 3 line number
Correction

Error 4 line number
Correction

[4]
(b) Write the pseudocode statement that would output the average calculated in line 13 of the
algorithm rounded to one decimal place.

[2]

© UCLES 2024

2210/21/M/J/24

5

www.dynamicpapers.com

(c) Explain how you should alter the original corrected algorithm to make sure that all the
numbers entered are between 1 and 500 inclusive. If any numbers fall outside these limits, a
replacement value is requested and entered.
You do not need to re-write the algorithm.

[4]
5

Write the pseudocode statements to perform this task:
•
accept the input of a whole number from 1 to 4 inclusive
•
use a CASE statement to:
○ output the number (1 to 4 inclusive) that was entered
○ output the word “ERROR” if a 1 to 4 inclusive number was not entered.

[5]

© UCLES 2024

2210/21/M/J/24

[Turn over

6
6

www.dynamicpapers.com

The flowchart represents an algorithm.
START
Result

INPUT
Limit

Count

Limit DIV 2 + 1

OUTPUT
Numbers[Result]

1

INPUT
Numbers[Count]

Count

No

STOP

Count + 1

IS Count >
Limit?
IS Numbers[Count] >
Numbers[Count + 1]?

Yes
Flag

TRUE

No

Yes
IS Flag =
TRUE?

Swap

No

Numbers[Count]

Numbers[Count]

Yes
Flag
False
Count
1

Numbers[Count + 1]
Flag

Yes

IS Count >
Limit – 1?

Swap

True

No
Count

© UCLES 2024

Numbers[Count + 1]

2210/21/M/J/24

Count + 1

www.dynamicpapers.com

7
(a) Complete the trace table for the input data:
7, 47, 50, 52, 60, 80, 63, 70
Numbers
Limit

Count

[1]

[2]

[3]

[4]

[5]

[6]

[7]

Flag

Swap

Result

OUTPUT

[7]
© UCLES 2024

2210/21/M/J/24

[Turn over

8

www.dynamicpapers.com

(b) Outline the processes involved in the algorithm shown in the flowchart on page 6.

[3]
7

(a) Outline why it is useful to store data in a file.

[2]
(b) The function LENGTH(X) calculates the length of a string X
Write the pseudocode statements to:
•
read the contents of the text file Quotation.txt into an appropriate string variable that
has been declared
•
output the string in upper case and the length of the string.

[4]

© UCLES 2024

2210/21/M/J/24

www.dynamicpapers.com

9
8

Consider the logic expression:
Z = (R OR NOT T) XOR (NOT S AND T)
(a) Draw a logic circuit for this logic expression.
Each logic gate must have a maximum of two inputs.
Do not simplify this logic expression.

R

S

Z

T

[5]
(b) Complete the truth table from the given logic expression.
R

S

T

0

0

0

0

0

1

0

1

0

0

1

1

1

0

0

1

0

1

1

1

0

1

1

1

Working space

Z

[4]

© UCLES 2024

2210/21/M/J/24

[Turn over

www.dynamicpapers.com

10
9

A database table called SoftDrinks stores details of the soft drinks sold by a small shop.
Field

Example data

Name

Cola

Supplier

Cambridge Beverages

Container

Can

SizeCl

330

NumberInStock

30

ReorderLevel

15

Reordered

Yes

(a) State whether any of the given fields would be suitable as a primary key and give a reason for
your answer.

[1]
(b) Complete the structured query language (SQL) statement to return the number of cans the
shop has in stock.
SELECT ( )
FROM
WHERE = ;

© UCLES 2024

2210/21/M/J/24

[5]

11

www.dynamicpapers.com

BLANK PAGE

© UCLES 2024

2210/21/M/J/24

[Turn over

12

www.dynamicpapers.com

10 The one-dimensional (1D) array Clubs[] is used to store the names of 12 cricket clubs in a local
sports league.
The two-dimensional (2D) array Statistics[] is used to store, for each cricket club, the number
of:
•
matches won
•
matches drawn
•
matches lost.
The 1D array Points[] is used to store the total number of points each cricket club has been
awarded.
The position of any cricket club’s data is the same in all three arrays. For example, the data in
index 2 of Statistics[] and index 2 of Points[] belongs to the cricket club in index 2 of
Clubs[]
The variable Matches stores the number of matches played by each team. Each team plays the
same number of matches.
Points are awarded for:
•
a win – 12 points
•
a draw – 5 points
•
a loss – 0 points.
Write a program that meets the following requirements:
allows the number of matches played to be input and stored, with a maximum of 22 matches
validates the number of matches played
allows the names of the cricket clubs to be input and stored
allows the number of matches won, drawn and lost to be input and stored for each team
validates the number of matches won, drawn or lost against the number of matches played
asks the user to re-enter the number of matches won, drawn or lost if the total does not match
the number of matches played
•
calculates and stores the total number of points for each club
•
finds the cricket club or clubs with the highest number of points
•
outputs the name or names of the winning club or clubs, the number of wins and the total
number of points awarded.

•
•
•
•
•
•

You must use pseudocode or program code and add comments to explain how your code works.
You do not need to declare any arrays or variables; you may assume that this has already been
done.
All inputs and outputs must contain suitable messages.

© UCLES 2024

2210/21/M/J/24

13

www.dynamicpapers.com

© UCLES 2024

2210/21/M/J/24

[Turn over

14

www.dynamicpapers.com

[15]
© UCLES 2024

2210/21/M/J/24

15
BLANK PAGE

© UCLES 2024

2210/21/M/J/24

www.dynamicpapers.com

16

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

2210/21/M/J/24

Advertisement