0% found this document useful (0 votes)
43 views27 pages

CS112 - 03 - Flowchart

This document discusses subroutines and flowcharts. It defines a subroutine as a logical collection of instructions that performs a specific task and can be called from different parts of a larger program. Pseudo-code and flowcharts are presented as ways to design programs. Pseudo-code uses a restricted vocabulary to describe algorithms, while flowcharts use standard symbols to show the steps and logic flows of a process. Common flowchart symbols include terminals, processes, decisions, and inputs/outputs. Flowcharts allow effective analysis and communication during program design.

Uploaded by

Jian Kusanagi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views27 pages

CS112 - 03 - Flowchart

This document discusses subroutines and flowcharts. It defines a subroutine as a logical collection of instructions that performs a specific task and can be called from different parts of a larger program. Pseudo-code and flowcharts are presented as ways to design programs. Pseudo-code uses a restricted vocabulary to describe algorithms, while flowcharts use standard symbols to show the steps and logic flows of a process. Common flowchart symbols include terminals, processes, decisions, and inputs/outputs. Flowcharts allow effective analysis and communication during program design.

Uploaded by

Jian Kusanagi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

INTRODUCTION TO

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

Statement 2 Procedure X Statement 2 Procedure X

Statement 3 Statement 2 Statement 3

Statement 4 Procedure X Statement 4

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.

It is similar to a 3GL, and for many programmers and program


designers it is the preferred way to state algorithms and
program specifications.

The subroutine is relatively independent of the remaining


statements of the program that invokes it.

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.

It is a graphical representation of a sequence of operations.

It contains symbols describing how an algorithm or program operates.

It is a program design tool which is used before writing the


actual program.

Flowcharts are generally developed in the early stages of


formulating solutions to problems.
11
STANDARDS FOR FLOWCHARTS
• Flowcharts must be drawn on white, unlined 8½" × 11"
paper, on one side only.
• Flowcharts start on the top of the page and low down and to
the right.
• Only standard flowcharting symbols should be used.
• A template to draw the final version of flowchart should be
used.
• The contents of each symbol should be printed legibly.
• English should be used in flowcharts, not programming
language.
12
STANDARDS FOR FLOWCHARTS
• The flowchart for each subroutine, if any, must appear on a
separate page. Each subroutine begins with a terminal
symbol with the subroutine name and a terminal symbol
labeled return at the end.
• Draw arrows between symbols with a straight edge and use
arrowheads to indicate the direction of the logic flow.

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

Terminal block Decision block

Process block
Connector

Input/Output block
Flow Lines
Initialization block
15
SYMBOLS USED IN FLOWCHART

START

Terminal block

• Start or end of the program or Example:


flowchart.
• Ovals or rounded rectangles are used
to indicate the start and the end of a
module or program. END

16
SYMBOLS USED IN FLOWCHART

Initialization block

A Display. Used for declaring / initializing


variables needed to solve a certain process.

Declaration – stating a variable name to be used.

Initialization – to set a starting value of a variable.


17
SYMBOLS USED IN FLOWCHART
Examples:

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

• Computational steps or processing


function of a program. Sum=Input1+Input2
• The rectangle indicates a processing
block, for such things as calculations,
opening and closing files, and so forth.

19
SYMBOLS USED IN FLOWCHART
Example:

Input/Output block

This parallelogram indicates input entry to


and/or output display operations. Get X Display X

20
SYMBOLS USED IN FLOWCHART

Decision block

• The diamond indicates a decision.


• It has one entrance and exactly two
exits from the block.
• One exit is the action when the
resultant is TRUE and the other exit is
the action when resultant is FALSE.

21
SYMBOLS USED IN FLOWCHART
CONVENTION
Example:
TRUE FALSE

T F T F

Condition YES NO

Y N

For a question or statement


Action when Action when
TRUE FALSE that gives you an answer of
T/F or Yes/No
22
SYMBOLS USED IN FLOWCHART
Example:

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.

NOTE: These connectors should be used as little as possible. A


23
They should only be used to enhance readability.
SYMBOLS USED IN FLOWCHART

Flow Lines

Indicated by straight lines with arrows to


show the direction of data flow.

Example:

24
OTHER SYMBOLS USED IN
FLOWCHART

Connects remote portions of the flowchart


not on the same page.

Adds comments or furnish clarifications

Magnetic tape Magnetic disk


25
ADVANTAGES OF USING
FLOWCHARTS
• Communication – Flowcharts are a better way of communicating the
logic of a system to all concerned.
• Effective analysis – With the help of flowcharts, problems can be
analyzed more effectively.
• Proper documentation - Program flowcharts serve as a good program
documentation needed for various purposes.
• Efficient coding – Flowcharts act as a guide or blueprint during the
systems analysis and program development phase.
• Proper debugging – Flowcharts help in the debugging process.
• Efficient program maintenance – The maintenance of an operating
program becomes easy with the help of a flowchart.
26
LIMITATIONS OF USING FLOWCHARTS

• Complex logic – Sometimes, the program logic is quite complicated. In


such a case, a flowchart becomes complex and clumsy.
• Alterations and modifications – If alterations are required, the flowchart
may need to be redrawn completely.
• Reproduction – Since the flowchart symbols cannot be typed in, the
reproduction of a flowchart becomes a problem.
• Loss of objective – The essentials of what has to be done can easily be
lost in the technical details of how it is to be done.

27

You might also like