Professional Documents
Culture Documents
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.
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
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
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
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:
Complete the trace table using the data given in the array.
[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
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"
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
No TotalWeight
> 100?
Yes
STOP
Page | 19
Complete the trace table for the input data: [5]
13, 17, 26, 25, 5, 10, 15, 35, 20, 15
...................................................................................................................................................
.............................................................................................................................................. [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]
(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
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [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
(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
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
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.
(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]
(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,
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
(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.
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
An overview of a program or
Procedure subroutine
(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
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
...................................................................................................................................................
............................................................................................................................................. [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]
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
(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.
18m16 Transformers: The Last Knight Action Sci-Fi Yes Yes Yes
18m19 Beauty and the Beast Fantasy Romance Yes Yes Yes
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.
(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.
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]