Chapter 1
FLOWGHARTING
ALGORITHMSCHAPTER 1: FLOWCHARTING AND ALGORITHMS
1.1 Flowchart Defined
“Use of symbols and phrases to designate the logic of how a
problem is solved” (sciives),
= ‘A.common method for defining the logical steps of flow within a
program by using a series of symbols to identify the basic Input,
Process and Output (IPO's) function within a program” (TRAt99)
- “A two-dimensional representation of an algorithm; the
predefined graphic symbols of a flowchart are used to indicate
the various operations and the flow of control” (swazae).
- “A diagram representing the logical sequence in which a
combination of steps or operations is to be performed. It is a
blueprint of the program’ (APU).
4.2 Algorithm Defined
“Algorithm is a finile set of instructions that specify a sequence of
operations to be carried out in order to solve a specific problem or class of
problems” ;swazes).
4.2 Basic Symbols Used in Flowcharting
Symbols. What it represents
[ = Used to signify the beginning and end of
flowchart
Terminal
= Signifies the preparation of data
- Used to select initial conditions
Preparation / Initialization
= Used to represent instructions or group of
instructions that will alter or modify a program's
course of execution.
Flowcharting and Algorithms 2Input / Output
Processing
Decision
On-pagé Connector
Off-page Connector
Flowcharting and Algorithms
“Shows input and output. Dala are to be read
into the computer memory from an input device
or data are to be passed from the memory to
an output device” (swazas),
Performs any calculations that are to be done
Signifies any decisions that are to be done
“Two altemative execution paths are possible.
The path to be followed is selected during the
execution by testing whether or not the
condition specified within the outline is fulfilled”
(Swazs9)
“Shows the entry or exit point of the flowchart’
(swazeo),
“A non-processing symbol used to connect one
part of a flowchart to another without drawing
flowlines” (LAPU8e),
“Conserves space by keeping related blocks
hear one another, reduces the number of
flowlines in complex programs, and eliminates
cross lines from taking place” (LAPUsé).
“Designates entry to or exit from one page
when a flowchart requires more than one
page” (LAPus6).—_ Signifies the process that is to be executed
next
-
Flowtin
1.4 Basic Gontrol Structures.
J. Sequence ~ process is executed from one to another in a straightforward
manner.
Examples:
4. Design a flowchart that will accept and display a number. Write its equivalent
algorithms.
Algorithm:
Step 1, Read in the vaiue of N.
x Step 2. Print the value of N.
ay
Lome /
cen
Flowcharting and Algorith2. Draw a flowchart that will compute and display the sum and product of two
numbers. Write its equivalent algorithm,
Sum =0
Product = 0
‘Sum= A+B »
Product = A*B [~—¥/
Algorithm:
Step 1. Initialize Sum and Product into
0.
Step 2. Read in the values of A and B.
Step 3. Compute Sum by adding A and
B then compute Product by
multiplying A and B.
Step 4. Print the computed value of Sum
and Product.
Print Sum,
Product
3. Construct a flowchart that will convert an inputted number in Fahrenheit to its
equivalent measure in Celsius.
Formula: C = (5/9) x (F-32)
C=)
Fahrenheit
Celsius = (5/9) * (F-
Flowcharting and Algorithms
Step 1. Initialize Celsius into 0.
Step 2. Read in the value of Fahrenheit.
Step 3. Compute the value of Celsius.
Step 4. Print the computed value of
Celsius.1. Selection (if — then ~ else) - a choice is provided between two
allernatives.
< Va
Noa
Operators Commonly Used in Flowcharting
Avithmetic Operators
Operators Meaning
: - Addition
: - Subtraction
_ = Multiplication
! - Division
Relational Operators
- Equal
Greater than
Less than
- Not Equat
- Greater than oF Equal to
s - Less than or Equal to
vAa
§
88 AND
i - OR
! - NOT
Floweharting and Algorithms 6Examples:
1. Draw a flowchart that will input values for A and B, Compare two values
inputted and print which of the values is higher including the remark “Higher".
White its equivalent algorithm.
sen |
Algorithm:
Step 1. Read in the values of A and B.
Step 2. Test if A is greater than B.
Step 3. If Ais greater than B, A is
higher. However, if A is less
than B, B is higher.
Step 4. Print the number and the
remark “Higher”.
——»/ PrintA,
“Higher”
Print B,
“Higher”
2. Draw a flowchart that will input @ grade of student and determine whether the
grade is passed or failed. Print the name, grade and remarks of student.
Write its equivalent algorithm.
Flowcharting and Algorithms 1— Algorithm:
Step 1. Inilialize name and remarks into
blanks.
Name =" Step 2. Read in values for Grade and
Remarks = “* Name,
Step 3. Test if Grade is greater than or
equal to 60,
Step 4. If Grade is greater than or equal
to 60, remark is “Passed”
Read Name, / However, if Grade is below 60,
Grade remark is “Failed”.
Step 5. Print the name, grade, and
——_—_—/ remarks,
Print Name,
Grade, Remarks
femarks = “Failed”
3. DEI Manufacturing Company plans to give a year-end bonus to each of ils
employee. Draw a flowchart which will compute the bonus of an employee
Consider the following conditions: If the employee's monthly salary is less
than 2,000 pesos, the bonus is 50% of the salary; for employees with salaries
greater than 2,000 pesos, the bonus is 1,500 pesos. Print the name and the
corresponding bonus for each employee. Write each equivalent algorithms.
Flowcharting and Algorithms 8oo Algorithen:
t Start
T Step 1. Initialize bonus to 0.
7 Siep 2. Read in employee's name and
Bonus =0 > salary.
4 Step 3. Test if employee's salary is tess
than 2,000.
. - Step 4. If salary < 2,000 then
yf Bonus = salary * 50%
Read Name, else
Salary Bonus = 1,500,
Step 8. Print the employee's name and
bonus.
7,500
Bonus
Flowcharting and Algorithms 9Equivalent flowchart of sample 3 using On-page connector
Read Name,
Salary
Print Name,
Bonus
L End
Flowcharting and Algorithms 104, Construct a flowchart that will accept the evaluation score of a faculty and
determine its equivalent remarks. Print the name of the faculty and the
remarks obtained. Remarks (Rem) are based on the following criteria: Write
its equivalent algorithms.
4.50-5.00 - Outstanding
400-449 - Very Satisfactory
350-399 - Satisfactory
300-349 - Needs Improvement
299 below = ~—- Poor
Read Name,
Score
tf Rem Outstanding’ |-¥(a)
Se i Very Satistactor
a Rem = “Very Saloon” |+(a)
Flowcharting and Algorithms "[a] +)
Print Name,
Rem
Equivalent Algorithms
Step 1. Initialize Rem into space or blanks.
Step 2. Read in the values of Name and Score.
Step 3. Test the score if itis greater than or equal to 4.50.
Step 4. If the score is greater than or equal to 4.50, Rem is “Outstanding”.
However, if the score is less than 4.50, do step 5.
Siep 5. Test the score if itis greater than or equal to 4.00
Step 6. If the score is greater than or equal to 4.00, Rem is “Very Satisfactory’.
However, if the score is less than 4.00, do step 7.
Step 7. Test the score if itis greater than or equal to 3.50
Step 8. If the score is greater than or equal to 3.50, Rem is “Satisfactory”
However, if the score is less than 3.50, do step 9.
Step 9. Test the score if tis greater than or equal to 3.00
Step 10. If the score is greater than or equal to 3.00, Rem is Satisfactory’
However, if the score is less than 3.00, Rem is “Poor”
Step 11. Print the name and Rem.
Flowcharting and Algorithms 2Mi, Repetition (Looping)
Do ~ while ~ “this structure provides for the repetitive execution of an operation
or routine while the condition is true. The condition is evaluated before executing
any process statement. As long as the condition Is true, the process is executed,
otherwise, control flows out of the structure” (i).
Loop
Examples:
1. Construct a flowchart that will count from 1 to 10 and print each number
counted using the do-while-repetition structure. Write its equivalent algorithnn
( Start Algorithm:
Y Step 1. Initialize the value of C to 0.
Step 2. Test if C is less than 10.
Step 3. If Cis less than 10, add 1 to the
value of C, print the value then
go back to Step 2. However, if
is greater than 10, stop
F ——— 3
: (ee a
Flowcharting and Algorithms 32. The initial value of the radius (R) of @ circle is equal to 1 unit and each
succeeding radius is 1 unit greater than the value before it. Draw a flowchart
‘to compute the Area of a circle starting with R= 1 up to R = 5, then print each
radius and the corresponding area of a circle.
Formula: Area = Pix R?
Algorithm:
Step 1. Initialize the value of R to 1 and
the vaiue of Pi to 3.1416.
Step 2. Compute area by multiplying Pi
to the square of R
Step 3. Print the value of R and the
computed Area.
Step 4. Increment the value of R by 4
Step 5. Testif R is less than or equal to
5.
Step 6. If R is less than or equal to 5,
loop back and repeat steps 2 to
5. However, if R is greater than
5, stop processing.
Flowcharting and Algorithms. ioieee
REVIEW EXERCISES
1 Fill in the blanks. :
1. Flowchart is a common method for defining the steps of
flow within a program by using a serles of to identity the
basic input, process and output functions within a program.
2 refers to a finite set of insiructions that specify @
sequence of operations to be caried out in orcer to solve a specific
or class of problems.
Flowchart is a dimensional representation of an algorithm.
4. Do - while structure provides for a repetitive execution of an operation or
while the condition is
5 structure provides process execution first before the
decision is tested.
i. “Identify the following symbols:
Review Exercises 6FLOWCHARTING EXERCISES
1
a
Draw a flowchart that will compute for the midterm grade of a student. The
Iidterm grade is equal to one-third of the minor A exam and two-thirds of the
midterm exam. Print the midterm grade.
Construct a flowchart that will compute and print the sum and average of 3
numbers
Draw a flowchart that will compute and display the Area of a rectangle using
the formula: Area = Length x Width
Construct a flowchart that will convert and display an inputted number in
inches (in.) to its equivalent number in feet (f). Hint: 4 ft = 12 in.
Draw a flowchart that accepts a number in kilowatts then display its
equivalent number in watts. Hint: 4 watt = 0.0001 kilowatt
Draw a flowchart that accepts a value for radius (R) and compute the
corresponding area of a circle. Print the value of the radius and the computed
area. Use the forr ula Area = Pix R
Construct a flowchart that accepts a number in square meter (m*) and display
its equivalent number in hectares (has). Hint: 1000 m? = 1 ha
Read 2 records in a computer. The first record will contain unit price and the
sec nd record will contain quantity. Draw a flowchart that will compute and
display the amount by multiplying unit price and quantity
Flowcharting Exercises 6E
|
|
9. Given two numbers X and Y, draw a flowchart lo determine the difference
I between X and Y. If X- Y is negative, compute R = X + Y; if X—~ ¥ is zero,
compute R = 2X + 2Y; and if X ~ ¥ is positive, compute R = X* Y. Print the
values of X, ¥, and R.
10. Draw a flowchart that will determine and display the largest number among 3
t
numbers being inputted.
41. Draw a flowchart that displays 3 inputted numbers in ascending order.
12. Construct a flowchart that asks for the amount purchased by the customer. If
the customer purchases more than 2,000 then a 5% discount is given.
Display the net amount to be paid by the customer.
13. Construct a flowchart to determine the equivalent grade of each student in a
class as follows:
a. Read in the student's name, midterm grade, minor 6, and final
exam ratings.
b. Determine the final grade of the student by the formula: final grade
= 0.30 of midterm grade + 0.10 of minor B + 0.60 of final exam.
c. Determine the equivalent grade for the numerical value obtained by
the following grading marks:
98-100 = 4.00
95-97 = 3.75
92-94 = 3.50
89-91 = 3.25
86-88 = 3.00
83-85 = 2.75
80~82 = 250
71-79 = 225
74-76 = 2.00
N-73 = 1.75
68-—-70 = 1.50
64-67 = 1.25
60-63 = 1.00
below 60 = 0.00
Flowcharting Exercises 014. Draw a flowchart that will read and print the names and individual score of 50
students for a particular examination. Also, determine the average score and
print it.
15.Design a flowchart that will generate the sum and product of 20 input
numbers,
16, Draw a flowchart that will input 20 integers. Output the number of negative
values and the sum of positive numbers.
17.Construct a flowchart that will compute the evaluation rating of a teacher
given by 32 students. Print the average.
Flowcharting Exercises 8