01 Flowchart
01 Flowchart
This slide is based upon Appendix C from Starting Out with C++: From
Control Structures to Objects (5th Edition), Tony Gaddis 2007,
Published by Addison-Wesley
Contents
o Flowchart
o Basic flowchart symbols
o Stepping through the flowchart
o Three flowchart structures
o Examples
o Exercises
Read PayRate
Multiply Hours
by PayRate.
Store result in
GrossPay.
Display
GrossPay
END
to the next
Multiply Hours
by PayRate.
Store result in
GrossPay.
Display
GrossPay
END
flowchart:
Display message
• rounded rectangle “How much do
you get paid per Parallelogram
hour?”
• parallelogram
• rectangle Read PayRate
Multiply Hours
by PayRate.
Rectangle Store result in
o Each symbol represents a GrossPay.
Read PayRate
START
Multiply Hours
by PayRate.
Store result in
GrossPay.
END
Display
GrossPay
Terminal
END
• represented by parallelograms
Display
• indicate an input or output operation message “How
much do you get
Input/Output
paid per hour?” Operation
Read PayRate
Display
Multiply Hours
message “How by PayRate.
you work?”
Display
GrossPay
END
• represented by rectangles
Display
• indicates a process such as a message “How
much do you get
paid per hour?”
mathematical computation or
variable assignment Read PayRate
Display
GrossPay
END
Read PayRate
Multiply Hours
by PayRate.
Store result in
Variable Contents: GrossPay.
Hours: ?
PayRate: ?
GrossPay: ? Display
GrossPay
END
you work?”
Read PayRate
Multiply Hours
by PayRate.
Store result in
Variable Contents: GrossPay.
Hours: ?
PayRate: ?
GrossPay: ? Display
GrossPay
END
How many
Step 2: An Input Read Hours
hours did Operation
you work?
(User types 40) Display
40 message “How
much do you get
paid per hour?”
Read PayRate
Multiply Hours
by PayRate.
Store result in
Variable Contents: GrossPay.
Hours: 40
PayRate: ? The value 40 is stored in
GrossPay: ? Hours. Display
GrossPay
END
Read PayRate
Multiply Hours
by PayRate.
Variable Contents: Store result in
GrossPay.
Hours: 40
PayRate: ?
GrossPay: ? Display
GrossPay
END
Read Hours
How much
do you get
paid per
Display
hour? 20 message “How
much do you get
paid per hour?”
END
Read Hours
How much
do you get
paid per
Display
hour? 20 message “How
Step 5: The product much do you get
paid per hour?”
of Hours times
PayRate is stored in
GrossPay
Read PayRate
Multiply Hours
by PayRate.
Store result in
Variable Contents: GrossPay.
Hours: 40
PayRate: 20
GrossPay: 800 Display
GrossPay
The value 800 is
stored in GrossPay.
END
Read PayRate
Multiply Hours
by PayRate.
Store result in
Variable Contents: GrossPay.
Hours: 40
PayRate: 20
GrossPay: 800 Step 6: An Display
GrossPay
Output Operation
END
NO YES
NO YES
x < y?
Process A Process B
NO YES
x < y?
Calculate a Calculate a as
as x plus y. x times 2.
YES
x < y? Process A
YES
x < y? Display x
YES
x < y? Display x Add 1 to x
YES
x < y? Display x Add 1 to x
o if the condition does not exist, the loop will never begin.
START A
END
A
executed.
Call calc_pay
function.
• A separate flowchart can be constructed
for the module. Display results.
END
combined.
Display “x is NO YES
outside the limits.”
x<
max?
Display “x is Display “x is
outside the limits.” within limits.”
else
Y GRADE<5 N
Print “PASS” 0
endif
Print “FAIL” Print “PASS”
STOP
o Pseudocode:
Input the length in feet (Lft)
Calculate the length in cm
(Lcm) by multiplying Lft with
30
Print length in cm (Lcm)
to centimeter. Lft
Lcm Lft x 30
o Pseudocode:
Print
Input the length in feet (Lft) Lcm
o Hint:
d = sqrt(b2 - 4ac),
if d < 0, there is no root.
else if d == 0, x1 = x2 = -b/2a
else the roots are: x1 = (–b + d)/2a and x2 = (–b – d)/2a