You are on page 1of 7

CHAPTER 1

FLOWCHARTING AND ALGORITHMS

FLOWCHART

A flowchart is a graphical representation of a program. It shows the logical


sequence of instruction which a computer has to follow. The individual instructions in
the flowchart are connected by arrow lines. These lines indicate the order on how the
instructions are followed or executed by the computer. The major uses of flowchart are
in program documentation and program presentation.

Two types of flowchart:

1. System flowchart – this type of flowchart illustrates which data is used and
how it interacts with the hardware and the user.
2. Program flowchart – which illustrates graphically the logical sequence of the
program.

The flowchart can help us to view the relationships between the two or more
parts and subparts of the program. How they relate or interact to each other. Moreover,
it improves the clarity of our logical thoughts, since we had seen its relationships to
each other in graphical form. The computer program involves the three basic main
operations:

Input (to enter data)


Process (to calculate or make choice)
Output (to produce a result or report)

Here is the graphical representation of these operations:

INPUT

PROCESS

INPUT
The basic flowcharting symbols are given below:

Signifies the start or end of a program.


Start/Stop Terminal Symbol

Indicate where the data are to be entered or results to


Input / Output Symbol be displayed.

Specifies processing procedures that usually involves


calculating e.g. addition, subtraction, division,
multiplication, etc.
Process Symbol

Denotes a choice or decision to be made by the


computer e.g. IF/THEN/ELSE.
Decision Symbol

Represent the direction of the flow of control.


Flow lines

Continues the flow on the same page. On-page


A connectors are defined with an alpha character starting
with A.
On-page conector

Continue the flow to another page. Off-page


connectors are defined with an alpha character and the
reference to the page which the flow is going, or the
page from which the flow has come, depending on the
Off-page connector nature of the connector.

Initialize or store the first value of variables.

Initialization/Preparation Symbol
Guidelines in drawing a flowchart:

▪ In drawing a proper flowchart, all necessary requirements should be listed out


in logical order.
▪ The flowchart should be clear, neat and easy to follow. There should not be
any room for ambiguity in understanding the flowchart.
▪ The usual direction of the flow of a procedure or system is from left to right or
top to bottom.
▪ Only one flow line should come out from a process symbol.
▪ 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.
▪ Only one flow line is used in conjunction with terminal symbol.
▪ Write within standard symbol briefly. As necessary, you can use the
annotation symbol to describe date or computational steps more clearly.
▪ 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.
▪ Ensure that the flowchart has a logical start and finish.
▪ It is useful to test the validity of the flowchart by passing through it with a
simple test data.

Example1: Finding the best way to school

• A simple case of processes and decisions if it is raining or not

Start

Ask “Is it
raining today?”

Yes Is it No
raining?

Take an Leave umbrella


umbrella. at home.

Start
ALGORITHMS (Pseudocodes)

An algorithm is an English-like way of writing and expressing a solution to a


problem. It is step by step list of instructions. Algorithm or pseudocode is like a
flowchart. It helps us to construct the actual program easily and clearly.

The advantage of using algorithm or flowchart before designing a program, is


that it relieves us from worrying the rules or syntax of a specific programming language.
Instead, it helps us to concentrate more on the logic of our ideas and programs.

Operators (Notations) Applied in Flowcharting

Mathematical Operators

+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
^ Exponent

Relational Operators

> Greater than


< Less than
>= Greater than or equal to
<= Less than or equal to
== Equal to
!= Not equal to

Logical Operators

AND or &&
OR or ‖
NOT or !!

A simple Input/Output Statement

Example:

1. Draw a flowchart that computes and prints the sum of two input numbers.

Solution: In Algorithm

Enter two numbers (n1, n2)


Compute the Sum (S = n1 + n2)
Print S (for Sum)
Solution: In Flowchart
Begin

Enter n1, n2

Sum=n1+n2

Print Sum

End

2. Write an algorithm and pseudocode the draw a flowchart to convert the length in
feet to centimeters.

Solution: In Pseudocode

Input the length in feet (Lft)


Compute the length in cm (Lcm) by multiplying Lft with 30
Print length in cm (Lcm)

Solution: In Algorithm

Step 1: Input Lft


Step 2: Lcm = Lft x 30
Step 3: Print Lcm

Solution: In Flowchart

Begin

Input Lft

Lcm = Lft x 30

Print Lcm

End
PRECEDENCE OF OPERATORS

Rule: In expressions where two operators can be applied to an operand, the table of
precedence is used to determine which operator should be applied FIRST.

Description Operator Precedence


Increment ++ 1
Decrement -- 1
Logical Not ! 1
Unary Minus - 1
Multiplication * 2
Division / 2
Modulus % 2
Addition + 3
Subtraction - 3
Less than < 4
Less than or equal <= 4
Great than > 4
Greater than or equal to >= 4
Equal == 5
Not Equal != 5
Logical and && 6
Logical or ‖ 6
Assignment =+=-=*=/=%=

Application of Simple If-Else Conditional Statements and Decision Symbols

Computer has the capability to make choices and decides logical decision based on
some conditions. Sometimes, this topic of flowcharting and programming is referred as
selection control structure, because it involves selection of two or more choices and
decide based on a given condition. In this conditional statement, there is a conditional
test to be performed by the computer to determine what course of action to be taken.
The conditional test produces either a true (yes) or false (no) value.

Example:

1. Draw a flowchart that determines if the input age is qualified to vote or not.
Qualifying age is 18. If qualified, print “Qualified to vote”, if not (else), print “Too
Young!”.

Solution: In Algorithm

Step 1: Enter Age


Step 2: If (Age>=18) then
Print “Qualified to vote”
else
Print “Too young!”
Solution: In Flowchart

Begin

Enter Age

If T
Qualified to vote
Age>+18

Too Young!

End

You might also like