4cp0 02 Que 20220609
4cp0 02 Que 20220609
4cp0 02 Que 20220609
Instructions
•• Use black ink or ball-point pen.
Fill in the boxes at the top of this page with your name,
centre number and candidate number.
•• Answer all questions.
Answer the questions requiring a written answer in the spaces provided
– there may be more space than you need.
• the
Only one programming language (Python, C# or Java) must be used throughout
examination.
• Carry out practical tasks on the computer system and save new or amended code
using the name given in the question with the appropriate file extension.
•• Do not overwrite the original code and data files provided to you.
You must not use the internet during the examination.
Information
•• The total mark for this paper is 80.
The marks for each question are shown in brackets
– use this as a guide as to how much time to spend on each question.
•• This paper covers Python, C# and Java.
The CODES folder in your user area includes all the code and data files you need.
• The invigilator will tell you where to store your work.
Advice
•• Read each question carefully before you start to answer it.
Save your work regularly.
• Check your answers if you have time at the end. Turn over
*P72406A0116*
P72406A
©2022 Pearson Education Ltd.
Q:1/1/1/e2/
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
(c) Complete the table by giving an example value for each data type.
The first row has been completed for you.
(2)
integer 12
char
real
2
*P72406A0216*
(d) Describe one difference between the data used in boundary testing and the data
used in erroneous testing.
(2)
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
*P72406A0316* Turn over
2 Raza is writing a program to tell the user whether a number they input is a
prime number.
A prime number is a whole number, larger than one, that can only be divided by
one and itself with no remainder.
This pseudocode contains the logic required to complete the program.
1 FUNCTION checkPrime(pNumber)
2 BEGIN FUNCTION
3 IF pNumber = 1 THEN
4 check = False
5 ELSE
6 check = True
7 FOR count FROM 2 TO pNumber DO
8 IF pNumber MOD count = 0 THEN
9 check = False
10 END IF
11 END FOR
12 END IF
13 RETURN check
14 END FUNCTION
15
16 SEND "Enter a number: " TO DISPLAY
17 RECEIVE number FROM (INTEGER) KEYBOARD
18 SET result TO checkPrime(number)
19
20 IF result = True THEN
21 SEND (number & " is a prime number") TO DISPLAY
22 ELSE
23 SEND (number & " is not a prime number") TO DISPLAY
24 END IF
4
*P72406A0416*
(a) Answer these questions about the pseudocode.
(i) Identify a line number where selection starts.
(1)
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
(iii) Identify a line number where a string and a number are printed on the
same line.
(1)
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5
*P72406A0516* Turn over
3 Manjit sells copies of a science textbook to schools.
She needs a program to process textbook orders. It must:
• accept the input of the number of textbooks required
• generate the price per textbook
• generate the total cost of the order
• display the price per textbook and the total cost of the order.
The price of one textbook depends on the number ordered:
1–5 £20.00
6–9 £15.00
10 or more £12.00
6
*P72406A0616*
BLANK PAGE
7
*P72406A0716* Turn over
4 Several encryption algorithms have been developed.
(a) Identify what is meant by encryption.
(1)
A Conversion of ciphertext into plaintext
A B C J K L S W
D E F M N O T U X Y
G H I P Q R V Z
Figure 1
Complete the table by adding the symbol for each letter in the word MAY.
(3)
Letter M A Y
Symbol
T I
H Y S
E M N
E E E R
N A
Figure 2
8
*P72406A0816*
(i) Give the key used in the first stage of the encryption process.
(1)
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
(iii) Give the name of the encryption algorithm that has been used to produce
the ciphertext.
(1)
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9
*P72406A0916* Turn over
5 Julia runs a computer gaming club.
(a) She wants a program to check passwords stored in a file.
The file passwords.txt contains the list of passwords.
The program must:
• check each password to ensure that:
• the first character is an uppercase letter
• if it is, that it also includes at least one digit (0–9)
• if a password does not meet these requirements:
• display the password
• increment the number of incorrect passwords
• display the total number of incorrect passwords after all the passwords have
been checked.
Open Q05a in the code editor.
Write the program.
You must use the structure given in Q05a to write the program.
Do not add any further functionality.
Save your code as Q05aFINISHED with the correct file extension for the
programming language.
(9)
10
*P72406A01016*
(b) Figure 3 shows an array that stores player scores after a game.
3 2 10 8 1 9
Figure 3
3 2 10 8 1 9
(ii) Explain one reason why a bubble sort is very efficient in terms of
memory usage.
(2)
................................. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ........................................................................................................................................... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ........................................................................................................................................... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ........................................................................................................................................... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ........................................................................................................................................... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11
*P72406A01116* Turn over
(c) Describe the steps a linear search algorithm takes to find a search item.
(3)
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12
*P72406A01216*
BLANK PAGE
13
*P72406A01316* Turn over
6 Carlos wants you to create a guess the animal game.
Open Q06 in the code editor.
The code contains an array of animals.
It also contains a function that randomly selects an animal from the array. This is the
secret word the user needs to guess.
Carlos wants the program to:
• generate the number of attempts the user has to guess the secret word.
The maximum number of attempts is the length of the secret word +3. For
example, the user has 8 attempts to guess when the secret word is tiger
• keep track of letters from incorrect attempts that are in the secret word and those
that are not. There should be no duplicated letters
• display a message telling the user:
• the number of letters in the secret word
• how many attempts they have left
• force the user to input a word that is the same length as the secret word
• check whether the input word matches the secret word:
• if the words match then a message that includes the secret word and the
number of attempts taken to guess it is displayed
• if the words do not match then:
• letters from the attempt that appear in the secret word should be added
to the correct letters store
• letters from the attempt that do not appear in the secret word should be
added to the wrong letters store
• the contents of the correct and wrong letter stores are displayed
• allow the user another attempt until they have guessed the word or have run out
of attempts
• display a message telling the user the game is over including the random word if
the maximum attempts have been taken and the word has not been guessed.
14
*P72406A01416*
Figure 4 shows the contents of the correct and wrong stores after two attempts to
guess the secret word cow.
Figure 4
Your program should include at least two subprograms that you have
written yourself.
You must include comments in the code to explain the logic of your solution.
Save your code as Q06FINISHED with the correct file extension for the
programming language.
15
*P72406A01516*
BLANK PAGE
16
*P72406A01616*
Pearson Edexcel International GCSE (9–1)
Paper
reference 4CP0/02
Computer Science
Component 2
Pseudocode command set
Resource Booklet
Do not return this Booklet with the question paper.
Turn over
*P72406A*
P72406A
©2022 Pearson Education Ltd.
Q:1/1/1/e2/
Pseudocode command set
Questions in the written examination that involve code will use this pseudocode
for clarity and consistency. However, students may answer questions using any
valid method.
Data types
INTEGER
REAL
BOOLEAN
CHARACTER
Type coercion
Type coercion is automatic if indicated by context. For example 3 + 8.25 = 11.25
(integer + real = real)
Mixed mode arithmetic is coerced like this:
INTEGER REAL
Coercion can be made explicit. For example, RECEIVE age FROM (INTEGER) KEYBOARD
assumes that the input from the keyboard is interpreted as an INTEGER, not a STRING.
Constants
The value of constants can only ever be set once. They are identified by the keyword
CONST. Two examples of using a constant are shown.
CONST REAL PI
SET PI TO 3.14159
SET circumference TO radius * PI * 2
Data structures
ARRAY
STRING
Indices start at zero (0) for all data structures.
All data structures have an append operator, indicated by &.
Using & with a STRING and a non-STRING will coerce to STRING. For example, SEND ‘Fred’
& age TO DISPLAY, will display a single STRING of ‘Fred18’.
2 P72406A
Identifiers
Identifiers are sequences of letters, digits and ‘_’, starting with a letter, for example:
MyValue, myValue, My_Value, Counter2
Functions
LENGTH()
For data structures consisting of an array or string.
RANDOM(n)
This generates a random number from 0 to n.
Comments
Comments are indicated by the # symbol, followed by any text.
A comment can be on a line by itself or at the end of a line.
Devices
Use of KEYBOARD and DISPLAY are suitable for input and output.
Additional devices may be required, but their function will be obvious from the context.
For example, CARD_READER and MOTOR are two such devices.
Notes
In the following pseudocode, the < > indicates where expressions or values need to be
supplied. The < > symbols are not part of the pseudocode.
P72406A 3
Turn over
Variables and arrays
SET Counter TO 0
SET Variable TO <value> Assigns a value to a variable.
SET MyString TO ‘Hello world’
Initialises a one-dimensional
SET Array TO [<value>, ...] SET ArrayValues TO [1, 2, 3, 4, 5]
array with a set of values.
Selection
4 P72406A
Repetition
Post-conditioned loop.
REPEAT Executes REPEAT
<command> <command> until <condition> SET Go TO Go + 1
UNTIL <expression> is true. The loop must execute UNTIL Go = 10
at least once.
P72406A 5
Turn over
Input/output
File handling
Subprograms
PROCEDURE CalculateAverage
PROCEDURE <id>
(Mark1, Mark2, Mark3)
(<parameter>, …)
BEGIN PROCEDURE
BEGIN PROCEDURE Defines a procedure.
SET Avg to (Mark1 + Mark2 +
<command>
Mark3)/3
END PROCEDURE
END PROCEDURE
FUNCTION AddMarks (Mark1,
FUNCTION <id>
Mark2, Mark3)
(<parameter>, …)
BEGIN FUNCTION
BEGIN FUNCTION
Defines a function. SET Total to (Mark1 + Mark2 +
<command>
Mark3)/3
RETURN <expression>
RETURN Total
END FUNCTION
END FUNCTION
Calls a procedure or a
<id> (<parameter>, …) Add (FirstMark, SecondMark)
function.
6 P72406A
Arithmetic operators
Symbol Description
+ Add
- Subtract
/ Divide
* Multiply
^ Exponent
MOD Modulo
Relational operators
Symbol Description
= equal to
Logical operators
Symbol Description
P72406A 7
BLANK PAGE
8 P72406A