Class notes3
Class notes3
1. Sukhjinder, a mathematics student, has defined a procedure using pseudocode. It calculates the area
of a parallelogram by multiplying the base by the height. All parallelograms will have an area of less
than 1000.
The procedure Sukhjinder has written is:
He has also begun writing an algorithm which calls the procedure and then passes back the area.
The main algorithm accepts inputs of the base and the height of 10 parallelograms, one at a time. It
will output the areas of the largest and smallest parallelograms.
Count<-0
Smalles<-1000
Largest<-0
WHILE COUNT<10
INPUT BASE,HEIGHT
CALL PARALLELOGRAM(BASE,HEIGHT)
THEN
SMALLEST<-AREA
ELSE
LARGEST<-AREA
ENDIF
COUNT<-COUNT + 1
END WHILE
PRINT SMALLEST
PRINT LARGEST
..........................................................................................................................................................
ENDIF .........................................................................................................................................................[8]
2. The average (mean) of a set of 10 numbers is calculated by:
• adding the numbers together to get a total
• dividing the total by 10.
Juan has attempted to draw a flowchart of an algorithm which finds the average of 10 numbers. He
has made some mistakes and omitted to include some boxes.[6]
COUNT0
TOTAL0
REPEAT
INPUT NUMBER
TOTALTOTAL+NUMBER
COUNTCOUNT+1
UNTIL COUNT=10
AVERAGETOTAL/NUMBER
There are two stages involved in calculating the wages after tax:
• the amount of tax paid by the worker is calculated by multiplying the WagesBeforeTax by the rate of
tax (35%);
(a) Write a procedure for calculating the wages after tax, assuming the value of WagesBeforeTax is
passed to it.[4]
(b) The programmer’s algorithm will use the BeforeTax() procedure and the procedure created in part (a)
to calculate and output the wage after tax for each worker.
Complete the algorithm. The statements have been numbered to help you.
7. A teacher wishes to produce a computer program to output the grades awarded for all of her
students.
If a student scores:
• more than 60 marks, they are awarded a grade A
• 50–60 marks, they are awarded a grade B
• 40–49 marks, they are awarded a grade C
• below 40 marks, they are awarded a grade D
The teacher has written the following algorithm before writing the program. Unfortunately, there are
errors and some lines have been left out (omitted). She has, however, managed to include the correct
number of ELSE statements.
Identify each error or omission and how these could be corrected. Line numbers have been included
to help you.
8. Josefine has started to draw a flowchart which inputs 10 numbers and outputs the largest value.
Complete the flowchart by filling in the empty boxes and by placing yes and no as appropriate in the
diagram.
9. Complete the flowchart below to add up 6 numbers. Use the variable total to store the sum of the
numbers and the variable count to control the number of times the loop is repeated.
10. The average (mean) of a set of numbers can be found by adding the numbers together and dividing
the resulting total by how many numbers there are in the set. Write an algorithm in pseudocode to
enter and find the average of a set of numbers using a REPEAT…UNTIL loop. Your algorithm must
work for different sets of numbers.[8]
11. Many houses in cooler countries have central heating systems. In a central heating system,
microprocessors are used to control the pump which sends water from the boiler to the individual
heaters.
Complete the pseudocode algorithm to show the processing which takes place in this
microprocessor-controlled central heating system. The algorithm must prevent attempting to
switch the pump on when it is already on and attempting to switch the pump off when it is already
off. You may assume temperature is the variable representing the actual temperature of the house
and preset represents the required temperature of the house.
REPEAT
INPUT temperature
THEN
12.
13
A
microprocessor-controlled car park barrier is used to allow cars to enter a car park. When a car approaches
the barrier, the barrier automatically rises to allow the car to enter. It does not lower until the car is safely
clear of the barrier system. There is a light sensor and light beam source immediately before the barrier. No
tickets are issued by the system. The system operates continuously while it is switched on. Complete this
pseudocode algorithm to describe the processing involved. Your pseudocode algorithm should include IF…
THEN statements.
REPEAT