230 likes | 342 Views
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.
E N D
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. • 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.
The Design Phase. • 1. Receive the problem specification. • 2. Understand / analyze the problem. • 3. Create an algorithm. • 4. Test and debug the algorithm Why?
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.
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?
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?
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?
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.
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.
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.
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.
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.
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?
Example of Design Phase (cont.). • II. PROCESS. • 1. Calculate TaxAmount = • SalesTaxRate * Price. • 2. Calculate TotalPrice = • Price + TaxAmount. • 3. Calculate Change = • AmountTendered - TotalPrice
Example of Design Phase (cont.). • III. OUTPUT. • 1. “Echo print” the user’s input. • 2. Display SalesTaxAmount • 3. Display TotalPrice. • 4. Display Change.
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.
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.
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.
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.”
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.
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.
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).
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!