The Program Life Cycle

download The Program Life Cycle

of 23

Transcript of The Program Life Cycle

  • 8/8/2019 The Program Life Cycle

    1/23

    The Program Life Cycle.

    1. Phases of the life cycle.

    2. Example of the Design Phase.3. Implementing the algorithm.

  • 8/8/2019 The Program Life Cycle

    2/23

    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.

  • 8/8/2019 The Program Life Cycle

    3/23

    The Design Phase. 1. Receive the problem specification.

    2. Understand / analyze the problem. 3. Create an algorithm.

    4. Test and debug the algorithm

    Why?

  • 8/8/2019 The Program Life Cycle

    4/23

    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.

  • 8/8/2019 The Program Life Cycle

    5/23

    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 datameaning?

  • 8/8/2019 The Program Life Cycle

    6/23

    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?

  • 8/8/2019 The Program Life Cycle

    7/23

    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/8/2019 The Program Life Cycle

    8/23

    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 ingrammar, spelling or punctuation.

  • 8/8/2019 The Program Life Cycle

    9/23

    How to avoid errors in

    implementation. 1. Master the programming language.In

    this way, you will know what C# statement

    corresponds to a statement ofEnglish.

    2. Learn what the compilers syntax

    error messages mean.

    This will enable you to edit the code until it

    is free of syntax errors.

  • 8/8/2019 The Program Life Cycle

    10/23

    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.

  • 8/8/2019 The Program Life Cycle

    11/23

    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.

  • 8/8/2019 The Program Life Cycle

    12/23

    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.

  • 8/8/2019 The Program Life Cycle

    13/23

    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?

  • 8/8/2019 The Program Life Cycle

    14/23

    Example of Design Phase (cont.). II. PROCESS.

    1. Calculate TaxAmount =

    SalesTaxRate * Price.

    2. Calculate TotalPrice =

    Price + TaxAmount.

    3. Calculate Change =

    AmountTendered - TotalPrice

  • 8/8/2019 The Program Life Cycle

    15/23

    Example of Design Phase (cont.).

    III. OUTPUT.

    1. Echo print the users input.

    2. Display SalesTaxAmount

    3. Display TotalPrice.

    4. Display Change.

  • 8/8/2019 The Program Life Cycle

    16/23

    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.

  • 8/8/2019 The Program Life Cycle

    17/23

    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.

  • 8/8/2019 The Program Life Cycle

    18/23

    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 aprogramming language.

  • 8/8/2019 The Program Life Cycle

    19/23

    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.

  • 8/8/2019 The Program Life Cycle

    20/23

    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.

  • 8/8/2019 The Program Life Cycle

    21/23

  • 8/8/2019 The Program Life Cycle

    22/23

    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).

  • 8/8/2019 The Program Life Cycle

    23/23

    Implementing an algorithm

    (cont.) The compiler, like Gods law, is totally

    unforgiving. It will only produce object

    code if there are NO syntax errors. Sinceonly the object code can be run, a program

    cannot run unless all syntax errors are

    removed. Fortunately, the editor covers a multitude of

    sins!