CHAPTER TWO Flowcharting
OBJECTIVES
Upon completion of this chapter, you should be able to:
•
•
•
•
Know the main steps for problem solving.
Define term flowchart.
List and discus advantages and disadvantages of flowchart
as a logic development tool.
Solve word problems using flowcharts.
A computer is simply a tool which serves to assist in problem solving. As a scissor helps to cut a piece of paper but cannot cut it itself, a computer helps to solve a problem. Computers share a common drawback, alone they are useless. The human brain is the only device capable of creative thinking.
Since this is the case, we should make every effort to improve our problem solving ability. This study of problem solving and flowcharting will demonstrate a systematic approach to problem solving which will apply in particular to computer programming problems.
1 The first step in problem solving is to define the problem. The problem
statement should be examined carefully to fully determine what question
should be answered.
١٠
For example, consider this problem. A farmer had 100 chicken and all but 20 of them died. How many chicken does the farmer have left?
The first impression is to subtract 20 from 100 to obtain an answer, but careful examination of the problem shows that this method will determine how many chicken died, where we have 20 chicken left. So we should study each problem carefully and be sure to determine what question must be answered before attempting to solve the problem.
After the problem is defined, the next step is to assemble all given data and to assign variable names to those quantities which are unknown. Like the following statment:
Let r = the radius of the circle
Next, all unnecessary information should be discarded. Many
problems contain information which has no meaning to the solution.
A man received a check for 300 pounds of which he deposited 120 pounds into his account. If his account balance was 200 pounds after this deposit, how much was his balance before the deposit?
The following example will illustrate the sequence of steps used in problem solving.
A school has 1000 students of whom 48 percent are boys. The school gave a party which 70 percent of the students attended. If 60 percent of those attending were boys, how many girls attended the party?
Solution:
1 . The question is: “How many girls attended the party?”
2 . Let x = the total number of students attending the party
Let y = the number of boys attending the party
Let z = the number of girls attending the party
3 . The given fact that 48 percent of the students are boys has no effect on
the problem and may be discarded.
4 . The relationships stated are:
a.
70 percent of the students attended ( x )
b.
60 percent of those attending were boys ( y )
c.
This implies that the difference between x and y represents the
number of girls attending (z).
So, we express these relationships as the following equations:
a.
x = 1000 * 0.70
b.
y = x * 0.60
c.
z = x – y
5 . Since the variable x must be known to find the variable y and both x
and y must be known in order to find z, the equations must be solved in
the given order.
We can summarize t he main needed steps for problem solving as follows:

. Define the problem

. Assemble known q uantities and assign variable names

. Discard unimporta nt data.

. Establish relationsh ips and express them as equations.

. Determine the prop er algorithm by arranging the equation s in correct sequence.
The flowchart is a me an of visually presenting the flow of data through an information proc essing systems, the oper ations
performed within
system and the seque nce in
which they are perfo rmed.
In this chapter, we

shall

concern ourselves wi th the

program flowchart,

which

describes what operati ons (and in what sequence) are requir ed to solve a
given problem.
2.2.1 THE MEANIN G OF A FLOWCHART
A flowchart is a diagr ammatic representation that illustrates the sequence of operations to be pe rformed to get the solution of a probl em. Once the flowchart is drawn, it becomes easy to write the program in a ny high
level language. Hence, it is correct to say that a flowchart is a must for the better documentation of a complex program.
2.2.2 GUIDELINES FOR DRAWING A FLOWCHART
Flowcharts are usually drawn using some standard symbols. Some standard symbols, which are frequently, required for flowcharting many computer programs are shown below:
Figure 2.1 Basic Flowcharting Shapes.
Note that the 5 basic flowcharting symbols are:
1Terminal block 3 Process block
2Input / Output
4
Decision block
5 Flow lines.
The following are some guidelines in flowcharting:

a. The flowchart should be clear, neat and easy to follow. There should not be any room for ambiguity in understanding the flowchart.

b. The usual direction of the flow of a procedure or a system is from left to right or top to bottom.

c. Only one flow line should come out or from a process symbol.

d. Only one flow line should enter a decision symbol, but two or three flow lines, one for each possible answer, should leave the decision symbol.

g. If the flowchart becomes complex, it is better to use connector symbols to reduce the number of flow lines. Avoid the intersection of flow lines if you want to make it more effective and better way of communication.

h. Ensure that the flowchart has a logical start and finish.

i. It is useful to test the validity of the flowchart by passing through it with a simple test data.
2.2.3 ADVANTAGES OF USING FLOWCHARTS
The benefits of flowcharts are as follows:

a. Communication: Flowcharts are a good way of communicating the logic of a system to all concerned.

b. Effective analysis: With the help of flowchart, problem can be analyzed in more effective way.

c. Proper documentation: Program flowcharts serve as a good program documentation.

d. Efficient coding: The flowcharts act as a guide during the system’s analysis and program development phase.

e. Proper debugging: The flowchart helps in debugging process.

f. Efficient program maintenance: The maintenance of a program becomes easy with the help of flowchart.
2.2.4 LIMITATIONS OF USING FLOWCHARTS

a. Complex logic: Sometimes, the program logic is quite complicated. In this case, flowchart becomes complex and clumsy.

b. Alterations and modifications: If alterations are required the flowchart may require redrawing completely.

c. The essentials of what is done can easily be lost in the technical details of how it is done.
2.3 SOME EXAMPLES ON FLOWCHARTING
Now we shall present few examples on flowcharting for proper understanding of this technique. Problems 1 through 8 are given for the normal students. Problems 9 through 11 are optional; they are used for enrichment of the material for the distinguished students.
Example 2.3
Draw flowchart to represent the process of reading two numbers,
dividing them, and then displaying the result.
Answer: You have to note that “Read number1” means that we read a number and store it in memory in a loca on which we call number1.
Figure 2.4 Flowchart for the division of two numbers problem.
Example 2.4
Draw a flowchart to find the sum of first 100 natural numbers. This means that we want to find sum where sum is given by:
Sum = 1 + 2 + 3 + …………………………………+ 99 + 100.
Answer: The required flowchart is shown below, where SUM is a location in memory (variable) at which we store the sum in it and N is a variable at which we store the natural number.
Figure 2.5 Sum of the first 100 natural numbers.
Draw a flowchart to find the sum of the first 25 odd natural numbers. This means that we want to find sum where sum is given by:
Sum = 1 + 3+ 5 + ………………………………… here we add 25 odd natural numbers
Answer: The required flowchart is shown below, Where N is working as a counter for the number of odd numbers that have been added to SUM, and T represents the value of the Term to be added to SUM.
Figure 2.6 Sum of the first 25 odd natural numbers.
Draw a flowchart to find the largest of three numbers A, B, and C.
Answer: The required flowchart is shown below:
Figure 2.8 Flowchart solution for example 2.7.
Now let's solve this problem by Assuming that the read numbers are : A=20, B=10, and C=30
Figure 2.9 Example on flowchart solution for example 2.7.
Ahlia Company desires to generate its payroll via computer. The information collected that every payroll period includes the employee social security number, pay rate, and working hours. The payroll department would like a report listing these items. Add to this, overtime pay, gross pay, tax withheld (20% of gross pay), and net pay. Note that the employee should be given overtime pay 1.5 of pay rate in case that he worked a number of hours greater than 150 hours.
Answer: Let's label the data items given to us in this problem with variable names as given below:
SSN

Social Security Number

PR

Pay Rate

WH

Working Hours

GP

Gross Pay

OP

Overtime Pay

TAX

Tax Withheld

NP

Net Pay

This approach will make the flowcharting process easier by using these
variable names inside the flowchart symbols.
Figure 2.10 Flowchart solution for example 2.8.
Now let's solve this problem by assuming that the read numbers
are :SSN=12345, HW=160 Hours, and PR=6 L.E.
Figure 2.11 Example of flowchart solution for example 2.8.
Some optional enrichment examples for distinguished Students.
The manager of your company has requested a report from the Personnel Department about all employees. The report should include
the following information:
1 The total number of males and females. 2 The number of employees by the following age categories:
3 The total number of people who have been working for the company for 10 years or more. 4 The total number of engineers.
Draw the needed flowchart
Solution:
Most of the variables that will be used in this problem are counters
that must be initialized to zero at the beginning of the problem. These variables are:
Male_count = number of males
Female_count

= number of females

under_20

= number of employees under 20

20_29

= number of employees between 20 and 29

30_39

= number of employees between 30 and 39

40_49

= number of employees between 40 and 49

50_60

= number of employees between 50 and 60

over_60

= number of employees over 60

In addition to that you have to read today’s date that can be stored at variable ‘Today’ , birthday that can be stored in variable ‘BD’ , in addition to the date of employment that can be stored in variable ‘DOE’. Assume that variable ‘OCC’ stores the occupation code which is ‘ENG’ for engineers.
Figure 2.12 Flowchart solution for example 2.9.
Assuming that the equation needed to be solved is given by
2 ^{}
13 15 0
That means that a , b, and c are equal to 2, 13, 15. The following flowchart shows the steps for the solution of this problem:
Figure 2.14 Example on flowchart solution for example 2.10.
Question 1:
Donia drew a Flowchart to add two numbers and printed the result as
follows.
Correct the Flowchart.
Question 2:
Draw a flowchart to read the age of Hany and Hesham, then it prints the
name of the elder.
Draw a flowchart that reads a temperature in Fahrenheit degrees and
convert it into Celsius degrees, using the formula
Question 4:
°
5
_{9}
° 32
Draw a flowchart that reads the radius of a sphere “r”, then it calculates
its volume “V” and surface area “A” using formulas
where
4
3
^{}
4
^{}
π
22
7
If the read radius is negative, the flowchart should print a warning message then terminates.
Question 5:
Draw a flowchart to read number “x”, then it calculate the value of
function y using the formula ^{}
3
^{}
^{}
5
^{}
_{7}
… … … … … ..
Where we add 100 terms.