Flowcharting
Flowcharting
Flowcharting
Flowcharting
1
objectives
1- understand what is the meaning
flowchart.
2- understand how to draw flowchart
3- understand how represent
algorithm by flowchart
2
Algorithm
• Steps to do something
• Ordered
START
program.
Read PayRate
• The figure shown here
is a flowchart for the Multiply Hours
by PayRate.
END
4
Basic Flowchart START Terminal
Multiply Hours
by PayRate.
START Store result in
GrossPay.
Display
GrossPay
END Terminal
END
5
Basic Flowchart START
Multiply Hours
by PayRate.
Display message Store result in
GrossPay.
“How many
Read Hours
hours did you Display
GrossPay
work?”
END
6
Basic Flowchart START
assignment
Multiply Hours
by PayRate.
Process Store result in
Multiply Hours GrossPay.
by PayRate.
Store result in Display
GrossPay
GrossPay.
END
7
8
9
Start
I will weekup
i will run my
computer
i will open my
school account
End
10
https://meet.google.com/
for-cjpb-ouk
Four Flowchart Structures
• Sequence
• Decision
• Repetition
• Case
12
Sequence Structure
• A series of actions are performed in sequence
• The pay-calculating example was a sequence
flowchart.
13
Decision Structure
• The flowchart segment below shows how a decision
structure is expressed in C++ as an if/else statement.
NO YES if (x < y)
x < y? a = x * 2;
else
Calculate a Calculate a a = x + y;
as x plus y. as x times 2.
14
Decision Structure
• The flowchart segment below shows a decision structure
with only one action to perform. It is expressed as an if
statement in C++ code.
Flowchart C++ Code
NO YES if (x < y)
x < y? a = x * 2;
Calculate a
as x times 2.
15
Repetition Structure
• The flowchart segment below shows a repetition structure
expressed in C++ as a while loop.
while (x < y)
YES x++;
x < y? Add 1 to x
16
Controlling a Repetition
Structure
• The action performed by a repetition structure must
eventually cause the loop to terminate. Otherwise, an
infinite loop is created.
• In this flowchart segment, x is never changed. Once the
loop starts, it will never end.
• QUESTION: How can this
YES
flowchart be modified so
x < y? Display x
it is no longer an infinite
loop?
17
Controlling a Repetition
Structure
• ANSWER: By adding an action within the repetition that
changes the value of x.
YES
x < y? Display x Add 1 to x
18
Case Structure
If years_employed = 2, If years_employed = 3,
bonus is set to 200 bonus is set to 400
If years_employed = 1, If years_employed is
CASE
bonus is set to 100 years_employed any other value, bonus
is set to 800
1 2 3 Other
19
Connectors
END
A
20
Modules
START
•The position of the module
symbol indicates the point the Read Input.
module is executed.
•A separate flowchart can be Call calc_pay
Display results.
END
21
Combining Structures
• This flowchart segment
shows two decision NO YES
structures combined. x > min?
Display “x is NO YES
outside the limits.”
x < max?
Display “x is Display “x is
outside the limits.” within limits.”
22
Review
• What do each of the following symbols
represent?
Input/Output
Operation Connector
Process Module
24
Review
• Name the four flowchart structures.
26
Review
• What type of structure is this?
28
Review
• What type of structure is this?
30
Review
• What type of structure is this?
32
Review
• What type of structure is this?
34
35
36
Examples ???
37