Flow Charts

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

CHAPTER 5 – FLOWCHARTS

Flowcharts are graphical representation of an algorithm. Flowcharts are easier to understand as the flow
of sequence is easily understood.

Before we draw a flowchart we need to know that there are different symbols for different types of
instructions.
Start or Stop Box (Terminal Box) This box is used at the beginning or
end of the flowchart. When used in
the start, START is written in it and
when used in the end, STOP is
written in it.
Input or Output Box This box is used to suggest the input
of data or the output of information.

Processing Box This box holds instructions to do the


process act. For example, statements
like SUM=X+Y , AVG=TOTAL/N
etc. will come in this box.
Decision Box This box is used when some
comparison has to be made,

Arrows or Flowlines This indicates flow of program.


It shows conection between the
shapes.
Loop Hexagon indicates beginning of
repetation of structure

Connectors It connects the flowchart between


two pages.

Advantages of Flowchart:
1. Communication: Flowcharts are better way of communicating the logic of a system to all
concerned or involved.
2. Proper Debugging: The flowchart helps in debugging (identify and remove errors from computer
program) process.
3. Efficient Program Maintenance: The maintenance of operating program becomes easy with the
help of flowchart.

Disadvantages of Flowchart:
1. Alterations and Modifications: If alterations are required the flowchart may require re-drawing
completely. This will usually waste valuable time.
2. Reproduction: As the flowchart symbols cannot be typed, reproduction of flowchart becomes a
tedious task.
Various Programming Constructs: We can have three types of programming
constructs which we will be learning through flowcharts.

I. Sequence construct:
In the sequence construct the program flow simply moves from one statement to another.

Here are some real world Sequence constructs:


1. Process of making fruit juice.
2. Addition of two numbers.

Example

Draw a Flowchart that takes two numbers from the user, add them and give the result as output
is shown here.
Start

Enter 2 numbers:
15 and 27

Sum= 15 +27

Display sum

Stop

In the above example always a specific set of given numbers (15, 27) are getting added. But this
flowchart can be used for any general 2 numbers with a slight modification in input box, like given
below:
Enter 2 numbers A
and B

Now A and B are now like boxes. At the time of calculation, A will have a number in it and B will
have another number in it. And sum is again like a box where the result of A + B will be kept safe.

15 27 42
A B sum

II. Selection or Decision construct:


In the Selection/Decision construct the program control is transferred from a central
instruction to some other instruction, depending upon the condition met.
Here are some real world Selection constructs:
1. You are going for an outing. Draw a 2. Your father has given you some money. Draw
flowchart to decide whether you should carry a flowchart to decide whether to buy an ice
an “Umbrella” or “Not”. cream or pizza from it. If the money given is
more than 50, buy pizza, otherwise buy an ice
START cream.
Start

Ask "Is It
raining today ?
" Accept “Money from father”

No Is it Yes
Raining?
YES
IS Money
Leave Take an > 50 Buy Pizza
umbrella at umbrella.
home NO

Buy Ice Cream


Stop
STOP

Let us now draw a flowchart to enter two numbers and find their sum. If the sum is greater than 100,
print “More”, otherwise print “Less” .
Start
Terminal Box

Input Box Enter 2 numbers A and B


(where A and B are unequal)

Processing Box C=A+B

Decision Box Yes


Is C >100

No PRINT “MORE”
PRINT “LESS”
Output Box

Stop
Now I understand about
flowchart boxes.

Example
Accept three numbers and find the average. If the average is greater than 80, print “Good”,
otherwise print “Work Hard”.
Start

Enter 3 numbers A, B and C

AVG=(A+B+C)/3

Is
AVG>80 Yes

PRINT “GOOD”
No

PRINT “WORK HARD”

Stop

III. Repetition or Loop construct:


In the Repetition construct loops are used. A loop is used to repeat a certain set of commands
again and again till a certain condition is met.

Here are some real life examples of loops:


1. Potato Race
2. Icing cup cakes. If you've just baked 30 cup cakes, you need to apply the same icing procedure
to each one.
3. Working in a supermarket. Keep serving customers until the end of your shift.
4. Filling water in a bucket with a MUG.
Start

A Bucket is empty

Is the Bucket
full of water?
Yes

No
Pour mug full of
water in a bucket
Stop

Understanding Counters
You can say that a counter was set to 0 in the beginning of each round and when one round gets
completed, it was incremented by 1.

If the counter is denoted by the variable CT, its value is incremented by the process CT=CT+1,
where CT on the left side of the “=” sign stores the latest value that is being calculated on the right
side, by adding 1 to the old values of CT after each round.
<final value of CT> = <old value of CT > +1

Round Counter
In the beginning 0
After first round 1
After Second round 2
And --So on -- --So on --
After sixth round 6

The above table now can be made like this:


Number of Times Value of counter CT ( CT = CT + 1 )
Before starting the process 0
After round 1 CT = 0 + 1 = 1
After round 2 CT = 1 + 1 = 2
After round 3 CT = 2 + 1 = 3
After round 4 CT = 3 + 1 = 4
After round 5 CT = 4 + 1 = 5
After round 6 CT = 5 + 1 = 6

The counter is a variable which is used to keep track of the number of repetition in a loop.
Example Example
To read five stories from a book. To print your name five times.
Start
Start

CT = 0
CT=0

Accept Name
Start Reading the Story

Print Name
CT= CT+1
Open the next Story CT = CT + 1

Is CT < 5 Yes
Is CT < 5
Yes
No
Stop No
Stop

Activity In the above flowcharts if CT is initialized to 1 i.e , CT = 1 what will be the change
in the Decision Box ?

Understanding an Accumulator
If there is some problem like you have to find the sum of ten numbers entered, you can assign a
variable for this purpose which will store the sum of numbers entered. With each new number entered,
its value will increase by the value of the new number entered.

An Accumulator is a variable used for the purpose of calculating the sum of numbers entered in
a loop.
Example
A flowchart to accept 5 START Number Accumulator
numbers and find their sum. Entered (SM)

CT = 0, SM = 0 No Initial Value = 0
Number
entered yet
INPUT N
5 0+5=5

SM = SM + N
7 5 + 7 =12

CT = CT +1
6 12 + 6 =18

Yes Is CT < 5
4 18 + 4 = 22
No

PRINT SM
8 22 + 8 = 30

STOP

Here CT is the
counter and SM is the
accumulator.

Quick Recap
¤ A flowchart is the Graphical representation of the sequence of steps required to solve the particular
problem.
¤ In programming, there are Sequence, Decision and Repetition constructs.
¤ In the Sequence construct, the program flow simply moves from one statement to next.
¤ In the Decision construct, the program control is transferred from a certain instruction to some other
instruction, depending upon the condition met.
¤ In the Repetition construct loops are used. A loop is used to repeat a certain set of commands again till
a condition is met.
¤ A Counter is a variable which is used to keep track of the number of repetitions in a loop.
¤ An Accumulator is a variable used for the purpose of calculating the sum of numbers entered in a loop.
Quick Practice

Draw a flowchart to accept numbers from a user and also find their sum. After each entry of
number, the program should prompt the user, “do you want to enter more numbers”. If the choice
is “Yes”, the program should continue, otherwise print the sum and the process should stop.

START

Sum=0

Accept Num

Sum= Sum + Num

Accept choice "Do you


want to enter more
number?"

Yes Is Choice =
"Yes"

No
Print Sum

STOP
Exercise Time
1. Write (T) for True and (F) for False statements.

1. Flowchart represents the sequence of steps in a written form.


2. The statement A= B +C will appear in the processing box of a flowchart.
3. The statement IS A< B will appear in the Input box of a flowchart.
4. In the decision construct, the program control is transferred from a certain condition met.
5. A loop is used to repeat a certain set of commands again and again till a condition is met.
6. An Accumulator is used to keep track of the number of repetitions done in a loop.

2. Select the suitable word and fill In the Blanks:

Terminal Processing Repetition Graphical Input/Output


Algorithm Flowchart Arrows Decision Graphical
1. is a sequence of steps used in solving a problem.
2. is a graphic representation of a sequence of steps or instruction.
3. connects one box to another in a flowchart.
4. box is used to represent decision making in a flowchart.
5. We can use instead of real numbers when designing a flowchart.
6. A flowchart is the representation of the sequence of steps required to solve a particular
problem.
7. A box is used at the beginning or end of the flowchart.
8. A is used to suggest the input of data or the output of information.
9. A box holds instructions to do the processing act.
10. In the construct loops are used.

3. Answer the following in 2-3 lines.

1. What is a flowchart? Draw and explain about symbols used in a flowchart.


2. Write about the Decision construct.
3. Write about the Repetition programming construct.
4. What are counters and accumulators?

Practice Time
1. Use MS WORD to create a flowchart that finds the average of any 3 numbers.
2. Create a flowchart that decides if you can go out with friends on Saturday. Check for conditions
like parents’ approval, timings, school working or not working etc.
3. Accept three numbers, multiply them and print their result.
4. Accept two numbers. Find their sum. If the sum is greater than 50 multiply the first number by 5
and print the result, otherwise multiply the second number by 5 and print the result.
5. Accept two different numbers. If the first number A is greater than the second number B subtract
the first number from the second number and print the result, otherwise subtract the second
number from the first number and print the result.
6. Input the numbers through a loop. The loop should continue as long as the sum of the numbers
entered is less than 99.
7. To input ten non-zero numbers and print how many are +ve and how many are –ve.
8. Accept the marks in marks in Math and Science of five students and find their sums individually.
9. Create a flowchart to calculate the area of a square and a rectangle. Try adding a menu that lets the
user choose between square and rectangle.

You might also like