Paper 2 CS 2024
Paper 2 CS 2024
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.
• using out
Carry practical tasks on the computer system and save new or amended code
the name given in the question with the appropriate file extension.
•• You mustoverwrite
Do not the original code and data files provided to you.
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
P75737A
©2024 Pearson Education Ltd.
F:1/1/1/1/1/
*P75737A0116*
Answer all questions.
Answer the questions requiring a written answer in the spaces provided.
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
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
2
*P75737A0216*
(c) Open Q01c in the code editor.
Use the code to answer these questions.
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
(ii) Give the text of a line that creates and initialises a variable.
(1)
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
(iii) Give the keyword that starts the selection used in the code.
(1)
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
(e) Complete the table to show the data type for each item.
(2)
45.82
True
3
*P75737A0316* Turn over
2 Programmers design, correct and test programs.
(a) Programmers design programs.
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
(i) Identify the term for a step‑by‑step description to complete a task.
(1)
A Algorithm
B Computational thinking
C Decomposition
D Pseudocode
(ii) A constant is a memory location whose value does not change during
program execution.
Give the name for a memory location whose value can change during
program execution.
(1)
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
*P75737A0416*
(c) Open Q02c in the code editor.
The program generates a random number for the width of a rectangle.
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
Figure 1
Complete the table to show two examples of erroneous, one example of normal
and one example of boundary test data for the memorable word field.
Each example must be different.
(4)
Erroneous
Erroneous
Normal
Boundary
5
*P75737A0516* Turn over
3 Programs use logic, display data and validate input.
(a) The truth table shows the initial values for A and B.
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
Complete the truth table to show the results of each operation.
(4)
0 0
0 1
1 0
1 1
(b) Figure 2 shows the intended output from a program that displays every other
name in an array of star names.
Alasia
Castor
Electra
Gudja
Izar
Kang
Maia
Ogma
Figure 2
Open Q03b in the code editor.
Amend the code to display every other name in the array of star names.
Do not add any further functionality.
Save your code as Q03bFINISHED with the correct file extension for the
programming language.
(3)
6
*P75737A0616*
(c) A program validates a number input by the user.
Figure 3 shows the output messages based on the inputted number.
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
Input Output
1 to 20 Acceptable
60 or more Acceptable
31 to 39 Centre
30 Perfect
Figure 3
Open Q03c in the code editor.
Amend the code to ensure the messages are generated correctly.
Do not add any further functionality.
Save your code as Q03cFINISHED with the correct file extension for the
programming language.
(6)
(Total for Question 3 = 13 marks)
7
*P75737A0716* Turn over
4 Programmers write code that keeps track of values, is efficient and uses subprograms.
(a) Global variables are different from local variables.
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
(i) State where a global variable is created.
(1)
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Figure 4
8
*P75737A0816*
1 SEND ‘Enter an integer: ’ TO DISPLAY
2 RECEIVE theNumber FROM (INTEGER) KEYBOARD
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
Figure 5
Explain the reason that the algorithm in Figure 4 is more efficient than the
algorithm in Figure 5.
(2)
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ........................................................................................................................................... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ........................................................................................................................................... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ........................................................................................................................................... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ........................................................................................................................................... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9
*P75737A0916* Turn over
(c) A program is required to create a new key.
The program takes two inputs.
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
The first input is a four‑character string.
The second input is a whole number.
The key is constructed by joining the first two characters from the string, the
number and the final two characters from the string.
When the user enters the four‑character string abcd and the integer 123, the
program must construct and display the new key ab123cd
Open Q04c in the code editor.
Amend the code to:
• complete the subprogram to construct the new key
• complete the call to the subprogram.
Do not add any further functionality.
Save your code as Q04cFINISHED with the correct file extension for the
programming language.
(6)
(Total for Question 4 = 10 marks)
10
*P75737A01016*
11
Turn over
*P75737A01116*
BLANK PAGE
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
5 Programmers refine algorithms, use searches and read data from files.
(a) Figure 6 shows an algorithm that determines whether the animal name inputted
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
by the user is found.
1 SET a1 TO ‘alpaca’
2 SET a2 TO ‘bear’
3 SET a3 TO ‘camel’
4 SET a4 TO ‘deer’
5
6 SEND (‘Enter an animal: ’) TO DISPLAY
7 RECEIVE target FROM (STRING) KEYBOARD
8
9 IF (a1 = target) THEN
10 SEND (‘Found’) TO DISPLAY
11 ELSE
12 IF (a2 = target) THEN
13 SEND (‘Found’) TO DISPLAY
14 ELSE
15 IF (a3 = target) THEN
16 SEND (‘Found’) TO DISPLAY
17 ELSE
18 IF (a4 = target) THEN
19 SEND (‘Found’) TO DISPLAY
20 END IF
21 END IF
22 END IF
23 END IF
Figure 6
12
*P75737A01216*
Explain one improvement to this algorithm that will reduce the number of
variables required and will enable it to work with any number of animals.
(2)
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10 12 13 14 15 16 17 18 19 20
13
*P75737A01316* Turn over
(c) Figure 7 shows the Sales.txt file. It stores sales information.
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
264,140,120,284,192
420,377,435,376,392
619,589,606,586,600
799,811,788,814,788
982,1007,1013,989,1009
Figure 7
1000
2000
3000
4000
5000
Grand total: 15000
Figure 8
14
*P75737A01416*
6 A program stores pairs of words in a two‑dimensional array.
Each word in a pair starts with a different letter.
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
Each pair of words should be in alphabetical order, but some are not.
The last pair in the array is an empty pair.
The program must:
• replace the final blank pair of words with the variables word1 and word2
• display the pair number of each pair, followed by each word in the pair, without
punctuation
• display the longer word in the pair, indented
• display any pair found to be not in alphabetical order, in alphabetical order,
indented, without punctuation.
Figure 9 shows part of the intended output from a functional program.
1 apple banana
banana
2 wrist leg
wrist
leg wrist
3 blue yellow
yellow
4 speaker keyboard
keyboard
keyboard speaker
Figure 9
15
*P75737A01516* Turn over
You may use this space for planning/design work.
DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA DO NOT WRITE IN THIS AREA
The content of this space will not be assessed.
16
*P75737A01616*
Pearson Edexcel International GCSE (9–1)
Monday 10 – Wednesday 12 June 2024
Paper
reference 4CP0/02
Computer Science
Component 2
Pseudocode command set
Resource Booklet
Do not return this Booklet with the question paper.
Turn over
P75737A
©2024 Pearson Education Ltd.
F:1/1/1/1/1/
*P75737A*
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 P75737A
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.
P75737A 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 P75737A
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.
P75737A 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 P75737A
Arithmetic operators
Symbol Description
+ Add
- Subtract
/ Divide
* Multiply
^ Exponent
MOD Modulo
Relational operators
Symbol Description
= equal to
Logical operators
Symbol Description
P75737A 7
BLANK PAGE
8 P75737A