0% found this document useful (0 votes)
210 views

Paper 2 CS 2024

The document outlines the examination details for the Pearson Edexcel International GCSE (9–1) Computer Science Paper 2, scheduled for June 10-12, 2024. It includes instructions for candidates regarding the use of programming languages, code editing, and practical tasks, along with advice on answering questions. The paper consists of various programming-related questions and tasks that require candidates to demonstrate their computational thinking and coding skills.

Uploaded by

mdmuzahmed04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
210 views

Paper 2 CS 2024

The document outlines the examination details for the Pearson Edexcel International GCSE (9–1) Computer Science Paper 2, scheduled for June 10-12, 2024. It includes instructions for candidates regarding the use of programming languages, code editing, and practical tasks, along with advice on answering questions. The paper consists of various programming-related questions and tasks that require candidates to demonstrate their computational thinking and coding skills.

Uploaded by

mdmuzahmed04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Please check the examination details below before entering your candidate information

Candidate surname Other names

Centre Number Candidate Number

Pearson Edexcel International GCSE (9–1)


Monday 10 – Wednesday 12 June 2024
Time 3 hours Paper
reference 4CP0/02
Computer Science  

PAPER 2: Application of Computational Thinking

You must have: A computer workstation with appropriate Total Marks


programming language code editing software and tools, including a
code interpreter / compiler, CODES folder containing code and data files,
and pseudocode command set (enclosed)

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

1 Programmers write programs to solve problems.


(a) Programmers use many different techniques and tools to solve problems.
Identify what is meant by the term abstraction.
(1)
A Breaking a problem down into smaller more manageable parts

B Deciding if a program is efficient in terms of execution time

C Drawing flowcharts with symbols used in the computer industry

D Removing unnecessary detail to highlight the important points

(b) Open Q01b in the code editor.


A user enters a name and an age when the program executes.
The program should display a welcome message when the user is less than 30
years of age.
Amend the code to complete the program.
Save your amended code as Q01bFINISHED with the correct file extension for
the programming language.
(4)

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

(i) Give the text of a comment used in the code.


(1)

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

(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)

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

(iv) Give the logical operator used in the code.


(1)

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

(d) Arrays and records are data structures.


Identify the data that must be stored in a record rather than an array.
(1)
A “King Lear”, “Macbeth”, “Romeo and Juliet”, “The Tempest”

B “King Lear”, 1983, 78.32, 99


C 1978, 1985, 1990, 2001

D 13.99, 12.75, 10.58, 11.43

(e) Complete the table to show the data type for each item.
(2)

Item Data type

45.82

True

(Total for Question 1 = 12 marks)

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)

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

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

(b) Programs can have runtime errors.


(i) State what is meant by the term runtime error.
(1)

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

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

(ii) Give one example of a runtime error.


(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

The length of the rectangle is always 4


The program should calculate the perimeter of the rectangle.
The program should display the width, the length and the perimeter of
the rectangle.
There are three errors in the code.
Amend the code to correct the errors.
Save your amended code as Q02cFINISHED with the correct file extension for the
programming language.
(3)
(d) Figure 1 shows part of an online form displayed in a browser.

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

(Total for Question 2 = 11 marks)

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)

A B A OR B NOT B (A OR B) AND (NOT B)

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

<empty> You must provide a number

Any negative number The number must be greater than zero

0 The number must be greater than zero

1 to 20 Acceptable

60 or more Acceptable

31 to 39 Centre

30 Perfect

Any other number No message

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)

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

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

(ii) State where a local variable is accessible.


(1)

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

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

(b) An algorithm reports the range that an integer falls within.


Integers from 0 to 39 are in the low range.
Integers from 40 to 69 are in the middle range.
Integers from 70 to 100 are in the high range.
Figure 4 and Figure 5 show two algorithms that solve this problem.

1 SEND ‘Enter an integer: ’ TO DISPLAY


2 RECEIVE theNumber FROM (INTEGER) KEYBOARD
3 IF (theNumber < 40) THEN
4 SEND ‘Low range’ TO DISPLAY
5 ELSE
6 IF (theNumber < 70) THEN
7 SEND ‘Middle range’ TO DISPLAY
8 ELSE
9 SEND ‘High range’ TO DISPLAY
10 END IF
11 END IF

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

3 IF (theNumber < 40) THEN


4 SEND ‘Low range’ TO DISPLAY
5 END IF
6 IF (theNumber > 39) AND (theNumber < 70) THEN
7 SEND ‘Middle range’ TO DISPLAY
8 END IF
9 IF (theNumber > 69) THEN
10 SEND ‘High range’ TO DISPLAY
11 END IF

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

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

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

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

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

(b) Binary search is a divide and conquer algorithm.


Here is a list of data.

10 12 13 14 15 16 17 18 19 20

A binary search is used to check whether the number 11 is in the list.


The midpoint is calculated by adding the high index to the low index and integer
dividing by 2
Complete the table to show the values for the high index, the low index and the
midpoint on each pass of a binary search.
You may not need to use all the rows in the table.
(4)

high index low index midpoint

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

A program is required to calculate and display:


• a subtotal for each line of sales
• a grand total for all the sales in the file.
Figure 8 shows the intended output from the program.

1000
2000
3000
4000
5000
Grand total: 15000

Figure 8

Open Q05c in the code editor.


Amend the code to produce the intended output.
You must use the structure and variables given in Q05c to complete the program.
Do not add any further functionality.
Save your code as Q05cFINISHED with the correct file extension for the
programming language.
(8)
(Total for Question 5 = 14 marks)

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

Open the file Q06 in the code editor.


Write a program to produce the intended output.
You must use the structure and variables given in Q06 to complete the program.
Your program should function correctly even if the number of pairs in the array
is changed.
You should use techniques to make your code easy to read.
Save your amended code as Q06FINISHED with the correct file extension for the
programming language.
(20)

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.

(Total for Question 6 = 20 marks)

TOTAL FOR PAPER = 80 MARKS

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

INTEGER INTEGER REAL

REAL REAL 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

Syntax Explanation of syntax Example

SET Counter TO 0
SET Variable TO <value> Assigns a value to a variable.
SET MyString TO ‘Hello world’

Computes the value of an


SET Sum TO Score + 10
SET Variable TO <expression> expression and assigns to
SET Size to LENGTH(Word)
a variable.

Assigns a value to an element SET ArrayClass[1] TO ‘Ann’


SET Array[index] TO <value>
of a one-dimensional array. SET ArrayMarks[3]TO 56

Initialises a one-dimensional
SET Array TO [<value>, ...] SET ArrayValues TO [1, 2, 3, 4, 5]
array with a set of values.

SET Array [RowIndex, Assigns a value to an element


SET ArrayClassMarks[2,4] TO 92
ColumnIndex] TO <value> of a two dimensional array.

Selection

Syntax Explanation of syntax Example

IF <expression> THEN IF Answer = 10 THEN


If <expression> is true then
<command> SET Score TO Score + 1
command is executed.
END IF END IF

IF <expression> THEN IF Answer = ‘correct’ THEN


If <expression> is true then first
<command> SEND ‘Well done’ TO DISPLAY
<command> is executed,
ELSE ELSE
otherwise second
<command> SEND ‘Try again’ TO DISPLAY
<command> is executed.
END IF END IF

4 P75737A

Repetition

Syntax Explanation of syntax Example

WHILE <condition> DO Pre-conditioned loop. Executes WHILE Flag = 0 DO


<command> <command> whilst SEND ‘All well’ TO DISPLAY
END WHILE <condition> is true. END WHILE

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.

Count controlled loop. The


REPEAT <expression> TIMES REPEAT 100-Number TIMES
number of times <command>
<command> SEND ‘*’ TO DISPLAY
is executed is determined by
END REPEAT END REPEAT
the expression.

FOR <id> FROM <expression>


Count controlled loop. FOR Index FROM 1 TO 10 DO
TO
Executes SEND ArrayNumbers[Index]
<expression> DO
<command> a fixed number of TO DISPLAY
<command>
times. END FOR
END FOR
FOR <id> FROM <expression>
TO FOR Index FROM 1 TO 500 STEP
<expression> STEP Count controlled loop using 25 DO
<expression> DO a step. SEND Index TO DISPLAY
<command> END FOR
END FOR
SET WordsArray TO [‘The’, ‘Sky’,
‘is’, ‘grey’]
FOR EACH <id> FROM SET Sentence to ‘‘
Count controlled loop.
<expression> DO FOR EACH Word FROM
Executes for each element of
<command> WordsUArray DO
an array.
END FOREACH SET Sentence TO Sentence &
Word & ‘ ‘
END FOREACH

P75737A 5
 Turn over
Input/output

Syntax Explanation of syntax Example

SEND ‘Have a good day.’ TO


SEND <expression> TO DISPLAY Sends output to the screen.
DISPLAY

RECEIVE Name FROM (STRING)


KEYBOARD
RECEIVE <identifier> FROM
RECEIVE LengthOfJourney
(type) Reads input of specified type.
FROM (INTEGER) CARD_READER
<device>
RECEIVE YesNo FROM
(CHARACTER) CARD_READER

File handling

Syntax Explanation of syntax Example

Reads in a record from a <file>


and assigns to a <variable>.
READ <File> <record> READ MyFile.doc Record
Each READ statement reads a
record from the file.

Writes a record to a file.


WRITE MyFile.doc Answer1,
WRITE <File> <record> Each WRITE statement writes a
Answer2, ‘xyz 01’
record to the file.

Subprograms

Syntax Explanation of syntax Example

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

DIV Integer division

Relational operators

Symbol Description

= equal to

<> not equal to

> greater than

>= greater than or equal to

< less than

<= less than or equal to

Logical operators

Symbol Description

Returns true if both conditions


AND
are true.
Returns true if any of the
OR
conditions are true.
Reverses the outcome of the
NOT expression; true becomes false,
false becomes true.

P75737A 7

BLANK PAGE

8 P75737A


You might also like