70 likes | 136 Views
The Five Steps. Understanding the problem Do a small example by hand Write an algorithm for solving the problem Translate the algorithm into a programming language (like C) Test the program. C Program Contents. Comments: in beginning and throughout program
E N D
The Five Steps • Understanding the problem • Do a small example by hand • Write an algorithm for solving the problem • Translate the algorithm into a programming language (like C) • Test the program
C Program Contents • Comments: in beginning and throughout program • Header statements: include C libraries • Functions (main, library, your functions): • Header: function name and arguments main() • Body • Declarations • Statements: assignments, expressions, calling other functions, generating output
Testing a program • Remove syntax errors: Look at compiler comments where errors occurred and check program around these lines • Remove link errors: again check comments where errors occurred • Run time errors: • Semantic errors (check function arguments) • Logic errors: manual trace, check precedence of operators, add debugging code to check variables
Good Programming Practices • Careful algorithm development • Modular programming • Incremental testing • Program tracing • Documenting code
Stock Portfolio Task Write a program to analyze a stock portfolio consisting of some number of different stocks we own. For each stock we have information on how many shares we own, how much we paid for each share, and how much each share is worth now. Stock prices are expressed as a whole dollar amount and a fraction (e.g. 1/2, 1/4, 1/8, etc.). We would like to compute how our portfolio is worth and how much profit we have made if we liquidated it today.
Bottom up ApproachAdd features Go back to five step design process and make modifications • Read input data from terminal • Compute profit or loss from number of shares owned and price bought and price sold • Read in several stock data information and compute profit of loss • Compute cumulative gains or losses