Introduction To Flowcharting: Jumail Bin Taliba
Introduction To Flowcharting: Jumail Bin Taliba
Flowcharting
by
Jumail Bin Taliba
Faculty of Computer Science & Information System
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 1
Today’s Topics
• Flowchart Symbols
• Control Structures
• Some examples
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 2
Flowchart:
Get A
Get B
Calculate Resut
C=A*B
Display the
Result C
Stop
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 3
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.
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.
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.
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 4
Example:
Start Terminal.
Start Program starts
here
Read A Input.
Read B Enter values for
A and B
Calculate Resut
C=A*B Process
Display the
Result C Output
Stop Terminal
Stop Program ends
here
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 5
Comments or description
Start
Yes
No
Stop
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 6
Connectors on the same page
Start
1 2
Stop
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 7
Connectors on a different page
Page 1 Page 2
Start
2
1
Stop
Yes 1
No
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 8
The detail of how the function works
is put in another flowchart.
Function
This is known as Function-Definition
Read
n1, n2 , n3
Body of a function is
AVRG (result, n1, n2,n3) the same with
normal flowchart
Stop
End terminal
must be a “Return”
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 9
Parameters used in a function-definition
Related terms and concepts are called formal parameters
Read
n1, n2 , n3
sum = a+ b+c
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 10
Related terms and concepts (cont.) In a function-definition, you should only
use formal parameters – R, a, b, c
Start
AVRG ( R, a, b,c)
Read
n1, n2 , n3
sum = n1 + n2 + n3
Print
R
Return
This is wrong!
R is an formal parameters.
Should use Stop
result instead.
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 11
Related terms and concepts (cont.)
Page 1 Page 2
Start
AVRG ( R, a, b,c)
Read
n1, n2 , n3
Stop
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 12
Related terms and concepts (cont.)
• Input
Data of the function
• Output
The result of the function
• Both
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 13
Function definition:
Related terms and concepts (cont.)
R is the output parameter
a, b, c are input parameters
Page 1 Page 2
Start
AVRG ( R, a, b,c)
Read
n1, n2 , n3
sum = a+ b+c
R = sum/3
Function call:
Print
result
result is the output
parameter.
n1, n2, n3 are the input Return
parameters.
Stop
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 14
Function definition:
Related terms and concepts (cont.)
x and y act as both input and output
parameters
Page 1 Page 2
Start EXCHG( x, y)
Read hold = x
p, q
x=y
EXCHG (p, q)
y = hold
Print Return
p, q
Function call:
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 15
Related terms and concepts (cont.)
If there is only one output parameter, the flowchart may “RETURN” the result
Example: let take a look again at the function that calculates the average of three numbers.
Original function flowchart: Since it has only one output, the output is “RETURN”
Page 2 Page 2
R = sum/3 R = sum/3
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 16
Related terms and concepts (cont.)
Since the function flowchart has been modified, the way of the function to be called will also be changed
Read Read
n1, n2 , n3 n1, n2 , n3
Stop Stop
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 17
Control Structure
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 18
Sequential Structure
A statement means
a command or an instruction
statement
statement
statement
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 19
Selection Structure
If
“do it or don’t” (one-choice)
TRUE
condition
condition
FALSE
statement
statement
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 20
Selection Structure (cont..)
If-else
“do this one or (two-choices)
the other one”
TRUE FALSE
condition
condition
°
If set condition is true, execute the first statement, else
execute second statement
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 21
Selection Structure (cont..)
Nested if
(if within if)
FALSE
test1 FALSE
test1
TRUE
TRUE
FALSE
TRUE
test2
° °
statement
Considered as
one statement ° °
it is an “one-choice” if
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 22
Selection Structure (cont..)
FALSE
condition
TRUE
statement
statement TRUE
condition
FALSE
statement
°
° Considered as one statement
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 23
Repetition Structure
while Loop
It is a pre-test loop
°
FALSE
condition
conditio
n
TRUE
statement
body of loop
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 24
Repetition Structure (cont…)
do-while Loop
It is a post-test loop
°
statement
statement
condition
TRUE
FALSE
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 25
Repetition Control Structure (cont…)
for Loop
It is a pre-test loop
initialization
° FALSE
condition
TRUE
body of loop
increment
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 26
Example:
Start
Read
Length,
Input:
Width Length <- 5
Width <- 3
Area: 15
Print
Area, Perimeter: 16
Perimeter
Stop
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 27
Example:
What is the output of the following flowchart when the input Num= 10
Start
Enter a Number >> 10
Category A
Input:
Read Num
Num <- 10
Num = 10
10 > 0 ? => YES
Num>0? No
Print
"Category B"
Yes
Print
Output:
"Category A"
“Category A”
Stop
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 28
Example:
What is the output of the following flowchart when the input is Num= 0
Start
Enter a Number >> 0
Category B
Read Num Input: Category A
Num <- 0
Num = 0 Output:
0 > 0 ? => NO “Category B”
Num>0? No
Print
"Category B"
Yes
Print
Output:
"Category A"
“Category A”
Stop
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 29
Example:
What is the output of the following flowchart when the input is Num= 4
Start Variables
Variables
Variables(in
(in
(inmemory):
memory):
memory):
Num
Num
Num [[[ 444 ]]]
Read Num Input: Result
Result
Result [[[ 4
0710]
9 ]]] 0497 +++ 4312
Num <- 4 Count
Count [[[ 3
Count 420
1 ]]] 4312 --- 111
Initialize
Result=0
Count=Num
Print
Result
Stop
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 30
Example:
What is the output of the following flowchart when the input is N = 6 10
Page 1 Page 2 5
average
Start
N=6
AVRG ( result,n1, n2,n3)
Read
N Sum = 10 + 5 + 6
result = sum/3
Print
average Output:
Average: 7
Return
Stop
Introduction To Flowcharting | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 31