CS Holidays Package
CS Holidays Package
1 Tick (3) one box to show which operator means less than or equal to.
A OR
B <
C <=
D >=
[1]
2 Tick (3) one box to show how a value can be passed to a procedure.
A function
B parameter
C return
D subroutine
[1]
Draw one line to link each description to the most appropriate data type.
Not all data types will be used.
BOOLEAN
a whole number
CHAR
a single letter
INTEGER
a word or phrase
REAL
[4]
2
4 Tick (3) one box to show which word accurately describes the scope of a variable declared in a
procedure.
A Function
B Global
C Local
D Subroutine
[1]
Draw one line to link each description to its most appropriate pseudocode statement.
Not all pseudocode statements will be used.
a statement to start a
pre-condition loop Value Value + 1
[4]
3
(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]
6 Describe the purpose of test data. Include an example of a type of test data in your answer.
Description .......................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Example ...........................................................................................................................................
..........................................................................................................................................................
[3]
4
7 The energy efficiency of an electrical appliance is the percentage of useful energy out compared with
the total energy in.
An algorithm has been written in pseudocode to calculate the energy efficiency of an appliance.
Values for total energy in and useful energy out are input. The efficiency is calculated and output
as a percentage.
The entry of the number –1 for either value stops the algorithm.
01 REPEAT
02 OUTPUT "Enter total energy in "
03 INPUT TotalEnergyIn
04 OUTPUT "Enter useful energy out "
05 OUTPUT UsefulEnergyOut
06 IF TotalEnergyIn <> -1 AND UsefulEnergy <> -1
07 THEN
08 Efficiency (UsefulEnergyOut / TotalEnergyIn) * 100
09 OUTPUT "Efficiency is ", Efficiency, "%"
10 ENDIF
11 UNTIL TotalEnergyIn <> -1 OR UsefulEnergyOut <> -1
(a) Identify the three errors in the pseudocode and suggest corrections.
Error 1 .......................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Error 2 .......................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Error 3 .......................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
[3]
(b) Write pseudocode to check for an efficiency of 92% or over for this appliance and to output
“A-rated” if the efficiency is 92% or over.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
5
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
[4]
6
9 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
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [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.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[6]
...................................................................................................................................................
............................................................................................................................................. [1]
7
10 The one-dimensional (1D) array TeamName[] contains the names of teams in a sports league.
The two-dimensional (2D) array TeamPoints[] contains the points awarded for each match.
The position of each team’s data in the two arrays is the same. For example, the team stored at
index 10 in TeamName[] and TeamPoints[] is the same.
The variable LeagueSize contains the number of teams in the league. The variable MatchNo
contains the number of matches played. All teams have played the same number of matches.
The arrays and variables have already been set up and the data stored.
Each match can be played at home or away. Points are recorded for the match results of each
team with the following values:
• 3 – away win
• 2 – home win
• 1 – drawn match
• 0 – lost match.
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.
You do not need to initialise the data in the arrays TeamName[] and TeamPoints[] or the
variables LeagueSize and MatchNo
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
15
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
9
A constant
A stores a value that can change at any time during the execution of a program.
MOD ...................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
RANDOM ............................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
[4]
3 Describe what happens when a function is called during the execution of a program.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [3]
10
Draw one line to link each description to the most appropriate check.
Description Check
format check
to check that some data has been entered
length check
to check that the data entered has an appropriate
number of characters
presence check
(b) Write an algorithm in pseudocode to make sure that an input for the variable Length is
between 15 and 35 inclusive. The code must iterate until a valid input has been made and the
code must include appropriate messages.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
14 An algorithm has been written in pseudocode to allow 100 positive numbers to be input. The total
and the average of the numbers are output.
01 Counter 100
02 Total 0
03 WHILE Counter > 100 DO
04 INPUT Number
05 IF Number > 0
06 THEN
07 Total Total + Counter
08 Counter Counter + 1
09 ENDCASE
10 ENDWHILE
11 OUTPUT "The total value of your numbers is ", Total
12 OUTPUT "The average value of your numbers is ", Total / 100
11
(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) Describe the changes you should make to the corrected algorithm so that a count-controlled
loop is used to allow 100 positive numbers to be input.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
12
START
Total 0
INPUT
Value
IS Yes
Value =
–1 ?
No OUTPUT
OUTPUT Total
"Rejected" Five1 Value DIV 5
STOP
Five2 Value / 5
No IS
Five1 =
Five2 ?
Yes
Ten2 Value / 10
No IS
Ten1 =
Ten2 ?
Yes
Total Total + Value
13
[6]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
14
...................................................................................................................................................
............................................................................................................................................. [1]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
15
17 A two-dimensional (2D) array Contacts[] is used to store names and telephone numbers. All
the data is stored as strings. The array must have the capacity to store 100 contacts in the form of:
• column 1 – contact names as: last name, first name
for example: Smith, John
• column 2 – telephone numbers.
The variable CurrentSize shows how many contacts are in the array.
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.
You do not need to initialise the data in the array Contacts[] and the variable CurrentSize
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
16
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
17
18 A high-level programming language makes use of arithmetic, Boolean and logical operators.
Arithmetic .........................................................................................................................................
..........................................................................................................................................................
Example ...........................................................................................................................................
..........................................................................................................................................................
Boolean ............................................................................................................................................
..........................................................................................................................................................
Example ............................................................................................................................................
..........................................................................................................................................................
Logical ..............................................................................................................................................
..........................................................................................................................................................
Example ...........................................................................................................................................
..........................................................................................................................................................
[6]
18
Numbers are input. The number 9999.9 is the last number to be input and is ignored.
(a) Write an algorithm in pseudocode to total the numbers input and to output the total.
You do not need to validate the input.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
(b) Write an algorithm in pseudocode to count and output the number of input values that are
greater than 100. You do not need to validate the input.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
19
20 An algorithm has been written in pseudocode to find and display the maximum and minimum
values in an array of 1000 positive numbers. The array List[] starts at index 1
01 Max List[1]
02 Min List[1]
03 FOR Counter 2 TO 1000
04 IF List[Counter] < Max
05 THEN
06 Max List[Counter]
07 ENDIF
08 IF List[Count] ˂ Min
09 THEN
10 Min List[Counter]
11 ENDWHILE
12 NEXT Counter
13 OUTPUT "Maximum value is ", Max
14 OUTPUT "Minimum value is ", Min
(b) Identify the line numbers of the three errors in the pseudocode and suggest a correction for
each error.
Correction .................................................................................................................................
...................................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
[3]
20
21 Circle the three words representing places where data may be stored.
22 The first stage of the program development life cycle is analysis. Two of the tasks in analysis are
abstraction and decomposition.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(b) Identify three of the component parts when a problem has been decomposed at the analysis
stage.
1 ................................................................................................................................................
2 ................................................................................................................................................
3 ................................................................................................................................................
[3]
(c) Identify and describe one other stage of the program development life cycle.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
21
START
A FALSE
B 1
IS List[B] > No
T List[B]
List[B + 1]?
Yes
List[B] List[B + 1]
List[B + 1] T
A TRUE
B B+1
No IS B =
5?
Yes
Yes IS A =
TRUE?
No
STOP
(a) The array List[1:5] used in the flowchart contains this data:
15 17 20 5 9
22
Complete the trace table using the data given in the array.
[5]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
ĬÓĉ¯Ġ³íËïÛđÕĢ·ĦµĐ×
23
24 A one-player game uses the two-dimensional (2D) array Grid[] to store the location of a secret
cell to be found by the player in 10 moves. Each row and column has 5 cells.
Start
Grid[1,1]
• The program places an ‘X’ in a random cell (not in Grid[1,1]) and empties all the other
cells in the grid.
• The player starts at the top left of the grid.
• The player has 10 moves.
• The player can move left, right, up or down by one cell and the move must be within the grid.
• “You Win” is displayed if the player moves to the cell with ‘X’ and has played 10 moves or
less.
• “You Lose” is displayed if the player has made 10 moves without finding the ‘X’.
You must use pseudocode or program code and add comments to explain how your code works.
You do not need to declare any arrays or variables; you may assume that this has already been
done.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
13
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
25
...................................................................................................................................................
............................................................................................................................................. [1]
26
1 ................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
3 ................................................................................................................................................
...................................................................................................................................................
4 ................................................................................................................................................
...................................................................................................................................................
[4]
The array:
A ................................................................................................................................................
The variables:
T ................................................................................................................................................
C ................................................................................................................................................
L ................................................................................................................................................
[3]
(d) State two other ways the algorithm can be made easier to understand and maintain.
1 ................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
[2]
27
............................................................................................................................................. [1]
START
STOP
[6]
28
(c) Give two different sets of test data for this algorithm and state the purpose of each set.
Set 1 .........................................................................................................................................
Purpose ....................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Set 2 .........................................................................................................................................
Purpose ....................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[4]
(d) Complete the headings for the trace table to show a dry-run for this algorithm.
You do not need to trace the algorithm.
[3]
(e) Describe an improvement that should be made to the requirements for this algorithm.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
29
27 Drama students put on a performance of a play for one evening. Seats in a small theatre can be
booked for this performance.
The theatre has 10 rows of 20 seats. The status of the seat bookings for the evening is held in the
two-dimensional (2D) Boolean array Evening[]
Each element contains FALSE if the seat is available and TRUE if the seat is booked.
Up to and including four seats can be booked at one time. Seats are allocated in order from those
available. A row or seat number cannot be requested.
The array Evening[] has already been set up and some data stored.
You must use pseudocode or program code and add comments to explain how your code works.
You do not need to declare any arrays or variables; you may assume that this has already been
done.
You do not need to initialise the data in the array Evening[]
All inputs and outputs must contain suitable messages.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
13
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................