program flowcharts

advertisement
The Program Design Phases
Define the problem
Propose and evaluate solutions
Determine the most efficient
solution
Develop and represent the
algorithm
Test and validate the solution
Programs are Solutions to Problems
Programmers can represent their solutions in
several ways :
 Pseudocode
 Flowcharts
Pseudocode


This technique is a text based “blue print” of
what the program steps will be.
Pseudocode is written in the programmer’s
native language and concentrates on the logic
in a program — i.e. getting the correct
solution.
Flowcharts
A flowchart is a pictorial representation of all the
steps in a process.
( A picture is worth a 1000 words )
There are different types of flowcharts but we are
interested in :
Program flowcharts
PROGRAM FLOWCHARTS
These represent the flow of logic in a
program and help programmers
“see” the design of the program.
They are also sometimes called logic
flowcharts.
Flow charts are drawn in the design
phase of problem solving.
PROGRAM FLOWCHARTS
A flowchart is comprised of
specialised symbols and flow lines.
Each symbol contains information
about what must be done at that
point; and the arrow shows the flow
of execution.
PROGRAM FLOWCHARTS cont’d
… show the step by step sequence of operations
carried out by a computer program




the start and end of the program
the input and output operations
how the data is processed
the main sections of the program
PROGRAM FLOWCHARTS cont’d
Program flowcharts should be sufficiently
detailed for the program code to be
written directly from it, making it,
therefore, just like pseudocode
PROGRAM FLOWCHARTS cont’d
The most common flowchart symbols
are :
PROGRAM FLOWCHARTS cont’d
The terminator (start / end) symbol
Each flowchart must begin and end with the terminator
symbol. The word START or STOP is written inside the
oval
PROGRAM FLOWCHARTS cont’d
START
STOP
PROGRAM FLOWCHARTS cont’d
The process symbol
This indicates an operation such as a calculation Details
are written in the rectangle and should begin with a
verb or be a calculation statement
PROGRAM FLOWCHARTS cont’d
sum  number + subtotal
PROGRAM FLOWCHARTS cont’d
The input / output symbol
This marks the point at which we get data or give
results. The input or output is written inside the
parallelogram.
PROGRAM FLOWCHARTS cont’d
read name
PROGRAM FLOWCHARTS cont’d
Display “Enter a number”
PROGRAM FLOWCHARTS cont’d
The decision symbol
This is used where a decision has to be made about
which to follow next. Note that while there is only
one entry point to the diamond there are 2 exits
PROGRAM FLOWCHARTS cont’d
Yes
Number > 0?
No
PROGRAM FLOWCHARTS cont’d
The pre-defined process symbol
This is used to represent a process which is broken down
elsewhere
PROGRAM FLOWCHARTS cont’d
Sort Marks
PROGRAM FLOWCHARTS cont’d
The connector symbols

on-page Connector

Off-page connector
These are used to break and continue links without crisscrossing
lines all over the place. So they link with another part of the
program or another page and show the user where to
continue reading.
PROGRAM FLOWCHARTS cont’d
B
A
A
B
Drawing Flow Charts

Use standard symbols only, you can vary the size but
not the shape

Try to keep the logic as flowing from top to bottom
and from left to right

Do not cross flow lines
PROGRAM FLOWCHARTS cont’d
Combining symbols
START
Step 1
Sequence of steps
Step 2
Step 3
STOP
PROGRAM FLOWCHARTS cont’d
Combining symbols
n  sum + grade
Decision (if statement)
N > 50?
Yes
No
Give
certificate
END
PROGRAM FLOWCHARTS cont’d
Combining symbols
Loops
n=n+1
WHILE loop
( loops involve
a) decisions and
branching
{if statements}
b) Returning to
previous
statements
)
N < 50?
False
True
< action continuing
program >
< an action >
PROGRAM FLOWCHARTS cont’d
Combining symbols
n=n+1
Loops
REPEAT loop
< an action >
In a REPEAT loop the action
takes place before the first check
False
< action continuing
program >
N < 50?
True
Start
Sum = 0
Input price
Sum = sum + price
CASH REGISTER PROGRAM
Yes
More
items?
No
Tax = sum x 0.15
Output sum, tax,
Stop
Common Flowchart Symbols
Common Flowchart Symbols
Terminator. Shows the starting and ending points of the program. A terminator has
flow lines in only one direction, either in (a stop node) or out (a start node).
Data Input or Output. Allows the user to input data and results to be displayed.
Processing. Indicates an operation performed by the computer, such as a variable
assignment or mathematical operation.
Decision. The diamond indicates a decision structure. A diamond always has two
Flow lines out. One flow line out is labeled the “yes” branch and the other is labeled the
“no” branch.
Predefined Process. One statement denotes a group of previously defined statements.
For instance, “Calculate m!” indicates that the program executes the necessary commands
to compute m factorial.
Connector. Connectors avoid crossing flow lines, making the flowchart easier to read.
Connectors indicate where flow lines are connected. Connectors come in pairs, one with
a flow line in and the other with a flow line out.
Off-page connector. Even fairly small programs can have flowcharts that extend several
pages. The off-page connector indicates the continuation of the flowchart on another
page. Just like connectors, off-page connectors come in pairs.
Flow line. Flow lines connect the flowchart symbols and show the sequence of operations
during the program execution.
FYI : Other Symbols
------
tape
annotation / notes
disk
display
document
Benefits of Flowcharts





Communication : a better way of communicating
because they are visual
Effective analysis : the visual nature allows quick
grasp of program logic
Aids in technical documentation
Good guide when it is time to code
Good aid when program maintenance becomes
necessary
Draw Backs of Flowcharts


When programs are large or complex, the
chart becomes too complicated
If alterations are required, the entire chart
may have to be re-drawn
Download