LESSON 2 - Flowchart
LESSON 2 - Flowchart
S TOPIC:
Algorithm
Representation
LESSON
3
Flowchart
1. Sequence
2. Decision
Flowchart
Algorithms
can be pictorially
represented.
A flowchart is:
gross pay = 0
Start
Display prompt
gross pay = 0 “How many
hours did you
work?”
Input hours
Input pay rate Input hours
gross pay =
hours * pay
rate
Outputy “Your
gross pay is” +
gross pay
STOP
Uses of Flowchart
Programmers use flowchart for a number
of purposes.
Display prompt
Display prompt
gross pay =
START hours * pay
rate
Output “Your
STOP gross pay is” +
gross pay
Rounded STOP
Rectangle
START
gross pay = 0
Display message
parallelograms
Input pay rate
indicate an input or
output operation
gross pay =
hours * pay
rate
Display message
“How many hours Input hours Output “Your
did you work?” gross pay is” +
gross pay
STOP
START
gross pay = 0
Display prompt
mathematical
computation or gross pay =
hours * pay
variable assignment Rectangle
rate
STOP
START
gross pay = 0
Hexagon
Display prompt
gross pay =
hours * pay
rate
gross pay = 0
Display “Your gross
pay is” + gross pay
STOP
START
gross pay = 0
Display prompt
Output “Your
gross pay is” +
gross pay
STOP
START
Flowchart
work?”
Input hours
gross pay =
hours * pay
rate
hours: ? STOP
pay rate: ?
gross pay: 0
START
Flowchart
work?”
Input Operation
Input hours
(User types 40)
gross pay =
hours * pay
rate
hours: 40 STOP
pay rate: ?
gross pay: 0
START
Flowchart
work?”
Input hours
Input Operation
Input pay rate
(User types
400)
gross pay =
hours * pay
rate
hours: 40
STOP
pay rate: 400
gross pay: 0
START
Flowchart
work?”
Input hours
hours: 40
STOP
pay rate: 400
gross pay: 16000
Flowchart Symbols
Flowchart Symbols
(con’t…)
Flowchart Structures
Sequence
Decision
Repetition
Sequence Structure
a series of actions
are performed in
sequence
The pay-
calculating
example was a
sequence
flowchart.
Decision Structure
One of two
false true
possible actions is IF
taken, depending condition
on a condition.
of structure is
commonly known true
as a loop. repeat until loop - If the condition
does not exist, the action is
repeated. This continues until the
condition already exists.
Repetition Structure
In the flowchart
segment, the question
“is x < y?” is asked. If
the answer is true, then
Process A is performed. true
The question “is x < y?” x < y? Process A
is asked again. Process
A is repeated as long as
false
x is less than y. When x
is no longer less than y,
the repetition stops and
the structure is exited.
Repetition Structure
In the flowchart
segment, the question
“is x == 0?” is asked. If
the answer is false, then
Process A is performed. Process A
The question “is x ==
y?” is asked again.
Process A is repeated as
long as x is not equal to false
0. When x becomes x = = 0?
equal to 0, the repetition
stops and the structure is true
exited.
ACT_1
Flowcharts
(Sequence)
Create flowcharts that:
1. reads in two integers and then outputs
their sum, difference, and product
(DONE)
2. reads in a student’s four exam scores,
as integers, and outputs the student’s
average
3. reads the radius of a circle and outputs
the area & circumference
Create flowcharts that:
4. reads in an integer and outputs if it’s
positive or negative (DONE)
5. reads in an integer and determines if
it’s even or odd (Note that zero is
considered as even)
6. reads in a non-zero integer and outputs
the square root if it is positive or
square if it is negative
Other Flowchart
Structures
Nested if
Case
Go to
Nested if structure
Nested if pseudo code:
It is an IF
statement in
which the true
or false
statement is
itself an IF
statement.
Nested if structure
Nested if flowchart:
Case structure
It Case pseudo code:
is a structure
where one of
several possible
actions is taken,
depending on
the contents of
a variable.
Nested if structure
Case flowchart:
switch
year
1 2 3 4 else
switch
If (year == 1) If (year ==2) do If (year ==3) do year If (year ==4) do If is any other value
do process A process B process C process D do process E
1 2 3 4 else