1 / 27

Program Design

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.

alexa
Download Presentation

Program Design

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CP1020 -Week 12 Program Design Last One

  2. Aims: - Demonstrate a simple development method - Develop a partial solution to a larger problem - Introduce an incremental program coding and testing strategy

  3. Problem Specification ACME Widgetsplc 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

  4. 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.

  5. 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

  6. 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

  7. 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 )

  8. 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

  9. 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

  10. Further calculations Tax = £100 at 25% = £25 + £75 at 50% = £37.50 total = £62.50 Net Pay =£275 - £62.50 = £212.50

  11. 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?

  12. Design - solution Answers: a. Calculate and display employee's pay b. Hours worked and hourly rate c. Gross pay(?), Tax, Net pay.

  13. Data Dictionary • List all items you think you’ll need • input variables • output variables • interim variables • Give each a Name and a type • Note what you plan to use each one for

  14. 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.

  15. Design again 1. Read in the employee's hours and rate. 1.1 get hours worked and hourly rate 2. Calculate Gross pay 2.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

  16. 3. Calculate Tax payable 3.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

  17. More design 4. Calculate Net pay 4.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

  18. Data Dictionary NAME TYPEDESCRIPTION fHours singleNo of hours worked fPayRate singleRate per hour fGrossPay singleTotal pay before tax fTax single Tax paid fTaxLowRate single Lower tax rate 25p fTaxHighRate single Higher tax rate 50p fNetPay singleNet Pay

  19. 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

  20. 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

  21. 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

  22. 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

  23. 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 "*******************************************"

  24. 6. Test the solution • Use your test cases and run the program • Check a few other possible values • If there are problems • rework the design • THEN rewrite the offending code

  25. 7. Documentation • Others need to know about the program • other programmers • the users • the management!

  26. Programmers guide • design • data dictionary • Algorithm • testing • code • comments • layout • variable names

  27. 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

More Related