Chapter II Flowcharts and Algorithm Student Copy 1
Chapter II Flowcharts and Algorithm Student Copy 1
OVERVIEW
Years before the dawn of computers, human had already begun writing
sequences of steps necessary to accomplish a particular task. For instance, in
culinary, a recipe is prepared according to the team-up of ingredients lined up
in place and arranged in the order in which they shall be tossed into the wok.
The order is necessary to make sure that what is being prepared goes with what
is expected by the costumers. A slight mistake in the sequence would certainly
affect the taste of the food. That is why there is a need to list down not only the
lineup of ingredients but most importantly the step-by-step procedure in cooking
the food.
But maybe, one of the most important turn of events which shapes the
method of writing down sequences of steps was after Pearl-Harbor. With the
soldiers sent to the front lines, women were recruited to do manual calculations
tor airborne trajectories on equipment that defies distance and gravity. They were
called “COMPUTERS”. Later, with the advent of electronic calculating machine,
the name “COMPUTER” was passed on to the latter and taught it to do math to
high speed which would spend many hours to complete, if done through manual
calculations. Computations were broken into elementary steps so that the
machine can execute and derive results with great precision. These elementary
steps that carry out specific task in logical order is what we called Algorithm.
An Algorithm is a step by step sequence of instructions that describe how data
is to be manipulated to generate specific output. Once coded into a computer-
language would transform into a computer program. A Computer program is
a set of instructions created for the purpose of telling the computer what to do
step by step and how the result should be generated according to the required
output based on a given set of data.
PROGRAMMING
DEVELOPMENT CYCLE
A program is developed for a certain purpose, and that is to provide
solution to a given problem using a computer. One have to design an
algorithm taken from the pieces of the basic steps arranged in the order
necessary to shape up a solution. These steps when collected will certainly
provide the required solution to the problem. After the program is
developed, it has to pass through the continuous process of refinement.
This process in which the program has to go by from beginning to end is
called Programming Development Cycle. A Programming
Development Cycle refers to the unbroken step of defining, coding,
compiling, executing and fine tuning the program until it is free from all
infirmities and the output generated conforms to the expected result.
Another reason why it is called a cycle is it starts over from where it ends.
1. Defining
& analyzing
the problem
6. 2. Planning
Maintenance the solution
&
5. 3. Coding
Implementat the solution
ion 4. Test &
Debug the
Solution
Figure 2-1 These steps need to be observed continuously until the program is completed, refined and applied.
Figure 0-1. These steps need to be observed continuously until the program is completed, refined and applied.
DEFINING & ANALYZING
THE PROBLEM
PROBLEM ANALYSIS
The problem itself is first broken into a few larger parts and its part into
smaller divisions and into smallest subdivisions if necessary, until it makes you
comfortable solving them piece by piece if necessary. Always remember that the
key to providing a good solution to a problem is to fully understand the entire
task and the details that comes with it.
Inspired with the determination to enter college for the second time,
the daughter hit the university belt. When she was close to the university,
she noticed a tiangge along the street where she immediately saw the
beautiful dresses and bags; she paused for a while and after a short
moment of hesitation, she went inside to shop. When she came out, she was
carrying those items feeling happy and contented. Counting with what is
left of her money, she realized that five thousand (5,000.00) pesos went to
her shopping spree.
Defining the Problem
Obviously, the 5,000.00 pesos that went to the shopping spree is the
problem – she can no longer turn to her mother to replace her shortage as she
was forewarned and advised. Finding for a solution is all her business now.
So let us find ways on how to solve her problem. We shall assume sources
of funds coming from friends and relatives. Five thousand is a big amount. If we
split it into two, we have two thousand five hundred (2,500.00) each. But still
2,500.00 is not a small amount to share. Splitting it into five, we have five one
thousand (1,000.00) each of her five friends, but still 1,000.00 is difficult to ask
from friends, then maybe, we can further break it down to 10 or perhaps to
twenty or maybe more.
Hence, the manner of splitting the said amount into smaller quantity is
clear and simple application of problem analysis. In problem analysis, our task
is not to outright solve the problem but to slice it in parts and further into smaller
parts until it becomes easier for us to start rendering a solution for each of the
broken pieces.
PLANNING THE
SOLUTION
ALGORITHM
One important thing to note is the fact that computers do not possess the
inherent intellect in the same way human would demonstrate in the conduct of
his task. Computers are dependent on programs which contains a series of steps
taken from the natural sequence of human actions, and perform them with
remarkable speed and precision. Although computers work a thousand times
faster than humans, still, it executes line of command one at a time. Each time
each line is executed, a pause occurs between each succeeding steps. But
because of its amazing speed, pauses are almost undetected.
Speed is the primary reason why we are using computers. However, the
procedures we intend the machine to perform are found not from technical
phrases known to it but from the very basic steps at which human shall readily
demonstrate if given the task to do it by himself.
MODELLING TOOLS
2 modelling tools:
1. Pseudocode – a non-standard English-like statements containing
sentences and phrases that look closely similar to the syntax of a
programming language. Unlike a programming language which observes a
strict rule on keywords and syntax, there is none in pseudocode. As long
as the contained statements are readable, understandable and outlines
the logical processes needed to accomplish the task – it is pseudocode.
The algorithm are statements that were written almost similar to
pseudocode.
As might be observed in figure 2, it contains logical steps that were
expressed in an English-like statements. It suggests in plain language how
the sales amount should be computed and displayed after inputting and
multiplying quantity being sold by the corresponding unit price. Take
note also, how the statements are placed within the context of BEGIN and
END instructions.
Begin:
Clear the screen
Display
“Quantity Sold”
Accept Quantity
Display “Unit Price”
Accept Unit Price
Figure
Figure1-2
0-3.Sample
SamplePseudocode
Pseudocode
START
Y
Is there a Debug the program X
syntax error?
Is there Y
X
logical error?
STOP
START
CLS
Display
“Quantity sold”
GET QUANTITY
DISPLAY UNIT
PRICE
GET PRICE
DISPLAY AMT
END
CODING THE
SOLUTION
The only thing understandable to computers are numbers Zero (0) and one
(1). These binary numbers serve the basic concept that makes the native
language of the computer.
Nonetheless, the starting line for drawing out our plan in solving a problem
does not begin with the use of any of the programming languages but from the
basic concept of algorithm through a flowchart or a pseudocode. It is only
after an algorithm or a flowchart have been developed that the whole process
is ready for conversion into statements ruled by a computer language.
TESTING AND
DEBUGGING THE SOLUTION
SOURC OBJEC
E T
CODE COMPILER CODE
3. TEST RUN
A test run is performed for purposes of correcting and removing
output errors left undetected during the compilation process.
During the test run, dummy data is fed into the program to suggest
output that might be expected.
During test run, two kinds of errors are normally detected; one is
run-time-error and the other is the logic-error. Run time error
causes the program to end abnormally (ABEND) during execution.
One of the causes of run time error is when a program tries to access
inexistent data-file. On the other hand, logic-error never
terminates the execution of the program but it affects the outcome
of the processing. Usually it is the output, which speaks of logic-
error. When the expected output is found different from what is
actually generated, logic-error will exist. There is logic-error when
what we mean in our program is not what it says during the run.
IMPLEMENTATION
After the program was tested and the output generated using a copy of
the live data conforms to the required output conditions, the actual use of the
program begins. This time a realtime or live data is attached and the program is
executed behind the strict supervision of the implementing programmer. The
output will be strictly examined to make sure that no errors will be left unnoticed
and uncorrected.
When the program is effectively controlling and processing, the need for
maintenance and documentation is mandatory. One of the reasons is “further
reference”. It is inevitable that during the program’s use, some changes might
need to be made as when there are changes to company rules or on government
policies; like if new taxes are implemented. The effect brought about by the
changes necessarily affects the programming cycle and the program had to be
updated.
The documentation process does not only mean providing lists of the whole
lines of program but also providing back-ups and storing data files on safe places
where they can be readily referred to as the need arises. Another reason and
treaded to be the most important value of maintenance and documentation is
when the programmer is unavailable or has to leave, the program will be left
under the care of another programmer and the documentation is the only means
by which program’s logic can be traced and some changes or updates are made.
THE FLOWCHART
Learning Outcomes:
At the end of this Chapter you should be able to:
Define what is a flowchart.
Distinguish flowchart from a pseudocode.
Explain the use of the different flowcharting symbols.
Discuss the different types of flowcharts.
Discuss the importance of algorithm to modelling tools.
USING A FLOWCHART
TYPES OF FLOWCHART
7. SYSTEM FLOWCHART
A SYSTEM FLOWCHART is a graphical representation showing the overview of
the processing employed in the whole system. When a system analyst is developing a new
system application, his ideas need to be written down on paper mostly in graphical illustrations.
One of the most important tools of the system analyst is the system flowchart as it brings
the most effective way of showing what input are required; what actions are to be taken to
process the inputted data, and what outputs should be as required by the system. System
Flowchart also shows connectivity to the software, hardware and peopleware involved in the
operation.
1. STANDARD SYMBOLS
Online
storage (file
Hard disk Magnetic tape
storage on
hard discs)
Visual Display Document
Data Processing
Unit (monitor (Printed
Operation
screen) Copy)
Manual input
Terminal Punch card
(i.e. keyboard)
Sort
(Alphabetical, Communication
Collate
chronological, Line
numeric)
On page
Off page
connector (a Merge (e.g. join
connector
link to or two files of
(link diagram
from another names, one file
from one page
part of a after another
to another)
diagram
System flow chart symbols
2. AS MEDIUM OFCOMMUNICATION
Most of the time the system analyst communicates in part with programmer through
graphical images, and it is within the context that a system flowchart is considered useful.
MERGE Program to
create
Updated Merging
Output file Master Report Output file
file
The above system flowchart tells the programmer to write a program which will sequentially
merge or rewrite the contents of both Master and Transaction files into updated Master file and to print a
report showing the contents of the new or updated master file. Files with flow lines pointing the
directions of the process (merge) box are input files. Files pointed by the directions of flow lines away
from the process box are output files.
The figure likewise transmits visual understanding to the programmer that both Master and
Transaction file are input files to the program while the Updated Master file and Merging report
are outputs that should be generated. Transaction and updated master files are stored on a disk. Master
file is stored on magnetic tape while the merging report is to be printed on the paper through a line
printer.
Error Report
Input Validate
Transactions
Validated
Transaction
Update
Master file
Update Report
The figure illustrates an instance when the output file in one program serves as an
input to another. The flowchart above speaks of (1) source transaction that is previously
recorded manually keyed in through a keyboard; (2) a validation program accepts the source
transaction record, evaluate it and write into validated transaction file when it is authentic, but
dump it to the printer when it bear errors. Once the validated transaction file is free from
errors, it can serve as an input for purposes of updating the master file. Thereafter, together
with the master file the validated transaction file is used to generate an update-repot.
The process as shown above is mostly sequential in nature except during an update
when double pointed arrow is used between update box and the master file. Double pointer
arrow means the access to the master file is direct and that the latter is simultaneously used as
an input and output (I/O) file in an update processing.
8. PROGRAM FLOWCHART
annotation
START
Note: shaded oval shapes are terminals.
STATEMENT 1 and STATEMENT 2 are
STATEMENT command formats
STATEMENT
STOP
2. PROCESS (rectangular)
A process symbol is used to represent arithmetic operation or when casing individual
variable assignments. This rectangular shape is the most frequently used symbol in
flowcharting. However, each process box may contain only one mathematical
equation; this means, if there two or more independent mathematical calculation to be
made, each calculation must use one process box. The same is true when assigning
data variables.
OPERATORS DESCRIPTION
= EQUAL
- SUBTRACTION
+ ADDITION
/ DIVISION
* MULTIPLICATION
^ OR ** EXPONENTIATION
OPEN For opening files
CLOSE For closing files
List of mathematical operators as well as input/output labels
The following example shows how process symbol is used:
START
X =X + 1
STOP
3. INPUT/OUTPUT (parallelogram)
This shape indicates input and output operations and also specifies the link between
the input and output devices. Hence, the input/output symbol shows the flow of data
and the device where such data is passing through during the processing.
STATEMENT DESCRIPTION
INPUT - When data is keyed in from the keyboard
READ - When data is retrieved from the disk storage
WRITE - When data is stored in disk storage
PRINT - When result is sent to the printer
DISPLAY - When the output is displayed on the screen
Mnemonics used in Input/Output symbol
START
INPUT X
PRINT X
STOP
4. Decision (diamond)
Decision symbol is used to evaluate a conditional statement and branch out to the required
process depending on the outcome of the test which could either be true or false. Only three
out of four corners of the decision symbol are used for connective processing. The left and
right shoulders of decision symbol is normally labeled with a tandem indicators such as
“YES” or “NO”, or “TRUE” or “FALSE”. These labels are used to indicate which path or
what course of action to take if the result of the evaluation is “YES” or “TRUE” or if result
is “NO” or “FALSE”.
LOGICAL SYMBOLS
= Equal
> Greater than
< Less than
!= Not equal
Test expression operators
The following flowchart demonstrates how a decision symbol is used to evaluate an expression
START
X=0
INPUT X
False True
X>0
PRINT X
STOP
5. Predefined
Pre-defined symbol indicates another block of code containing processing steps which are
declared but purposely separated from the main line of instructions. Simply, this shape is used to
describe a sub-routine or a function in the program which may be called runtime.
In structured programming, certain block of code must be separated and placed in a
subroutine or a function. The purpose of this is to make the block of code aptly available from any
point of call in the main program.
MAIN
SUB-TEST
START
START
X=0
False True
X=0
INPUT X
PRINT X
SUBTEST
RETURN
DISPLAY
“DONE”
STOP
Using pre-defined process in calling a subroutine’s execution, the control is temporarily transferred to SUB-
TEST. The RETURN command in the subroutine allows control to go back to the main flowchart to
execute the next line of command following the call. IF STOP is put instead of RETURN, the control will
not go back to the main routine and the execution had to end abnormally.
6. Preparation (hexagon)
The preparation box is used to define a set of variables. Normally, variables are defined by
using the process box, but sometimes because of the limitations associate with the process
symbol, its use is critically inappropriate. A process box may be used to define a single
variable and that if two variables are to be defined, then two process boxes have to be drawn.
Preparation box works differently. It accepts variables regardless of its count. It should
immediately follow the terminal START symbol, it must appear only once in the flowchart
and must be used only for defining variables.
The following flowchart shows how set of variables are accommodated into a single preparation
box and how said variables are held into two separate process symbols.
FLOWCHART A FLOWCHART B
START
START
A=0 A=0
B =0
B=0
INPUT A,B
INPUT A,B
PRINT A,B
PRINT A,B
STOP
STOP
START
S
A=0
B=0 B=B+A
INPUT A
PRINT A,B
INPUT B
STOP
A = A* 5
S
When the lower edge is reached, the continuation is placed on the right side of the page. Two small circles
are used with letter S as link indicator.
8. Off-page Connector (pentagon)
The off-page connector is a small pentagon shape that is used to show flowcharting jump
from one page to the next. To show matching jump points, connectors are usually labeled
with unique uppercase alphabet. The symbol is used when the flowchart would require
several pages within which the rest of the steps had to be continuously inscribed.
Page 1 of 2 P Page 2 of 2
START
B=B+A
A=0
B=0
PRINT A,B
INPUT A
STOP
INPUT B
A = A* 5
When the edge of the page below is reached, the continuation of the flowchart is laced onto the next
page. To indicate connectivity, a small pentagon is used with the letter P as page link indicator.
9. Flowline (Arrow)
A flowline is used to show directional flow of the process in the flowchart. It helps the
reader to follow the procedural sequences in the flowchart by simply looking at where the
direction of the flowline is heading.
Chapter Quiz
NAME: DATE:
YEAR/COURSE: SCORE:
_______________1. These are elementary steps that carry out specific task in
logical order.
_______________2. It is referred to as a set of instructions created to tell the
computer what to do step by step and how the result should be
generated according to the required output based on a given set of
data.
_______________3. It refers to the unbroken step of defining, coding,
compiling, executing and fine tuning the program until it is free from
all infirmities and the output generated conforms to the expected
result.
_______________4. It is the manner of splitting the said amount into smaller
quantity.
_______________5. It is a method of preparing the steps in logical manner to
achieve a specific task.
_______________6. It is a non-standard English-like statements containing
sentences and phrases that look closely similar to the syntax of a
programming language.
_______________7. It refers to as a visual diagram showing the progress of
work through the sequence of operations.
_______________8. This modelling tool serves as the blueprint which shows
the exact flow of the steps in solving a problem.
_______________9. It is a term referred to the method of validating the
program to ensure that it will correct work on the required task.
_______________10. It is the totality of instructions written in English-like
statements made under programming language rules of syntax.
_______________11. It is a special kind of software which translates a source
code into an object or executable code.
_______________12. These are Errors detected during the compilation process.
_______________13. It is a process performed in computer programming to
correct and remove output errors left undetected during the
compilation process.
_______________14. This programming error causes the program to end
abnormally.
_______________15. What is the complete name of our University President?
II ENUMERATION
A. WHAT ARE THE STEPS IN PROGRAMMING DEVELOPMENT CYCLE?
III. ESSAY
1. Who is more intelligent? A human or a computer? Justify your answer.
IV. ANALYSIS
2. September, It is the harvest season of corn in Alfonso Lista, Mang Juan,
has a passenger jeep and he was hired to load the Corn of Mang Gusting
as he wanted to bring his harvest to Santiago City because price of corn in
the city is more expensive than in the barrio. Mang Gusting’s jeep has only
a maximum load capacity of 3000 kg. The load is exactly 3000kg but with
the two passengers, the load is already beyond the capacity of the vehicle.
Mang Gusting knew the risk if they will not unload some of the sacks of
corn, but he could not resist the request of Mang Juan. While they were
on their way, the front tire of the vehicle blew up in front of the gate of the
IFUGAO STATE UNIVERSITY. One of the students in CCS with the subject
Computer Programming I saw the incident and he decided to site it as an
example for his “real time” algorithm and titled it as : HOW TO CHANGE
A FLAT TIRE OF Mang Gusting’s jeepney”.