12438_lect 1-3

Upload: rounit-roy

Post on 03-Jun-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 12438_Lect 1-3

    1/23

  • 8/12/2019 12438_Lect 1-3

    2/23

    Purpose of Program Planning

    If your teacher asked you to solve an

    arithmetic problem & you are not familiar

    with the steps involved in solving the problem,

    you will not be able to solve it.

    The same principle applies to writing computer

    programs also.

    A programmer cannot write the instructions for acomputer to execute unless the programmer knows

    how to solve the problem manually.

  • 8/12/2019 12438_Lect 1-3

    3/23

    Contd

    If you know the steps for solving a problem but

    while solving it, you forget to apply some of the

    steps or you apply the steps in the wrong

    sequences, you will get a wrong answer. While writing a computer program, if the programmer

    leaves out some of the instructions for the computer or

    writes the instructions in the wrong sequence, the

    computer will produce a wrong answer.

    So, to produce an effective computer program it is

    compulsory to write every instruction in the correct

    sequence.

  • 8/12/2019 12438_Lect 1-3

    4/23

    Contd

    Therefore, program before learning how to

    write a computer, we will first learn how to

    plan its logic.

    Program Planning Tools:-

    Algorithms

    Flowcharts

    Pseudocodes

    Decision Tables

    Programs

  • 8/12/2019 12438_Lect 1-3

    5/23

    Algorithm

    Refers to the logic of the program

    It is a step by step description of how to arrive at a solution

    of the given problem.

    Basically, it is defined as a sequence of instructions that

    when executed in the specified sequence, the desired results

    are obtained.

    Characteristicsof an algorithm: -

    Each instruction should be precise & unambiguous.

    Each instruction should be executed in a finite time.

    One or more instructions should not be repeated infinitely. This

    ensures that the algorithm will ultimately terminate.

    After executing the instructions (when the algorithm terminates),

    the desired results are obtained.

  • 8/12/2019 12438_Lect 1-3

    6/23

    Representation of Algorithms

    As Flowcharts

    As Pseudocodes

    As programs

    Note: - Any program is an algorithm, but the

    reverse is not true.

  • 8/12/2019 12438_Lect 1-3

    7/23

    Flowcharts

    It is a pictorial representation of an algorithm.

    The process of drawing a flowchart for an

    algorithm is called flowcharting. Uses boxes of different shapes to denotes

    different types of instructions.

  • 8/12/2019 12438_Lect 1-3

    8/23

    Basic Flowchart Symbols

    Terminal

    Input / Output

    Processing

    Decision

    Flow Lines

    Connectors

  • 8/12/2019 12438_Lect 1-3

    9/23

    Flowcharting Rules

    First chart the main line of logic, & then incorporate

    details.

    Maintain a consistent level of details for a given flowchart.

    Dontchart every detail.

    Use common statements that are easy to understand for

    words within flowchart symbols.

    Be consistent in using names & variables in the flowchart.

    Go from left to right & top to bottom in constructing

    flowcharts. Keep the flowchart as simple as possible. Crossing of flow

    lines should be avoided.

    If a new flowcharting page is needed, break the flowchart

    at an i/o point. Use properly labeled connectors to link the

  • 8/12/2019 12438_Lect 1-3

    10/23

    Adv. & Disadv. of Flowcharts

    Advantages : -

    Better communication

    Proper program Documentation

    Efficient Coding

    Systematic Debugging & Systematic Testing Disadvantages : -

    Very time consuming & laborious to draw with proper

    symbols & spacing especially for large complex

    programs.

    Any change/modifications in the program logic will use a

    require a completely new flowchart.

    No standards determining the amount of detail.

  • 8/12/2019 12438_Lect 1-3

    11/23

  • 8/12/2019 12438_Lect 1-3

    12/23

    Pseudo Code

    Phrases written in ordinary natural language

    that computer cantunderstand

    Also known as Program Design Language It does not have any syntax rules for

    formulating instructions

  • 8/12/2019 12438_Lect 1-3

    13/23

    Contd

    Flowchart Pseudo code

    Read NAME, BALANCE,

    RATE

    Compute INTEREST as

    BALANCE x RATE

    Write (Display) NAME and

    INTEREST

  • 8/12/2019 12438_Lect 1-3

    14/23

    Adv & Disadv of Pseudocode

    Advantages: -

    As compared to a flowchart, converting a pseudocode to a PL is mucheasier.

    As compared to a flowchart, it is easier to modify the pseudocode of

    program logic when program modifications are necessary.

    Writing of pseudocode involves much less time & effort than drawing

    an equivalent flowchart.

    Disadvantages: -

    In case of pseudocode, a graphic representation of program logic is not

    available.

    No standard rules to follow in writing pseudocode. Communicationproblem occurs due to lack of standardization.

    It is more difficult to follow the logic of pseudocode or write

    pseudocode as compared to flowcharting.

  • 8/12/2019 12438_Lect 1-3

    15/23

  • 8/12/2019 12438_Lect 1-3

    16/23

  • 8/12/2019 12438_Lect 1-3

    17/23

    Decision tables

    A table of contingencies for defining a

    problem and actions to be taken

    Single representation of relationship betweenconditions and actions

  • 8/12/2019 12438_Lect 1-3

    18/23

  • 8/12/2019 12438_Lect 1-3

    19/23

  • 8/12/2019 12438_Lect 1-3

    20/23

    Constructing a Decision Table

    PART 1. FRAME THE PROBLEM. Identify the conditions (decision criteria). These are the factors that will

    influence the decision.

    E.g., We want to know the total cost of a students tuition. What

    factors are important? Identify the range of values for each condition or criteria.

    E.g. What are they for each factor identified above?

    Identify all possible actions that can occur.

    E.g. What types of calculations would be necessary?.

  • 8/12/2019 12438_Lect 1-3

    21/23

  • 8/12/2019 12438_Lect 1-3

    22/23

    Rules

    Decision Table should be given a name at top

    left.

    Standardized language must be used consistently. Duplication of terms/meanings should be

    eliminated.

  • 8/12/2019 12438_Lect 1-3

    23/23

    Thank You!!!