CS112 - 03 - Flowchart
CS112 - 03 - Flowchart
ALGORITHM
AND PROGRAMMING CONCEPTS
PART II: SUBROUTINES
PSEUDO-CODE
FLOWCHART
1 SUBROUTINES
“
A simple program is a
combination of statements that
are implemented in a sequential
order.
A statement block is a group of
statements.
3
WHAT IS A SUBROUTINE?
A logical collection of instructions that is invoked from
within a larger program to perform a specific task.
The subroutine is relatively independent of the remaining
statements of the program that invokes it.
The subroutine can be invoked several times from
several places during a single execution of the invoking
program.
After completing the specific task, a subroutine returns to
the point of invocation in the larger program.
4
Start Start Start
Subroutine
Statement 1 Statement 1 Statement 1
Sample
program
structures:
Statement N Statement N Statement N
Call
End End End
Return
(b) A structure of a (c) A structure of a
(a) A structure of
simple program with simple program using a
a simple program
repeated procedures subroutine 5
2 Pseudo-code
WHAT IS A PSEUDO-CODE?
Like step-form, Pseudo-code is a written statement of an
algorithm using a restricted and well-defined vocabulary.
7
WHAT IS A PSEUDO-CODE?
For instance, a sample pseudo-code is written as follows:
dowhile kettle_empty
Add_Water_To_Kettle
end dowhile
As can be seen, it is a precise statement of a while loop.
Pseudo-code is useful:
• To describe how an algorithm should work
• To explain a computing process to less-technical users
• To design code in a group setting.
8
Another example of a pseudo-code:
Enter number
if value greater than 10
say “Your number is greater than 10”
if value less than 10
say “Your number is less than 10”
9
2 Flowcharts
WHAT IS A FLOWCHART?
A Flowchart depicts appropriate steps to be followed in order to
arrive at the solution to a problem.
13
GUIDELINES FOR DRAWING A
FLOWCHART
Flowcharts are usually drawn using standard symbols; however,
some special symbols can also be developed when required.
14
SYMBOLS USED IN FLOWCHART
Process block
Connector
Input/Output block
Flow Lines
Initialization block
15
SYMBOLS USED IN FLOWCHART
START
Terminal block
16
SYMBOLS USED IN FLOWCHART
Initialization block
Declaration Initialization
stating only the states or
variable names assigned the
to be used later value of each
on the process of variable that is
Input1, Input1=7,
Input2 algorithm Input2=4
needed in the
process
18
SYMBOLS USED IN FLOWCHART
Example:
Process block
19
SYMBOLS USED IN FLOWCHART
Example:
Input/Output block
20
SYMBOLS USED IN FLOWCHART
Decision block
21
SYMBOLS USED IN FLOWCHART
CONVENTION
Example:
TRUE FALSE
T F T F
Condition YES NO
Y N
page 1 page 2
Connectors
•
A
Connects remote parts of the
flowchart on the same page.
• This circle is used as a connection
point between two sections of a
flowchart that are not adjacent or
closely located to each other.
Flow Lines
Example:
24
OTHER SYMBOLS USED IN
FLOWCHART
27