Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
2K views24 pages

Paper 2 2023

This document provides details for a computer science examination, including the date and time, paper reference, and materials required. It instructs candidates to fill in personal information and answer all questions, carrying out tasks on the provided computer system. Code files are to be saved with specified names and only one programming language is to be used.

Uploaded by

affordabalz
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)
2K views24 pages

Paper 2 2023

This document provides details for a computer science examination, including the date and time, paper reference, and materials required. It instructs candidates to fill in personal information and answer all questions, carrying out tasks on the provided computer system. Code files are to be saved with specified names and only one programming language is to be used.

Uploaded by

affordabalz
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 5 – Wednesday 7 June 2023
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.
• 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.

Answer the questions requiring a written answer in the spaces provided.

Some questions must be answered with a cross in a box . If you change your mind about an
answer, put a line through the box and then mark your new answer with a cross .

Carry out practical tasks on the computer system and save new or amended code using the
name given with the appropriate file extension.

Use only ONE programming language throughout the examination.

Indicate the programming language that you are using with a cross in a box .

C# Java Python

1 Programs are used to handle financial transactions.


(a) Monthly account statements are created by a program.
Figure 1 shows a statement.

Date Description Debit (£) Credit (£) Balance (£)


01 Jan Opening balance 128.35
04 Jan Music store 10.23 118.12
07 Jan Salary 1,515.28 1,633.40
11 Jan Electricity company 50.00 1,583.40
19 Jan Uniform shop 12.56 1,570.84
27 Jan Refund 25.00 1,595.84
29 Jan Rent 750.00 845.84
31 Jan Interest 0.25 846.09

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.

(i) Give the contents of a comment.


(1)

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

(ii) Identify a logical operator used in this program.


(1)

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

(iii) Give the name of a global variable.


(1)

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

(iv) Give the name of a constant.


(1)

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

(v) Give the name of a parameter.


(1)

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

(c) Variables and constants are used in program code.


(i) State the purpose of a constant.
(1)

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

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

(ii) Give one benefit of using a constant.


(1)

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

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

(Total for Question 1 = 10 marks)

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

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

(ii) Identify which one of these must return a result.


(1)
A Function

B Iteration
C Procedure

D Selection

(iii) State what is meant by the term local variable.


.(1)

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

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

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)

19 100 150 Stocks available

15 100 150 Order 4.0 kilograms

Save your amended code as Q02biiFINISHED with the correct file extension
for the programming language.
(4)

(Total for Question 2 = 11 marks)

5
 *P72938A0516* Turn over
3 Algorithms can be represented in flowcharts, pseudocode or program code.

(a) Trace tables can be used with flowcharts or pseudocode.


Give two characteristics of a trace table.
(2)

1 ............................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

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

2 ............................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................................................................................................................................ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

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

(b) An algorithm has been written to validate numbers entered by the user.
Figure 2 shows the pseudocode for the algorithm.

1 RECEIVE num1 FROM (INTEGER) KEYBOARD


2 RECEIVE num2 FROM (INTEGER) KEYBOARD
3 IF (((num1 < 16) AND (num2 < 23)) OR (num2 = 13)) THEN
4 SEND "State 1" TO DISPLAY
5 ELSE
6 IF ((num2 > 12) AND (num1 > 20)) THEN
7 SEND "State 2" TO DISPLAY
8 ELSE
9 IF ((num1 = 88) OR NOT (num2 = 18)) THEN
10 SEND "State 3" TO DISPLAY
11 ELSE
12 SEND "State 4" TO DISPLAY
13 END IF
14 END IF
15 END IF

Figure 2

Complete the table to show the output for each set of inputs.
(3)

num1 num2 Output

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

Is base equal Yes


to 0?
Stop
No
Enter value
for exponent

Is exponent Yes Display error


negative? message

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)

(Total for Question 3 = 15 marks)

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)

Plaintext Shift Ciphertext

PIXEL –4

CLOUD FORXG

(ii) Plaintext is encrypted using a Caesar cipher.


Compare the ciphertexts produced for the plaintext GOLD by:
• a shift of –6 followed by a shift of +8
• a single shift of +2.
(2)

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

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

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

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

(iii) Ann has written a Caesar cipher algorithm.


When the algorithm encrypts the plaintext BYTE with a shift of +5 the result
is GVYJ.
This is incorrect.
Explain the error.
.(2)

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

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

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

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

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

Open Q04b in the code editor.


Write the program.
Do not add any further functionality.
Save your code as Q04bFINISHED with the correct file extension for the
programming language.
(8)

(Total for Question 4 = 14 marks)

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.

Bigeye Blackfin Albacore Longtail Bluefin

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.

1 SET myTuna TO ["Bigeye", "Blackfin", "Albacore",


2 "Longtail", "Bluefin"]
3 SET tmp TO 0
4 SET swaps TO True
5 SET length TO LENGTH (myTuna)
6
7 WHILE (swaps = True) DO
8 SET swaps TO False
9 FOR ndx FROM 0 TO length - 1 DO
10 IF myTuna[ndx] > myTuna[ndx + 1] THEN
11 SET tmp TO myTuna[ndx + 1]
12 SET myTuna[ndx] TO myTuna[ndx + 1]
13 SET myTuna[ndx + 1] TO tmp
14 SET swaps TO True
15 END IF
16 END FOR
17 END WHILE

Figure 6

There is an error in the loop between line 9 and line 16.


Complete the table to give the line number with an error and a corrected line
of pseudocode.
(2)

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

Open Q05c in the code editor.


Write the program.
You must use the structure given in Q05c to write the program.
Do not add any further functionality.
Save your code as Q05cFINISHED with the correct file extension for the
programming language.
(6)

(Total for Question 5 = 10 marks)

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.

You may use this space for planning/design work.

The content of this space will not be assessed.

(Total for Question 6 = 20 marks)

TOTAL FOR PAPER = 80 MARKS

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

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

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 P72938A

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

P72938A 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 P72938A

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.

P72938A 7

BLANK PAGE

8 P72938A


You might also like