Unit I FlowChart
Unit I FlowChart
UNIT I
INTRODUCTION TO COMPUTERS AND
ALGORITHMS
FLOWCHART
3
Introduction to FlowChart
START
Display message
“How many
hours did you
• A flowchart is a diagram that work?”
Multiply Hours
by PayRate.
Store result in
GrossPay.
Display
GrossPay
END
4
Basic Flowchart Symbols
START Terminal
Display message
“How many
hours did you
work?”
ending point
Read PayRate
Multiply Hours
by PayRate.
START Store result in
GrossPay.
Display
GrossPay
END Terminal
END
5
Basic Flowchart Symbols
START
Display message
“How many
hours did you
work?”
output operation
Read PayRate
Multiply Hours
by PayRate.
Display message Store result in
GrossPay.
“How many
Read Hours
hours did you Display
GrossPay
work?”
END
6
Introduction to Flowchart
START
Display message
“How many
hours did you
work?”
computation or variable
assignment Read PayRate
Multiply Hours
by PayRate.
Process Store result in
Multiply Hours GrossPay.
by PayRate.
Store result in Display
GrossPay
GrossPay.
END
7
Structures of Flowchart
• Sequence
• Decision
• Repetition
• Case
8
Sequence
9
Decision Structure
• The flowchart segment below shows how a decision structure is expressed in C++
as an if/else statement.
Flowchart C Code
Yes No if (x > y)
x>y? printf(“X is bigger”);
else
printf(“Y is bigger”);
X is Big Y is Big
10
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.
NO YES if (x < y)
x < y? a = x * 2;
Calculate a
as x times 2.
11
Repetition Structure
Flowchart C Code
while (x < y)
YES x=x+1;
x<y? Add 1 to x
No
12
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
flowchart be modified so
it is no longer an infinite YES
loop? x < y? Display x
13
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
14
Case Structure
If years_employed = 2, If years_employed = 3,
bonus is set to 200 bonus is set to 400
If years_employed = 1, CASE If years_employed is
years_employed more than 3, bonus is
bonus is set to 100
set to 800
1 2 3 Other
15
Connectors
END
A
16
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
17
Combining Structures
Display “x is NO YES
outside the limits.”
x < max?
Display “x is Display “x is
outside the limits.” within limits.”
18
Review
Decision
Terminal
Input/Output
Operation Connector
Process Module
20
Example- Adding Two Numbers
21
Example- Finding an Item
Example
23
References