27
Program Design CP1020 -Week 12 Las t One

Program Design

  • Upload
    alexa

  • View
    24

  • Download
    1

Embed Size (px)

DESCRIPTION

CP1020 -Week 12. Program Design. Last One. Aims:. - Demonstrate a simple development method - Develop a partial solution to a larger problem - Introduce an incremental program coding and testing strategy. Problem Specification. - PowerPoint PPT Presentation

Citation preview

Page 1: Program Design

Program DesignCP1020 -Week 12

Last

One

Page 2: Program Design

Aims:

- Demonstrate a simple development method

- Develop a partial solution to a larger problem

- Introduce an incremental program coding and testing strategy

Page 3: Program Design

Problem Specification

ACME Widgets plc require a program to calculate and display the pay details for hourly paid workers.

Gross pay is calculated by multiplying the hours worked by the hourly rate, but any hours worked over 40 are treated as overtime and paid at "time and a half” rate.

...continued

Page 4: Program Design

ACME Widgets PLC

Tax deductions must also be calculated.

The first £100 each week is tax free, the next £100 is taxed at 25% and any pay over £200 is taxed at 50%.

Net pay is gross pay minus all deductions.

Page 5: Program Design

Tackling the problem.

1. Read the problem

2. Read it again!

3. Work through problem on paper; prepare test data & results

4. Design solution

5. Code solution

6. Test solution

7. Document

Page 6: Program Design

Steps 1 and 2

Read the spec. carefully.

Underline the important bits

Check out any queries you have

Make sure you’ve got all the facts

Page 7: Program Design

Step 3. Prepare test data

e.g. Employee No.1 works 20 hours at £3.00 per hour.

Gross pay = 20 x £3.00 = £60

No tax payable (first £100 tax free) therefore deductions = 0

Net Pay = Gross Pay - deductions = £60

(Total wage bill so far = £60 )

Page 8: Program Design

More Test Data

e.g. Employee No. 2 works 40 hours at £4.00 per hour

Gross pay = 40 x £4.00 = £160.00

Tax payable on £60 at 25% = £15.00

Net Pay = £160 - £15 = £145.00

Page 9: Program Design

Yet more test data

e.g. Employee No. 3 works 50 hours at £5.00 per hour. (N.B. 10 hours overtime!)

Gross pay = 40 hours at £5.00 = £200.00

10 hours at £7.50 = £ 75.00

Total = £275.00

Page 10: Program Design

Further calculations

Tax = £100 at 25% = £25

+ £75 at 50% = £37.50

total = £62.50

Net Pay =£275 - £62.50 = £212.50

Page 11: Program Design

Step 4. Design a Solution

Questions:

a. WHAT is the program to do?

b. WHAT are the inputs to the program?

c. WHAT are the outputs from the program?

Page 12: Program Design

Design - solution

Answers:

a. Calculate and display employee's pay

b. Hours worked and hourly rate

c. Gross pay(?), Tax, Net pay.

Page 13: Program Design

Data Dictionary

List all items you think you’ll need input variables output variables interim variables

Give each a Name and a typeNote what you plan to use each one for

Page 14: Program Design

Splitting the Program into tasks

1. Read in the employee's hours and rate.

2. Calculate Gross pay

3. Calculate Tax payable

4. Calculate Net pay

5. Print out pay details.

Page 15: Program Design

Design again1. Read in the employee's hours and rate.

1.1 get hours worked and hourly rate

2. Calculate Gross pay2.1 if hours worked > 40 then

gross pay = 40 X hourly rate

+ (hours worked -40) X (hourly rate * 1.5)

else

gross pay = hours worked X hourly rate

Page 16: Program Design

3. Calculate Tax payable3.1 If gross pay > £200 then

tax = (gross pay - 200) * Tax High rate

+ (100 * Tax low rate)

else if gross pay > £100 then

tax = (gross pay - 100) * Tax low rate

else

tax = 0

Page 17: Program Design

More design

4. Calculate Net pay4.1 Net pay = gross pay - tax

5. Print out pay details.5.1 print gross pay

5.2 print tax

5.3 print net pay

Page 18: Program Design

Data Dictionary

NAME TYPE DESCRIPTION

fHours single No of hours worked

fPayRate single Rate per hour

fGrossPay single Total pay before tax

fTax single Tax paidfTaxLowRate single Lower tax rate 25p

fTaxHighRate single Higher tax rate 50p

fNetPay single Net Pay

Page 19: Program Design

5. Code the solution

Use your design and data dictionary to develop the code

Remember to use sensible names put in comments/remarks use indentation

You could code it in small blocks and test by adding a few dummy print statements

Page 20: Program Design

The code

REM payroll program

REM written by I Coulson

REM ////declare variables/////

DIM fHours, fGrossPay, fTax AS SINGLE

DIM fNetPay, fPayRate AS SINGLE

DIM fTaxLowRate, fTaxHighRate AS SINGLE

fTaxLowRate = .25

fTaxHighRate = .50

Page 21: Program Design

CLS

PRINT " ACME WIDGETS PLC Payroll”

REM Read in the employee data

INPUT ”How many hours did this employee work ? "; fHours

INPUT "And the hourly rate for this employee "; fPayRate

REM Calculate gross pay and overtime

if fHours > 40 then

fGrossPay = 40 * fPayRate

+ ( fHours - 40) * ( fPayRate * 1.5 )

else

fGrossPay = fPayRate * fHours

Page 22: Program Design

REM Calculate Tax payable

IF fGrossPay > 200 THEN

fTax=(100 * fTaxLowRate)+

((fGrossPay-200) * fTaxHighRate)

ELSEIF fGrossPay > 100 THEN

fTax = (fGrossPay - 100) * fTaxLowRate

ELSE

fTax = 0 REM No Tax to pay

END IF

Page 23: Program Design

REM Calculate Net pay

fNetPay = fGrossPay - fTax

REM Display Employees Pay Details

PRINT "gross pay is "; fGrossPay

PRINT "Pay after tax of "; fTax; " is "; NetPay

PRINT "*******************************************"

Page 24: Program Design

6. Test the solution

Use your test cases and run the programCheck a few other possible valuesIf there are problems

rework the design THEN rewrite the offending code

Page 25: Program Design

7. Documentation

Others need to know about the program other programmers the users the management!

Page 26: Program Design

Programmers guide

design data dictionary Algorithm

testingcode

comments layout variable names

Page 27: Program Design

The User Guide

Those who use the program need to know: how to get it started the data required from them the screens they might see how to quit the program