Computer Science · June 2021 · Question paper · Paper 2

Edexcel International GCSE Computer Science question paper for Paper 2, June 2021 — 4CP0/02, file 4CP0_02_que_20210427-1.pdf.

Advertisement
Loading the paper…
Text of this paper

Please check the examination details below before entering your candidate information
Candidate surname

Pearson Edexcel
International GCSE (9–1)

Other names

Centre Number

Paper
reference

Time 3 hours

Candidate Number

4CP0/02

Computer Science

PAPER 2: Application of Computational Thinking

You must have:
A computer workstation with appropriate programming language code
editing software and tools, including a code interpreter/compiler, CODES
folder containing code files, pseudocode command set (enclosed)

Total Marks

Instructions

black ink or ball-point pen.
•• Use
Fill in the boxes at the top of this page with your name,
centre number and candidate number.
all questions.
•• Answer
Answer the questions requiring a written answer in the spaces provided
– there may be more space than you need.
one programming language (Python, C# or Java) must be used throughout
• Only
the examination.
out practical tasks on the computer system and save new or amended code using
• Carry
the name given in the question with the appropriate file extension.
the original code and data files provided to you.
•• DoYounotmustoverwrite
not use the internet during the examination.

Information

total mark for this paper is 80.
•• The
The marks for each question are shown in brackets
– use this as a guide as to how much time to spend on each question.
paper covers Python, C# and Java.
•• This
The CODES folder in your user area includes all the code you need.
• The invigilator will tell you where to store your work.

Advice

each question carefully before you start to answer it.
•• Read
Save your work regularly.
your answers if you have time at the end.
•• Check
Good luck with your examination.

P66490A
©2021 Pearson Education Ltd.

1/1/1/1

*P66490A0116*

Turn over

Answer all questions.
Answer the questions requiring a written answer in the spaces provided.
Some questions must be answered with a cross in a box . If you change your mind about an
answer, put a line through the box and then mark your new answer with a cross .
Carry out practical tasks on the computer system and save new or amended code using the
name given with the appropriate file extension.
Use only ONE programming language throughout the examination.
Indicate the programming language that you are using with a cross in a box .
C#

Java

Python

1 Computer programs make use of many programming constructs.
(a) Identify which one of these is a logic operator.

(1)

A modulus
B OR
C >=
D =
(b) Describe one difference between a one-dimensional array and a
two-dimensional array.

(2)

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(c) Open Q01c in the code editor.

The program should calculate how many £20 are in £113 and how much is
left over.

There are three errors in the code.

Amend the code to correct the errors.

Save your amended code as Q01cFINISHED with the correct file extension for the
programming language.

2

*P66490A0216*

(3)

(d) Raoul has written a program that counts the number of vowels in a sentence.
Open Q01d in the code editor.

Amend the code by adding a suitable comment (you may need to add more than
one comment to a line):

(i) at the end of the line where there is a relational operator

(ii) at the end of a line where iteration starts

(iii) at the end of the line where selection starts

(iv) at the end of a line where a data structure is initialised.

Save your amended code as Q01dFINISHED with the correct file extension for
the programming language.

(1)
(1)
(1)
(1)

(Total for Question 1 = 10 marks)

*P66490A0316*

3

Turn over

2 A book club uses computer applications.
(a) The club wants a program to ensure that logins are valid.

A flowchart for a test version of the program has been designed.

The test version uses:

•

a username of bard423

•

a password of nX2934?

Here is the flowchart.
Start

Initialise
variables

Enter username and
password

Are username
and password
correct?

No

Display error
message

Yes
Display welcome
message

Stop

4

*P66490A0416*

Write a program to implement the logic in the flowchart.

Open Q02a in the code editor.

You must use the structure given in Q02a to write the program.

Do not add any further functionality.

Save your code as Q02aFINISHED with the correct file extension for the
programming language.

*P66490A0516*

(11)

5

Turn over

(b) The club sells books.

It needs a computer program to monitor:
•

the number of books sold

•

the amount of profit made.

Q02b provides a structure for the program.
Open Q02b in the code editor.

Amend the code to complete the If statement used to produce the outputs
described in the table.
Condition

Output message

Number of books sold is at least 5 and
profit made is at least 10

Sales and profit are good this week

Number of books sold is over 20 and
profit made is at least 20

Sales and profit are excellent this week

Number of books sold is under 5 or profit
made is under 5

Poor performance this week

All other inputs

Alert manager

Do not add any further functionality.

Save your code as Q02bFINISHED with the correct file extension for the
programming language.

6

*P66490A0616*

(4)

(c) Boundary testing is an important part of program development.

The boundary value is the most extreme value that will pass the test.

For example, if the boundary condition is no more than 30 then the boundary test
data would be 30.

Complete the test table to show the boundary test data that could be used for
each test.

Test data
booksSold
profit
booksSold
profit
booksSold
profit

(3)

Expected output
Poor performances this week

Sales and profit are good
this week
Sales and profit are excellent
this week
(Total for Question 2 = 18 marks)

*P66490A0716*

7

Turn over

3 Several encryption algorithms have been developed.
(a) Ahmed has started to create a Caesar cipher encryption program.

Caesar cipher encryption works by giving a number value to a key.

Each letter in a plaintext message is replaced by a new ciphertext letter using
the key.

For example, as shown in the table, a key value of +2 would change the plaintext
message encrypt to the ciphertext message gpetarv.
Plaintext

e

n

c

r

y

p

t

Ciphertext

g

p

e

t

a

r

v

Ahmed’s program already converts from plaintext to ciphertext.

He wants to extend the program to:
•

accept the input of a plaintext message

•

accept the input of the key, which must be a positive integer between
1 and 25

•

write the generated ciphertext to a text file named Cipher.txt

•

display the ciphertext.

Open Q03a in the code editor.

Complete the program code.

You must use the structure given in the file Q03a to complete the program.

Do not add any further functionality.

Save your code as Q03aFINISHED with the correct file extension for the
programming language.

(b) Explain one reason why the Caesar cipher is a weak encryption algorithm.

(8)
(2)

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

8

*P66490A0816*

(c) The Vigenere cipher encrypts plaintext using a series of Caesar ciphers, based on
the letters of a keyword and a Vigenere square.
Figure 1 shows a Vigenere square.

a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z

a
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z

b
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
a

c
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
a
b

d
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
a
b
c

e
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
a
b
c
d

f
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
a
b
c
d
e

g
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
a
b
c
d
e
f

h
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
a
b
c
d
e
f
g

i
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
a
b
c
d
e
f
g
h

j
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
a
b
c
d
e
f
g
h
i

k
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
a
b
c
d
e
f
g
h
i
j

l
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
a
b
c
d
e
f
g
h
i
j
k

m
m
n
o
p
q
r
s
t
u
v
w
x
y
z
a
b
c
d
e
f
g
h
i
j
k
l

n
n
o
p
q
r
s
t
u
v
w
x
y
z
a
b
c
d
e
f
g
h
i
j
k
l
m

o
o
p
q
r
s
t
u
v
w
x
y
z
a
b
c
d
e
f
g
h
i
j
k
l
m
n

p
p
q
r
s
t
u
v
w
x
y
z
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o

q
q
r
s
t
u
v
w
x
y
z
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p

r
r
s
t
u
v
w
x
y
z
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q

s
s
t
u
v
w
x
y
z
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r

t
t
u
v
w
x
y
z
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s

u
u
v
w
x
y
z
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t

v
v
w
x
y
z
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u

w
w
x
y
z
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v

x
x
y
z
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w

y
y
z
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x

z
z
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y

Figure 1

Complete the table to perform a Vigenere decryption of the ciphertext message
flmktrwhee using the keyword thirty.

Encrypted letter

f

l

m

k

t

r

w

h

e

(4)
e

Keyword letter
Decrypted letter

*P66490A0916*

9

Turn over

(d) A user-defined function uses a Vigenere cipher to encrypt plaintext
into ciphertext.

This pseudocode shows how the function is called.

SET ciphertext TO ciphertext & getCipherLetter(keywordLetter, plaintextLetter)

(i) State what would be returned by this function.

(1)

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(ii) Give the name of one parameter passed to this function.

(1)

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(iii) State what is meant by a built-in subprogram.

(1)

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(Total for Question 3 = 17 marks)

10

*P66490A01016*

4 Zak sells snacks at an after-school club.
(a) He wants a program that will hold details of the products he sells.

The program must:
•

•

generate a five-character product code that:
–

starts with the first three letters of the product name

–

ends with a random number between 10 and 30

display the product code followed by the product name.

Open Q04a in the code editor.

Write the program.

You must use the structure given in the file Q04a to complete the program.

Do not add any further functionality.

Save your code as Q04aFINISHED with the correct file extension for the
programming language.

(7)

(b) Zak plans to implement a binary search algorithm to search a table of products.
(i) Explain one advantage of a binary search compared to a linear search.

(2)

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

*P66490A01116*

11

Turn over

(ii) Figure 2 shows an algorithm for a binary search.
1 #
Initialise variables
2
SET productSearch TO " "
3
SET startPosition TO 1
4
SET midPosition TO 0
5
SET endPosition TO LENGTH(productList)
6
SET found TO False
7
8
#
Print prompts, take and check input from user
9
SEND "Enter the product code" TO DISPLAY
10
RECEIVE productSearch FROM (STRING) KEYBOARD
11
REPEAT
12
midPosition = (startPosition + endPosition) DIV 2
13
IF productList[midPosition] < productSearch THEN
14
startPosition = midPosition + 1
15
END IF
IF productList[midPosition] > productSearch THEN
16
17
endPosition = midPosition – 1
18
END IF
19 UNTIL productList[midPosition] = productSearch OR startPosition = endPosition
Figure 2

This binary search algorithm will be used to search the product list for the
product code str15.

Complete the table to indicate the order in which the product codes will be
examined by the algorithm.

Write the number 1 by the first product code to be examined, 2 by the second
code to be examined, and so on.

Position in list

12

Product code

1

ark11

2

asp11

3

bar13

4

dri15

5

mil19

6

rib10

7

str15

8

tor16

Order examined

*P66490A01216*

(4)

(iii) Zak has another list containing the names of five students who attend the
after-school club.

Give the maximum number of names that would need to be examined by the
binary search algorithm to determine whether a name appears in the list.

(1)

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(iv) Give the name of an algorithm that could be used to sort a list.

(1)

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(Total for Question 4 = 15 marks)

*P66490A01316*

13

Turn over

5 Bianca has started to write a program.
The program is a guessing game about countries and their capital cities.
Open Q05 in the code editor.
The program already:
•

displays this menu
Menu
[1] Add player name
[2] Play guess the capital city
[3] End game
Input your menu choice:

•

asks for the user’s menu choice.

Write the program code for the menu choices.
Menu choice [1] Add player name
If a player chooses this option, then they must input a player name.
Menu choice [2] Play guess the capital city
If a player chooses this option, then:
•

they must answer five questions

•

they select a question to answer by choosing a valid question number

•

each question can only be selected once (they must not be able to choose
a number more than once)

•

the question should be displayed

•

they must input the name of the capital city

•

if they guess correctly their score must be incremented by 1

•

if they guess incorrectly the correct answer must be displayed.

Menu choice [3] End game
If the user chooses this option, then the player name and score should be displayed.
Your program should function correctly even if the number of countries and
capital cities in the file is increased.
Save your code as Q05FINISHED with the correct file extension for the
programming language.

14

*P66490A01416*

(20)

You may use this space for planning / design work.
The content of this page will not be assessed.

(Total for Question 5 = 20 marks)
TOTAL FOR PAPER = 80 MARKS

*P66490A01516*

15

BLANK PAGE

16

*P66490A01616*

Advertisement