ý

Decompostion and algorithm practice questions - OCRDecomposing the problem – example one

Every programming problem needs decomposing so that it can be properly understood. From this, an algorithm can be designed and tested.

Part of Computer ScienceStudy skills

Decomposing the problem – example one

This section examines how to take a problem, decompose it and design an algorithm to solve it.

The following example has been written by ý Bitesize consultants as a suggestion of the type of problem that may appear in an exam paper.

The problem

An employee's weekly pay depends on the rate of pay and the number of hours worked per week. Employees work a minimum of 1 hour per week, and a maximum of 60. An employee who works more than 40 hours is paid 112 times the normal pay rate for all hours worked over 40. Normal pay is £10.00 per hour. A program is required to calculate and output the weekly pay for any employee.

Decompose the problem

The first step is to break down (decompose) the overall problem into several smaller, more easily solved problems:

  1. Find out how many hours are worked.
  2. Find out how many of those hours are to be paid at the normal rate.
  3. Find out how many, if any, of those hours are to be paid at the overtime rate.
  4. Work out the pay for the normal hours.
  5. Work out the pay for the overtime hours.
  6. Total the pay for normal and overtime hours.
  7. Output the result.

Variables and constants

From the above, the solution will require the following variables. These values will change as the program is run.

VariableData type
hours_workedFloat
overtime_hoursFloat
normal_payFloat
overtime_payFloat
total_payFloat
Variablehours_worked
Data typeFloat
Variableovertime_hours
Data typeFloat
Variablenormal_pay
Data typeFloat
Variableovertime_pay
Data typeFloat
Variabletotal_pay
Data typeFloat

The following constants will be used. These values will not change when the program is run.

ConstantData type
HOURLY_RATEFloat
OVERTIME_RATEFloat
MAX_HOURSInteger
MIN_HOURSInteger
NORMAL_HOURSInteger
ConstantHOURLY_RATE
Data typeFloat
ConstantOVERTIME_RATE
Data typeFloat
ConstantMAX_HOURS
Data typeInteger
ConstantMIN_HOURS
Data typeInteger
ConstantNORMAL_HOURS
Data typeInteger