Flowcharts

  1. A flowchart is a type of diagram that is used to illustrate an algorithm
    1. It's much easier to learn algorithm development using a flowchart rather than jumping straight into C++
    2. Following a flowchart is very straight-forward, creating one is much more difficult
  2. Flowcharting symbols
    1. Process       process
      Used for executing a primitive, a task that requires no further explanation

    2. Sub-process       subprocess
      Used for executing a non-primitive, a task that has another flowchart describing the process

    3. Decision       decision
      For asking a yes/no question

    4. Start and Stop   start or stop
      Indicates the beginning and end of the algorithm

    5. Connector       connector
      Directs order of execution

  3. Structured flowcharts are composed of three fundamental structures:
    1. Sequence   sequence
      Any number of consecutive processes is considered a sequence

    2. Choice   choice
      Also called the if-then-else

    3. Repetition   repetition
      Also called the pre-test loop

    4. Any algorithm can be implemented with combinations of these three structures
    5. See the article on structured programming for more background on this popular programming paradigm
  4. Additional or alternate-form structures
    1. if-then choice structure if-then choice
      Alternate form of the if-then-else with an empty process for the "no" answer

    2. post-test loop structure post-test loop
      Alternate form of the pre-test loop where process is executed at least once

  5. Nesting structures
    1. Any of these five fundamental structures can be nested inside the process of any other structure
    2. This allows an algorithm to be as complex as needed to solve the problem
    3. Example: Nesting a sequence and a post-test loop in an if-then-else structure:
      nesting structures
  6. Structured vs. unstructured
    1. A flowchart is structured if it can be decomposed into the five fundamental flowcharting structures (sequence, two forms of choice structures, two forms of repetition structures)
    2. If any single part cannot be decomposed into the five fundamenal structures, it is unstructured.
    3. A flowchart may be unstructured but still work correctly, but our goal is to always produce structured flowcharts
    4. Why is it important that we create structured flowcharts?
      1. Our goal is to later convert all our flowcharts into C++ programs
      2. C++ is a structured language, meaning that there are C++ programming constructs that allow us to implement sequence, choice, and repetition
      3. Only structured flowcharts can be converted into C++ programs (there are some exceptions to this rule, but for now let's assume this is always true)
  7. Flowchart example
    1. Try the flowchart with X and Y values of 1 and 3, 2 and 4, 9 and 6. What answers do you get?
    2. Can you figure out what this flowchart is calculating?
    3. Is the flowchart structured? If not, how can it be modified so it is structured and still produces the correct answers?

    flowchart