Flowcharts
- A flowchart is a type of diagram that is used to illustrate an algorithm
- It's much easier to learn algorithm development using a flowchart rather than
jumping straight into C++
- Following a flowchart is very straight-forward, creating one is much more difficult
-
Flowcharting symbols
- Process
Used for executing a primitive, a task that requires no further explanation
- Sub-process
Used for executing a non-primitive, a task that has another flowchart
describing the process
- Decision
For asking a yes/no question
- Start and Stop
Indicates the beginning and end of the algorithm
- Connector
Directs order of execution
- Structured flowcharts are composed of three fundamental structures:
- Sequence
Any number of consecutive processes is considered a sequence
- Choice
Also called the if-then-else
- Repetition
Also called the pre-test loop
- Any algorithm can be implemented with combinations of these three structures
-
See the article on structured
programming for more background on this
popular programming paradigm
-
Additional or alternate-form structures
- if-then choice structure
Alternate form of the if-then-else with an empty process for the "no" answer
- post-test loop structure
Alternate form of the pre-test loop where process is executed at least once
-
Nesting structures
- Any of these five fundamental structures can be nested inside the process of
any other structure
- This allows an algorithm to be as complex as needed to solve the problem
- Example: Nesting a sequence and a post-test loop in an if-then-else structure:
Structured vs. unstructured
- 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)
-
If any single part cannot be decomposed into the five fundamenal structures, it
is unstructured.
- A flowchart may be unstructured but still work correctly, but our goal is to
always produce structured flowcharts
-
Why is it important that we create structured flowcharts?
-
Our goal is to later convert all our flowcharts into C++ programs
-
C++ is a structured language, meaning that there are C++ programming constructs
that allow us to implement sequence, choice, and repetition
-
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)
Flowchart example
- Try the flowchart with X and Y values of 1 and 3, 2 and 4, 9 and 6.
What answers do you get?
- Can you figure out what this flowchart is calculating?
- Is the flowchart structured? If not, how can it be modified so it is structured
and still produces the correct answers?