Paper 2 2023
Paper 2 2023
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.
• examination.
Only one programming language (Python, C# or Java) must be used throughout the
• 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
P72938A
©2023 Pearson Education Ltd.
N:1/1/1/1/1/E2/1/
*P72938A0116*
Answer all questions.
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.
Indicate the programming language that you are using with a cross in a box .
C# Java Python
Figure 1
Complete the table to identify an input, an output and a process used by the
program to generate the furthest right column.
(3)
Input
Processing
Output
2
*P72938A0216*
(b) A tax rate is applied to a gross value to give a net value.
Open Q01b in the code editor.
Use the code to answer these questions.
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
*P72938A0316* Turn over
2 Solutions to problems are made up of many different components.
(a) Programmers use subprograms when developing code.
(i) Give two reasons to use subprogram libraries when developing code.
(2)
1 ............................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2 ............................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
B Iteration
C Procedure
D Selection
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
*P72938A0416*
(b) A school is planning a fish and chip dinner for the students and their families.
(i) Tickets are only sold to families.
A family is one to four adults and one to six children.
A program is being written to help manage ticket sales.
Complete the table to show examples of normal, boundary and erroneous
numeric test data for the program.
(3)
Adult Children
Normal
Boundary
Erroneous
(ii) The kitchen staff use a program to determine whether they have enough
chips or how many more they need to order.
Open Q02bii in the code editor.
There are four errors in the code.
Amend the code to correct the errors.
Use this test data to help you find the errors.
Chips in stock
Number of adults Number of children Expected output
(kilograms)
Save your amended code as Q02biiFINISHED with the correct file extension
for the programming language.
(4)
5
*P72938A0516* Turn over
3 Algorithms can be represented in flowcharts, pseudocode or program code.
1 ............................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2 ............................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
(b) An algorithm has been written to validate numbers entered by the user.
Figure 2 shows the pseudocode for the algorithm.
Figure 2
Complete the table to show the output for each set of inputs.
(3)
88 18
17 18
12 19
6
*P72938A0616*
(c) A program is required to calculate the result of raising one integer (the base) to
the power of another (the exponent).
Figure 3 shows a flowchart for the algorithm.
Start
Initialise variables
Enter value
for base
No
Set answer to 1
Set count to 0
Is count No
less than Inform user
exponent? of the result
Yes
Set answer to
answer x base
Increment count
Figure 3
7
*P72938A0716* Turn over
The program has these requirements:
• outputs meaningful error messages
• outputs the final answer with the base and the exponent.
Open Q03c in the code editor.
Write a program to implement the logic in the flowchart.
Do not add any further functionality.
Save your code as Q03cFINISHED with the correct file extension for the
programming language.
(10)
8
*P72938A0816*
4 Data is encoded for encryption and for identifying records in databases.
(a) A Caesar cipher is one method of encryption.
(i) Complete the table to show the result of applying a Caesar cipher.
(2)
PIXEL –4
CLOUD FORXG
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9
*P72938A0916* Turn over
(b) A program is needed to create a key for a database.
A user enters a two‑letter word, a whole number and a decimal number.
The program must ensure the word is only two characters long.
The program must display an error message when the word is not two
characters long.
A key is generated from the whole number, the reversed word and the whole
number part of the decimal number.
Figure 4 shows the input values and a valid key.
Enter a word: at
Enter a whole number: 12
Enter a decimal number: 7.89
12ta7
Figure 4
10
*P72938A01016*
5 A marine scientist is conducting a study of tuna in the world’s oceans.
(a) A list of tuna species needs to be sorted into descending alphabetical order
using a merge sort algorithm.
Figure 5 shows the lists created at the end of the splitting process.
Each list is a single tuna species.
Figure 5
It will require three passes to merge the lists into a single sorted list in
descending order.
Complete the merge sort using the space provided.
(2)
11
*P72938A01116* Turn over
(b) A bubble sort could be used to sort the list of tuna species into ascending order.
Figure 6 shows an algorithm for a bubble sort.
Figure 6
Line number
with error
Corrected line
of pseudocode
12
*P72938A01216*
(c) The scientist is collecting and storing data about tuna.
The data collected is:
• species
• length in centimetres
• weight in kilograms
• age in years.
The data is stored in an array.
The collected data needs to be written to a file named TunaData.txt
Each record stored in the file must have a code number in the first field.
Code numbers must start at 101
Each field in a record should be separated by a comma.
Figure 7 shows the contents of the file.
101,Yellowfin,105,15,3
102,Albacore,90,15,5
103,Skipjack,50,3,4
104,Bigeye,105,25,4
105,Atlantic Bonito,50,4,2
106,Northern Bluefin,190,120,11
107,Southern Bluefin,190,120,11
108,Tongol,90,20,4
Figure 7
13
*P72938A01316* Turn over
6 An agricultural college has a herd of dairy cows.
Data collected for the cows is stored in arrays.
The data stored is:
• the name of the breed
• the ease of care rating for that breed (1 is highest and 3 is lowest)
• the number of cows in the herd of that breed
• the volume of milk per day for a cow of that breed.
The college wants to present the data to farmers and to recommend the best breed
of cows for them.
The best breed has the highest care rating and the largest volume of milk per day for
a cow of that breed.
Open the file Q06 in the code editor.
Write a program to:
• calculate the daily volume of milk produced by each breed
• add this daily volume to the data structure tbl_dailyVolume
• display a message informing the user what each field holds, such as breed, rating,
volume per cow, count and total volume
• display the data for each breed
• calculate and display the total volume of milk produced each day by the herd
• find the recommended breed
• display the recommended breed by name.
Figure 8 shows the output from a functional program.
Figure 8
14
*P72938A01416*
Your program should function correctly even if the number of breeds
represented in the data is changed.
Save your amended code as Q06FINISHED with the correct file extension for the
programming language.
15
*P72938A01516*
BLANK PAGE
16
*P72938A01616*
Pearson Edexcel International GCSE (9–1)
Monday 5 – Wednesday 7 June 2023
Paper
reference 4CP0/02
Computer Science
Component 2
Pseudocode command set
Resource Booklet
Do not return this Booklet with the question paper.
Turn over
P72938A
©2023 Pearson Education Ltd.
N:1/1/1/1/1/E2/1/
*P72938A*
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 P72938A
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.
P72938A 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 P72938A
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.
P72938A 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 P72938A
Arithmetic operators
Symbol Description
+ Add
- Subtract
/ Divide
* Multiply
^ Exponent
MOD Modulo
Relational operators
Symbol Description
= equal to
Logical operators
Symbol Description
P72938A 7
BLANK PAGE
8 P72938A