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 Decision Symbol: Represents a decision in the logic involving the comparison Of two values. Predefined Process Symbol:
The three basic control structures
1. Sequence Statemement a Statemement b Statemement c
2. Selection Condition p? Statemement a Statemement b TF
Selection (2) Condition p? Statemement a T F
3. Repetition Condition p? Statemement block T F
Example 12.1 Add three numbers A program is required to read three numbers, add them together and print their total.
Defining diagram InputProcessingOutput Number1 Number2 Number3 Read three numbers Add number together Print total number total
Solution Algorithm Add numbers to total Read Number1 Number2 number3 Print total Start 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 InputProcessingOutput Max_temp Min_temp Prompt for temperatures Get temperatures Calculate average temperature Display average temperature Avg_temp
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 InputProcessingOutput Block_lenght Block_width House_lenght House_width Prompt for block measurements Get block measurements Prompt for house measurements Get house measurements Calculate mowing area Calculate mowing time Mowing_time
Solution Algorithm
Flowchart and the selection control structure
Simple IF statement Account_ balance < $300? Service_charge = $5 Service_charge = $2 TF
Null ELSE statement
Combined IF statement
Nested IF statement Increment Counter_A Record Code =`A‘ ? Increment Counter_B Increment Counter_C Increment Error_counter Record Code =`B‘ ? Record Code =`C‘ ? T T T F F F
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 InputProcessingOutput Char_1 Char_2 Char_3 Prompt for characters Accept three characters Sort three characters Output three characters Char_1 Char_2 Char_3
Solution Algorithm ?
Case Structure Case Of variable Statement_aStatement_bStatement_cStatement_d Value 1 Value 2Value 3Value 4
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 InputProcessingOutput 18 exam scoresPrompt the scores Get scores Compute class average Display scores Display class average 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 Total_score = zero I = 1 Add scores(I) to Total score I = I + 1 Calculate average I = I + 1 Prompt and get Scores (I) I = 1 I <= 18 ? Display Scores (I) I <= 18 ? Display average Stop T F T 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 InputProcessingOutput Char_1 Char_2 Char_3 Prompt for characters Accept three characters Sort three characters Output three characters Char_1 Char_2 Char_3
Hierarchy chart Process_three_ characters Sort_three_ characters
Process_three_characters Start Prompt For characters Sort_ Three_ characters Outpur characters Get characters Prompt For characters Get characters Stop Characters NOT = xxx ? F T
Sort_three_characters
Thanks Finish!