introduction to algorithm design and documentation csis 1595: fundamentals of programming and...
TRANSCRIPT
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
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
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
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
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)
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
Comments
• Can create directly from pseudocode– Often write comments before writing code