introduction to flowcharts

35
Introduction To Flowcharting

Upload: binjad

Post on 02-Nov-2015

8 views

Category:

Documents


0 download

DESCRIPTION

Description of FlowCharts

TRANSCRIPT

DECISION

Introduction To FlowchartingTodays TopicsFlowchart SymbolsStructuresSequenceSelectionRepetition

21. Flowchart:The flowchart is a means of visually presenting the flow of control through an information processing systems, the operations performed within the system and the sequence in which they are performed.

It is a graphic representation of how a process works, showing, at a minimum, the sequence of steps.

Represents an algorithm in graphical symbols.

Flowcharts are generally drawn in the early stages of formulating computer solutions. 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.

2. Flowchart Symbols4Decision: 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.

2. Flowchart Symbols 5Off-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.

2.Flowchart Symbols 63.1 Comments or description

73.2 Connectors on the same page

1- connection on the same flowchart portion

2- connection on the different flowchart portion83.3 Connectors on a different page Page 1Page 2

93.4 FunctionPage 1

Page 2

End terminal must be a ReturnStart terminal for aFunction is different.Do not use StartThe detail of how the function works is put in another flowchart.

This is known as Function-DefinitionAt this point, we only focus on whatto do. How to do it, it comes later.

This part is known asFunction-CallBody of a function is the same with normal flowchartThis flowchart calculates the average of three numbers10ADVANTAGES OF USING FLOWCHARTS: Communication: Flowcharts are better way of communicating the logic of a system.

Effective analysis: Problem can be analyzed in more effective way.

Proper documentation: Flowcharts serve as a good program documentation.

Efficient Coding: Flowcharts act as a guide or blueprint during the systems analysis and program development phase.

ADVANTAGES OF USING FLOWCHARTS (Contd):Proper Debugging: Flowchart helps in debugging process.

Efficient Program Maintenance: The maintenance of operating program becomes easy with the help of flowchart.

4. The main Flowcharting StructuresSequenceSelectionRepetition

A flowchart expressing the solution to an involved problem may have:the main program flowchart on one page with subprograms continuing the problem solution on subsequent pages.

4.1 Each of the five acceptable structures can be built from the basic elements as shown below.

4.2 Each of the five acceptable structures can be built from the basic elements as shown below.

4.3 Each of the five acceptable structures can be built from the basic elements as shown below.4.4.1 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 pseudocode, sequence is expressed as:

process 1process 2process nIn a flowchart, sequence is expressed as:

4.4.1 Sequence

An Example Using Sequence

Problem: Write a set of instructions that describe how to make a pot of tea.Pseudocode

BEGINfill a kettle with waterboil the water in the kettleput the tea leaves in the potpour boiling water in the potEND

Flowchart

Binary Selection

In pseudocode, binary selection is expressed in the following ways:

IF condition THENprocess 1ENDIF

IF condition THENprocess 1ELSEprocess 2ENDIF

Binary Selection

In flowcharts, binary selection is expressed in the following ways:

Selection is used in a computer program or algorithm to determine which particular step or set of steps is to be executed.4.4.2 Selection : Binary (structure)4.4.2 Selection : Binary (structure)Binary Selection

In pseudocode, binary selection is expressed in the following ways:

IF condition THENprocess 1ENDIF

IF condition THENprocess 1ELSEprocess 2ENDIF

Binary Selection

In flowcharts, binary selection is expressed in the following ways:

4.4.2 Selection : Binary (flowchart structure)Note: In a flowchart it is most important to indicate which path is to be followed when the condition is true, and 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.The condition is expressed as a statement and the two possible outcomes are indicated byTrueFalse

2. The condition is expressed as a question and the two possible outcomes are indicated by YesNo

4.4.2 Selection : Binary (examples) Selection is used in a computer program or algorithm to determine which particular step or set of steps is to be executed.

Examples Using Binary SelectionProblem 1: Write a set of instructions to describe when to answer the phone. Binary SelectionPseudocode

IF the telephone is ringing THENanswer the telephoneENDIF

Binary SelectionFlowchart

4.4.2 Selection : Binary (examples) Examples Using Binary SelectionProblem 2: Write a set of instructions to follow when approaching a set of traffic control lights.Binary SelectionPseudocode

IF the signal is green THENproceed through the intersectionELSEstop the vehicleENDIF

Binary SelectionFlowchart

4.4.2 Selection : Multi-way (structure)Multi-way Selection

In pseudocode, multiple selection is expressed as:

CASEWHERE expression evaluates tochoice a : process achoice b : process b . . . . . . OTHERWISE : default processENDCASE

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.

Multi-way Selection

In flowcharts, multi-way selection is expressed as:

4.4.2 Selection : Multi-way (examples)Example Using Multi-way SelectionProblem: Write a set of instructions that describes how to:respond to all possible signals at a set of traffic control lights.Multi-way SelectionPseudocode

CASEWHERE signal isred : stop the vehicleamber : stop the vehiclegreen : proceed through the intersection OTHERWISE : proceed with cautionENDCASEMulti-way SelectionFlowchart

RepetitionRepetition allows for a portion of an algorithm or computer programto 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 at the beginning and is known as a pre-test loop orat the end of the loop and is known as a post-test loop. RepetitionPre-test (structure)Repetition: Pre-TestA pre-tested loop is so named because the condition has to be met at the very beginning of the loop or the body of the loop is not executed. This construct is often called a guarded loop. The body of the loop is executed repeatedly while the termination condition is true.Repetition

In pseudocode, pre-test repetition is expressed as:

WHILE condition is trueprocess(es)ENDWHILERepetition

In flowcharting pre-test repetition is expressed as:

Repetition Post-test (structure)Repetition: Post-TestA post-tested loop executes the body of the loop before testing the termination condition. This construct is often referred to as an unguarded loop. The body of the loop is repeatedly executed until the termination condition is true.An important difference between a pre-test and post-test loop is that the statements of a post-test loop are executed at least once even if the condition is originally true, whereas the body of the pre-test loop may never be executed if the termination condition is originally true. A close look at the representations of the two loop types makes this point apparent.Repetition

In pseudocode, post-test repetition is expressed as:

REPEATprocessUNTIL condition is trueRepetition

In a flowchartpost-test repetition is expressed as:

Repetition Pre-test (example)An Example Using Pre-Test RepetitionProblem: Determine a safety procedure for travelling in a carriage on a moving train.Pre-test RepetitionPseudocode

WHILE the train is movingkeep wholly within the carriageENDWHILEPre-test RepetitionFlowchart

Repetition Post-test (example)An Example Using Post-Test RepetitionProblem: Determine a procedure to beat egg whites until fluffy.Post-test RepetitionPseudocode

REPEATbeat the egg whitesUNTIL fluffyPost-test RepetitionFlowchart

Example:

Input:Length YESInput:Num > 10Output:Category ACategory A32

Example: What is the output of the following flowchart when the input is Num= 0

Num = 00 > 0 ? => NOOutput:Category BInput:Num > 0Category BOutput:Category ACategory A33

Example: What is the output of the following flowchart when the input is Num= 4

Input:Num 4Variables (in memory):

Num [ ]Result [ ]Count [ ]Variables (in memory):

Num [ 4 ]Result [ ]Count [ ]Count = 44 > 0 ? => YESVariables (in memory):

Num [ 4 ]Result [ 0 ]Count [ 4 ]Count: 4Variables (in memory):

Num [ 4 ]Result [ 4 ] 0 + 4Count [ 3 ] 4 - 1Count: 3Count = 33 > 0 ? => YESVariables (in memory):

Num [ 4 ]Result [ 7 ] 4 + 3Count [ 2 ] 3 - 1Count: 2Count = 22 > 0 ? => YESVariables (in memory):

Num [ 4 ]Result [ 9 ] 7 + 2Count [ 1 ] 2 - 1Count: 1Count = 11 > 0 ? => YESVariables (in memory):

Num [ 4 ]Result [ 10] 9 + 1Count [ 0 ] 1 - 1Count: 0Count = 00 > 0 ? => NOResult: 1034Page 1

Page 2

Example: What is the output of the following flowchart when the input is N = 6

average105N=6Sum = 10 + 5 + 6average = 21/3Output:Average: 735