FLowchart

advertisement
2nd Term
DIS 2011 - 2012
Computer Department
Student Name:
Grade 12 Com
___________________________________________________
Section: _____________
Flowcharts
A flowchart consists of special geometric symbols connected by arrows. Within each symbol is phrase
presenting the activity at that step. The shape of the symbol indicates the type of operation that is to occur.
The arrows connecting the symbols, called flowlines, show the progression in which the steps take place.
Flowchart should “flow” from the top of the page to the bottom.
The main advantage of using a flowchart to plan a task is that it provides a pictorial representation of the
task, which makes the logic easier to follow. The major disadvantage which flowchart is that when program
is very large, the flowcharts may continue for many pages, making them difficult to follow and modify.
A table of flowchart symbols adopted by the American National Standards Institute (ANSI) Follows:
Symbol
Name
Meaning
Flowline
Used to connect symbols and indicate the flow of logic.
Terminal
Used to present the beginning (Start) or the end (End) of a task.
Input / Output
Used to input and output operations, such as reading and printing.
The data to be read or printed are described inside.
Processing
Used for arithmetic and data manipulation operations. The
instructions are listed inside the symbol.
Decision
Used for any logic or comparison operations. Unlike the
input/output and processing symbols, which have one entry and
one exit flowline, the decision symbol has one entry and two exit
paths. The path chosen depends on whether the answer to
question is “yes” or “no”.
Used to join different flowlines.
Connector
Offpage
connector
Used to indicate that the flowchart continues to a second page.
Predefined
process
Used to represent a group of statements that perform one
processing task.
Annotation
Used to provide additional information about another flowchart
symbol.
2nd Term
DIS 2011 - 2012
Computer Department
Grade 12 Com
Example:
Start
Read
Sheet
s
Input
Set Stamp =
Sheets / 5
Processing
Round stamps
up to next
whole number
Processing
Display
stamp
Output
End
Figure 21. Flowchart for the postage stamp problem
Pseudocode
Pseudocode is an abbreviated version of actual computer code. Pseudocode allows the programmer to
focus on the steps required to solve a problem rather than on how to use the computer language.
Example:
Pseudocode for the postage stamp problem:
Program: Determine the proper number of stamps for a letter
Read Sheets
Set the number of stamps to Sheets / 5
Round the number of stamps up to the next whole number
Display the number of stamps
(input)
(processing)
(processing)
(output)
Pseudocode has several advantages. It is compact and probably will not extend for many pages as
flowcharts commonly do. Also the plan looks like the code to be written and so is preferred by many
programmers.
2nd Term
DIS 2011 - 2012
Computer Department
Grade 12 Com
Hierarchy Chart
The hierarchy chart shows the overall program structure. Hierarchy charts are also called Structure Charts,
HIPO (Hierarchy plus Input-Process-Output) charts, Top-Down charts, or VTOC (Visual Table of contents)
charts. Hierarchy Chart is read from top to bottom and from left to right.
Example:
Postage Stamp
Program
Read
Calculate
DIsplay
Sheets
Stamps
Stamps
Set stamps =
Round stamps up to
sheets / 5
nest whole number
Figure 2. Hierarchy chart for postage stamp problem
The main benefit of hierarchy charts is the initial planning of a program.
Decision Structure
This kind of structure requires a decision to determine whether a series of instructions should be executed.
If the answer to a question is “Yes”, then one group of instructions should be executed. If the answer is
“No”, then another is executed.
No
If condition is true then
Is
Condition
True?
Yes
Process step(s) 1
Process
Step(s) 2
Else
Process step(s) 2
End If
Figure 3. Pseudocode and flowchart for Decision Structure
Process
Step(s) 1
2nd Term
DIS 2011 - 2012
Computer Department
Grade 12 Com
Select Case Structure
Evaluate
Selector
In value
list
1?
Yes
In Value
List
2?
Yes
Action 1
No
No
Action 2
≈
In Value
List
n?
≈
Yes
Action n
Perform action of
last resort
Figure 4. Flowchart for Select Case Structure
2nd Term
DIS 2011 - 2012
Computer Department
Grade 12 Com
Loop Structure
This kind of structure requires the repetition of a series of instructions. A programming structure that
executes instructions many times is called a Loop Structure.
Is
Condition
True?
Do while condition is true
No
Process step(s)
Loop
Yes
Process
Step(s)
Execute statements
within the loop
Do
No
Is
Condition
True?
Statements(s)
Loop Until condition is true
Yes
Execute statements
that follow loop
Figure 5. Pseudocode and flowchart for Loop Structure.
Download