0% found this document useful (0 votes)
193 views111 pages

Homework #07 - Questions

Uploaded by

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

Homework #07 - Questions

Uploaded by

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

Homework #07 – Questions

Question 1

Jatinder uses Internet banking. This pseudocode checks her PIN.


c ← 0
INPUT PIN
x ← PIN
REPEAT
x ← INT(x/10)
c ← c + 1
UNTIL x < 1
IF c <> 5
THEN
PRINT "Error in PIN entered"
ELSE
PRINT "PIN OK"
ENDIF

What value of c and what message would be output if the following PINs were entered? [2]

51020 Value of c:…………………………………………………………………………………

Message: :…………………………………………………………………………………
5120 Value of c: :…………………………………………………………………………………

Message: :…………………………………………………………………………………
What type of validation check is being carried out here?
…………………………………………………………………………………………………………
Question 2

The flowchart inputs the size of a number of car engines; a value of –1 stops the input. This
information is output: average engine size and number of engines with size > 1.5 [6]
Complete the trace table for the input data. 1.8, 2.0, 1.0, 1.3, 1.0, 2.5, 2.0, 1.3, 1.8, 1.3, –1

Engine Count Number Size Average OUTPUT


Question 3

Read this section of program code that inputs twenty (20) numbers and then outputs the largest
number input.

1 h = 0
2 c = 0
3 REPEAT
4 READ x
5 IF x > h THEN x = h
6 c = c + 1
7 PRINT h
8 UNTIL c < 20

There are three errors in this code.


Locate these errors and suggest a corrected piece of code.[3]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 4

Write an algorithm, using pseudocode or flowchart only, which:

 inputs three numbers


 outputs the largest of the three numbers [3]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

Question 5

Write an algorithm, using pseudocode or flowchart only, which:

• inputs 1000 numbers


• outputs how many of these numbers were whole numbers (integers)

(You may use INT(x) in your answer, e.g. y = INT(3.8) gives the value y = 3) [4]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Describe, with examples, two sets of test data you would use to test your algorithm. [2]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

Question 6

Read this section of program code that should input 10 positive numbers and then output the
smallest number input. [4]

1 Small = 0
2 Counter = 0
3 REPEAT
4 INPUT Num
5 IF Num < Small THEN Num = Small
6 Counter = Counter + 1
7 PRINT Small
8 UNTIL Counter < 10
There are four errors in this code.
Locate these errors and suggest a corrected piece of code for each error.

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 7

The flowchart below inputs the weight of a number of parcels in kilograms. Parcels weighing more
than 25 kilograms are rejected. A value of –1 stops the input.
The following information is output: the total weight of the parcels accepted and number of parcels
rejected. [4]
Complete the trace table for the input data:
1.8, 26.0, 7.0, 11.3, 10.0, 2.5, 25.2, 5.0, 19.8, 29.3, –1

Question 8

Explain the difference between a variable and a constant in a program. [2]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

Question 9

Identify three different loop structures that you can use when writing pseudocode. [3]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 10

Read this section of program code that should input 30 positive numbers and then output the largest
number input. [4]

1 Large = 9999
2 Counter = 0
3 WHILE Counter > 30
4 DO
5 INPUT Num
6 IF Num < Large THEN Large = Num
7 Counter = Counter - 1
8 ENDWHILE
9 PRINT Large
There are four errors in this code.
Locate these errors and suggest a corrected piece of code for each error.
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 11

The flowchart below inputs six single digit numbers. The predefined function MOD gives the value
of the remainder, for example, Y ← 10 MOD 3 gives the value Y = 1
Complete a trace table for each of the two sets of input data. [4]
Set 1

5, 2, 4, 3, 1, 5
Set 2

3, 2, 1, 0, 7, 3

Trace table set 1 5, 2, 4, 3, 1, 5

Trace table set 2 3, 2, 1, 0, 7, 3

State the purpose of the flowchart [1]

…………………………………………………………………………………………………………

Identify a problem with this flowchart and explain how to correct it. [3]

Problem – …………………………………………………………………………………………

…………………………………………………………………………………………………………

Solution –
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 12

Read this section of program code that should input 50 numbers and then output the average. [4]

1 Total = 0
2 For Counter = 1 TO 50
3 INPUT Num
4 Total = Total + 1
5 Counter = Counter + 1
6 Average = Total/Counter
7 NEXT Counter
8 PRINT Average

There are four errors in this code.


Locate these errors and suggest code corrections to remove each error.

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 13

The flowchart inputs an integer. The predefined function DIV gives the integer result of the
division, e.g. Y = 10 DIV 3 gives the value Y = 3. The predefined function MOD gives the
value of the remainder, e.g. Y = 10 MOD 3 gives the value Y = 1.
Complete a trace table for each of the two input values 5 and 12.
Trace table for input value 5
Trace table for input value 5

Trace table for input value 12

State the purpose of the flowchart


…………………………………………………………………………………………………………
Question 14

Identify two different conditional statements that you can use when writing pseudocode.

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

Question 15

Read this section of program code that should input 50 numbers and then output the average of the
positive numbers only.

1 Total = 0
2 PosCount = 0
3 FOR Counter = 1 TO 50
4 INPUT Num
5 IF Num < 0 THEN Total = Total + Num
6 IF Num > 0 THEN Counter = Counter + 1
7 Average = Total/PosCount
8 NEXT Counter
9 PRINT Num

There are four errors in this code.


Locate these errors and suggest code corrections to remove each error.

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 16

This pseudocode inputs an integer. The predefined function DIV gives the value of the division, e.g.
Y = 10 DIV 3 gives the value Y = 3. The predefined function MOD gives the value of the
remainder, e.g. Y = 10 MOD 3 gives the value Y = 1.

INPUT X
WHILE X > 15
DO
T1 ← X DIV 16
T2 ← X MOD 16
CASE T2 OF
10:OUTPUT A
11:OUTPUT B
12:OUTPUT C
13:OUTPUT D
14:OUTPUT E
15:OUTPUT F
OTHERWISE OUTPUT T2
ENDCASE
X ← T1
ENDWHILE
CASE X OF
10:OUTPUT A
11:OUTPUT B
12:OUTPUT C
13:OUTPUT D
14:OUTPUT E
15:OUTPUT F
OTHERWISE OUTPUT X
ENDCASE
Complete a trace table for each of the two input values 37 and 191.
Trace table for input value 37

Trace table for input value 191

State the purpose of the pseudocode [1]

…………………………………………………………………………………………………………
Question 17

Read this section of program code that inputs 10 positive numbers and then outputs the smallest
number input.

1 Small = 1000
2 Counter = 0
3 REPEAT
4 INPUT Num
5 IF Num < Small THEN Small = Num
6 Counter = Counter + 1
7 UNTIL Counter = 10
8 PRINT Small

Identify three changes you would need to make to find the largest number input instead of the
smallest number. [3]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

Rewrite the program code with your changes. [3]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 18

The flowchart below inputs the height of children who want to ride on a rollercoaster. Children
under 1.2 metres are rejected. The ride starts when eight children have been accepted. [4]
Complete the trace table for the input data:
1.4, 1.3, 1.1, 1.3, 1.0, 1.5, 1.2, 1.3, 1.4, 1.3, 0.9, 1.5, 1.6, 1.0

Question 19

REPEAT ... UNTIL is one type of loop structure.


Identify and describe two other types of loop structure that you could use when writing pseudocode.

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 20

Read this section of program code that inputs 10 positive numbers and then outputs the total.

1 Total = 0
2 Counter = 0
3 REPEAT
4 INPUT Num
5 Total = Total + Num
6 PRINT Total
7 Counter = Counter + 1
8 UNTIL Counter = 10

This code works, but it is inefficient. Suggest three improvements that could be made. [3]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

Rewrite the program code with your improvements.[3]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 21

The flowchart below calculates the number of tins of paint required to paint walls. The flowchart
inputs the height and width of a wall in metres, the number of doors and the number of windows. A
value of –1 for the height stops the input.
Complete the trace table for the input data:
3, 5, 1, 0, 3, 7, 0, 0, 3, 5, 0, 3, 3, 7, 1, 1, –1, 0, 0, 0

Question 22

Read this section of program code that:


 inputs 10 numbers
 checks whether each number is within a specified range
 totals the numbers within the range and outside the range

1 InRange = 0
2 OutRange = 1000
3 FOR Count = 1 TO 10
4 INPUT Num
5 IF Num > 10 AND Num < 20 THEN InRange = InRange + 1
6 ELSE OutRange = OutRange - 1
7 Count = Count + 1
8 NEXT X
9 PRINT InRange, OutRange

There are four errors in this code.


Locate these errors and suggest a correction to remove each error.

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Decide, with reasons, whether the numbers 10 and 20 are within or outside the range. [4]
Question 23

The flowchart below inputs the price of an item under $10. The change from a $10 note is output.
Any amount less than 5 cents is rounded up to 5 cents.
The predefined function INT rounds a number down to the nearest whole number; for example
Z ← INT(5.7) gives the value Z = 5
Complete the trace table for the input data: 6.29
[5]

Question 24

REPEAT ... UNTIL and WHILE ... DO ... ENDWHILE are two different loop
structures you can use when writing pseudocode. Explain, using examples, why you would choose
to use each type of loop. [4]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 25

Read this section of program code that inputs positive numbers, discards any negative numbers and
then outputs the average. An input of zero ends the process.

1 Total = 0
2 Counter = 100
3 REPEAT
4 REPEAT
5 INPUT Num
6 UNTIL Num < 0
7 Total = Total + 1
8 Counter = Counter + Num
9 UNTIL Num = 0
10 Average = Total / (Counter - 1)
11 Print Average

There are four errors in this code.


Locate these errors and suggest a correction to remove each error. [4]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 26

The flowchart below inputs an integer. The predefined function DIV gives the value of the division,
for example Z ← 11 DIV 3 gives the value Z = 3. The predefined function MOD gives the value
of the remainder, for example Z ← 11 MOD 3 gives the value Z = 2.
Complete a trace table for each of the two input values 33 and 75.
Trace table for input value 33
[2]

Trace table for input value 75


[2]

Question 27

IF...THEN...ELSE...ENDIF and CASE...OF...OTHERWISE...ENDCASE are two


different conditional statements that you can use when writing pseudocode. Explain, using
examples, why you would choose to use each conditional statement. [4]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 28

Describe each of the following data types used in programming. In each case, give an example of
a piece of data to illustrate your answer. Each example must be different. [6]
Char
Description:
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

Example:
…………………………………………………………………………………………………………

String
Description:
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

Example:
…………………………………………………………………………………………………………

Boolean
Description
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

Example:
…………………………………………………………………………………………………………

Question 29

Give an example of a conditional statement using pseudocode. [2]


…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Describe the purpose of a conditional statement [2]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 30

An algorithm has been written in pseudocode to input 100 numbers, select and print the
largest number and smallest number.
Count ← 1
INPUT Number
High ← Number
Low ← Count
REPEAT
INPUT Number
IF Number > High THEN
High ← Number
ENDIF
IF Number > Low THEN
Low ← Number
ENDIF
Count ← Count + 1
UNTIL Count = 99
PRINT "Largest Number is ", Number
PRINT "Smallest Number is ", Low

Find the four errors in the pseudocode and suggest a correction for each error. [4]
Error 1
…………………………………………………………………………………………………………

Correction
…………………………………………………………………………………………………………

Error 2
…………………………………………………………………………………………………………

Correction
…………………………………………………………………………………………………………

Error 3
…………………………………………………………………………………………………………

Correction
…………………………………………………………………………………………………………

Error 4
…………………………………………………………………………………………………………

Correction
…………………………………………………………………………………………………………
Show how you would change the corrected algorithm to total the numbers and print the total.
Use a variable Total. [4]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

Question 31

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]
Question 32

Describe the purpose of variables and constants. Use an example of each in your answer. [4]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 33

This pseudocode algorithm calculates the weight and number of bags in a load of firewood. The
weight in kilograms of each bag is input. The algorithm finishes when either 50 bags have been
weighed, or as soon as the total weight exceeds 1000 kilograms. Only then are the total weight and
the number of bags in the load output.
01 TotalWeight ← 1000
02 BagCount ← 0
03 MaxBag ← 50
04 MaxWeight ← 1000
05 REPEAT
06 OUTPUT "Please Enter weight of bag"
07 INPUT Weight
08 TotalWeight ← TotalWeight + Weight
09 BagCount ← BagCount + 1
10 OUTPUT "Number of bags in the load is ", BagCount
11 UNTIL TotalWeight > MaxWeight AND BagCount >= MaxBag
12 OUTPUT "Total weight of the load is ", MaxWeight

Give the line number(s) from the algorithm of:


an assignment statement …………………………………………
a loop …………………………………………
a counting statement …………………………………………
a totalling statement …………………………………………
Give the line numbers of the four errors in this pseudocode. Suggest a correction for each error. [4]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Explain how you could extend the algorithm to calculate and display the average weight of a bag of
firewood in the load. [4]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 34

This flowchart inputs five numbers and performs a calculation.


The predefined function MOD finds the remainder from integer division for example

R ← 25 MOD 11 gives R a value of 3


Complete the trace table for this set of input data:
5, 4, 6, 2, 1, 9, 3, 2, 1, 6, 7, 6, 1, 5, 1, 0, 0, 0, 0, 0

Describe the purpose of this flowchart [2]


…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 35

An algorithm has been written in pseudocode to check the temperature readings taken from a
freezer are within the range –18 degrees to –25 degrees inclusive.
The algorithm counts the number of times that the temperature reading is below –25 degrees and the
number of times that the temperature reading is above –18 degrees.
An engineer is called if there are more than 10 temperature readings below –25 degrees.
An alarm sounds if there are more than 5 temperature readings above –18 degrees.
01 TooHot ← 0
02 TooCold ← 1000
03 REPEAT
04 OUTPUT "Please enter temperature"
05 INPUT Temperature
06 IF Temperature < -25
07 THEN
08 TooCold ← TooCold – 1
09 ENDIF
10 IF Temperature > -18
11 THEN
12 TooHot ← TooHot + 1
13 ENDIF
14 UNTIL TooHot > 5 OR TooCold > 10
15 IF TooHot < 5
16 THEN
17 INPUT "Alarm!!"
18 ENDIF
19 IF TooCold > 10
20 THEN
21 OUTPUT "Call the Engineer"
22 ENDIF

Give the line number(s) from the algorithm of: [4]


an assignment statement ……………………………………………
a loop ……………………………………………
a counting statement ……………………………………………
a selection statement ……………………………………………
Give line numbers where the four errors are to be found in the pseudocode. Suggest a correction for
each error. [4]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

Explain how you could extend the algorithm to count the number of times the temperature readings
are within the range –18 degrees to –25 degrees inclusive. [4]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 36

This flowchart represents an algorithm that allows the input of two numbers and performs a
calculation. The predefined function MOD finds the remainder from integer division for example
X ← 8 MOD 5 gives X a value of 3.
Complete a trace table for this set of input data: [4]
11, 4, 6, 2, 3, 9, 3, 2, 2, 6, 0, 0, 1, 1

Explain the purpose of this algorithm. [2]


…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 37

Name and describe the most appropriate programming data type for each of the examples of data
given. Each data type must be different. [6]
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


…………………………………………………………………………………………………………
Question 38

The flowchart represents an algorithm.


The algorithm will terminate if –1 is entered.
Complete the trace table for the input data:
50, 75, 99, 28, 82, 150, –1, 672, 80

Describe the purpose of the algorithm. [2]


…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 39

Read this section of code that inputs the ages of people entering an event. The input sequence is
ended by inputting a negative value for age. The code outputs the number of people at the event
over the age of 18.
01 Num18 = 0
02 INPUT Age
03 WHILE Age >= 0 DO
04 IF Age >= 18 THEN
05 Num18 = Num18 + Age
06 ENDIF
07 ENDWHILE
08 PRINT Num18 – Age

There are four errors in this code.


Locate these errors and suggest code correction to remove each error. [4]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 40

There is a program that stores the following data:


 EmployeeID, an employee ID which must be two letters followed by 4 numbers, e.g.
TY4587
 Manager, whether the employee is a manager or not
 AnnualHoliday, number of whole days’ annual holiday
 PayGrade, the employee’s pay grade which must be a single letter A–F
Complete the following table to identify:
 The most appropriate data type for each variable [4]

Variable Data type

EmployeeID

Manager

AnnualHoliday

PayGrade

Question 41

Study the flowchart. [4]


Complete the trace table for the input values 4, 3, −1:

Question 42

Explain the differences between a WHILE … DO … ENDWHILE and a REPEAT … UNTIL loop.
[2]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 43

This section of program code asks for 50 numbers to be entered. The total and average of the
numbers are calculated. [4]

1 Total = 0
2 Counter = 50
3 PRINT ′When prompted, enter 50 numbers, one at a time′
4 REPEAT
5 PRINT ′Enter a number′
6 INPUT Number
7 Total + Number = Total
8 Number = Number + 1
9 UNTIL Counter = 50
10 Average = Number * Counter
11 PRINT ′The average of the numbers you entered is ′, Average

There are four errors in this code.


State the line number for each error and write the correct code for that line.

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 44

Write an algorithm, using pseudocode, to input a number between 0 and 100 inclusive. The
algorithm should prompt for the input and output an error message if the number is outside this
range. [4]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 45

This flowchart inputs a range of temperatures in degrees Fahrenheit.


As each temperature is input, it is compared with the previous highest temperature. If it is higher
than the current highest, it replaces the previous highest temperature and then it is converted to
degrees Celsius. For ease of calculation, the final step of the Fahrenheit to Celsius conversion has
been approximated as division by 2. When –1 is entered, the input process stops and the highest
temperature (in both Fahrenheit and Celsius) is output [5]
Complete the trace table for the input data:
68, 46, 50, 86, 65, 50, 40, 30, –1
Question 46

Write an algorithm to input three different numbers, and then output the largest number. Use either
pseudocode or a flowchart. [4]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Give two sets of test data to use with your algorithm in previous question and explain why you
chose each set [4]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 47

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. [4]
Complete the trace table for the input data:
13, 17, 26, 25, 5, 10, 15, 35, 20, 15

Question 48

An algorithm has been written in pseudocode to input 100 numbers and print out the sum.
A REPEAT … UNTIL loop has been used. [2]
Count ← 0
Sum ← 0
REPEAT
INPUT Number
Sum ← Sum + Number
Count ← Count + 1
UNTIL Count > 100
PRINT Sum

Find the error in the pseudocode and suggest a correction.

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Rewrite the correct algorithm using a more suitable loop structure. [3]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 49

Write an algorithm using either pseudocode or a flowchart, to:


 input a positive integer
 use this value to set up how many other numbers are to be input
 input these numbers
 calculate and output the total and the average of these numbers. [6]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 50

IF … THEN … ELSE … ENDIF is one type of conditional statement used when writing
pseudocode. Identify and describe another type of conditional statement that you could use when
writing pseudocode. Give a reason why you would use this type of conditional statement. [3]

Identification:
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Description:
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Reason:
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 51

This flowchart checks a batch of 10 rice sacks for weight. Sacks should weigh 50 kilograms each.
Sacks weighing over 50.5 kilograms or less than 49.5 kilograms are rejected. The number of sacks
accepted and the number of sacks rejected is output. [5]
Complete the trace table for the input data:
50.4, 50.3, 49.1, 50.3, 50.0, 49.5, 50.2, 50.3, 50.5, 50.6

The size of the batch has increased to 50 sacks. It has been decided to only reject sacks that are
underweight. State the changes that need to be made to the flowchart. [2]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 52

An algorithm has been written in pseudocode to input some numbers and print out any numbers that
are greater than or equal to 100. The number 999 stops the algorithm.

INPUT Number
WHILE NUMBERS <> 999 DO
IF Number > 100 THEN PRINT Number ENDIF
ENDWHILE
PRINT Number

Find the four errors in the pseudocode and suggest corrections. [4]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Show, using pseudocode, how you would change the corrected algorithm to print out any numbers
between 100 and 200 inclusive [2]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 53

This flowchart inputs the weight in kilograms of a passenger stepping into a lift. The lift can take a
maximum of eight passengers or a maximum weight of 640 kilograms. [4]
Complete the trace table for the passenger input data:
50, 70, 65, 100, 95, 50, 55, 85, 70, 75

Question 54

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. [4]

Value 1
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Value 2
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
Question 55

Explain the difference between the programming concepts of sequence and selection. Include an
example of a programming statement for each concept in your explanation.

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 56

Write an algorithm to input 1000 numbers. Count how many numbers are positive and how many
numbers are zero. Then output the results. Use either pseudocode or a flowchart. [6]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Give one change you could make to your algorithm to ensure initial testing is more manageable. [2]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 57

A programmer has written a routine to check that prices are below $10.00. These values are used as
test data.
10.00 9.99 ten
Explain why each value was chosen. [3]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 58

Explain the difference between the programming concepts of counting and totalling. Include an
example of a programming statement for each concept in your explanation. [4]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 59

Draw a flowchart for an algorithm to input numbers. Reject any numbers that are negative and
count how many numbers are positive. When the number zero is input, the process ends and the
count of positive numbers is output. [5]
Explain the changes you will make to your algorithm to also count the negative numbers. [2]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 60

This pseudocode algorithm inputs two non-zero numbers and a sign, and then performs the
calculation shown by the sign. An input of zero for the first number terminates the process.

INPUT Number1, Number2, Sign


WHILE Number1 <> 0
IF Sign = '+' THEN Answer ← Number1 + Number2 ENDIF
IF Sign = '-' THEN Answer ← Number1 - Number2 ENDIF
IF Sign = '*' THEN Answer ← Number1 * Number2 ENDIF
IF Sign = '/' THEN Answer ← Number1 / Number2 ENDIF
IF Sign <> '/' AND Sign <> '*' AND Sign <> '-' AND Sign <> '+'
THEN Answer ← 0
ENDIF
IF Answer <> 0 THEN OUTPUT Answer ENDIF
INPUT Number1, Number2, Sign
ENDWHILE

Complete the trace table for the input data:


5, 7, +, 6, 2, –, 4, 3, *, 7, 8, ?, 0, 0, /
Show how you could improve the algorithm written in pseudocode by writing an alternative type of
conditional statement in pseudocode. [4]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 61

Examine the following pseudocode:


INPUT A
INPUT B
INPUT C
INPUT D
INPUT E
INPUT F
INPUT G
INPUT H
INPUT I
INPUT J
INPUT K
INPUT L
T ← A + B + C + D + E + F + G + H + I + J + K + L
OUTPUT "The average equals ", T / 12

Describe what happens in this pseudocode. [3]


…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Describe how this pseudocode could be altered to allow any number of values to be input. [3]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Re-write the given pseudocode to allow any number of values to be input. [3]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 62

An algorithm has been written in pseudocode to select a random number using the function
RandInt(n), which returns a whole number between 1 and the argument n. The algorithm then

allows the user to guess the number.


Number ← RandInt(100)
TotalTry ← 1
REPEAT
PRINT "Enter your guess now, it must be a whole number"
INPUT Guess
IF TotalTry > Number THEN
PRINT "Too large try again"
ENDIF
IF Guess > Number THEN
PRINT "Too small try again"
ENDIF
TotalTry ← Guess + 1
UNTIL Guess <> Number
TotalTry ← TotalTry - 1
PRINT "Number of guesses ", TotalTry

Find the four errors in the pseudocode and suggest a correction to remove each error. [4]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 63

The flowchart checks the lengths of a batch of 10 ropes. For the batch to be accepted 90% of the
lengths need to be between 24.9 and 25.1 metres.
Complete the trace table for the input data: [4]
24.88, 25.01, 24.98, 25.00, 25.05, 24.99, 24.97, 25.04, 25.19, 25.07

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

…………………………………………………………………………………………………………

Explain how the algorithm to reject batches could be improved to make it more effective. [2]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 64

A programmer writes a program to weigh baskets of fruit in grams, keeping a total of the weight
and counting the number of baskets. The total weight is stored in a variable Total and the number
of baskets is stored in a variable BasketCount.

Explain, including examples of programming statements, how totalling and counting could be used
in this program. [4]
Totalling:
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

Counting:
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 65

The following pseudocode algorithm uses nested IF statements


IF Response = 1 THEN
X ← X + Y
ELSE
IF Response = 2 THEN
X ← X – Y
ELSE
IF Response = 3 THEN
X ← X * Y
ELSE
IF Response = 4 THEN
X ← X / Y
ELSE
OUTPUT "No response"
ENDIF
ENDIF
ENDIF
ENDIF

Name the type of statement demonstrated by the use of IF … THEN … ELSE … ENDIF [1]

…………………………………………………………………………………………………………
Re-write the pseudocode algorithm using a CASE statement [3]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 66

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 [4]
Error 1
…………………………………………………………………………………………………………
Correction
…………………………………………………………………………………………………………
Error 2
…………………………………………………………………………………………………………
Correction
…………………………………………………………………………………………………………
Error 3
…………………………………………………………………………………………………………
Correction
…………………………………………………………………………………………………………
Error 4
…………………………………………………………………………………………………………
Correction
…………………………………………………………………………………………………………
Show how you would change the corrected algorithm to only total numbers greater than 0 and less
than 20. [2]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 67

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.
Complete the trace table for the passenger input data: [5]
S, S, S, A, C, C, C, A, A, A, A, W, S, S, D, C, Z, D, S
Question 68

An algorithm has been written in pseudocode to input the weight of 500 items and reject any that
are over-weight or under-weight, then print the percentage rejected.
Count ← 1
Reject ← 0
Over ← 62
Under ← 58
REPEAT
INPUT ItemWeight
IF ItemWeight > Over AND ItemWeight < Under THEN
Reject ← Reject – 1
ENDIF
Count ← Count + 1
UNTIL Count > = 500
Reject ← Reject / 100
PRINT "Percentage rejected is ", Reject

Find the four errors in the pseudocode and suggest a correction for each error. [4]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Describe how you would change the corrected algorithm to calculate the number accepted
instead of rejected, using a variable Accept, and print a warning if fewer than 50% are
accepted. [3]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 69

This flowchart inputs the tread depth of five tyres, four on the car and a spare tyre. Any tread
depth of 1.6mm or less is rejected. To be potentially roadworthy, a car must have four tyres with a
tread depth greater than 1.6mm. [4]
Complete Trace table 1 for the tread depth input data:
1.7, 1.9, 1.4, 1.8, 2.0

Trace table 1
Complete Trace table 2 for the tread depth input data:
1.2, 1.9, 1.4, 1.8, 2.4

Trace table 2
Question 70

Identify and describe three loop structures that are available in pseudocode. [6]
Loop structure 1
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Description
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Loop structure 2
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Description
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Loop structure 3
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Description
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 71

This flowchart inputs student percentage marks for three examinations. If the average of these
marks is 80% or over then a distinction grade is awarded. If the average of these marks is less than
40% then a fail grade is awarded. Otherwise a pass grade is awarded. [5]
Complete a trace table for each set of input data:
Set 1: 88, 74, 60

Set 2: 20, 33, 67

Set 3: 79, 91, 70

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

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 72

An algorithm has been written in pseudocode to:


 input 25 positive whole numbers less than 100
 find and output the largest number
 find and output the average of all the numbers
01 A ← 0
O2 B ← 0
03 C ← 0
04 REPEAT
05 REPEAT
06 INPUT D
07 UNTIL D > 0 AND D < 100 AND D = INT(D)
08 IF D > B
09 THEN
10 B ← D
11 ENDIF
12 C ← C + D
13 A ← A + 1
14 UNTIL A >= 25
15 E ← C / A
16 OUTPUT "Largest number is ", B
17 OUTPUT "Average is ", E

Give the line number for the statements showing: [4]


Totalling ……………………………………………
Counting ……………………………………………
Range check ……………………………………………
Calculating the average ……………………………………………
State an example for each type of test data needed to test the input of the number: [3]
Normal test data example
…………………………………………………………………………………………………………
Erroneous/abnormal test data example
…………………………………………………………………………………………………………
Extreme test data example
…………………………………………………………………………………………………………
The algorithm needs to be changed to include finding and outputting the smallest number input.
Describe how you would change the algorithm. [4]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 73

This algorithm accepts weights of bags of cookies. Any cookie bag weighing between 0.9 and 1.1
kilograms inclusive is acceptable. Underweight bags weigh less than 0.9 kilograms and overweight
bags weigh more than 1.1 kilograms. An input of a negative number stops the process. Then the
total number of bags, the number of overweight bags and the number of underweight bags weighed
are output.
Accept ← 0
Over ← 0
Under ← 0
OUTPUT "Enter weight of first cookie bag"
INPUT BagWeight
WHILE BagWeight > 0
IF BagWeight > 1.1 THEN
Error ← 1
ELSE
IF BagWeight < 0.9 THEN
Error ← 2
ELSE
Error ← 0
ENDIF
ENDIF
CASE Error OF
0 : Accept ← Accept + 1
1 : Over ← Over + 1
2 : Under ← Under + 1
ENDCASE
OUTPUT "Weight of next bag?"
INPUT BagWeight
ENDWHILE
Total ← Accept – Over – Under
OUTPUT "Number of bags weighed ", Total
OUTPUT "Number overweight ", Over
OUTPUT "Number underweight ", Under
Complete a trace table for the given algorithm using this input data: [7]
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

There is an error in this algorithm.


Identify the error and write the corrected pseudocode statement. [2]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 74

Write an algorithm in pseudocode to input 500 positive whole numbers. Each number input must be
less than 1000. Find and output the largest number input, the smallest number input and the range
(difference between the largest number and smallest number). [6]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Describe how the algorithm could be changed to make testing less time-consuming. [2]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 75

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
Complete the trace table for the algorithm using this input data: [3]
Secret, Secret, VerySecret, VerySecret, Pa55word, Pa55word, 999, 888

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

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 76

An algorithm has been written to:


 input the ages of 100 students
 count and output the number of students aged 7 and under 12
 count and output the number of students aged 12 and under 18
 count and output the number of students aged 18 and over.
Complete the pseudocode algorithm: [4]
01 Count7to12 ← 0
02 Count12to18 ← 0
03 CountOver18 ← 0
04 FOR Student ← 1 TO ………………………………………………
05 OUTPUT "Please enter student's age in years "
06 INPUT Age
07 IF Age >= 7 ………………………………………………
08 THEN
09 Count7to12 ← Count7to12 + 1
10 ENDIF
11 IF Age >= 12 AND Age < 18
12 THEN
13 Count12to18 ← ………………………………………………
14 ENDIF
15 IF Age >= 18
16 THEN
17 CountOver18 ← CountOver18 + 1
18 ENDIF
19 NEXT Student
20 OUTPUT "There are ", Count7to12, " students aged 7 and under 12."
21 OUTPUT "There are ", Count12to18, " students aged 12 and under 18."
22 OUTPUT "There are ", ………………………, " students aged 18 and over."

Write the extra pseudocode statements that are needed to count and output the number of students
under the age of 7. Use the variable CountUnder7; assume CountUnder7 has already been set
to zero. [4]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 77

This flowchart inputs a whole number. The function INT returns the integer value of a number. For
example, INT (7.5) is 7

An input of -1 ends the routine [6]


Complete the trace table for the given algorithm using this input data:
7, 6, 5, 4, –1, 12, 34

Describe the purpose of this algorithm [2]


…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Describe the problem that occurs if a whole number smaller than 4 and not equal to –1 is input. [2]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Explain how to change the flowchart to prevent this problem occurring. [2]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 78

The algorithm shown by this flowchart allows the input of examination marks for a class of
students. A mark of –1 ends the process. If a mark is 80 or over then a distinction grade is awarded.
The number of distinctions for the whole class is calculated. If this is over 50% of the class, the
class is awarded a highly commended certificate. [5]
Complete a trace table for the algorithm using this input data:
88, 74, 60, 90, 84, 87, 95, 72, 84, 66, –1
Question 79
1 Continue  1
2 WHILE Continue = 0
3 OUTPUT "Enter 1 for +, 2 for -, 3 for * or 4 for /"
4 INPUT Operator
5 OUTPUT "Enter the first value"
6 INPUT Value1
7 OUTPUT "Enter the second value"
8 OUTPUT Value2
9 IF Operator
10 1: Answer  Value1 + Value2
11 2: Answer  Value1 - Value2
12 3: Answer  Value1 * Value2
13 4: Answer  Value1 / Value2
14 ENDCASE
15 OUTPUT "The answer is ", Value1
16 OUTPUT "Do you wish to enter more values (Yes or No)?"
17 INPUT MoreValues
18 IF MoreValues = "No"
19 THEN
20 Continue  1
21 ENDIF
22 UNTIL Continue = 0

Find the five errors in the pseudocode and suggest a correction for each error. [5]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
The algorithm needs changing to allow only the numbers 1, 2, 3, or 4 to be entered for the input
variable Operator. Write the pseudocode to perform this task and state where in the algorithm it
would be located. [5]
Pseudocode
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Location in algorithm
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 80

The flowchart represents an algorithm.


The algorithm will terminate if –1 is entered at the List input. [5]
Complete the trace table for the algorithm using this input data:
2, 77, 2, 16, 1, 35, 2, –7, 5, 18, 1, 11, 1, 12, 2, 20, –1, 18
Question 81

An algorithm has been written in pseudocode to generate 50 positive random integers with values
less than or equal to 100. These numbers are stored in the array NumRand[]

The function RandUp(X,Y) generates a random integer greater than X and less than or equal to
Y For example, RandUp(1,4) generates 2 or 3 or 4
1 Count  0
2 WHILE Counter > 50 DO
3 NumRand[Counter]  RandUp(1,100)
4 Counter  Counter – 2
5 ENDWHILE

Find the four errors in the pseudocode and write a correction for each error. [4]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
The pseudocode for this algorithm could be shortened by the use of a FOR … NEXT loop.

Rewrite the algorithm using a FOR … NEXT loop. [3]

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 82

The algorithm, shown by this flowchart, allows the input of examination marks for a class of
students. A mark of 999 ends the process. If a mark is 40 or over then a pass grade is awarded. The
number of pass grades is calculated for the whole class. If this is under 50% of the class, the class is
offered extra help [5]
Complete a trace table for the algorithm using this input data:
88, 24, 60, 30, 44, 17, 25, 22, 54, 6, 999, −1
Question 84

The pseudocode represents an algorithm.


The pre-defined function DIV gives the value of the result of integer division.
For example, Y = 9 DIV 4 gives the value Y = 2

The pre-defined function MOD gives the value of the remainder of integer division.
For example, R = 9 MOD 4 gives the value R = 1
First ← 0
Last ← 0
INPUT Limit
FOR Counter ← 1 TO Limit
INPUT Value
IF Value >= 100 THEN
IF Value < 1000 THEN
First ← Value DIV 100
Last ← Value MOD 10
IF First = Last THEN
OUTPUT Value
ENDIF
ENDIF
ENDIF
NEXT Counter

Complete the trace table for the algorithm using this input data:
8, 66, 606, 6226, 8448, 642, 747, 77, 121
Describe the purpose of the algorithm. [2]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

Question 85

This algorithm checks the temperature of hot food being served to customers. [7]
Complete the trace table for the algorithm using this input data:
75, 78, 84, 87, 91, 80, 75, 70, 65, 62, –1, 20
State how the final output from the algorithm could be improved. [2]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Identify the process in the algorithm that is not required. [1]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

Question 86

Describe what is meant by the terms variable and constant and give an example of each in your
answer. [4]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 87

The flowchart shows an algorithm that should:


• allow 100 numbers to be entered into the variable Number
• total the numbers as they are entered
• output the total and average of the numbers after they have all been entered.
Complete this flowchart:
[6]
Question 88

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

Identify the three errors in the pseudocode and suggest corrections. [3]
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

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

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Question 89

This flowchart represents an algorithm to find the average value of a number of sales.
[4]

Complete the trace table using this data:


5.50, 3.40, 6.25, 3.85, –11.00, 0
Identify the error in the algorithm and describe how to correct it. [3]
Error
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………
Correction
…………………………………………………………………………………………………………

…………………………………………………………………………………………………………

You might also like