You are on page 1of 125

Page | 2

Contents
General Guidance.................................................................................................................................................... 3
Learner’s Guide: Paper 2: ........................................................................................................................................ 3
0b Specimen Paper 2b .......................................................................................................................................... 14
1b FebMar 23 P22 ................................................................................................................................................. 21
March 2019 Paper 22, question 2, question 3, 4 and question 5 ......................................................................... 27
Summer 2019 P21 Q 4 .......................................................................................................................................... 33
Summer 2019 P22 - question 2, question 3 and question 5 ............................................................................ 36
Winter 2019 P23 Question 5 & 6 .......................................................................................................................... 43
Winter 2019 P22 Question 2, 3, 4 .................................................................................................................... 45
March 2020 P22 Question 2, 3 & 4 ................................................................................................................. 48
May/June 2020 P21 Q1e, 2, 3 4 and 5 ........................................................................................................... 52
May/June 2020 P22 Question 1(b), 2, 3 & 4 .................................................................................................. 59
Winter 20 P22 Questions 2, 3, 4, 5 & 6 ................................................................................................................. 66
16C Winter 20 P23 – Questions 2, 3 & 4 ............................................................................................................... 72
Feb/Mar 21 P22 – Questions 2, 3 & 4 ................................................................................................................... 77
18a S21 P21 – Questions 2, 3 & 4 ......................................................................................................................... 83
18c Summer 2021 P22 – Question 2, 3, 4 & 5 ...................................................................................................... 90
18c Summer 2021 P23 – Question 2, 3, 4 & 5 .............................................................................................. 95
Page | 3

General Guidance
Paper 2 advice
When drawing logic gate diagrams repeat the process backwards to make sure your answ
er is correct. For example draw the diagram for the statement, then write the statement or
your diagram and check that they match.
Make sure you have answered the algorithm questions in the way they want the answer. If
the question asks for a flowchart, make sure you draw a flowchart. If a question asks for a
description, then only drawing a flowchart or writing code will not be acceptable.
Split your time appropriately between the scenario question at the end of the paper and t
he rest of the questions. You should spend approximately 30 minutes on the scenario ques
tion. Do not got too much over this otherwise you may not have enough time for the rest o
f the exam paper.
If you get stuck on an algorithm, don't spend a long time trying to fix it. Move on and you c
an always come back later after you've answered the other questions, in that time away yo
u might be able to look at it afresh.
Test run any algorithms you write. Use some sample data and work through each line of y
our algorithm to make sure it works. If it doesn't, then you should be able to find out wher
e the problem is.
Check your spelling and case (lower or upper) especially with any database questions, e.g.
queries. Spelling and case must be exact, if in the database table it is called HOUSE, then w
riting house is inaccurate. After you have answered each question check the words you ha
ve used against those in the question.
If a question asks for an example, make sure you give one as there will be at least 1 mark
available for this.

Learner’s Guide: Paper 2:


7 Algorithm design and problem-solving
7 Algorithm design and problem-solving R A G
1 Understand the program development life cycle, limited to: analysis, design, coding and testing
a. Understand that every computer system is made up of sub-systems, which are made up of
further sub-systems
2
b. Understand how a problem can be decomposed into its component parts
c. Use different methods to design and construct a solution to a problem
3 Explain the purpose of a given algorithm
4 Understand standard methods of solution
Page | 4

a. Understand the need for validation checks to be made on input data and the different types
of validation check
5
b. Understand the need for verification checks to be made on input data and the different
types of verification check
6 Suggest and apply suitable test data
7 Complete a trace table to document a dry-run of an algorithm
8 Identify errors in given algorithms and suggest ways of correcting these errors
Write and amend algorithms for given problems or scenarios, using: pseudocode, program
9
code and flowcharts
8 Programming
8.1 Programming concepts R A G
1 Declare and use variables and constants
2 Understand and use the basic data types
3 Understand and use input and output
a. Understand and use the concept of sequence
b. Understand and use the concept of selection
c. Understand and use the concept of iteration
4
d. Understand and use the concepts of totalling and counting
e. Understand and use the concept of string handling
f. Understand and use arithmetic, logical and Boolean operators
5 Understand and use nested statements
a. Understand what is meant by procedures, functions and parameters
6 b. Define and use procedures and functions, with or without parameters
c. Understand and use local and global variables
7 Understand and use library routines
8 Understand how to create a maintainable program
8.2 Arrays R A G
1 Declare and use one-dimensional (1D) and two-dimensional (2D) arrays
2 Understand the use of arrays
3 Write values into and read values from an array using iteration
8.3 File handling R A G
1 Understand the purpose of storing data in a file to be used by a program
2 Open, close and use a file for reading and writing
9 Databases
9 Databases R A G
1 Define a single-table database from given data storage requirements
2 Suggest suitable basic data types
Understand the purpose of a primary key and identify a suitable primary key for a given
3
database table
Read, understand and complete structured query language (SQL) scripts to query data stored
4
in a single database table
10 Boolean logic
10 Boolean logic R A G
1 Identify and use the standard symbols for logic gates
2 Define and understand the functions of the logic gates
a. Use logic gates to create given logic circuits from
a:ii) problem statement
3 iii) logic expression iv) truth table
b. Complete a truth table from
a:i) problem statement
Page | 5

ii) logic expression


iii) logic circuit
c. Write a logic expression from
a:i) problem statement
ii) logic circuit
iii) truth table
Page | 6

0a Specimen Paper 2a
1 Four pseudocode descriptions and five pseudocode statements are shown.
(a) Draw a line to link each pseudocode description to the most appropriate pseudocode statement.
Some pseudocode statements will not be used.
Pseudocode description Pseudocode statement
A loop that will always iterate at FOR…TO…NEXT
least once

A conditional statement to deal IF…THEN…ELSE…ENDIF


with many possible outcomes

A loop that will always iterate a set WHILE…DO…ENDWHILE


number of times

conditional statement with CASE…OF…OTHERWISE…ENDCASE


different outcomes for true and
false

REPEAT…UNTIL

(b) Using a single loop, write an algorithm in pseudocode to output 50 names that have been stored in
the array, Name[]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[3]
2 Describe the purpose of validation and verification checks during data entry.
Include an example for each.
Validation check ................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Page | 7

..........................................................................................................................................................
Verification check ..............................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..................................................................................................................................................... [4]
3 Tick () one box to show the named section of a program that performs a specific task. [1]
A File
B Function
C Parameter
D Process
4 A satellite navigation system is an example of a computer system that is made up of sub-systems.
Part of a satellite navigation system:
• allows the user to enter details for a new destination or select a previously saved destination
• displays directions in the form of a visual map or as a list.
Draw a structure diagram for this part of the satellite navigation system. [4]
Page | 8

5 An algorithm has been written in pseudocode to input some numbers. It only outputs any numbers
that are greater than or equal to 100. The number 999 is not output and stops the algorithm.
INPUT Number
WHILE Numbers <> 999 DO
IF Number > 100 THEN
OUTPUT Number
ENDIF ENDWHILE
OUTPUT Number
(a) Identify the four errors in the pseudocode and suggest corrections.
Error 1 .......................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Error 2 .......................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Error 3 .......................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Error 4 .......................................................................................................................................
Correction .................................................................................................................................
............................................................................................................................................... [4]
(b) Write a pseudocode statement to change the corrected algorithm to output all numbers between
100 and 200 inclusive.
You do not need to rewrite the whole algorithm
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [2]
Page | 9

6 Consider this logic expression.


X = ( A AND B ) OR ( B AND NOT C )
(a) Draw a logic circuit for this logic expression.
Each logic gate must have a maximum of two inputs.
Do not simplify this logic expression. [4]

B X

(b) Complete the truth table from the given logic expression. [4]

A B C Working space X

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1
Page | 10
7 This flowchart represents an algorithm.

START

Flag 0
Count 1

IS Name[Count] Yes
> Name[Count + 1]? Temp Name[Count]

No Name[Count] Name[Count + 1]

Name[Count + 1] Temp

Flag 1

Count Count + 1

No IS Count
=4?

Yes

No IS Flag
=0?

Yes

STOP
Page | 11
(a) The array Name[1:4] used in the flowchart contains the following data:

Name[1] Name[2] Name[3] Name[4]

Jamal Amir Eve Tara

Complete the trace table using the data given in the array.

Flag Count Name[1] Name[2] Name[3] Name[4] Temp

Jamal Amir Eve Tara

[5]
(b) Describe what the algorithm represented by the flowchart is doing.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [2]
Page | 12
8 A programmer has written an algorithm to check that prices are less than $10.00
These values are used as test data:
10.00 9.99 ten
State why each value was chosen as test data.
10.00 ................................................................................................................................................ ................
..........................................................................................................................................
9.99 .................................................................................................................................................. ................
..........................................................................................................................................
ten ....................................................................................................................................................
....................................................................................................................................................... [3]
9 Explain why a program might need to store data in a file.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..................................................................................................................................................... [3]
10 A function is declared using pseudocode.
FUNCTION ConvertToCm(Inches: REAL) RETURNS REAL
RETURN Inches * 2.4
ENDFUNCTION
Tick () one box which accurately describes the use of the variable Inches [1]
A Answer
B Call
C Parameter
D Response
Page | 13
12 The variables X, Y and Z are used to store data in a program:
• X stores a string
• Y stores a position in the string (e.g. 2)
• Z stores the number of characters in the string.
(a) Write pseudocode statements to declare the variables X, Y and Z.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [3]
(b) The function Length(X) finds the length of a string X.
The function SubString(X,Y,Z) finds a substring of X starting at position Y and Z
characters long. The first character in X is in position 1.
Write pseudocode statements to:
• store the string "Programming is fun" in X
• find the length of the string and output it
• extract the word fun from the string and output it.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [6]
Page | 14
0b Specimen Paper 2b
1 A range check is used to check that a value input is above 10 and below 20.
Tick one box to show which value would be accepted. [1]
A 10
B 15
C 20
D 30
2 Four programming concepts and four descriptions are shown.
Draw one line to connect each programming concept to the most appropriate description. [3]
Programming concept Description
A subroutine that may not return a
Library routine
value

A standard subroutine that is


Structure diagram
available for immediate use

A subroutine that can be used in an


Procedure
assignment statement

An overview of a program or
Function
subroutine
3 A program checks if the weight of a baby is at least 2 kilograms.
Give, with reasons, two different values of test data that could be used for the baby’s weight. Each reason
must be different.
Value 1 .............................................................................................................................................
Reason .............................................................................................................................................
..........................................................................................................................................................
Value 2 .............................................................................................................................................
Reason .............................................................................................................................................
.................................................................................................................................................. [4]
Page | 15
4 (a) Circle the two actions that a program needs to take to store data in a file.
activate calculate close open output
print read search sort write [2]
(b) A program halted unexpectedly with the error message ‘File not found’ whilst trying to read data from
a file. Outline the actions that the program needs to take to prevent this error occurring.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [2]
4 (a) Draw a flowchart for an algorithm to:
• allow numbers to be input
• ignore any numbers that are negative
• count how many numbers are positive
• output the count of positive numbers when zero is input and end the algorithm.[6]
Page | 16
(b) Explain the changes you will make to your algorithm to also count the negative numbers.
...................................................................................................................................................
...................................................................................................................................................
..................................................................................................................................................
........................................................................................................................................... [2]
5 This section of program code asks for 80 numbers between 100 and 1000 inclusive to be entered. The
pseudocode checks that the numbers are in the correct range and then stores the valid numbers in an
array. It counts how many of the numbers are larger than 500 and then outputs the result when finished.

01 Count ← 0
02 FOR Index ← 1 TO 80
03 INPUT "Enter a number between 100 and 1000 ", Number
04 WHILE Number <= 99 AND Number >= 1001
05 INPUT "This is incorrect, please try again", Number
06 ENDWHILE
07 Num[80] ← Number
08 IF Number > 500 THEN Count ← Count + 1 ENDIF
09 UNTIL Index = 80
10 PRINT Index
11 PRINT "numbers were larger than 500"

There are four lines of code that contain errors.

State the line number for each error and write the correct code for that line.
Error 1 Line Number ....................
Correct Code ....................................................................................................................................
Error 2 Line Number ....................
Correct Code ....................................................................................................................................
Error 3 Line Number ....................
Correct Code ....................................................................................................................................
Error 4 Line Number ....................
Correct Code ...................................................................................................................... [4]
Page | 17
7 Consider the truth table:

A B C X

0 0 0 0

0 0 1 0

0 1 0 0

0 1 1 0

1 0 0 1

1 0 1 0

1 1 0 0

1 1 1 1
(a) Draw a logic circuit to represent the given truth table. Each logic gate should have a maximum of two
inputs. Do not simplify the logic circuit. [6]

B X

(b) Write a logic expression for the given truth table. Do not simplify the logic expression.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [3]
Page | 18
8 This flowchart inputs the weight of items, in kilograms, to be loaded on a trailer.
Any item over 25 kilograms is rejected. The trailer can take up to 100 kilograms.
START

TotalWeight 0
Reject 0

INPUT
Weight

IS Weight Yes Reject Reject + 1


> 25?
No

TotalWeight TotalWeight + Weight

IS
No TotalWeight
> 100?
Yes

TotalWeight TotalWeight – Weight

OUTPUT "Weight of items",


TotalWeight, "Number of items
rejected", Reject

STOP
Page | 19
Complete the trace table for the input data: [5]
13, 17, 26, 25, 5, 10, 15, 35, 20, 15

Weight Reject TotalWeight OUTPUT

9 Verification checks can be made on input data.


Tick (ü) one box to show which check is a verification check on input data. [1]
A Checksum
B Double entry check
C Echo check
D Parity check
10 A function LENGTH(X) finds the length of a string X and a function SUBSTRING(X,Y,Z) finds a substring of X
starting at position Y and Z characters long. The first character in the string is position 1.
(a) Show the value of the variable after each pseudocode statement has been executed. [5]
01 P ← "Computer Science" ........................................................................................
02 Q ← LENGTH(P) ............................................................................................................
03 R ← SUBSTRING(P,10,7) ..........................................................................................
04 S ← LENGTH(R) ............................................................................................................
05 T ← SUBSTRING(R,1,3) ............................................................................................
Page | 20
(b) Write a pseudocode statement to extract the word Computer from P and store it in the variable F.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................ [2]
11 (a) Rewrite this pseudocode algorithm using a WHILE … DO … ENDWHILE loop.
B ← FALSE
INPUT Num
FOR Counter ← 1 TO 12
IF A[Counter] = Num
THEN
B ← TRUE
ENDIF
NEXT Counter
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
..................................................................................................................................................
.............................................................................................................................................. [4]
(b) Identify the purpose of the algorithm in (a).

...................................................................................................................................................
.............................................................................................................................................. [1]
(c) Explain the difference between a WHILE … DO … ENDWHILE and a REPEAT … UNTIL loop.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [3]
Page | 21
1b FebMar 23 P22
1 Tick one box to show which word accurately describes the scope of a variable declared in a procedure.[1]

A Function
B Global
C Local
D Subroutine
(a) Four descriptions and five pseudocode statements are shown.
Draw one line to link each description to its most appropriate pseudocode statement. Not all pseudocode
statements will be used.
Description Pseudocode statement
FOR Count  1 TO 10
a statement to count
Value  Value + NewValue
a statement to total
WHILE Value > 10 DO
a statement to start a pre-condition loop
Value  Value + 1
a statement to start a post-condition loop
REPEAT
(b) Write an algorithm in pseudocode, using a single loop, to output the average of 50 numbers that have
been stored in the array Number[]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
Page | 22
2 Describe the purpose of test data. Include an example of a type of test data in your answer.
Description .......................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Example ...........................................................................................................................................
..................................................................................................................................................... [3]
4 Describe how variables and constants are used in programming.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [3]
5 A food ordering system is an example of a computer system that is made up of sub-systems.
The food ordering system:
• allows the user to enter the details of the food they want to order and to pay for the order •
displays food available as pictures or as a list.
Complete the structure diagram for the given parts of the food ordering system. [4]

Food ordering system


Page | 23
6 The energy efficiency of an electrical appliance is the percentage of useful energy out compared
with the total energy in.
An algorithm has been written in pseudocode to calculate the energy efficiency of an appliance. Values for
total energy in and useful energy out are input. The efficiency is calculated and output as a percentage.
The entry of the number –1 for either value stops the algorithm.
01 REPEAT
02 OUTPUT "Enter total energy in "
03 INPUT TotalEnergyIn
04 OUTPUT "Enter useful energy out "
05 OUTPUT UsefulEnergyOut
06 IF TotalEnergyIn < > -1 AND UsefulEnergy < > -1
07 THEN
08 Efficiency (UsefulEnergyOut / TotalEnergyIn) * 100
09 09 OUTPUT "Efficiency is ", Efficiency, "%"
10 ENDIF
11 UNTIL TotalEnergyIn <> -1 OR UsefulEnergyOut <> -1

(a) Identify the three errors in the pseudocode and suggest corrections. [3]

Error 1 .......................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Error 2 .......................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Error 3 .......................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
(b) Write pseudocode to check for an efficiency of 92% or over for this appliance and to output “A-rated” if

the efficiency is 92% or over.

...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
Page | 24
7 Consider this logic expression.
X = (A OR NOT B) AND (B AND NOT C)
(a) Draw a logic circuit for this logic expression. Each logic gate must have a maximum of two inputs. Do
not simplify this logic expression. [5]

B X

Complete the truth table from the given logic expression. [4]

A B C Working space X

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1
Page | 25
8 This flowchart represents an algorithm to find the average value of a number of sales.

START

NumberSales 0
Total 0

INPUT
SaleValue

IS Yes
SaleValue Average Total / NumberSales
= 0?

No OUTPUT
"Average sale
NumberSales NumberSales + 1 value ", Average

Total Total + SaleValue STOP

(a) Complete the trace table using this data: 5.50, 3.40, 6.25, 3.85, –11.00, 0 [4]
NumberSales Total SaleValue Average OUTPUT

(b) Identify the error in the algorithm and describe how to correct it. [3]
Error ..........................................................................................................................................
...................................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Page | 26
10 The variables X, Y and Z are used in a program: X stores a whole number, Y stores a decimal number and
Z stores a flag that can be set to TRUE or FALSE
(a) Write pseudocode statements to declare the variables X, Y and Z
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
(b) The function Same(A,B) returns TRUE if the value of A is the same as the value of B when B is rounded
to the nearest whole number and FALSE otherwise.
Write pseudocode statements to:
• define the function
• call the function with X and Y and store the return value in Z
Function definition ....................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Function call .............................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
..............................................................................................................................................[6]
(c) State the difference between defining and calling a function.
...................................................................................................................................................
............................................................................................................................................. [1]
Page | 27
March 2019 Paper 22, question 2, question 3, 4 and question 5
2 (a) An algorithm has been written in pseudocode to input 50 numbers and total only the positive
numbers.
Count ←1
Total ← Count
REPEAT
INPUT Number
IF Number <> 0
THEN
Total ← Total + Count
ENDIF
Count ← Count + 1
UNTIL Count < 50
PRINT Total

Find the four errors in the pseudocode and suggest a correction for each error.
Error 1 .......................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Error 2 .......................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Error 3 .......................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Error 4 .......................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................[4]
(b) Show how you would change the corrected algorithm to only total numbers greater than 0and
less than 20.
............................................................................................................................................................
............................................................................................................................................................
...................................................................................................................................................... [2]
Page | 28
3 This flowchart inputs the type of passenger for a survey: S for Senior, A for Adult, C for Child. All
other values are ignored, apart from Z which ends the process.
Page | 29

Complete the trace table for the passenger input data:


S, S, S, A, C, C, C, A, A, A, A, W, S, S, D, C, Z, D, S [5]
Senior Adult Child Type OUTPUT
Page | 30
4 For each of the four groups of statements in the table, place a tick in the correct column to show
whether it is an example of Selection or Repetition. [4]

Statements Selection Repetition


FOR X ← 1 TO 10
SUM ← SUM + 1
NEXT X
WHILE X > 10 DO
SUM ← SUM + 1
X←X-1
ENDWHILE
IF X > 10
THEN
SUM ← SUM + 1
X←X-1
ENDIF
REPEAT
SUM ← SUM + 1
X←X-1
UNTIL X > 10
5 A programmer restricts input values to less than 90 and greater than 60.
(a) State whether this is called validation or verification.
...................................................................................................................................................
Name the check that needs to be used.
...................................................................................................................................................[2]
(b) State three different types of test data the programmer would need to use. Give an example
of each type and the reason that the programmer chose that test data.
Type 1 .......................................................................................................................................
Example ....................................................................................................................................
Reason .....................................................................................................................................
...................................................................................................................................................
Type 2 .......................................................................................................................................
Example ....................................................................................................................................
Reason .....................................................................................................................................
...................................................................................................................................................
Type 3 .......................................................................................................................................
Example ....................................................................................................................................
Reason .....................................................................................................................................
...................................................................................................................................................[9]
Page | 31
Page | 32
Page | 33
Summer 2019 P21 Q 4
4 This section of program code may be used as a validation check.
1 PRINT "Input a value between 0 and 100 inclusive"
2 INPUT Value
3 WHILE Value < 0 OR Value > 100
4 PRINT "Invalid value, try again"
5 INPUT Value
6 ENDWHILE
7 PRINT "Accepted: ", Value
(a) Give a name for this type of validation check.
............................................................................................................................................. [1]

(b) Describe what is happening in this validation check.


............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
....................................................................................................................................................... [2]
(c) Complete the trace table for this program code using the test data: 200, 300, –1, 50, 60[3]
Value OUTPUT

(d) Draw a flowchart to represent this section of program code.


Page | 34
Page | 35
Page | 36
Summer 2019 P22 - question 2, question 3 and question 5
2 (a) An algorithm has been written in pseudo code to input 100 numbers, select and print the
largest number and smallest number.
Count 1
INPUT Number
High Number
Low Count
REPEAT
INPUT Number
IF Number > High
THEN
High Number
ENDIF
IF Number > Low
THEN
Low Number
ENDIF
Count Count + 1
UNTIL Count = 99
PRINT "Largest Number is ", Number
PRINT "Smallest Number is ", Low

Find the four errors in the pseudo code and suggest a correction for each error.
Error 1........................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Error 2........................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Error 3........................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Error 4........................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................[4]
Page | 37
(b) Show how you would change the corrected algorithm to total the numbers and print the total.
Use a variable Total.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
Page | 38
3 This flowchart inputs the marks gained in an examination. An input of –1 ends the routine.

Complete the trace table for the mark input data: 50, 70, 65, 30, 95, 50, 55, 85, 65, 35, –1, 45[4]
Total Count Distinction Mark OUTPUT
Page | 39

4 For each of the four groups of statements in the table, place a tick in the correct column to show
whether it is an example of Selection or Repetition. [4]
Statements Selection Repetition
FOR A 1 TO 100
B B + 1
NEXT A
CASE A OF
100: B A
200: C A
ENDCASE
IF A > 100
THEN
B A
ENDIF
REPEAT
A B * 10
UNTIL A > 100
5 Explain what is meant by validation and verification.
Give an example for each one.
Validation ..........................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Example ...........................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Verification ........................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Example ...........................................................................................................................................
..........................................................................................................................................................
Page | 40
...................................................................................................................................................... [6]
Page | 41
Page | 42
Page | 43
Winter 2019 P23 Question 5 & 6
5 The algorithm performs an operation on the array named MyData DIV means integer division, so
only the whole number part of the result is returned e.g. 7 DIV 2 returns a value of 3
First 0
Last 16
Found FALSE
INPUT UserIn
WHILE (First <= Last) AND (Found = FALSE) DO
Middle (First + Last) DIV 2
IF MyData[Middle] = UserIn THEN
Found TRUE
ELSE
IF UserIn < MyData[Middle] THEN
Last Middle - 1
ELSE
First Middle + 1
ENDIF
ENDIF
ENDWHILE
OUTPUT Found
This table shows the contents of the array: MyData e.g. MyData[2] stores the value 5
MyData
Index [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16]
Value 2 3 5 6 8 10 12 13 14 16 18 20 25 27 29 34 36
(a) Complete the trace table for the input data: 10 [6]
First Last UserIn Middle Found OUTPUT

(b) Describe the function being performed by the algorithm.


............................................................................................................................................................
Page | 44
............................................................................................................................................................
...................................................................................................................................................... [2]
6 Draw four different flowchart symbols and describe how they are used in a program flowchart.[4]
Flowchart symbol Description of use
Page | 45
Winter 2019 P22 Question 2, 3, 4
2 An algorithm has been written in pseudo code to select a random number using the function
RandInt(n), which returns a whole number between 1 and the argument n. The algorithm then
allows the user to guess the number.
Number  RandInt(100)
TotalTry  1
REPEAT
PRINT "Enter your guess now, it must be a whole number"
INPUT Guess
IF TotalTry > Number
THEN
PRINT "Too large try again"
ENDIF
IF Guess > Number
THEN
PRINT "Too small try again"
ENDIF
TotalTry  Guess + 1
UNTIL Guess <> Number
TotalTry  TotalTry – 1
PRINT "Number of guesses ", TotalTry

Find the four errors in the pseudocode and suggest a correction to remove each error.
Error 1 ..............................................................................................................................................
Correction .........................................................................................................................................
..........................................................................................................................................................
Error 2 ..............................................................................................................................................
Correction .........................................................................................................................................
..........................................................................................................................................................
Error 3 ..............................................................................................................................................
Correction .........................................................................................................................................
..........................................................................................................................................................
Error 4 ..............................................................................................................................................
Correction .........................................................................................................................................
Page | 46
...................................................................................................................................................... [4]
3 (a) The flowchart checks the lengths of a batch of 10 ropes. For the batch to be accepted 90% of
the lengths need to be between 24.9 and 25.1 metres.

Complete the trace table for the input data:


24.88, 25.01, 24.98, 25.00, 25.05, 24.99, 24.97, 25.04, 25.19, 25.07 [4]
Reject Count Length OUTPUT
Page | 47

(b) (i) It has been decided to only reject batches of rope that contain ropes that are too short.
State the change required to the algorithm.
............................................................................................................................................................
.................................................................................................................... [1]
(ii) Explain how the algorithm to reject batches could be improved to make it more effective.
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
.................................................................................. [2]

4 Four validation checks and four descriptions are shown.


Draw a line to connect each validation check to the correct description. [3]
Validation Description
Check
Range check Checks that some data is entered.

Checks for a maximum number of


Presence check
characters in the data entered.

Checks that the characters entered are all


Length check
numbers.

Checks that the value entered is between an


Type check
upper value and a lower value.
Page | 48
March 2020 P22 Question 2, 3 & 4
2 (a) An algorithm has been written in pseudocode to input 50 numbers. Positive numbers are
stored in the array PosNum[ ]. Negative numbers are stored in the array NegNum[ ].
Zeros are not included in the positive and negative counts.
Count ← 0
PosCount ← Count
NegCount ← Count
REPEAT
INPUT Number
IF Number > 0
THEN
PosCount ← PosCount + 1
PosNum[PosCount] ← Number
ELSE
NegCount ← NegCount + 1
NegNum[NegCount] ← Number
ENDIF
Count ← Count + 1
UNTIL Count >= 50
OUTPUT "There are ", PosCount," positive numbers"
OUTPUT "There are ", NegCount," negative numbers"
Describe the error in the pseudocode and write the correction for this error.
Error ..........................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
................................................................................................................................................... [4]
(b) The algorithm needs to be changed so there is no limit to how many numbers can be input.
When the number 9999 is input, the algorithm stops more numbers being input and outputs the
results. The number 9999 is not to be stored nor counted as a positive number.
Explain how you would change the algorithm.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
Page | 49
3 This flowchart inputs student percentage marks for three examinations. If the average of these
marks is 80% or over then a distinction grade is awarded. If the average of these marks is less
than 40% then a fail grade is awarded. Otherwise a pass grade is awarded.
Page | 50
(a) Complete a trace table for each set of input data: [5]
Set 1: 88, 74, 60
Mark1 Mark2 Mark3 Total Average OUTPUT

Set 2: 20, 33, 67


Mark1 Mark2 Mark3 Total Average OUTPUT

Set 3: 79, 91, 70


Mark1 Mark2 Mark3 Total Average OUTPUT

(b) It has been decided to include an extra grade of Merit when the average of the marks is 60%
or more, and less than 80%. Describe the changes that will need to be made to the flowchart.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
4 Explain why validation and verification checks are needed when data is input.
Include an example of each type of check in your answer.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [4]
Page | 51
Page | 52
May/June 2020 P21 Q1e, 2, 3 4 and 5
1 All variables, constants and other identifiers must have meaningful names.

Section B
2 Tick (ü) one box in each row to identify if the statement about structure diagrams is true or false. [2]
True False
Statement
() ( )
A structure diagram is a piece of code that is available throughout the structure of a
program.
A structure diagram shows the hierarchy of a system.
A structure diagram is another name for an array.
A structure diagram shows the relationship between different components of a
system.

3 Programs can perform validation and verification checks when data is entered.
(a) Give the names of two different validation checks and state the purpose of each one.
Check 1 .....................................................................................................................................
Purpose .....................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Check 2 .....................................................................................................................................
Purpose .....................................................................................................................................
...................................................................................................................................................
................................................................................................................................................... [4]
(b) Give the name of one verification check.
............................................................................................................................................. [1]
(c) Describe the difference between validation and verification.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
Page | 53
4 The pseudocode algorithm shown should allow numbers to be entered and should allow 50 numbers to be stored in
an array.#

Count ←0
REPEAT
INPUT Values[Count]

Count ← Count + 1
UNTIL Count = 0
(a) Explain why the algorithm will never end.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(b) Re-write the original pseudocode so that it terminates correctly and also prevents numbers below 100 from being
stored in the array Values[ ]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
(c) Describe how you could change your pseudocode in part (b) so that it prevents numbers below 100 and above 200
from being stored in the array Values[ ]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
Page | 54
5 The flowchart represents an algorithm.
The predefined function DIV gives the value of the result of integer division,

for example, y ← 9 DIV 4 gives y a value of 2


An input value of –1 ends the algorithm.
Page | 55

(a) Complete the trace table for the input data:


50, 33, 18, 15, 30, –1, 45, 12, 90, 6 [4]
Value Calc1 Calc2 OUTPUT

(b) Describe the purpose of the algorithm.


...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
Page | 56
Page | 57
Page | 58
Page | 59
May/June 2020 P22 Question 1(b), 2, 3 & 4
1b) Data input by a customer for Task 1 includes the day and the hour of arrival.
Identify one suitable validation check for each input and justify your choice. Your validation checks must be different.
Day of arrival – validation check ...............................................................................................
Justification ...............................................................................................................................
Hour of arrival – validation check .............................................................................................
Justification ............................................................................................................................... [4]

2 Most programming languages include basic data types. Ahmad is describing the basic data types he has used.
State the data type that Ahmad is describing in each sentence.
Choose the data type from this list of programming terms.
Array Boolean Char Constant Function Integer
Iteration Procedure Real String Variable
A number with a fractional part that can be positive or negative and used in calculations
Data type ..........................................................................................................................................
A whole number that can be positive, negative or zero and used in calculations
Data type ..........................................................................................................................................
A single number, symbol or letter
Data type ..........................................................................................................................................
A sequence of characters
Data type ..........................................................................................................................................
A data type with two values, True or False
Data type .......................................................................................................................................... [5]
Page | 60
3 (a) An algorithm has been written in pseudocode to input the names and marks of 35 students.
The algorithm stores the names and marks in two arrays Name[ ] and Mark[ ]. The highest mark awarded is found and
the number of students with that mark is counted. Both of these values are output.

Give line numbers where the four errors are to be found in the pseudocode. Suggest a
correction for each error.
Error 1 line number ...................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Error 2 line number ...................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Error 3 line number ...................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Error 4 line number ...................................................................................................................
Correction .................................................................................................................................
................................................................................................................................................... [4]
Page | 61
(b) Explain how you could extend the algorithm to also find the lowest mark awarded, count the number of students
with that mark, and output both these values.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
Page | 62
4 This flowchart inputs the points won and the points lost when playing a game. The difference between the points
won and lost is calculated and depending on the result the player can: move up to the next level, stay at the same level,
or move down to the previous level. The flowchart finishes when the input for points won is –1.
Page | 63

(a) Complete a trace table for this set of input data:


5000, 4474, 6055, 2000, 7900, 9800, 3000, 2150, –1, 6700, 7615 [3]
PointsWon PointsLost Difference OUTPUT

(b) The flowchart needs to be changed. When the difference is more than 5000 the output message is ‘Fantastic leap
up two levels’.
Describe the changes that will need to be made to the flowchart.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]

5 Arrays are data structures used in programming. Explain what is meant by the terms dimension and index in an
array. Use examples of arrays in your explanations.
Dimension ........................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Index ................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.......................................................................................................................................................... [3]
Page | 64
Page | 65
Page | 66
Winter 20 P22 Questions 2, 3, 4, 5 & 6
2 Tick (3) one box in each row to identify if the statement about subroutines is true or false. [2]
Statement true false
A subroutine is called from within a program.
A subroutine is not a complete program.
A subroutine is a self-contained piece of code.
A subroutine must return a value to the code
from which it was called.

3 This pseudocode algorithm is used as a validation check.


PRINT "Input a number from 1 to 5000"
REPEAT
INPUT Number
IF Number < 1 OR Number > 5000
THEN
PRINT "Invalid number, please try again"
ENDIF
UNTIL Number >= 1 AND Number <= 5000
PRINT Number, " is within the correct range"
Identify three different types of test data. For each type, give an example of the test data you
would use to test this algorithm and state a reason for your choice of test.
Type of test data 1 ...........................................................................................................................
Test data ...........................................................................................................................................
Reason .............................................................................................................................................
..........................................................................................................................................................
Type of test data 2 ...........................................................................................................................
Test data ...........................................................................................................................................
Reason .............................................................................................................................................
..........................................................................................................................................................
Type of test data 3 ...........................................................................................................................
Test data ...........................................................................................................................................
Reason .............................................................................................................................................
.................................................................................................................................................... [6]
Page | 67
4 This pseudocode algorithm allows 5000 numbers to be entered and stored in an array called
Number.
FOR Count = 1 TO 5000
INPUT Number[Count]
NEXT Count

Extend and re-write the algorithm using pseudocode to also count and output how many of the
numbers stored in the array are greater than 500, using the variable Higher. Only output Higher
once with an appropriate message.

..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [6]
Page | 68
5 This pseudocode represents an algorithm.
REPEAT
Flag <--- 0
FOR Count <-- 0 TO 3
IF Num[Count] < Num[Count + 1]
THEN
Store <-- Num[Count]
Num[Count] <-- Num[Count] + 1
Num[Count + 1] <-- Store
Flag = 1
ENDIF
NEXT Count
UNTIL Flag=0
(a) The contents of the array at the start of the algorithm are:
Num[0] Num[1] Num[2] Num[3] Num[4]
45 56 30 12 15
Complete the trace table for the algorithm using the data given in the array. [5]
Flag Count Num[0] Num[1] Num[2] Num[3] Num[4] Store
45 56 30 12 15

(b) Describe the purpose of the algorithm.


...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
Page | 69

6 Draw a flowchart symbol to represent each of the following: [2]


Input/Output Decision
Page | 70
Page | 71
Page | 72
16C Winter 20 P23 – Questions 2, 3 & 4
2 An algorithm has been written in pseudocode to check the temperature readings taken from a freezer
are within the range –18 degrees to –25 degrees inclusive.
The algorithm counts the number of times that the temperature reading is below –25 degrees and the
number of times that the temperature reading is above –18 degrees.
An engineer is called if there are more than 10 temperature readings below –25 degrees.
An alarm sounds if there are more than 5 temperature readings above –18 degrees.
01 TooHot = 0
02 TooCold = 1000
03 REPEAT
04 OUTPUT "Please enter temperature"
05 INPUT Temperature
06 IF Temperature < -25
07 THEN
08 TooCold = TooCold – 1
09 ENDIF
10 IF Temperature > -18
11 THEN
12 TooHot = TooHot + 1
13 ENDIF
14 UNTIL TooHot > 5 OR TooCold > 10
15 IF TooHot < 5
16 THEN
17 INPUT "Alarm!!"
18 ENDIF
19 IF TooCold > 10
20 THEN
21 OUTPUT "Call the Engineer"
22 ENDIF
Page | 73
(a) Give the line number(s) from the algorithm of:
an assignment statement .........................................................................................................
a loop ........................................................................................................................................
a counting statement ................................................................................................................
a selection statement ................................................................................................................ [4]
(b) Give line numbers where the four errors are to be found in the pseudocode. Suggest a correction for
each error.
Error 1 line number ...................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Error 2 line number ...................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Error 3 line number ...................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Error 4 line number ...................................................................................................................
Correction .................................................................................................................................
................................................................................................................................................... [4]
(c) Explain how you could extend the algorithm to count the number of times the temperature readings
are within the range –18 degrees to –25 degrees inclusive.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
Page | 74
3 Four programming concepts and five descriptions are shown.
Draw a line to connect each Programming concept to its correct Description. Not all Descriptions will be
connected to a Programming concept.
[4]
Programming
Description
concept
A subroutine that does not have
to return a value

An automatic check to ensure


Validation that data input is reasonable
and sensible

A subroutine that always returns


Verification
a value

An overview of a program or
Procedure subroutine

A check to ensure that data


Function
input matches the original
Page | 75
4 This flowchart represents an algorithm that allows the input of two numbers and performs a calculation.
The predefined function MOD finds the remainder from integer division for example X =8 MOD 5 gives X a
value of 3.
Page | 76
(a) Complete a trace table for this set of input data: [4]
11, 4, 6, 2, 3, 9, 3, 2, 2, 6, 0, 0, 1, 1
Y Z A OUTPUT

(b) Explain the purpose of this algorithm.


...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
Page | 77
Feb/Mar 21 P22 – Questions 2, 3 & 4
2 An algorithm has been written in pseudocode to:
• input 25 positive whole numbers less than 100
• find and output the largest number
• find and output the average of all the numbers
01 A←0
O2 B←0
03 C←0
04 REPEAT
05 REPEAT
06 INPUT D
07 UNTIL D > 0 AND D < 100 AND D = INT(D)
08 IF D > B
09 THEN
10 B←D
11 ENDIF
12 C←C+D
13 A←A+1
14 UNTIL A >= 25
15 E ←C/A
16 OUTPUT "Largest number is ", B
17 OUTPUT "Average is ", E
(a) Give the line number for the statements showing:
Totalling ....................................................................................................................................
Counting ...................................................................................................................................
Range check .............................................................................................................................
Calculating the average ............................................................................................................ [4]
(b) State an example for each type of test data needed to test the input of the number:
Normal test data example .........................................................................................................
Erroneous/abnormal test data example ....................................................................................
Extreme test data example ....................................................................................................... [3]
Page | 78
(c) The algorithm needs to be changed to include finding and outputting the smallest number input.
Describe how you would change the algorithm.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
3 Four pseudocode statements and three flowchart symbols are shown.
Draw a line from each pseudocode statement to its correct flowchart symbol. [4]
Page | 79
4 This algorithm accepts weights of bags of cookies. Any cookie bag weighing between 0.9 and
1.1 kilograms inclusive is acceptable. Underweight bags weigh less than 0.9 kilograms and
overweight bags weigh more than 1.1 kilograms. An input of a negative number stops the process.
Then the total number of bags, the number of overweight bags and the number of underweight
bags weighed are output.
Accept ← 0
Over ← 0
Under ← 0
OUTPUT "Enter weight of first cookie bag"
INPUT BagWeight
WHILE BagWeight > 0
IF BagWeight > 1.1
THEN
Error ← 1
ELSE
IF BagWeight < 0.9
THEN
Error ← 2
ELSE
Error ← 0
ENDIF
ENDIF
CASE Error OF
0 : Accept ← Accept + 1
1 : Over ← Over + 1
2 : Under ← Under + 1
ENDCASE
OUTPUT "Weight of next bag?"
INPUT BagWeight
ENDWHILE
Total ← Accept – Over – Under
OUTPUT "Number of bags weighed ", Total
OUTPUT "Number overweight ", Over
OUTPUT "Number underweight ", Under
Page | 80

(a) Complete a trace table for the given algorithm using this input data:
1.05, 0.99, 1.2, 0.85, 1.1, 0.9, 1.5, 0.95, 1.05, 1.00, 1.07, 0.89, –10 [7]
BagWeight Accept Over Under Error Total OUTPUT

(b) There is an error in this algorithm.


Identify the error and write the corrected pseudocode statement.
Error ..........................................................................................................................................
Correction .................................................................................................................................
................................................................................................................................................... [2]
Page | 81
Page | 82
Page | 83
18a S21 P21 – Questions 2, 3 & 4
2 Tick one box in each row to identify if the statement is about validation, verification or both. [3]
Statement Validation Verification Both
Entering the data twice to check if both entries are
the same.
Automatically checking that only numeric data has
been entered.
Checking data entered into a computer system
before it is stored or processed.
Visually checking that no errors have been
introduced during data entry.

3 Name and describe the most appropriate programming data type for each of the examples of
data given. Each data type must be different.
Data: 37
Data type name ................................................................................................................................
Data type description .......................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Data: Cambridge2021
Data type name ................................................................................................................................
Data type description .......................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Data: 47.86
Data type name ................................................................................................................................
Data type description .......................................................................................................................
..........................................................................................................................................................
....................................................................................................................................................... [6]
Page | 84
4 The pseudocode algorithm shown has been written by a teacher to enter marks for the students
in her class and then to apply some simple processing.
Count ← 0
REPEAT
INPUT Score[Count]
IF Score[Count] >= 70
THEN
Grade[Count] ← "A"
ELSE
IF Score[Count] >= 60
THEN
Grade[Count] ← "B"
ELSE
IF Score[Count] >= 50
THEN
Grade[Count] ← "C"
ELSE
IF Score[Count] >= 40
THEN
Grade[Count] ← "D"
ELSE
IF Score[Count] >= 30
THEN
Grade[Count] ← "E"
ELSE
Grade[Count] ← "F"
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
Count ← Count + 1
UNTIL Count = 30
Page | 85
(a) Describe what happens in this algorithm.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
(b) Write the pseudocode to output the contents of the arrays Score[] and Grade[] along with
suitable messages.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]

(c) Describe how you could change the algorithm to allow teachers to use it with any size of class.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
Page | 86
5 The flowchart represents an algorithm. The algorithm will terminate if –1 is entered.
Page | 87

(a) Complete the trace table for the input data: [4]
50, 75, 99, 28, 82, 150, –1, 672, 80
Value Diff1 Diff2 OUTPUT

(b) Describe the purpose of the algorithm.


...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
Page | 88
Page | 89
Page | 90
18c Summer 2021 P22 – Question 2, 3, 4 & 5
2 (a) Write an algorithm in pseudocode to input 500 positive whole numbers. Each number input
must be less than 1000. Find and output the largest number input, the smallest number input and
the range (difference between the largest number and smallest number).

...................................................................................................................................................
............................................................................................................................................. [6]

(b) Describe how the algorithm could be changed to make testing less time-consuming.
...................................................................................................................................................
............................................................................................................................................. [2]
3 (a) Draw the most appropriate flowchart symbol for each pseudocode statement. [3]
Pseudocode statement Flowchart symbol

IF Number = 20

PRINT Number

Number ← Number + 1

(b) State the type of each pseudocode statement. For example, X ← X + Y is totalling.
IF Number = 20 ........................................................
PRINT Number .........................................................
Number ← Number + 1 .............................................[3]
Page | 91
4 This algorithm checks passwords.
• Each password must be 8 or more characters in length; the predefined function Length returns
the number of characters.
• Each password is entered twice, and the two entries must match.
• Either Accept or Reject is output.
• An input of 999 stops the process.
REPEAT
OUTPUT "Please enter password"
INPUT Password
IF Length(Password) >= 8
THEN
INPUT PasswordRepeat
IF Password <> PasswordRepeat
THEN
OUTPUT "Reject"
ELSE
OUTPUT "Accept"
ENDIF
ELSE
OUTPUT "Reject"
ENDIF
UNTIL Password = 999
(a) Complete the trace table for the algorithm using this input data:
Secret, Secret, VerySecret, VerySecret, Pa55word, Pa55word, 999, 888 [3]
Password PasswordRepeat OUTPUT
Page | 92
(b) Explain how the algorithm could be extended to allow three attempts at inputting the matching
password. Any pseudocode statements used in your answer must be fully explained.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................ [4]
5 A one-dimensional array dataArray[1:20] needs each element set to zero.
(a) Write a pseudocode routine that sets each element to zero. Use the most suitable loop
structure.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
(b) Explain why you chose this loop structure.
...................................................................................................................................................
............................................................................................................................................. [1]
Page | 93
Page | 94
Page | 95
18c Summer 2021 P23 – Question 2, 3, 4 & 5
2 Draw a line to connect each Data Type to the most appropriate Description. [3]

Data Type Description


Real Must be a whole number

String Must be one of two values

Integer May be any number

Boolean May contain any combination of characters

3 Identify a suitable validation check that could be used for each piece of normal test data and
describe how it would be used. Each validation check must be different.
Test data for entering an email address: id27@cambridgeuniversity.com
Validation check name .....................................................................................................................
Description of use ............................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Test data for entering a year: 2021
Validation check name .....................................................................................................................
Description of use ............................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Test data for entering a name: Ericson-Bower
Validation check name .....................................................................................................................
Description of use ............................................................................................................................
..........................................................................................................................................................
..................................................................................................................................................... [6]
Page | 96
4 The pseudocode algorithm should allow a user to input the number of scores to be entered and
then enter the scores. The scores are totalled, the total is output and the option to enter another
set of scores is offered.
1 Count ← 0
2 REPEAT
3 FullScore ← 20
4 INPUT Number
5 FOR StoreLoop ← 1 TO Number
6 INPUT Score
7 FullScore ← FullScore
8 UNTIL StoreLoop = Number
9 OUTPUT "The full score is ", FullScore
10 OUTPUT "Another set of scores (Y or N)?"
11 OUTPUT Another
12 IF Another = "N"
13 THEN
14 Count ← 1
15 ENDIF
16 UNTIL Count = 1
(a) Identify the four errors in the pseudocode and suggest a correction for each error.
Error 1 ....................................................................................................................................
Correction ..............................................................................................................................
...............................................................................................................................................
Error 2 ....................................................................................................................................
Correction ..............................................................................................................................
...............................................................................................................................................
Error 3 ....................................................................................................................................
Correction ..............................................................................................................................
...............................................................................................................................................
Error 4 ....................................................................................................................................
Correction ..............................................................................................................................
............................................................................................................................................... [4]
(b) Show how you could change the algorithm to store the individual scores in the array
ScoreArray[], then find and print the average score once the scores have all been entered.

...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
Page | 97

5 The flowchart represents an algorithm.


The algorithm will terminate if 0 is entered at the Op input.
Page | 98
(a) Complete the trace table for the algorithm using this input data: [5]
1, 87, 14, 3, 2, 30, 5, 10, 6, 4, 10, 2, 0, 2, 90, 6
Op Value1 Value2 Ans OUTPUT

(b) State the purpose of the algorithm.


...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [1]
(c) Suggest an addition that could be made to the algorithm to make it more useful.
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [1]
Page | 99
Page | 100
Page | 101
Page | 102
1b FM 23 P22
9 A shop that sells books has set up a new database table called BookList to store book details. Part of this
table is given.
CatNo Title Fiction Author PaperBack Price StockLevel

BK01 The Princes’ Story Yes B Penn Yes 4.50 500

BK02 The Princesses’ Story Yes B Penn Yes 4.50 350

BK03 Computer Science No Way Yu Yes 19.99 20

BK04 The Modern World No P Patel No 25.00 5

BK05 The Ancient World Yes P Patel No 25.00 5

BK06 Computer Science No R Dale Yes 27.35 8

BK07 The Princes’ Story Yes B Penn No 12.50 3

BK08 The Princesses’ Story Yes B Penn No 12.50 0

BK12 Famous Five Yes E Bly Yes 2.75 45

BK15 Secret Seven Yes E Bly Yes 2.75 25

BK16 The Last Knight Yes P Mann Yes 5.99 7

BK17 The Dark Tower Yes P Mann Yes 5.99 5

BK19 The Final Chase Yes P Mann Yes 5.99 5

BK21 Maths Today Part 1 No B Ward Yes 6.75 25

BK22 Maths Today Part 2 No B Ward Yes 6.75 15

BK23 Maths Today Part 3 No B Ward Yes 6.75 10

BK26 Maths Today Workbook No B Ward Yes 6.75 30

BK27 Knitting for Beginners No A Smith Yes 6.99 3

BK30 Woodwork for Beginners No A Smith Yes 6.99 4

BK31 Networking for Beginners No A Smith Yes 6.99 0


(a) State the number of records in this part of the database table.
............................................................................................................................................. [1]
(b) (i) Give the name of the field that would be used for the primary key.
..................................................................................................................................... [1]
Page | 103
(ii) State the reason for choosing this field for the primary key.
...........................................................................................................................................
..................................................................................................................................... [1]
(c) Complete the table to identify the most appropriate data type for each field based on the data shown

in the table BookList [2]


Field Data type
CatNo
Title
Fiction
Price

(d) Write the output from this structured query language (SQL) statement.
SELECT CatNo, Title, Author
FROM BookList
WHERE StockLevel = 0;
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(e) Complete this SQL statement to display all the titles by the author B Penn. [2]
SELECT .....................................................................................................................................
FROM .........................................................................................................................................
WHERE .....................................................................................................................................;
Page | 104
0a Specimen Paper 2a
11 A database table, 2018MOV, is used to keep a record of movie details.

CatNo Title Genre1 Genre2 Blu-ray DVD Streaming

18m01 Power Rangers Adventure Fantasy Yes No Yes

18m02 Baywatch Comedy Drama Yes No Yes

18m03 Table 19 Comedy Drama Yes Yes No

18m04 Wonder Woman Action Fantasy Yes No Yes

18m05 Justice League Action Fantasy Yes Yes Yes

18m06 Twilight Thriller Action Yes Yes No

18m07 Ant Man Action Fantasy No Yes No

18m08 Venice Beach Action History No Yes No

18m12 Fast Five Action Thriller No Yes No

18m15 King Kong Adventure Fantasy No Yes No

18m16 Transformers: The Last Knight Action Sci-Fi Yes Yes Yes

18m17 The Dark Tower Fantasy Sci-Fi Yes Yes No

18m19 Beauty and the Beast Fantasy Romance Yes Yes Yes

18m21 The Mummy Action Fantasy No No Yes

18m22 Star Wars: Episode VIII Sci-Fi Action Yes No Yes

18m23 Guardians of the Galaxy Action Sci-Fi Yes Yes Yes

18m26 Thor Action Sci-Fi No Yes Yes

18m27 Twilight Fantasy Sci-Fi No No Yes

18m30 Beneath Action Fantasy Yes No No

18m31 Despicable Me Animation Action Yes Yes No


(a) State the number of records in the database table.
.............................................................................................................................................. [1]
Page | 105
(b) (i) Give the name of the field that would be used for the primary key.
...................................................................................................................................... [1]
(ii) State the reason for choosing this field for the primary key.
...........................................................................................................................................
...................................................................................................................................... [1]
(c) Complete the table to identify the most appropriate data type for each field based on the data shown in
the database table, 2018MOV.

Field Data type

CatNo

Title

Genre1

Streaming
[2]
(d) Complete the structured query language (SQL) to return the category number and title for all Comedy
movies.
SELECT CatNo, Title
.................................................. 2018MOV
WHERE Genre1 = ..................................................; [2]
Page | 106
0b Sp P22 2b
12 A database table, PERFORMANCE, is used to keep a record of the performances at a local theatre.

ShowNumber Type Title Date SoldOut

SN091 Comedy An Evening at Home 01 Sept Yes

SN102 Drama Old Places 02 Oct No

SN113 Jazz Acoustic Evening 03 Nov No

SN124 Classical Mozart Evening 04 Dec Yes

SN021 Classical Bach Favourites 01 Feb Yes

SN032 Jazz 30 Years of Jazz 02 Mar Yes

SN043 Comedy Street Night 03 Apr No

SN054 Comedy Hoot 04 May No


(a) State the number of fields and records in the table.
Fields ........................................................................................................................................
Records ........................................................................................................................... [2]
(b) Give two validation checks that could be performed on the ShowNumber field.
Validation check 1 .....................................................................................................................
..................................................................................................................................................
Validation check 2 .....................................................................................................................
............................................................................................................................................ [2]
(c) Show the output that would be given by this structured query language (SQL) statement:
SELECT Date, Title
FROM PERFORMANCE
WHERE NOT SoldOut AND Type = "Jazz";
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [2]
Page | 107
Practice Question 1
A database ELEMENTS was set up to show the properties of certain chemical elements. Part of
the database is shown below.

(a) How many fields and records are there?


Fields: ...................................................................................................................................... [1]
Records: .................................................................................................................................. [1]
(b) Which field would be best suited as primary key?
.................................................................................................................................................. [1]
(c) Write a SQL statement to display all the records in the table.
.................................................................................................................................................
……………............................................................................................................................ [2]
(d) Write a SQL statement to display name of elements and their symbols of having melting point
lesser than 40 and whose atomic weight is more than 100.
.................................................................................................................................................
……………............................................................................................................................
.................................................................................................................................................
……………........................................................................................................................... [2]
(e) Write a SQL statement to Count the number of elements having melting point lesser than 0.
.................................................................................................................................................
……………............................................................................................................................
.................................................................................................................................................
……………........................................................................................................................... [2]
Page | 108

(f) Write a SQL statement to display total atomic weight whose state at room temperature is liquid.
.................................................................................................................................................
……………............................................................................................................................
.................................................................................................................................................
……………........................................................................................................................... [2]
(g) Write a SQL statement to display total boiling point.
.................................................................................................................................................
……………............................................................................................................................
.................................................................................................................................................
……………........................................................................................................................... [2]
(h) Write a SQL statement to count elements having melting point more than 0.
.................................................................................................................................................
……………............................................................................................................................
.................................................................................................................................................
……………........................................................................................................................... [2]
Summer 2019 P21
5 The table, BEVERAGES, shows the number of calories in 100ml of a range of popular
beverages. It also shows the availability of these drinks in a can, a small bottle and a large bottle.
BevNo BevName Calories Can Small Bottle Large Bottle
Bev01 Cola 40 Yes Yes Yes
Bev02 Lime 45 Yes No Yes
Bev03 Energy Drink 1 52 Yes Yes No
Bev04 Energy Drink 2 43 Yes No No
Bev05 Mango 47 Yes No Yes
Bev06 Lemon Iced Tea 38 Yes No Yes
Bev07 Lemonade 58 Yes Yes Yes
Bev08 Orange Juice 46 Yes Yes No
Bev12 Apple Juice 50 Yes Yes No
Bev15 Chocolate Milk 83 Yes Yes No
(a) Give a reason for choosing BevNo as the primary key for this table.
...................................................................................................................................................
............................................................................................................................................. [1]
Page | 109
(b) State the number of records shown in the table BEVERAGES.
............................................................................................................................................. [1]
(c) Write a SQL statement to output a list showing just the names and primary keys
of all the beverages with a calorie count greater than 45. The list should be in alphabetical
order of names.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
(d) Show the output that would be given by this structured query language (SQL) statement:
SELECT BavNo, BevName, Calories
FROM BEVERAGES
WHERE NOT Calories < 60 ;
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [2]
Summer 2019 P22
6 A database table, FLIGHT, is used to keep a record of flights from a small airfield. Planes can
carry passengers, freight or both. Some flights are marked as private and only carry passengers.
Flight number Plane Notes Departure time Passengers
FN101 Caravan 1 Private passenger flight 08:00 Y
CN101 Caravan 2 Freight only 08:30 N
CN102 Piper 1 Freight only 09:00 N
FN104 Piper 2 Passengers only 09:20 Y
FN105 Piper 1 Freight and passengers 10:00 Y
FN106 Caravan 1 Passengers only 10:30 Y
CN108 Caravan 2 Freight only 08:00 N
CN110 Lear Private passenger flight 08:00 Y
(a) State the field that could have a Boolean data type.
Field .................................................................................................................................... [1]
(b) Wrtie a SQL statement to display just the flight numbers of all planes leaving after 10:00 that
only carry passengers.
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
Page | 110
(c) Show the output that would be given by this structured query language (SQL) statement:
SELECT Flight number, Plane, Departure Time
FROM FLIGHT
WHERE NOT Notes=”Freight only";
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [2]
27 Winter 19 P23
7 A teacher has decided to use a database table as her mark book for her Computer Science
class, which she has called MARKBOOK. For each student, the following data will be recorded:
first name, last name, their year 10 test score and their year 11 test score. The class has 32
students.
(a) State the number of fields and records required for this database.
Number of Fields ......................................................................................................................
Number of Records ..................................................................................................................[2]
(b) The data in MARKBOOK is stored under category headings: LastName, FirstName,
Y10TestScore and Y11TestScore.
State, with a reason, whether any of these headings would be suitable as a primary key.
............................................................................................................................................................
...................................................................................................................................................... [2]
(c) Write down a SQL statement to only display the first name, last name and year 10
test score of each student who achieved 50 or more in their year 10 test. The output should
be in test score order with the highest marks at the top of the list.
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
...................................................................................................................................................... [2]
Page | 111
Winter 19 P22
7 A database table, SALES, is used to keep a record of items made and sold by a furniture maker.
Item umber Order number Notes Amount Status
CH001 1921 Smith – six dining chairs 6 Delivered
TB003 1921 Smith – large table 1 In progress
CH001 1924 Hue – extra chairs 4 In progress
CH003 1925 For stock 2 Cancelled
BN001 1927 Patel – replacement bench 1 Not started
ST002 1931 Sola – small table 1 Delivered
CH003 1927 Patel – eight dining chairs with arms 8 Not started
TB003 1927 Patel – large table 1 Not started
(a) Explain why the field Item number could not be used as a primary key.
...................................................................................................................................................
............................................................................................................................................. [1]
(b) Write a SQL statement to display only the order number and item numbers of any items in
progress or not started.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................[5]
(c) Show the output that would be given by this structured query language (SQL) statement:
SELECT Item Number, Notes, Status
FROM SALES
WHERE NOT Order Number = 1927;
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [2]
Page | 112
Unseen Scenarios
0a Specimen Paper 2a
13 The 1D array StudentName[] contains the names of students in a class. The 2D array StudentMark[]
contains the mark for each subject, for each student. The position of each student’s data in the two arrays is
the same, for example, the student in position 10 in StudentName[] and StudentMark[] is the same.
The variable ClassSize contains the number of students in the class. The variable SubjectNo contains the
number of subjects studied. All students study the same number of subjects.
The arrays and variables have already been set up and the data stored.
Students are awarded a grade based on their average mark.

Average mark Grade awarded

greater than or equal to 70 distinction

greater than or equal to 55 and less than 70 merit

greater than or equal to 40 and less than 55 pass

less than 40 fail


Write a program that meets the following requirements:
• calculates the combined total mark for each student for all their subjects
• calculates the average mark for each student for all their subjects, rounded to the nearest whole number
• outputs for each student:
– name
– combined total mark
– average mark
– grade awarded
• calculates, stores and outputs the number of distinctions, merits, passes and fails for the whole class.
You must use pseudocode or program code and add comments to explain how your code works.
You do not need to initialise the data in the array.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Page | 113
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Page | 114
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
................................................................................................................................................... [15]
Page | 115
0Sp P22 2b
13 The names of patients are stored in the one-dimensional (1D) array Patient[] of type string. A separate
two-dimensional (2D) array Readings[] stores the latest data recorded about each patient. The array
already contains the readings taken by a nurse for each patient: • temperature measured to one decimal
place
• pulse rate, a whole number.
Temperature readings should be in the range 31.6 to 37.2 inclusive.
Pulse readings should be in the range 55.0 to 100.0 inclusive.
The hospital number given to the patient is used for the index on both arrays, this is a value between 1 and
1000 inclusive.
When the data for a patient is checked a warning is given if any of the readings are out of range. If both
readings are out of range, then a severe warning is given.
Write a procedure, using pseudocode or program code, that meets the following requirements:
• takes the hospital number as a parameter
• checks if the number is valid
• outputs an error message and exits the procedure if the number is not valid
• if the hospital number is valid:
– output the patient’s name
– output ‘Normal readings’ if both the readings are within range
– output ‘Warning’ and the name of the reading e.g. ‘Pulse’ if one reading is out of range
– output ‘Severe warning’ and the names of the two readings ‘Pulse and temperature’ if both
readings are out of range – exits the procedure.
You must use pseudocode or program code and add comments to explain how your code works.
You do not need to initialise the data in the arrays.
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
Page | 116
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
Page | 117
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
............................................................................................................................................................................
........................................................................................................ [15]
Page | 118
1b FM23 P22
11 The one-dimensional (1D) array TeamName[] contains the names of teams in a sports league. The two-
dimensional (2D) array TeamPoints[] contains the points awarded for each match. The position of each
team’s data in the two arrays is the same. For example, the team stored at index 10 in TeamName[] and
TeamPoints[] is the same.
The variable LeagueSize contains the number of teams in the league. The variable MatchNo contains the
number of matches played. All teams have played the same number of matches.
The arrays and variables have already been set up and the data stored.
Each match can be played at home or away. Points are recorded for the match results of each team with the
following values:
• 3 – away win
• 2 – home win
• 1 – drawn match
• 0 – lost match.
Write a program that meets the following requirements:
• calculates the total points for all matches played for each team
• counts the total number of away wins, home wins, drawn matches and lost matches for each team
• outputs for each team:
– name
– total points
– total number of away wins, home wins, drawn matches and lost matches
• finds and outputs the name of the team with the highest total points
• finds and outputs the name of the team with the lowest total points.

You must use pseudocode or program code and add comments to explain how your code works.
You do not need to declare any arrays, variables or constants; you may assume that this has already been
done.
All inputs and outputs must contain suitable messages.
You do not need to initialise the data in the arrays TeamName[] and TeamPoints[] or the variables LeagueSize
and MatchNo

..........................................................................................................................................................
Page | 119
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.......................................................................................................................................................... ........
..................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Page | 120
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................. [15]
Page | 121
Trial Question-1
A parcel delivery service accepts parcels of a certain weight and size for delivery.
A customer can check whether the parcel is suitable for delivery by entering the weight and the
dimensions (length, width and height) of each parcel.
The parcel is accepted for delivery if the following rules apply:
 each dimension (length, width and height) must be no more than 80 cm
 the sum of the three dimensions must be no more than 200 cm
 the weight must be between 1 and 10 kg, inclusive.
The prices for a parcel are based on the weight as shown in the following table:
Weight in kg >=1 and <=5 >5 and <=7.5 >7.5 and <=10
Price in $ 10 12.5 15
Write a program that meets the following requirements:
 requires a customer to input the weight and the dimensions of the parcel to be checked, with a
suitable prompt
 validates each input so only a positive numerical value is allowed
 uses a function or procedure to check if the parcel has a valid weight and valid dimensions:
– if valid, the price is calculated and output with a suitable message
– if not valid, outputs error message(s) clearly explaining the problem
 requires the customer to input whether they need to check a new parcel, with a suitable prompt:
– if they need to check a new parcel, the program repeats
– if they do not need to check a new parcel, the program ends.
You must use pseudocode or program code and add comments to explain how your code works.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Page | 122
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Page | 123
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
............................................................................................................................................................
........................................................................................................................................................
..........................................................................................................................................................
............................................................................................................................................................
................................................................................................................................................... [15]
Page | 124
Trial Question 2
A shop stores receipt numbers and amount spent on that receipt. This data is stored in the 2D
array Receipt. The first index is the receipt number and the second index is the amount spent.
If a customer wants 1% of the total spent to be given to charity, they enter their receipt number into
a computer in the shop.
The receipt number is validated to see if it has been used before. If it has not been used before,
the amount spent is retrieved. 1% of the amount spent and the choice of charities are displayed.
The customer inputs whether they want to donate to Charity1, Charity2 or Charity3.
Write a program that meets the following requirements:
 requires the customer to input their receipt number, with a suitable prompt
 a receipt number of 9999 ends the program
 validates the receipt number by checking:
– the input is a four-digit number
– the receipt number already exists in the array Receipt
 if the receipt number is valid:
– calculate and output 1% of the amount spent
– output the three charity choices
– requires the customer to input their choice of charity
 if the receipt number is not valid, output one or more error messages that clearly identify the
problem
 the program repeats.
You must use pseudocode or program code and add comments to explain how your code works.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Page | 125
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Page | 126
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
............................................................................................................................................................
...........................................................................................................................................................
................................................................................................................................................... [15]

You might also like