1 / 23

The Program Life Cycle.

The Program Life Cycle. 1. Phases of the life cycle. 2. Example of the Design Phase. 3. Implementing the algorithm. Phases of the program life-cycle. A. The Design Phase. Creation of an algorithm . Analogy: drawing up a blueprint for a house. B. The Implementation Phase.

marcia-wade
Télécharger la présentation

The Program Life Cycle.

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. The Program Life Cycle. 1. Phases of the life cycle. 2. Example of the Design Phase. 3. Implementing the algorithm.

  2. Phases of the program life-cycle. • A. The Design Phase. • Creation of an algorithm. • Analogy: drawing up a blueprint for a house. • B. The Implementation Phase. • Creation of a program. • Analogy: building a house. • C. The Maintenance Phase. • Use and modification of a program. • Analogy: adding an extension, repair of house.

  3. The Design Phase. • 1. Receive the problem specification. • 2. Understand / analyze the problem. • 3. Create an algorithm. • 4. Test and debug the algorithm Why?

  4. Where may errors arise? • 1. Failure to understand the problem. • May solve a different problem instead! • 2. Incorrect algorithm. • Either the solution fails to be an algorithm (fails one or more of four criteria) or it fails to give the correct answer in all cases.

  5. How to avoid errors in design. • We can reduce the number and severity of errors by: • 1. Taking time to fully understand the problem. • 2. Ensuring that we have a true algorithm and that it works for both “normal” and “unusual” data—meaning?

  6. Importance of Design Phase. • Studies show that time spent in the design phase is always a good investment. • Analogy: • which is most cost-effective and causes least problems --- • preventative care or treatment of illness?

  7. The Implementation Phase. • After the design phase: • 1. Code the program: translate the algorithm into a programming language. A program = an algorithm coded in a programming language. • 2. Compile the program. • 3. Test and debug the program. Again?

  8. Where may errors arise? • 1. Bad translation. The C# source code does not say the same thing as the algorithm. (Monty Python Danish-English phrase book: “Your hovercraft is full of eels”!) • 2. Syntax errors. The code has errors in grammar, spelling or punctuation.

  9. How to avoid errors in implementation. • 1. Master the programming language.In this way, you will know what C# statement corresponds to a statement of English. • 2. Learn what the compiler’s syntax error messages mean. • This will enable you to edit the code until it is free of syntax errors.

  10. The Maintenance Phase. • 1. Use the program. • 2. Discover and fix errors missed in testing. • Danger: fixing one problem may introduce others. • 3. Enhance the program by adding additional capabilities.

  11. Example of Design Phase. • 1. Receive problem. • Determine the change due to a customer. Assume that the sales tax may vary. • 2. Understand the problem. • Analyze the problem into the 3 main activities of a program: • (1) INPUT (2) PROCESS (3) OUTPUT.

  12. Example of Design Phase (cont.). • 3. Create algorithm. • Figure out the instructions required under the 3 headings. These can be written as pseudocode (English imperatives which look like a program) e.g. • Input Price, • Calculate Change, • Display Change.

  13. Example of Design Phase (cont.). • I. INPUT. • 1. Input Amount Tendered. • 2. Input Price. • 3. Input Sales Tax. • How is this ambiguous? • How can we make it unambiguous?

  14. Example of Design Phase (cont.). • II. PROCESS. • 1. Calculate TaxAmount = • SalesTaxRate * Price. • 2. Calculate TotalPrice = • Price + TaxAmount. • 3. Calculate Change = • AmountTendered - TotalPrice

  15. Example of Design Phase (cont.). • III. OUTPUT. • 1. “Echo print” the user’s input. • 2. Display SalesTaxAmount • 3. Display TotalPrice. • 4. Display Change.

  16. Test and debug the algorithm. • How? • “Play computer.” Try some data values. Calculate what the change should be, then follow the instructions of the algorithm exactly as a computer would (i.e. blindly), and see if you get the same result. • Also, consider usual and unusual data.

  17. Test and debug the algorithm (cont). • You may think that our algorithm is obviously correct. • But, can it handle unusual data? • No, if the AmountTendered is less than the TotalPrice it will give negative change instead of recording an error! • A validation check and loop would be needed to fix this.

  18. Implementing an algorithm. • The algorithm is just an idea in our head / on paper. It has no power to make a computer do anything. • So: how can we make the computer execute the algorithm? • We must translate the algorithm into a programming language.

  19. Implementing an algorithm (cont.) • Why? Why is English unsuitable? • It is too vague. E.g “several,” “a few,” “many.” • It is ambiguous. E.g. “glasses,” “bat.” • It can express actions which a computer cannot perform e.g. “vote your conscience.”

  20. Implementing an algorithm (cont.) • Thus we need a programming language. • Definition: A programming language is a formal (symbolic) language which is: • (1) precise; • (2) unambiguous; • (3) restricted to operations a CPU can perform.

  21. Implementing an algorithm (cont.) • But even the programming language is not in the CPU’s native tongue. • The CPU only “understands” binary. It cannot directly obey C#. • Therefore, it can implement our program only if it is translated into binary form. • This is accomplished by the compiler.

  22. Implementing an algorithm (cont.) • Thus programming requires 2 stages of translation: • (1) the programmer translates the algorithm into a programming language; • (2) the compiler translates the program (source code) into binary (object code).

  23. Implementing an algorithm (cont.) • The compiler, like God’s law, is totally unforgiving. It will only produce object code if there are NO syntax errors. Since only the object code can be run, a program cannot run unless all syntax errors are removed. • Fortunately, the editor covers a multitude of sins!

More Related