You are on page 1of 31

CMPRG

Computer Programming

FLOW CHART
Flow Charts
Algorithm for large problems becomes
complex and thereby difficult to write the code.
Problem analysts found ‘Flow charts’

• an easier way to solve the problem.


• each step is represented by a symbol and
contains a short description of the process steps
within the symbol.
• Flow charts are linked by arrows.
• Other names of flow chart are flow diagram,
process chart, and business flow diagram etc.,.
Flow Charts

Flow charts can be used for the following


aspects

• Define and analyze


• Build step by step picture of a process
• To find the areas of improvement in the
process
Flow Charts Advantages

• Communication – it is better way of


communicating the logic of a program solution

• Effect analysis – with the help of flow charts


problem can be analyze in a effective way

• Effective coding – flow charts acts as a blue


print during the system analysis iv. Proper
debugging – flow chart helps in debugging
process.
Flow Charts Limitations

• Alterations and modifications:


If alterations are required, the flowchart may
require re-drawing completely.
Types of Flow Charts

System flow charts


• used by system analyst to describe the
data flow and operation in a data
processing cycle

• defines the broad processing in


organizations showing the origin of data
filing structure, processing to be performed
and output to be generated.
Types of Flow Charts

Program flow charts:


• are used by programmers.
• used to describe the sequence of
operations and decisions for a particular
problem. Generally to solve any of the
programs belonging to C, C++, Java. .
etc., program flow charts are used.
Symbols used in Flow Charts

The flow chart being a symbolic


representation, standard symbols is used for
each specific operation.

These symbols are used to represent the


sequence of operations and flow of data and
documents required for programming. Flow
should be from top to bottom.
Symbols used in Flow Charts

Start or end of the program


Computational steps or processing function of program
Input or output operation
Initialization
Decision making and branching
On-page connector
Off-page connector
Subroutine
Database
Document printout
Writing Expressions in
Computer Language
1. To read the input ;
The following symbol is used to read
one or more inputs.

Read a
Here ‘a’ is the variable where the value of
Input is stored
Writing Expressions in
Computer Language

2. To produce output :
The following symbol is used to print one or
more outputs.

Print a

Here ‘a’ is the variable where the value of


Output is stored.
Writing Expressions in
Computer Language
3. Assignment operator
The result of arithmetic operation is stored
in a variable.
– Let a and b be inputs
– Operation  addition
– Result is stored in variable c
Writing Expressions in
Computer Language

,b

Example of Assignment operator.


Examples:
Flow Charts
1. Fahrenheit Scale
Convert into Celsius
Scale
Solution:
Formula: C = (F-32)/1.8
where F is Fahrenheit
value and C is Celsius
value.
Examples:
Flow Charts
2. Draw a flowchart that
will compute and print
the area of the circle
assuming that the radius
is equal to 5.
Examples:
Flow Charts
3. Draw a flowchart that
will read two numbers
the compute and print
for their sum and
product.
Examples:
Flow Charts
4. Draw a flowchart to find greater of 2
numbers

b
Examples:
Flow Charts
5. A Class has four
exams. Draw a flowchart
that will read in the value
of four exams and output
the student’s average.

b
Examples:
Flow Charts
6. Draw a flowchart that determines if an
inputted number is odd or even.

b
Basic Control Structure of
a Flowchart
Most of the times some part of the program needs to
be repeated at a specified number of times or until a
condition is satisfied, the process is called looping. It
makes the flow of control in a program dependent on
the value of the specified condition.
1. Sequence (begin..end or start..stop)
In this kind of structure the steps involved follow
each other one after It should be noted however
that every flowchart begins and ends with this kind
of notation.
Basic Control Structure of
a Flowchart

2. Decision
(if..then..else)
Part of the flowchart
that employs two or
more possible
alternative solution
and one of which will
be chosen for
execution depending
on the value of the
given condition.
Basic Control Structure of
a Flowchart
3. Loop (while..do, repeat ..until)/Iteration
Loop is part of the flowchart that repeats at
a specified number of time. This process is
called looping. It can be made to stop
when a certain condition is met or stop at a
specified number of repetitions. A counter
is needed to keep track at the number of
times a loop is executed. Failure to set the
condition will cause the loop to iterate
indefinitely.
Basic Control Structure of
a Flowchart
Designing a Loop
There are three things to consider in
designing a loop:
1. The body
2. The initializing statement
3. The conditions for terminating a loop
Methods for Terminating a
Loop
There are various ways of terminating a
loop. Each way depends on the given
condition of the problem

1. Count controlled loop


The user ask for the number of times a loop is to
be repeated.
Ask before iterating
The user is prompted after each loop whether or
not a loop is iterated again
Methods for Terminating a
Loop
3. Using a sentinel value
The user assigns a sentinel value to terminate a
loop. Sentinel has a value that is distinct so that it
will indicate the end of the loop. A good example is
when a program reads in positive integers, a
negative number can be used as a sentinel value.
4. Running out of input
A loop that runs out of input will terminate with an
error.
5. Exit on a Flag condition
This condition uses a variable that changes its value
to indicate that some event has taken place.
Examples:
Flow Charts
1. Write a flowchart to
add natural numbers
from 1 to 50
Examples:
Flow Charts
2. Draw a flowchart that
add first N numbers
Examples:
Flow Charts
3. Draw a flowchart that accepts 10
numbers. Determine if the numbers entered
are odd or even. Compute for the total of all
odd numbers, all even numbers, and the
total of all numbers.
31

You might also like