0% found this document useful (0 votes)
10 views

Class notes3

Notes

Uploaded by

vidhya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Class notes3

Notes

Uploaded by

vidhya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

CHAPTER 4

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.

Complete the algorithm for Sukhjinder by filling in the missing lines.

Count<-0

Smalles<-1000

Largest<-0

WHILE COUNT<10

INPUT BASE,HEIGHT

CALL PARALLELOGRAM(BASE,HEIGHT)

IF AREA < SMALLEST

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]

COUNT0

TOTAL0

REPEAT

INPUT NUMBER

TOTALTOTAL+NUMBER

COUNTCOUNT+1

UNTIL COUNT=10

AVERAGETOTAL/NUMBER

3. A programmer is writing an algorithm in


pseudocode to determine whether a number is a
factor of another number.
Y is a factor of X if the result of X/Y is a whole
number
In pseudocode INT(W) returns the whole number
part of W.
If W is the same as INT(W) that means W is a
whole number
Complete the algorithm, including the missing
first line, in pseudocode. Each THEN or ELSE
statement should be on a separate line to the
action resulting from it. The algorithm uses:
W to store the result of X divided by Y
• Z to store the value of INT(W)
The algorithm must output the values of Y and X
together with an appropriate message if Y is a
factor of X or if Y is not a factor of X.[8]
4. A company employs workers as:
• labourers who are paid $18 per hour
• office workers who are paid $22 per hour
• managers who are paid $30 per hour.
A computer programmer has written part of an algorithm in pseudocode. The completed algorithm
will calculate and output the wage for each worker.
The inputs will be:
the number of workers
• the job code for each worker (L for labourer, O for office worker or M for manager)
• the number of hours each worker has worked.
If L, O or M is not entered for the job code then the message ‘Invalid job code’ will be output. The
algorithm will terminate when all the workers’ details have been entered. It will use the CASE…
ENDCASE construct to determine the rate of pay.
Complete the algorithm by filling in the missing lines.
5. In Ruritania these are the tax rules.
• People who earn up to $10000 pay no tax.
• People who earn between $10000 and $40000 pay 20% tax on their earnings above $10000.
• People who earn more than $40000:
pay $6000 ($30000 × 20%)
and pay 40% tax on their earnings above $40000.
Complete this flowchart which shows how the net wage (the money earned after tax is paid) is
calculated and is output for an individual in Ruritania.
6. A programmer is writing an algorithm in pseudocode to represent a company’s payroll system. The
system calculates a worker’s wages before tax by multiplying the number of hours worked by the
rate of pay per hour. A procedure within the main algorithm representing this could be:

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%);

• the amount of tax paid is then subtracted from the WagesBeforeTax.

(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

IF temperature < press

THEN

12.

Many companies use computers to process their payroll.


A transaction file is produced once a week. It consists of the WorkerID and HoursWorked fields. The
master file contains the WorkerID, RateOfPay and WagesSoFar fields as well as other details. The
WagesSoFar field represents how much each worker has earned so far this year.
Each worker’s wage is calculated by multiplying the HoursWorked by the RateOfPay. When the wage for
that week is calculated, it is added on to the WagesSoFar field.
Every week the master file has to be updated to include the new wage earned so far this year.
(a) Complete the following pseudocode algorithm which shows the process of updating the master file.
You can assume no other transactions are being carried out.
READ first record in transaction file
READ first record in old master file
WHILE not end of transaction file
IF transaction file WorkerID = master file WorkerID
THEN

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

INPUT reading from induction loop


13. Jose has a greenhouse to grow his plants. He lives in a country which has a warm climate so the
greenhouse does not need a heater but has microprocessor controlled windows and a temperature
sensor.
Complete this pseudocode algorithm to show the processing which takes place to control the
temperature of the greenhouse.

WHILE system switched on


INPUT temperature
IF temperature > preset
THEN
IF window closed
THEN
14. Complete this flowchart which will allow the input of ten numbers
15.
16.
A house has a microprocessor-controlled central heating system.
Complete the flow chart to show how the temperature in the house is continuously controlled.

You might also like