Introduction To FlowCharts
Introduction To FlowCharts
Flowcharting
Todays Topics
Flowchart Symbols
Structures
Sequence
Selection
Repetition
1. Flowchart:
O The flowchart is a means of visually presenting
through
an
information
2. Flowchart Symbols
Terminal:
Used to indicates the start and end of a
flowchart.
Single flow line.
Only one Start and Stop terminal for each
program.
The end terminal for function/subroutine must
use Return instead of Stop.
Process:
Used whenever data is being manipulated.
One flow line enters and one flow line exits.
Input/Output:
Used whenever data is entered (input) or
displayed (output).
One flow line enters and one flow line exits.
2. Flowchart Symbols
Decision:
Used to represent operations in which
there are two possible selections.
One flow line enters and two flow lines
(labeled as Yes and No) exit.
Function / Subroutine:
Used to identify an operation in a separate
flowchart segment (module).
One flow line enters and one flow line
exits.
On-page Connector:
Used to connect remote flowchart portion
on the same page.
One flow line enters and one flow line
exits.
2.Flowchart Symbols
Off-page Connector:
Used to connect remote flowchart portion
on different pages.
One flow line enters and one flow line
exits.
Comment:
Used to add descriptions or clarification.
Flow line:
Used to indicate the direction of flow of
control.
Start
Read N,
M
Yes
No
Stop
Stop
1
Page 1
Start
2
1
Stop
Yes
No
2
3.4 Function
Page 1
Start
Page 2
Read
n1, n2 , n3
At this point,
we only focus on what
to do. How to do it,
it comes later.
Body of a function is
the same with
normal flowchart
result = sum/3
Print
result
Return
Stop
End terminal
must be a Return
O Proper
O Efficient
4.4.1 Sequence :
In a computer program or an algorithm, sequence
involves simple steps which are to be executed one
after the other.
The steps are executed in the same order in which they are
In a flowchart,
written.
sequence is expressed as:
In pseudocode,
sequence is expressed
as:
process 1
process 2
process n
4.4.1 Sequence
4.4.2 Selection :
Binary
(structure)
Binary Selection
Binary Selection
In pseudocode, binary
selection is expressed in the
following ways:
1.
IF condition THEN
process 1
ENDIF
2. IF condition THEN
process 1
ELSE
process 2
ENDIF
4.4.2 Selection :
Binary
(structure)
Binary Selection
Binary Selection
In pseudocode, binary
selection is expressed in the
following ways:
1.
IF condition THEN
process 1
ENDIF
2.
IF condition THEN
process 1
ELSE
process 2
ENDIF
4.4.2 Selection :
4.4.2 Selection :
Binary
(examples)
Binary Selection
Flowchart
4.4.2 Selection :
Binary
(examples)
Binary Selection
Pseudocode
IF the signal is green
THEN
proceed through
the intersection
ELSE
stop the vehicle
ENDIF
Binary Selection
Flowchart
4.4.2 Selection :
Multi-way
(structure)
Multi-way Selection
Multi-way Selection
In pseudocode, multiple
selection is expressed as:
CASEWHERE expression
evaluates to
choice a
:
process a
choice b
:
process b
.
.
.
.
.
.
OTHERWISE :
default
process
ENDCASE
Note: As the flowchart version
of the multi-way selection
indicates, only one process
on each pass is executed as a
result of the implementation of
4.4.2 Selection :
Multi-way
(examples)
Multi-way Selection
Pseudocode
CASEWHERE signal is
red
: stop the
vehicle
amber
: stop the
vehicle
green
: proceed
through the intersection
OTHERWISE : proceed
with caution
ENDCASE
Multi-way Selection
Flowchart
Repetition
Repetition allows for a portion of an algorithm or computer
program
to be done any number of times
dependent on some condition being met.
An occurrence of repetition is usually known as a loop.
An essential feature of repetition is that
each loop has a termination condition
to stop the repetition,
or the obvious outcome is that
the loop never completes execution (an infinite loop).
The termination condition can be checked or tested
1. at the beginning and is known as a pre-test loop or
2. at the end of the loop and is known as a post-test
loop.
Repetition
Pre-test
(structure)
Repetition: Pre-Test
A pre-tested loop is so named because the condition has to be met at
the very beginning of the loop or the body of the loop is not executed.
This construct is often called a guarded loop.
The body of the loop is executed repeatedly while the termination condition is true.
Repetition
Repetition
In pseudocode, pre-test
repetition is expressed as:
WHILE condition is true
process(es)
ENDWHILE
In flowcharting
pre-test repetition
is expressed as:
Repetition
Post-test
(structure)
Repetition: Post-Test
A post-tested loop executes the body of the loop before testing the
termination condition.
The body of the loop is repeatedly executed until the termination condition is
true.
An important difference between a pre-test and post-test loop is that the
statements of a post-test loop are executed at least once even if the
condition is originally true, whereas the body of the pre-test loop may never be
executed if the termination condition is Repetition
originally true.
A close look at the representations of the two loop types makes this point apparent.
Repetition
In pseudocode, post-test
repetition is expressed as:
REPEAT
process
UNTIL condition is true
In a flowchart
post-test repetition
is expressed as:
Repetition
Pre-test
(example)
Pre-test Repetition
Flowchart
Pre-test
Repetition
Pseudocode
WHILE the train is
moving
keep wholly within
the carriage
ENDWHILE
Repetition
Post-test
(example)
Post-test Repetition
Flowchart
Post-test Repetition
Pseudocode
REPEAT
beat the egg whites
UNTIL fluffy
Example:
Start
Read
Length,
Width
Calculate Area
Area=Length * Width
Calculate Perimeter
Perimeter=
2 * (Width+Length)
Print
Area,
Perimeter
Stop
Input:
Length <- 5
Width <- 3
Process:
Area = 5 * 3 = 15
Process:
Perimeter =
2* (5+3)
= 16
Output
Area: 15
Perimeter: 16
Example:
What is the output of the following flowchart when the input Num= 10
Start
Read Num
Num = 10
10 > 0 ? => YES
Num>0?
No
Print
"Category B"
Yes
Print
"Category A"
Stop
Output:
Category A
Category A
Example:
What is the output of the following flowchart when the input is Num= 0
Start
Read Num
Num = 0
0 > 0 ? => NO
Num>0?
No
Print
"Category B"
Yes
Print
"Category A"
Stop
Category B
Category A
Output:
Category A
Output:
Category B
Example:
What is the output of the following flowchart when the input is Num= 4
Variables
Variables
(in
memory):
Variables(in
(inmemory):
memory):
Start
Input:
Num <- 4
Read Num
Num
Num
Num
[[[ 444 ]]]
Result
Result
9 ]]] 0497 +++ 4312
Result [[[ 0
4710]
Count
Count
420
1 ]]] 4312 --- 111
Count [[[ 3
Initialize
Result=0
Count=Num
Result=Result + Count
Count>0?
Yes
Count=Count - 1
No
Print
Result
Stop
Count: 4
Count: 3
Count: 2
Count: 1
Count: 0
Result: 10
Example:
What is the output of the following flowchart when the input is N = 6
10
Page 1
average
Page 2
Start
5
N=6
Read
N
Sum = 10 + 5 + 6
sum = n1+ n2+n3
average =
21/3
result = sum/3
Print
average
Output:
Average: 7
Return
Stop