Presentation is loading. Please wait.

Presentation is loading. Please wait.

More Algorithm Design CSIS 1595: Fundamentals of Programming and Problem Solving 1.

Similar presentations


Presentation on theme: "More Algorithm Design CSIS 1595: Fundamentals of Programming and Problem Solving 1."— Presentation transcript:

1 More Algorithm Design CSIS 1595: Fundamentals of Programming and Problem Solving 1

2 Example Requirements: Write program to compute income taxes from gross income and dependents. – Tax is a tax rate (currently 20%) of deductible income. – Deductible income is gross income minus deductions. – Deductions include a standard deduction (currently $10,000) and a $3000 dependent deduction rate for each dependent.

3 Algorithm Design in Terms of Data What information do you need to keep track of? – Look for nouns in requirements – These will often become your variables Where will that information come from? – Input by user? – Specified in advance? – Computed from something else? If so, how?

4 Variables in Example tax deductible income × tax rate tax_rate Set at 20% deductible_income gross income minus deductions gross_income Input by user deductions standard deduction + dependents × dependent deduction rate standard_deduction Set at 10000 dependents Input by user dependent_deduction Set at 3000

5 Algorithm Design in Terms of Steps Order of steps often determined by data dependency Cannot compute variable until values it depends on is known – Assign variables with set values – Prompt user for variables they must provide – Compute remaining variables in order of dependencies

6 Dependencies in Example Set tax_rate, standard_deduction, and dependent_deduction_rate values Prompt user for gross_income and dependents values Compute deductions from standard_deduction, dependents, and dependent_deduction Compute taxable_income from gross_income and deductions Compute tax from taxable_income and tax_rate

7 Example Pseudocode

8 Constants Many values considered “named constants” – Do not change value during program – May change value in future versions of program (so should be easy to change in future) Define named constant at beginning of code – Convention: Use all caps to distinguish from variables TAX_RATE = 0.2 – Use named constant in program instead of value tax = taxable_income * TAX_RATE

9 Scaffold Testing Problem: Only output we have for testing is final tax value If not correct, error could come from any (or several) previous calculations – Computation of deductions – Computation of taxable income – Computation of tax

10 Scaffold Testing Solution: Print all intermediate values as they are computed – deduction – taxable_income Make sure these computed in advance for test Can comment out when finished – Do not delete, since may need in future!

11 Scaffold Testing


Download ppt "More Algorithm Design CSIS 1595: Fundamentals of Programming and Problem Solving 1."

Similar presentations


Ads by Google