Transcript Flowcharts

Flowcharts
Symbol
Terminal Symbol:
indicates the starting or stopping pointin the logic.
Input/Output Symbol:
Represents an input or output process in an algorithm
Process Symbol:
Represents any single process in an algorithm
Predefined Process Symbol:
Decision Symbol:
Represents a decision in the logic involving the comparison
Of two values.
The three basic control
structures
1. Sequence
Statemement a
Statemement b
Statemement c
2. Selection
T
F
Condition p?
Statemement a
Statemement b
Selection (2)
F
Condition p?
T
Statemement a
3. Repetition
F
Condition p?
T
Statemement block
Example 12.1 Add three numbers
 A program is required to read
three numbers, add them together
and print their total.
• Defining diagram
Input
Processing
Number1 Read three numbers
Number2 Add number together
Number3 Print total number
Output
total
Solution Algorithm
Start
Read
Number1
Number2
number3
Add numbers to total
Print total
Stop
Example 12.2 Find average
temperature
• A program is required to prompt
the terminal operator for the
maximum and minimum temperature
readings on a particular day,
accept those readings as
integers, and calculate and
display to the screen the
average temperature, calculated
by (maximum temperature +
minimum temperature)/2.
• Defining diagram
Input
Max_temp
Min_temp
Processing
Output
Prompt for temperatures
Avg_temp
Get temperatures
Calculate average temperature
Display average temperature
Solution Algorithm
Example 12.3 Compute mowing time
• A program is required to read from
the screen the lenght and widht of
a rectangular house block, and the
lenght and width of the rectangular
house that has been built on the
block. The algorithm should then
compute and display the mowing time
required to cut the grass around
the house, at the rate of two
square metres per minute.
• Defining diagram
Input
Block_lenght
Block_width
House_lenght
House_width
Processing
Prompt for block measurements
Get block measurements
Prompt for house measurements
Get house measurements
Calculate mowing area
Calculate mowing time
Output
Mowing_time
Solution Algorithm
Flowchart and the selection
control structure
Simple IF statement
T
Service_charge = $5
Account_
balance <
$300?
F
Service_charge = $2
Null ELSE statement
Combined IF statement
Nested IF statement
T
F
Record
Code =`A‘
?
F
T
Record
Increment
Counter_A
Code =`B‘
?
F
Record
Code =`C‘
Increment
Counter_B
?
T
Increment
Counter_C
Increment
Error_counter
Example 12.4 Read three
characters
• Design an algorithm that will
prompt a terminal operator for
three characters, accept those
characters as input, sort them
into ascending sequence and
output them to the screen.
• Defining diagram
Input
Char_1
Char_2
Char_3
Processing
Prompt for characters
Accept three characters
Sort three characters
Output three characters
Output
Char_1
Char_2
Char_3
Solution Algorithm ?
Case Structure
Case
Of
variable
Value 1
Statement_a
Value 2
Value 3
Value 4
Statement_b
Statement_c
Statement_d
Flowchart and Array
• Design a program that will prompt for and
receive 18 examination scores from a
mathematics test, compute the class
average, and display all the scores and
the class average to the screen.
• Defining diagram
Input
18 exam scores
Processing
Prompt the scores
Get scores
Compute class average
Display scores
Display class average
Output
18 exam scores
Class_average
Control Structures required
1. An array to store the exam scores –
called ´scores´
2. An index to identify each element in the
array
3. A DO loop to accept the scores
4. Another DO loop to display the scores to
the screen.
Solution Algorithm
Start
Calculate
average
Total_score =
zero
Display
average
I=1
I=1
Stop
Prompt and
get
Scores (I)
Display
Scores (I)
Add scores(I)
to
Total score
I=I+1
T
I=I+1
I <= 18 ?
F
T
I <= 18 ?
F
Flowchart and Module
Design a solution algorithm that will prompt
a terminal operator for three characters,
accept those characters as input, sort
them into ascending sequence and output
them to the screen. The algorithm is to
continue to read characters until ´XXX`is
entered.
• Defining diagram
Input
Char_1
Char_2
Char_3
Processing
Prompt for characters
Accept three
characters
Sort three characters
Output three
characters
Output
Char_1
Char_2
Char_3
Hierarchy chart
Process_three_
characters
Sort_three_
characters
Process_three_characters
Start
Prompt
For
characters
Get
characters
F
Characters
NOT = xxx ?
Sort_
Three_
characters
Outpur
characters
Prompt
For
characters
Stop
T
Get
characters
Sort_three_characters
Thanks
Finish!