FLOWCHART
This covers the following topics .
Item Topic
1 Common flowchart symbols
2 Writing flowcharts to solve problems
3 Dry running of flowcharts
4 Problems based on flowcharting
Page 1 of 11
This docement covers the development of algorithms (both in pseudocode and
flowchart form) and also introduces logic gates which is a new topic from 2011.
Introduction to Flowcharts
This section covers the use of flow diagrams (charts) in the production of algorithms.
Systems flowcharts are different and these are covered in a different section
(Systems analysis).
This section primarily covers four areas:
1 Common flow chart symbols
2 Writing flowcharts to solve problems
3 Dry running of flowcharts to determine its function and outputs
4 Exercises to test the above concepts
1 Common flowchart symbols
1.1 The start and end box: START
END
1.2 The process box:
X←X+1
1.3 Input/Output box: Print X
1.4 Decision/query box:
Yes
Is X >
5?
Page 2 of 11
2 Writing flowcharts to solve problems
The following five problems are also covered in section 3.2 where the
algorithms are constructed using pseudocode. Candidates may choose to
answer questions using either flowcharts or pseudocode but a working
knowledge of both techniques is well advised.
2.1 Example 1
A town contains 5000 houses. Each house owner must pay tax based on
the value of the house. Houses over $200 000 pay 2% of their value in tax,
houses over $100 000 pay 1.5% of their value in tax and houses over $50
000 pay 1% of their value in tax. All others pay no tax. Write an
algorithm to solve this problem in the form of a flowchart.
2.2 Example 2
The following formula is used to calculate n: n ← (x * x)/(1 - x). The
value x = 0 is used to stop the algorithm. The calculation is repeated
using values of x until the value x = 0 is input. There is also a need to
check for error conditions. The values of n and x should be output.
Write an algorithm to show this repeated calculation in the form of a
flowchart.
2.3 Example 3
Write an algorithm in the form of a flowchart which takes temperatures
input over a 100 day period (once per day) and outputs the number of
days when the temperature was below 20C and the number of days
when the temperature was 20C and above.
2.4 Example 4
Write an algorithm in the form of a flowchart which:
inputs the top speeds (in km/hr) of 5000 cars
outputs the fastest speed and the slowest speed
outputs the average (mean) speed of all the 5000 cars
Page 3 of 11
START
count ← 1
Example 1
Input
house
Yes
Is house> tax ← house *
200000 0.02
No
Yes
Is house> tax ← house *
100000 0.015
No
Yes tax ← house *
Is house>
50000 0.01
No
Tax ← 0
print tax
No
count ← Is count END
count + 1 < 5001
Yes
Page 4 of 11
START
Example 2
input X
is x = 0 Yes
? END
No
is x = 1 Yes output
? “error”
No
n ← (x*x)/(1-x)
output n, x
Page 5 of 11
START
count ← 1
total1 ← 0, total 2 ← 0
Example 3
input temp
is temp Yes total1 ← total1 + 1
< 20 ?
No
is temp Yes total2 ← total2 + 1
> 19 ?
No
count ← count + 1
is count output
< 101 ? total1, total2 END
Yes No
Page 6 of 11
START
Example 4
fastest ← 0
slowest ← 1000
total ← 0
count ← 1
input topspeed
is Yes
topspeed > fastest ← topspeed
fastest ?
No
is Yes
topspeed < slowest ← topspeed
slowest ?
No
total ← total +
topspeed
END
count ← count + 1
Output fastest,
slowest, average
No average ← total *
is count <
5001 ? 100/5000
Yes
Page 7 of 11
3 Dry running of flowcharts
Dry running of flowcharts is basically a technique to:
• determine the output for a known set of data to check it carries out the
task correctly
• check on the logic of the algorithm
• determine the function of the algorithm
When dry running a flowchart it is advisable to draw up a trace table showing
how variables change their values at each stage in the algorithm. The
advantages of doing this are:
• if you make a mistake, it is easier to back track to where the error
occurred rather than starting from the beginning again
• there is less chance of an error being made
• encourages a more logical approach
The following three examples show all stages in the dry running for the given
set of input data:
3.1 Example 1
This algorithm inputs 3 numbers, each number goes through
successive division by 10 until its value is less than 1. An output is
produced which contains the number input and a value generated by
the flowchart processing.
Data to be used: X = 85, 3190, -40
3.2 Example 2
This algorithm inputs 5 values and outputs how many input numbers
were negative and how many were positive.
Data to be used: N = 1, -5, 2, -8, -7
3.3 Example 3
This algorithm inputs the number of hours of sunshine recorded each
day for a week (7 days). The output is the highest value for hours of
sunshine and the average (mean) value for the numbers of hours of
sunshine per day.
Data to be used: hours = 9.0, 7.8, 1.2, 4.5, 10.0, 6.4, 3.1
Page 8 of 11
START
input X Example 1
N←1
T←X
X ← X/10
Is X Yes Output
<1? T,N END
No
N←N+1
Trace Table
X N T Output T, N
85 1 85
8.5 2
0.85 85, 2
3190 1 3190
319 2
31.9 3
3.19 4
0.319 3190, 4
-40 1 -40
-4 -40, 1
Page 9 of 11
START
C ← 1, neg ← 0 Example 2
, pos ← 0
Input N
Yes
Is N < 0 neg ← neg + 1
No
Yes
Is N > 0 pos ← pos + 1
No
C←C+1
Is C < output
neg, pos END
5
Trace Table
C N neg pos Output neg, pos
1 1 0 0
2 -5 1 1
3 2 2 2
4 -8 3
5 -7
6 3, 2
Page 10 of 11
START
C←1 Example 3
high ← 0, total ← 0
Input
hours
Yes
Is hours high ← hours
> high
No
total ← total + hours
C←C+1
Yes
Is C <= 7
No
avge ← total/7 output END
avge, high
Trace Table
C hours high total avge Output avge, high
1 9 0 0 6
2 7.8 9 9
3 1.2 10 16.8
4 4.5 18
5 10 22.5
6 6.4 32.5
7 3.1 38.9
8 42
6, 10
Page 11 of 11