3 Program Flowchart Lecture

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 37

FLOWCHART

CPEN21A – PROGRAMMING LOGIC AND DESIGN


PREPARED BY: JOVEN RAMOS
Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

General Rules and


Program Development
Advantages of
Cycle
Flowchart

Type, Purpose, Operation, Topic Operator Precedence


and Associativity in
and Desk Checking of
Flowchart Outline Python Program

What are the symbols Structure of the


used in flowchart? flowchart.
Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

ANALYZE
DOCUMENTATION
Define the
Describe the problem.
program.

DEBUG
Program
DESIGN
AND TEST
Locate and remove any Plan the solution to
errors in the program.
Development the problem.

Cycle
CODE INTERFACE
Translate the algorithm Select the objects
into a programming (programming
language. language).
Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

WHAT IS A FLOWCHART?
• Program flowchart is a diagram that uses a set of standard graphic
symbols to represent the sequence of coded instructions fed into a
computer, enabling it to perform specified logical and arithmetical
operations.(www.edrawsoft.com)

• Flowchart is a diagrammatic representation of an algorithm.


Flowchart are very helpful in writing program and explaining
program to others. (www.programiz.com)
Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

WHAT IS A FLOWCHART?
•A flowchart is a diagram that depicts a process, system or computer
algorithm. They are widely used in multiple fields to document, study,
plan, improve and communicate often complex processes in clear,
easy-to-understand diagrams. (www.lucidchart.com)

• Flowchart is a graphical representation of an algorithm. Programmers


often use it as a program-planning tool to solve a problem. It makes
use of symbols which are connected among them to indicate the flow
of information and processing. (www.geeksforgeeks.org)
Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

TYPES OF FLOWCHARTS?
Program Flowcharts.
• These are used by programmers.
• It is graphical description of sequence of logical operations
performed by the computer in a computer program. PFC are drawn
by use of specific symbols.
•A program flowchart shows the program structure, logic flow and
operations performed.
• The emphasis in a program flowchart is on the logic.
Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

TYPES OF FLOWCHARTS?
System Flowcharts.
• System flowcharts are used by system analyst to show various
processes, sub systems, outputs and operations on data in a
system.
• It is graphical description of relationships among the inputs,
outputs and processes in an IS (modeling systems in physical
terms). SFC are drawn by use of specific symbols.
Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

TYPES OF FLOWCHARTS?
DFD (Data Flow Diagrams)
• It shows how the data moves within a system. DFD are also drawn
by some specific symbols.
Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

PURPOSE OF PROGRAM FLOW


CHART:
• An aid in developing the logic of a program.
• Verification that all possible conditions have been considered in a
program.
• Provides means of communication with others about the program.
• A guide in coding the program.
• Documentation for the program.
Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

PROCESSING OPERATION:
• Arithmetic Calculation
• Reading Input
• Producing Output
• Comparison
• Moving data
• Initializing value
• Branching and Looping
• Modular Technique
Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

DESK CHECKING
• The process of testing the flowchart with different data as input,
and checking the output.

• The test data should include nonstandard data as well as typical


data.
Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

FLOWCHART SYMBOLS
START

Read Hours,
PayRate

• Used to
Multiply Hours
connect by PayRate.
Store result in
FLOW LINES symbols and GrossPay.

indicate the Display


flow of logic GrossPay

END

SYMBOL NAME FUNCTION SAMPLE


Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

FLOWCHART SYMBOLS
START Terminal

•Used to Read Hours,


PayRate
START represent the
beginning Multiply Hours
by PayRate.
(START) and Store result in
TERMINAL end (END) of GrossPay.

END
a task. Display
GrossPay

Terminal END

SYMBOL NAME FUNCTION SAMPLE


Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

FLOWCHART SYMBOLS
pi = 3.1416 • Used to set
num = 0
initial/ constant
value in an
identifier name.
INITIALIZATION/
T for i in F
LOOPING BOX • Used to evaluate
range(3) the looping
condition.

SYMBOL NAME FUNCTION SAMPLE


Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

FLOWCHART SYMBOLS
START
• Used for input
and output Read Hours,
Read Hours, operations, such PayRate
PayRate
as reading and
displaying. Multiply Hours Input and
by PayRate. Output
Store result in
INPUT/OUTPUT
Operation
Display
• The data to be GrossPay.

GrossPay read or displayed


are described Display
GrossPay
inside.
END

SYMBOL NAME FUNCTION SAMPLE


Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

FLOWCHART SYMBOLS
START

Read Hours,
• Used for PayRate

arithmetic and
Multiply Hours data manipulation Multiply Hours
by PayRate.
by PayRate. operations. Store result in Process
Store result in PROCESS • The instructions GrossPay.

GrossPay. are listed inside


the symbol. Display
GrossPay

END

SYMBOL NAME FUNCTION SAMPLE


Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

FLOWCHART SYMBOLS Decision/Selection


/Condition
NO YES
• Used for any logic or x>
min?
comparison operations.
• Unlike the input/output
and processing
Display “x is
X symbols, which have outside the
one entry and one exit ”
T > F
flowline, the decision
limits. NO x<
max?
YES

min symbol has one entry


? DECISION and two exit paths.
• The exit path chosen Display “x is Display “x is
depends on whether outside the limits.” within
limits.”
the answer to a
question is “yes” or
“no”.

SYMBOL NAME FUNCTION SAMPLE


Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

FLOWCHART SYMBOLS
On-page connector

START A

ON-PAGE • Used to join


CONNECTOR different
1 flowlines.
END
A

SYMBOL NAME FUNCTION SAMPLE


Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

FLOWCHART SYMBOLS

• Used to
indicate that
1 OFF-PAGE the flowchart
CONNECTOR continues to
a second
page.

SYMBOL NAME FUNCTION SAMPLE


Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

FLOWCHART SYMBOLS
START
• Used to
represent a Read Input.
group of
statements that
Call PREDEFINED perform one Call calc_pay Predefined
processing task. function. process
calc_pay
function
PROCESS •A separate
flowchart can be Display results.
constructed for
the module.
END

SYMBOL NAME FUNCTION SAMPLE


Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

FLOWCHART SYMBOLS
• Used to
provide
Process
additional description
information
ANNOTATION
about another
flowchart
symbol

SYMBOL NAME FUNCTION SAMPLE


Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

Connectors are used to connect


breaks in the flowchart.
Examples are:
1 All boxes of the flowchart are 5 • From one page to another page.
connected with Arrows. (Not lines) • From the bottom of the page to
the top of the same page.
• An upward flow of more then 3
symbols.
Flowchart symbols have an entry
point on the top of the symbol with
no other entry points. The exit Subroutines and Interrupt programs
2 6 have their own and independent
point for all flowchart symbols is
on the bottom except for the flowcharts.
Decision symbol.

The Decision symbol has two exit All flow charts start with a Terminal
3 points; these can be on the sides 7 or Predefined Process (for interrupt
or the bottom and one side. programs or subroutines) symbol.

Generally a flowchart will flow


from top to bottom. However, an
All flowcharts end with a
4 upward flow can be shown as 8
terminal or a contentious loop.
long as it does not exceed 3
symbols.

GENERAL RULES IN FLOWCHARTING


ADVANTAGES OF FLOWCHARTING

Title Text block


01. Communication

Title Text block


Effective
Analysis 02.

Title Text block


Documentation of
03.
Program/System

Title Text block


Coding of the
Program 04.

Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN


OPERATOR PRECEDENCE AND
ASSOCIATIVITY
NAME MEANING ASSOCIATIVITY
1 () Parentheses (grouping) Left-to-Right
2 ** Exponent Right-to-Left
3 +x, -x Unary plus, Unary minus Left-to-Right
Multiplication, Division, Floor division,
4 *, /, //, % Left-to-Right
Modulus
5 +, - Addition, Subtraction Left-to-Right
==, != Equality
6 >, >=, <, <= Comparison Left-to-Right
is, is not, in, not in Identity, Membership
7 not Logical NOT Left-to-Right
8 and Logical AND Left-to-Right
9 or Logical OR Left-to-Right

Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN


OPERATOR PRECEDENCE AND
ASSOCIATIVITY
NAME MEANING ASSOCIATIVITY
=
+=
-=
*=
10 Assignment operators Left-to-Right
/=
//=
%=
**=

Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN


Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

STRUCTURE OF A FLOWCHART
START

Read Input.

Call calc_pay
function.

Display results.

END
Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

FLOWCHARTS FOR
COMPUTATIONS (SEQUENCE)
• Computers are used to perform many calculations at high speed.
When you develop a program it also involves several calculations.
• The general format of the flowcharting steps for computations is :
• Create identifier used in calculations and read operation.
• Get required data input using identifier.
• Perform the necessary calculations.
• Print the result.
PROGRAMMING CONSIDERATIONS
WHILE USING COMPUTATION
TECHNIQUES
• Most languages have provision for creating identifier.
• The exact syntax depends on the language used.
• In most cases (but not all) your programs have to create and initialize
the identifier before you can use them.

Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN


Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

EXAMPLE USING COMPUTATION


TECHNIQUES
• Write an algorithm and draw a flowchart that asks the user for a
weight in kilograms and converts it to pounds. There are 2.2 pounds in
a kilogram.

• Write an algorithm and draw a flowchart that takes two numbers and
prints the quotient and remainder.

• Write an algorithm and draw a flowchart that takes both the values
from the user and swaps them without using temporary variable.
Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

FLOWCHARTS FOR DECISION


MAKING
• Computers are used extensively for performing various types of
analysis. The decision symbol is used in flowcharts to indicate it.
• The general format of steps for flowcharting is as follows:
• Perform the test of the condition.
• If condition evaluates true branch to Yes steps.
• If condition evaluates false branch to No steps.
PROGRAMMING CONSIDERATIONS
WHILE USING DECISION MAKING
TECHNIQUES
• Most programming languages have commands for performing test
and branching.
• The exact commands and syntax depends on the language used.
Some of the conditional constructs available in programming
languages for implementing decision making in programs are as
follows:
• If, If - else – endif, If - elseif – endif, and nested if
• The operators available for implementing the decision test are as
follows:
• Relational Operators (which determine equality or inequality)
• Logical Operators, (useful for combining expressions)

Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN


EXAMPLE USING DECISION
MAKING TECHNIQUES
• Writean algorithm and draw a flowchart that takes a number and
checks whether it is positive or negative.

• Writean algorithm and draw a flowchart that takes in a year and


checks whether it is a leap year or not.

Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN


FLOWCHARTS FOR LOOPS
• Looping refers to the repeated use of one or more steps. i.e. the
statement or block of statements within the loop are executed
repeatedly.

• There are two types of loops. One is known as the fixed loop where
the operations are repeated a fixed number of times. In this case, the
values of the variables within the loop have no effect on the number of
times the loop is to be executed.

Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN


FLOWCHARTS FOR LOOPS
• In the other type which is known as the variable loop, the operations
are repeated until a specific condition is met. Here, the number of
times the loop is repeated can vary.

• The loop process in general includes :


• Setting and initializing a counter
• execution of operations
• testing the completion of operations
• incrementing the counter

• The test could either be to determine whether the loop has executed
the specified number of times, or whether a specified condition has
been met.

Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN


Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

PROGRAMMING CONSIDERATIONS
WHILE USING LOOP TECHNIQUES
• Most of the programming languages have a number of loop constructs
for efficiently handling repetitive statements in a program. These
include :

• while loop
• for loop

• In most of the looping situations, we make use of counters. In


situations where the loop is to be repeated on the basis of conditions,
relational operators are used to check the conditions.
EXAMPLE USING LOOP
TECHNIQUES
• Write an algorithm and draw a flowchart that takes a number and
reverse a given number.

• Write an algorithm and draw a flowchart that takes in a number and


finds the sum of digits in a number.

Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN


PROGRAMMING CONSIDERATIONS
WHILE USING MODULAR
TECHNIQUES
• Today structured and modular programming is accepted as the best
way to developed software applications.

• Each module treats the other module as a predefined process.


• The development of the library routines also envisions the use of
predefined process.

• It prevents us from having to write separate programs again and again


each time to do the same task, in different applications.

Topic Discussion: Flowchart CPEN21A – PROGRAMMING LOGIC AND DESIGN

You might also like