flow control analysis & design tool: flowcharts

8
Flow Control Analysis & Design Tool: Flowcharts Flowchart - a graphical way of writing algorithms – Rectangle is used for calculations – Parallelogram is used for input and output – Circle is used as connector – Diamond is used as decision Symbols are connected by arrows to represent the order of the operations

Upload: lowell

Post on 04-Jan-2016

28 views

Category:

Documents


0 download

DESCRIPTION

Flow Control Analysis & Design Tool: Flowcharts. Flowchart - a graphical way of writing algorithms Rectangle is used for calculations Parallelogram is used for input and output Circle is used as connector Diamond is used as decision - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Flow Control Analysis & Design Tool: Flowcharts

Flow Control Analysis & Design Tool: Flowcharts

• Flowchart - a graphical way of writing algorithms

– Rectangle is used for calculations

– Parallelogram is used for input and output

– Circle is used as connector

– Diamond is used as decision

– Symbols are connected by arrows to represent the order of the operations

Page 2: Flow Control Analysis & Design Tool: Flowcharts

Flowcharts Symbols: Calculations

Calculations (e.g. arithmetic expressions) are shown in rectangles

Examples: Total = Cost + Tax

Num = Num + 1

Total = Cost + Tax

Num = Num + 1 (add one to the current value of Num and make that the new value of Num)

Page 3: Flow Control Analysis & Design Tool: Flowcharts

Flowcharts Symbols: Input/Output

Data input and output are shown in parallelograms

Input means a read operation of data from a peripheral device to memory (e.g. a user typing in data at a keyboard)

READ Num

WRITE Num Output means a write operation of

data to a peripheral device from memory (e.g. data displayed to the monitor)

Page 4: Flow Control Analysis & Design Tool: Flowcharts

Flowcharts Symbols: Decisions

Decisions are shown within diamonds and specify a condition to be tested

Based on the condition being TRUE or FALSE, the next operation will be determined

Gross > 50000

Rate = 0.31

Rate = 0.28True

False

A decision is composed of : A condition An operation to be done if

condition is TRUE Possibly an operation to be done if

condition is FALSE

Page 5: Flow Control Analysis & Design Tool: Flowcharts

Flowcharts Symbols: Start and End

Every algorithm starts somewhere and terminates somewhere

Every flowchart must have one start symbol and one end symbol

Start and end symbols are ovalssquare = num x num

input num

print square

start

stop

A start symbol denotes the start of the algorithm

An end symbol indicates the algorithm has terminated

Page 6: Flow Control Analysis & Design Tool: Flowcharts

Sequential AlgorithmFlowchart

• Pseudocode Algorithm:

– PROMPT for Age of Child1

– READ Age of Child1

– PROMPT for Age of Child2

– READ Age of Child2

– CALCULATE Allowance for Child1 = Age of Child1 x Rate

– CALCULATE Allowance for Child2 = Age of Child2 x Rate

– DISPLAY Allowance for Child1

– DISPLAY Allowance for Child2

Allow1 = Age1 x Rate

input Age1

start

Print Allow1

stop

prompt Age1

Allow2 = Age2 x Rate

Print Allow2

input Age2

prompt Age2

Page 7: Flow Control Analysis & Design Tool: Flowcharts

Selection AlgorithmFlowchart

• Previous Pseudocode Algorithm:

– PROMPT for Age

– READ Age

– IF Age less than 10

• THEN CALCULATE Allowance = Age x YoungRate

• ELSE CALCULATE Allowance = Age x OlderRate

– DISPLAY Allowance

Allow = Age x YoungRate

start

Print Allow

stop

prompt Age

Allow = Age x OlderRate

Age < 10 FALSETRUE

input Age

Page 8: Flow Control Analysis & Design Tool: Flowcharts

Looping AlgorithmFlowchart

• Previous Pseudocode Algorithm:

– Set KidsPaid to 0

– Set Total to 0

– WHILE KidsPaid < 3 DO

• PROMPT for Age

• READ Age

• CALCULATE Allowance = Age x Rate

• ADD Allowance to Total

• INCREMENT KidsPaid

– DISPLAY Total

start

Display Total

stop

Read Age

Calc Allowance

KidsPaid < 3FALSETRUE

KidsPaid = 0

Total = 0

Add Allowance to Total

Increment KidsPaid

Prompt Age