Worked example 1
A simple payroll program needs to get an employee's hours worked and rate of pay, calculate the gross pay, and display the result.
- Design a structure diagram for this program.
- Using your design, show the calculation for an employee who worked 37.5 hours at a rate of $20.00 per hour.
Show solution outline
1. Design (Structure Diagram) The design process follows top-down decomposition:
- Top Level: The main module is 'Process Payroll'.
- First Breakdown: 'Process Payroll' is broken into three main steps: GetData, CalculateGrossPay, and DisplayGrossPay.
- Second Breakdown: The GetData module is refined into GetHoursWorked and GetRateOfPay.
This results in a structure diagram with 'Process Payroll' at the top, calling 'GetData', 'CalculateGrossPay', and 'DisplayGrossPay'. 'GetData' in turn calls 'GetHoursWorked' and 'GetRateOfPay'.
2. Worked Calculation Let's trace the process with sample data. Assume the user inputs the following values:
- Hours Worked = 37.5 hours
- Rate of Pay = $20.00 per hour
Step 1: Get Data
- The GetHoursWorked module gets the value 37.5.
- The GetRateOfPay module gets the value 20.00.
Step 2: Calculate Gross Pay
- The CalculateGrossPay module receives these two values.
- Formula: Gross Pay = Hours Worked × Rate of Pay
- Calculation:
- Result:
Step 3: Display Gross Pay
- The DisplayGrossPay module receives the calculated gross pay.
- Output: The program displays a message like "Gross Pay: $750.00".