01 Algorithms-FlowCharts (1)

download 01 Algorithms-FlowCharts (1)

of 20

Transcript of 01 Algorithms-FlowCharts (1)

  • 8/10/2019 01 Algorithms-FlowCharts (1)

    1/20

  • 8/10/2019 01 Algorithms-FlowCharts (1)

    2/20

    2

    Introduction

    Software is developed with programming

    languages

    Before programming, it is necessary to:

    understand the problem and its elementary

    components

    determine what functionality each component

    must embody how the components logically fit together to

    accomplish the task at hand.

  • 8/10/2019 01 Algorithms-FlowCharts (1)

    3/20

    3

    Programming

    Classic Life Cycle

  • 8/10/2019 01 Algorithms-FlowCharts (1)

    4/20

    Design an Algorithm

    An algorithm is not a solution but a process

    to obtain a solution

    Divide the problem into subproblems. Design an algorithm for each subproblem.

    Check the correctness of each algorithm

    Can test using sample data

    Some mathematical analysis might be

    required

    4

  • 8/10/2019 01 Algorithms-FlowCharts (1)

    5/20

    Design the Algorithm

    Program logic usually follows a basic

    pattern:

    Obtain the inputProcess the data

    Store relevant data

    Display the output

    Try to avoid over-thinking the problem

    5

  • 8/10/2019 01 Algorithms-FlowCharts (1)

    6/20

  • 8/10/2019 01 Algorithms-FlowCharts (1)

    7/20

    Design the Algorithm

    7

    Disadvantages:

    Conflicts with the urge to write the code

    May be necessary to generate formaldocumentation

  • 8/10/2019 01 Algorithms-FlowCharts (1)

    8/20

  • 8/10/2019 01 Algorithms-FlowCharts (1)

    9/20

    Design the Algorithm

    Pseudo-code

    9

    A self defined language

    No formal rules

    A combination of words and / or symbolsthat convey meaning

    Self determined level of detail

  • 8/10/2019 01 Algorithms-FlowCharts (1)

    10/20

    Design the Algorithm

    Pseudo-code

    10

    Benefits:

    Does not require digital technology

    Is [programming] language independent,

    including free use of symbols Disadvantages:

    May be difficult for someone else to understand

    May not be digitally documentable

    May require standardization

    Standard logical structures are not evident

    Tends to approach actual code

  • 8/10/2019 01 Algorithms-FlowCharts (1)

    11/20

    End of Part 1

    11

  • 8/10/2019 01 Algorithms-FlowCharts (1)

    12/20

    Introduction to Computer ScienceC++ Programming

    Developing Algorithms &

    Flow Charts

    Part 2

  • 8/10/2019 01 Algorithms-FlowCharts (1)

    13/20

    Design an AlgorithmFlowcharting

    A set of standard symbols used to describe

    the variety of operations and interactions of

    a logical set of steps. Text within and accompanying the symbols

    define the precise action to be taken.

    The direction of flow is indicated by the useof arrows.

    Flowchart Symbols

    13

  • 8/10/2019 01 Algorithms-FlowCharts (1)

    14/20

    Design an AlgorithmFlowcharting

    14

    Benefits:

    The logic is visual you can see the flow

    Standard logical structures are clearly identifiable

    Can be drawn free-hand

    Governed by standard rules

    Disadvantages:

    Governed by standard rules

    May require software for formal documentation

  • 8/10/2019 01 Algorithms-FlowCharts (1)

    15/20

  • 8/10/2019 01 Algorithms-FlowCharts (1)

    16/20

    Design an AlgorithmPseudo-code

    Algorithm to Calculate Bathroom Flooring Cost

    1. Get the number of bathrooms to be done [number]

    2. Get the [budget]ed amount

    3. Get the [price] per square foot of the flooring material

    4. Set [count] and [total area] to zero

    5. For each bathroom (count < number)

    1. Get the [length] and [width] to determine the total square footage [area]1. area = length x width

    2. Add the area to the [total area] of all bathrooms

    1. total area = total area + area

    3. Add 1 to count

    6. Calculate the total [cost] for the flooring

    1. Total cost = total area x material price7. Compare the total cost to your budgeted amount

    8. If total cost

  • 8/10/2019 01 Algorithms-FlowCharts (1)

    17/20

    Design an AlgorithmFlowchart

    17

    Flow Chart to Calculate Bathroom Flooring Cost

    F

    TF

    T

    { While Loop }

    Start

    Get [number]

    of bathrooms

    and [budget]

    amount

    1

    Get material

    [price]

    [count] = 0

    [total area] = 0

    count budget

    Sto

    { Do Loop }

    2

    Display over

    budget

    message

    Display OK

    to proceed

    message

  • 8/10/2019 01 Algorithms-FlowCharts (1)

    18/20

    End of Part 2

    18

  • 8/10/2019 01 Algorithms-FlowCharts (1)

    19/20

  • 8/10/2019 01 Algorithms-FlowCharts (1)

    20/20

    20

    Assignment #1

    Design an algorithm to meet the following specifications:

    Calculate and display the sales bonus for the entered sales amount.

    Prompt the user and get the sales amount.

    Calculate and display the bonus amount as follows:

    If the dollar value of the sales amount is less than 25000, the bonus is

    1% of the sales amount otherwise the bonus is 5% of the sales amount

    Display the bonus amount.

    Ask the user if another salesmans bonus is to be calculated.

    If the response is Y[es] repeat the process for the next salesman; if N[o],

    end the program.

    Name the file: SalesBonus

    Submit a pseudo-code document via the WebStudy Assignment

    Assignment #1 in the Assignments tab.