Introduction of Flowchart 3664210
Introduction of Flowchart 3664210
Todays Topics
Flowchart Symbols Structures Sequence Selection Repetition
Flowchart Symbols
Terminal: Used to indicates the start and end of a flowchart. Single flow line. Only one Start and Stop terminal for each program. The end terminal for function/subroutine must use Return instead of Stop. Process: Used whenever data is being manipulated. One flow line enters and one flow line exits. Input/Output: Used whenever data is entered (input) or displayed (output). One flow line enters and one flow line exits.
Flowchart Symbols
Decision: Used to represent operations in which there are two possible selections. One flow line enters and two flow lines (labeled as Yes and No) exit.
Function / Subroutine: Used to identify an operation in a separate flowchart segment (module). One flow line enters and one flow line exits. On-page Connector: Used to connect remote flowchart portion on the same page. One flow line enters and one flow line exits. Off-page Connector: Used to connect remote flowchart portion on different pages. One flow line enters and one flow line exits. Comment: Used to add descriptions or clarification. Flow line: Used to indicate the direction of flow of control.
Comments or description
Start
Read N, M
Yes
No
Stop
1- connection on the same flowchart portion 2- connection on the different flowchart portion
Stop
1
Start
2
Stop
Yes
No
Function
Page 1
Start
This is known as Function-Definition Start terminal for a Function is different. Do not use Start Page 2
Read n1, n2 , n3
At this point, we only focus on what to do. How to do it, it comes later. This part is known as Function-Call
Print result
Return
Stop
End terminal must be a Return This flowchart calculates the average of three numbers
3.Repetition
A flowchart expressing the solution to an involved problem may have: 1. the main program flowchart on one page 2. with subprograms continuing the problem solution on subsequent pages.
Each of the five acceptable structures can be built from the basic elements as shown below.
Each of the five acceptable structures can be built from the basic elements as shown below.
Each of the five acceptable structures can be built from the basic elements as shown below.
Sequence
In a computer program or an algorithm, sequence involves simple steps which are to be executed one after the other. The steps are executed in the same order in which they are written.
In a flowchart, sequence is expressed as: In pseudocode, sequence is expressed as: process 1 process 2 process n
Sequence
Flowchart
Problem: Write a set of instructions that describe how to make a pot of tea. Pseudocode BEGIN fill a kettle with water boil the water in the kettle put the tea leaves in the pot pour boiling water in the pot END
Selection is used in a computer program or algorithm to determine which particular step or set of steps is to be executed
Binary Selection
In pseudocode, binary selection is expressed in the following ways: Binary Selection In flowcharts, binary selection is expressed in the following ways:
1.
2.
Selection
Binary (structure)
Binary Selection
In pseudocode, binary selection is expressed in the following ways: Binary Selection In flowcharts, binary selection is expressed in the following ways:
1.
2.
Selection
Binary (flowchart structure)
Note: In a flowchart it is most important to indicate 1. which path is to be followed when the condition is true, and 2. which path to follow when the condition is false. Without these indications the flowchart is open to more than one interpretation. Note: There are two acceptable ways to represent a decision in all of the structures. Either method is acceptable. For consistency, the method 1 is used throughout this document. 1. The condition is expressed as a 2. The condition is expressed as a
statement and the two possible outcomes are indicated by True False question and the two possible outcomes are indicated by Yes No
Selection
Binary (examples)
Examples Using Binary Selection Problem 1: Write a set of instructions to describe when to answer the phone. Binary Selection Flowchart
Binary Selection
Pseudocode IF the telephone is ringing THEN answer the telephone ENDIF
Selection
Binary (examples) Examples Using Binary Selection Problem 2: Write a set of instructions to follow when approaching a set of traffic control lights. Binary Selection
Flowchart
Binary Selection
Pseudocode
IF the signal is green THEN proceed through the intersection ELSE stop the vehicle ENDIF
Selection
Multi-way (structure)
Multi-way Selection
In pseudocode, multiple selection is expressed as: CASEWHERE expression evaluates to choice a : process a choice b : process b . . . . . . OTHERWISE : default process ENDCASE Note: As the flowchart version of the multi-way selection indicates, only one process on each pass is executed as a result of the implementation of the
Multi-way Selection
Selection
Multi-way (examples)
Example Using Multi-way Selection Problem: Write a set of instructions that describes how to: respond to all possible signals at a set of traffic control lights.
Multi-way Selection
Pseudocode CASEWHERE signal is red : stop the vehicle amber : stop the vehicle green : proceed through the intersection OTHERWISE : proceed with caution ENDCASE
Repetition
Repetition allows for a portion of an algorithm or computer program to be done any number of times dependent on some condition being met. An occurrence of repetition is usually known as a loop. An essential feature of repetition is that each loop has a termination condition to stop the repetition, or the obvious outcome is that the loop never completes execution (an infinite loop). The termination condition can be checked or tested 1. at the beginning and is known as a pre-test loop or 2. at the end of the loop and is known as a post-test loop.
Repetition
In pseudocode, pre-test repetition is expressed as: WHILE condition is true process(es) ENDWHILE
Repetition
Repetition
In pseudocode, post-test repetition is expressed as:
Pre-test Repetition
Pseudocode WHILE the train is moving keep wholly within the carriage ENDWHILE
Post-test Repetition
Pseudocode REPEAT beat the egg whites UNTIL fluffy
Example:
Start
Process: Area = 5 * 3 = 15
Process:
Perimeter = 2* (5+3) = 16
Output
Area: 15 Perimeter: 16
Stop
Example:
What is the output of the following flowchart when the input Num= 10
Start
Category A
Read Num
Num>0?
Yes
Output: Category A
Stop
Example:
What is the output of the following flowchart when the input is Num= 0
Start
Category B Category A
Num>0?
Yes
Output: Category A
Stop
Example:
What is the output of the following flowchart when the input is Num= 4
Start
Read Num
Num [ 4 ] Num Num [ 4 ] [ 4 ] Result [ 4 ] 4 + 3 9 Result [ 0 ] 07 + 42 Result [ 7 ] 9 + 1 10] Count [ 3 ] 3 - 1 1 Count [ 2 ] 1 0 Count [ 4 ] 42 -- 11
No
Print Result
Stop
Example:
What is the output of the following flowchart when the input is N = 6
10
Page 1
Start
average
Page 2
5 N=6
Read N
Sum = 10 + 5 + 6
sum = n1+ n2+n3
average = 21/3
result = sum/3
Print average
Output: Average: 7
Return
Stop
T. O. L
Quiz
1. What is a flowchart?
2. It is used to connect remote flowchart
portion on the same page. One flow line enters and one flow line exits. 3-5. Control Structures of Flowchart.