introduction to algorithm design and documentation csis 1595: fundamentals of programming and...

8
Introduction to Algorithm Design and Documentation CSIS 1595: Fundamentals of Programming and Problem Solving 1

Upload: edith-shaw

Post on 12-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Algorithm Design and Documentation CSIS 1595: Fundamentals of Programming and Problem Solving 1

Introduction to Algorithm Design and Documentation

CSIS 1595: Fundamentals of Programming and Problem Solving 1

Page 2: Introduction to Algorithm Design and Documentation CSIS 1595: Fundamentals of Programming and Problem Solving 1

Stages of Program Development

• Analysis: What must the program do?

• Design: How should the program work?

• Implementation: Coding the program

• Testing: Making sure the program works

• Maintenance: Upgrading to meet new requirements

Page 3: Introduction to Algorithm Design and Documentation CSIS 1595: Fundamentals of Programming and Problem Solving 1

Example

Requirements:Write program to compute taxes. • Taxes are computed as the tax

rate (currently 20%) times taxable income.

• Taxable income is gross income minus total deductions.

• Total deductions are a standard deduction (currently $10,000) plus a dependent deduction (currently $3,000) times the number of dependents.

• Implementation:

Very difficult to do this directly

Page 4: Introduction to Algorithm Design and Documentation CSIS 1595: Fundamentals of Programming and Problem Solving 1

Algorithms and Pseudocode

• Algorithm: Set of steps to solve problem– Usually pseudocode– Can use to implement code

• Example: Computing Celsius temperature1. Ask user for Fahrenheit temperature2. Compute Celsius temperature from the Fahrenheit

temperature3. Display the Celsius temperature to the user

Page 5: Introduction to Algorithm Design and Documentation CSIS 1595: Fundamentals of Programming and Problem Solving 1

Algorithm Design

• Often involves refining for more detail– Additional steps– Detail about computation

• Example: Computing Celsius temperature1. Ask user for Fahrenheit temperature

1. Convert to floating point value

2. Compute Celsius temperature from Fahrenheit temperatureusing formula (Fahrehneit – 32)/1.8

3. Display the Celsius temperature to the user

Page 6: Introduction to Algorithm Design and Documentation CSIS 1595: Fundamentals of Programming and Problem Solving 1

Readability

• Code must be easily understood by people– Other programmers who maintain your code– Yourself in future

• Descriptive variable names• White space– Spaces between words on same line– Blank lines between sections of code

• Comments (documentation)

Page 7: Introduction to Algorithm Design and Documentation CSIS 1595: Fundamentals of Programming and Problem Solving 1

Comments

• Comments: Text in program meant to explain how it works– What each section does– How it does it (if not obvious)– Often includes header that briefly describes what program

does as a whole

• Syntax in Python: # comment– Anything after the # is ignored by the Python interpreter

Page 8: Introduction to Algorithm Design and Documentation CSIS 1595: Fundamentals of Programming and Problem Solving 1

Comments

• Can create directly from pseudocode– Often write comments before writing code