Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

UNIT 3 Flowchart & Activity Diagram

Learning objectives

To introduce students to solving problems graphically

To introduce students to communicate their solution to various stakeholders

Learning outcomes

A student should be able to solve problems using graphical symbols

A student should be able to use a diagram to explain their solution to a given problem

Flowchart

A flowchart is a graphical representation of a solution to a given problem. It presents the


solution as the sequence of operations to be performed in order to solve a problem. The
operations can be one of taking input, processing, making decisions, repeating certain
operations, as well as emitting output. In other words, a flowchart is an illustration of an
algorithm using visual symbols. Thus, a flowchart can be converted into an algorithm and
vice versa. The flowchart symbols define the logic of an algorithm and are read from top to
bottom.

A flowchart can be used to communicate the solution to a problem to various stakeholders


including non-technical users. Just like algorithms, flowcharts may also be used at the
different phases of problem solving and can be served as documentation. The following is an
outline of common symbols used in a flowchart.

Terminal: The terminal symbol indicates the start or end of an algorithm. The following
figures show the symbol and the usage example.

Start

Terminal
Figure 3.1a: Terminal symbol
End
Figure 3.1b: Terminal symbol indicating the start

Figure 3.1c: Terminal symbol indicating the end


Figure 3.1: Terminal symbol and its usage

Page 1
Unidirectional arrow: The unidirectional arrow indicates the flow of the process in the
algorithm. The following figure shows the unidirectional symbol.

Figure 3.2: Unidirectional Arrow


.

Input & Output: The input & output symbol represents an input or output from the
algorithm. The following figures show the symbol and the usage example.
start
input & utput
print totalScore
Figure3.3a: Input/output symbol
input caScore, examScore
end

Figure 3.3c: Input/output symbol used for


Figure 3.3b: Input/output symbol used for taking
printing the totaScore as output
caScore and examScore as inputs

Figure 3.3: input/output symbol and its usage

Processing symbol: The processing symbol represents any internal processing step to solve a
given problem, such as initialization of variables and arithmetic operation. The following
figures show the processing symbol and its usage example.

Processing totalScore = caScore + examScore


Figure 3.4 a: Processing symbol Figure 3.4b: The process captured is the addition of caScore
and examScore. The result is assigned to the totalScore.

Figure 3.4: Processing symbol and its usage


Decision symbol (aka branching symbol): The decision symbol represents the logical
evaluation of a conditional operation. It has two branches, one for if the result of the
evaluation is true, and the other for if the result of the evaluation is false. The following
figures (Figure 5) show the symbol and the usage example.

Decision

Figure 3.5a: Decision symbol

Page 2
totalScore = caScore + examScore

false true
(totalScore < 40)

Print pass Print fail

end

Figure 5b: Decision symbol used to decide what path to take depending on the value of totalScore. The decision tests
whether or not the totalScore is less than forty (40); If true, the path to Print fail will be followed; if false the path to Print pass
will be followed.
start

counter = 0

false true
(counter < 6)

Input caScore, exam score

totalScore = caScore + examScore


end

Print totalScore

counter = counter +1

Figure 3.5c: Decision symbol used to repeat the branching to the true path of the flowchart six (6) times. First, the counter is
initialized to zero (0). The decision tests whether or the counter is less than six (6); If true, caScore and examScore will be
taken as inputs. Next, the caScore and the totalScore are added; the result is assigned to totalScore. Next, the totalScore is
printed as output. Lastly, the counter is incremented by 1. The repetition continues until the counter is no longer less than
six(6). In that case, the false path or branch, which leads to the end, will be followed.

Page 3
Connector Symbol
The connector symbol is used to connect a break in a flowchart. Figure 3.6a depicts the
connector symbol. The flowchart of Figure 3.6b is broken at the point A (because the
flowchart is not complete), and from which the flowchart in Figure 3.6c connects to (the
flowchart in Figure 3.6c is the completion of the flowchart in Figure 3.6b).

Figure 3.6a Connector symbol

start

input caScore, examScore

totalScore = caScore + examScore

Figure 3.6b: a flowchart broken at point A Figure 3.6b: a flowchart connected to the flowchart of Figure 3.6b
at point A

Flowchart examples

Example 3.1: Using a flowchart, describe an algorithm for finding the sum of two numbers.

Solution:

Start

input firstNumber

input secondNumber

sum= firstNumber + secondNumber

print sum

Stop

Page 4
Example 3.2: Using a flowchart, describe an algorithm that accepts three numbers as input
and output the highest number among the three.

Start

input numb1

input numb2

input numb3

high = numb1

true
if (high < numb2)

false high= numb2

true
if (high < numb3)

high= numb3
false

print high

Stop

Example 3.3

Using a flowchart, describe an algorithm that prints integer numbers from 1 to 100.
Solution:
Start
.
counter = 1

while (counter < 101)

Print counter

counter = counter+1

Stop

Page 5
Class Activity

Elite Guru has opened a branch at Al-Qalam University Market place and 20 Software
Engineering students rushed to make purchases. The following is an algorithm to compute the
total of 1% discount that may be given to 20 students. Sketch the flowchart for the algorithm.

totalDiscount = 0

counter = 1

while (counter < 20)

input totalCostOfItems

if (totalCostOfItems >= 10000 )

discount = (1/100)*totalCostOfItems

else

discount = 0;

end if

totalCostOfItems = totalCostOfItems – discount

totalDiscount = totalDiscount + discount

end while

print totalDiscount

3.2 Exercises

1. Using a flowchart, describe an algorithm to find the average of four unknown


numbers
2. Using a flowchart, describe an algorithm to find the circumference of a circle. Hint :
circumference of a circle =  r 2
3. Using a flowchart, describe an algorithm to find all the roots of a quadratic equation.

b2  4ac
Hint x  b 
2a
4. Using a flowchart, describe an algorithm that accepts three unknown numbers and out
put the lowest among the three.
5. Using a flowchart, describe an algorithm to calculate 4!

Page 6
6. Using a flowchart, describe an algorithm that accepts a student score and prints the
score grade using the following table.

Score Grade
0 – 39 F
40 – 49 D
50 – 59 C
60 – 69 B
70 – 100 A

Page 7

You might also like