You are on page 1of 41

Flow Charts

What is a Flow Chart? 2

 A flowchart is a Pictorial representation of


an algorithm

 It is a diagram that depicts the “flow” of a


program

 It uses boxes of different shapes to


denote instructions of different types
Basic Flowchart Symbols 3

Process / Input /
Start / End
Task Output
The start or end Process or Data: Inputs
of a workflow action to, and
outputs from,
a process

Decision Connector

Flow Lines Decision point in a Used to connect


process or workflow one part of a
flowchart to
another
Calculate Pay 4

Algorithm:
 Ask employee for the number of hours
he/she works
 Ask employee for his/her pay rate (salary
per hour)
 Multiply hours with pay rate
 Store result in Total Pay
 Display Total Pay on screen
5

Calculate Pay
START

Display message

Flowchart
“How many hours
did you work?”

Read Hours
 The figure shown here is a
flowchart for the pay- Display message
calculating algorithm “How much do you
get paid per hour?”

Read PayRate

Multiply Hours by
PayRate. Store result
in Total Pay.

Display Total Pay

END
START Terminal 6

Basic Flowchart Symbols Display message


“How many
hours did you
work?”

 Terminals Read Hours

 represented by rounded Display message


rectangles “How much do
you get paid per
 indicate a starting or hour?”

ending point
Read PayRate

Multiply Hours
by PayRate.
START Store result in
Total pay.

Display Total
pay

END Terminal
END
START
7

Basic Flowchart Symbols Display message


“How many
hours did you
work?”

 Input/Output Operations Read Hours

 represented by Display message


parallelograms “How much do Input/Output
you get paid per
Operation
 indicate an input or hour?”

output operation
Read PayRate

Multiply Hours
by PayRate.
Display message Store result in
Total pay.
“How many
Read Hours
hours did you Display Total
pay
work?”
END
START
8

Basic Flowchart Symbols Display message


“How many
hours did you
work?”

 Processes Read Hours

 represented by Display message


rectangles “How much do
you get paid per
 indicates a process such hour?”

as a mathematical
computation or an action Read PayRate

Multiply Hours
by PayRate.
Process Store result in
Multiply Hours Total pay.
by PayRate.
Store result in Display Total
pay
Total pay.
END
Basic Flowchart Symbols 9

 Connectors:
 The “A” connector indicates that the second
flowchart segment begins where the first
segment ends START A

END
A
Four Flowchart Structures 10

 Sequence
 Decision
 Repetition
 Case
Sequence Structure 11

 A series of actions are performed in


sequence
 The pay-calculating example was a
sequence flowchart
Decision Structure 12

 The flowchart segment below shows how a


decision structure is expressed in C++ as an if/else
statement

Flowchart
C++ Code
NO YES
x < y?
if (x < y)
a = x * 2;
Calculate a Calculate a
else
as x plus y as x times 2
a = x + y;
Decision Structure 13

 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
Repetition Structure 14

 The flowchart segment below shows a


repetition structure expressed in C++ as a
while loop

Flowchart C++ Code

while (x < y)
YES x++;
x < y? Add 1 to x
Controlling a Repetition 15

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
flowchart be modified so YES
it is no longer an infinite x < y? Display x
loop?
Controlling a Repetition 16

Structure
 ANSWER: By adding an action within the
repetition that changes the value of x

YES
x < y? Display x Add 1 to x
Case Structure 17

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

bonus = 100 bonus = 200 bonus = 400 bonus = 800


Combining Structures 18

 This flowchart segment


shows two decision
structures combined NO YES
x > min?

Display “x is NO YES
outside the limits.”
x < max?

Display “x is Display “x is
outside the limits.” within limits.”
Review 19

 What do each of the following symbols


represent?
Answer 20

 What do each of the following symbols


represent?

Decision
Terminal

Input/Output
Operation Connector

Process
Review 21

 Name the four flowchart structures


Answer 22

 Sequence
 Decision
 Repetition
 Case
Review 23

 What type of structure is this?


Answer 24

 Repetition
Review 25

 What type of structure is this?


Answer 26

 Sequence
Review 27

 What type of structure is this?


Answer 28

 Case
Review 29

 What type of structure is this?


Answer 30

 Decision
31

Algorithm and Flow Chart


Examples
Length Example 32

 Write an algorithm and draw a flowchart


to convert the length in feet to
centimeter

 Algorithm:
 Input the length in feet (LFT)
 Calculate the length in cm (LCM) by
multiplying LFT with 30
 Print length in cm (LCM)
Length Example 33

 Flow chart
Start

Input
LFT

LCM  LFT x 30

Print
LCM

Stop
Calculate Interest 34

Write an Algorithm to Calculate Interest of a


Bank Deposit

Algorithm:
 Step 1: Read amount
 Step 2: Read years
 Step 3: Read rate
 Step 4: Calculate the interest with formula
"Interest=Amount*Years*Rate/100
 Step 5: Print interest
Calculate Interest 35

Flow Chart
Even or Odd Number 36

 Write an Algorithm to determine if a


number is Even or Odd

 Algorithm:
 Step 1: Take a number N as input from
user
 Step 2: Set remainder as N modulo 2
 Step 3: If remainder is equal to 0 then
number N is even, else number N is odd
 Step 4: Print output
Even or Odd Number 37

 Flow Chart
Selection Sort 38

Algorithm
 Step 1: Find the smallest number. Swap it with the
first number

 Step 2: Find the second-smallest number. Swap it


with the second number

 Step 3: Find the third-smallest number. Swap it with


the third number

 Step 4: Repeat finding the next-smallest number,


and swapping it into the correct position until the
list is sorted
START

Selection Sort Loc=0


39

Is Loc less
Flow chart than length
of list-1? false

true

Find smallest number in


list starting from Loc

Swap smallest number


found with number at Loc

Add 1 in Loc

STOP
40

Write an Algorithm and


draw a flow chart for
Login process
References 41

 Introduction To Computer Science by ITL


Education Solutions Limited

 https://www.edrawsoft.com/algorithm-
flowchart-examples.php

You might also like