Title: Modular flowcharts
1Modular flow-charts
Applied Computing AC1101
2Selection
- Choose to perform an action or not perform it
- Choose to perform an action or otherwise do
something else - Choose to perform one of a set of possibilities
3Repetition
- Do something a fixed number of times
- Do something until something becomes true
- While something is true, do something
4Getting into detail
- Advantages of structure diagrams
- Show overall structure of solution
- Clearly identify individual modules
(functions?)and relationships between them - Limitations
- Clumsy for showing selection repetition
- Sometimes easier to understand solution as a flow
of events and actions than as a structure
5Modular flowcharts
- Symbols to show events and actions
- All symbols connected by lines
- Lines show allowable actions at any point
- Modular flowcharts have only one way in and one
way out - Modules have only one entranceand one exit point
6Flowchart symbols
Note rounded edges
Terminator
Action boxor module
Selection
7Sequence
Time
No need tosay anything here -Its obviously the
end
8Selection boxes
Selection box can have two lines coming out, one
for if the condition is true, the other for false
9Selection (1)
if the condition is true, do Things to do,
otherwise miss it out
10Selection (2)
if the condition is true, do Things to do, or
else do Other things to do
11Selection (3)
if condition 1 is true, do Something, or else if
condition 2 is true do Other thing, or else do
Default
12Repetition (1)
Do these things again and again ...
until this condition has been met
Always does Things to do at least once
13Repetition (2)
Only does Things to do while the condition is
true ... so may not do Things to do at all
14Top-down design using flowcharts
- Modules must have only one entry and one exit
point - So nesting becomes possible
- Helps to identify functions
- And so on
15Nesting of top-down design
Nesting of modules is easybecause of the
ruleone line in, one line out
16Example 1
17Example 2
18Example 3
19Exam marks example
- We have the marks from sixty students who have
sat an exam. - We want to know how many students have passed and
how many have failed - The pass mark is 50
20Example to work out
- A survey has been carried out to count the number
of vehicles crossing the Tay Bridge.The number
of cars crossing during each hour is recorded,
giving 24 counts per day. - Draw a modular flowchart for a program which
reads the counts for one day and produces an
output giving the total number of vehicles
crossing during the day and the maximum number
crossing in one hour. - If time, calculate total income for the day (each
vehicle pays 80p) and average vehicles per hour - Can you identify candidates for separate
functions?
21Summary - modular flowcharts
- Good way to show flow of program,especially
selection and repetition - Because only one entrance and exit allowed, very
good for representing stepwise refinement - Helps to identify functions
- Good for checking correctness of solutions