Professional Documents
Culture Documents
Lecture 12
Lecture 12
Lecture 12
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
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?
Statemement a
3. Repetition
F
Condition p?
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 Output
Read
Number1
Number2
number3
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
Service_charge = $5 Service_charge = $2
Null ELSE statement
Student_ F
attendance =
P/T?
Increment
part_time_count
Combined IF statement
F
Student =
P/T AND
Gender =
F?
Increment
Female_part_time_count
Nested IF statement
T F
Record
Code =`A‘ ?
F
T
Record
Increment Code =`A‘ ?
Counter_A
F
Record
Code =`A‘ ?
Increment T
Counter_B
Increment
Increment Error_counter
Counter_C
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
Calculate Display
Total_score = average
zero average
I=1
I=1
Stop
Prompt and
Display
get
Scores (I)
Scores (I)
Add scores(I)
to I=I+1
Total score
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
Process_three_
characters
Sort_three_
characters
Process_three_characters
Start
Sort_
Three_
Prompt
characters
For
characters
Outpur
Get characters
characters
Prompt
Characters For
NOT = xxx ? characters
F
Stop
Get
T characters
Sort_three_characters
Start
T Char_1 >
Char_2 ?
Swap
F
Char_1,
Char_2
Char_2 >
Char_3 ?
T F
Swap
Char_2,
Char_3
Char_1 >
Char_2 ?
Swap
T F
Char_1,
Char_2
Stop
Assignment: Calculate Employee‘s pay
Compute_employee_pay
Employee_details
Valid_input_
fields
Print_
Validate_ Stop Employee_
Input: details
fields
Read_
Employee_
details
Validate_input_fields
Start
Hours_
Valid_input_ Worked
fields = T > 60
Print
Error
Pay_rate message
> $ 25
Print
Error Valid_
message Input_
Fields = T
Valid_
Input_
Fields = F
Stop