flow charting

104
Flow Charting Damian Gordon

Upload: cindy

Post on 23-Feb-2016

68 views

Category:

Documents


0 download

DESCRIPTION

Flow Charting. Damian Gordon. Introduction. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Flow Charting

Flow Charting

Damian Gordon

Page 2: Flow Charting

Introduction

• We mentioned it already, that if we thing of an analyst as being analogous to an architect, and a developer as being analogous to a builder, then the most important thing we can do as analysts is to explain our designs to the developers in a simple and clear way.

• How do architects do this?

Page 3: Flow Charting
Page 4: Flow Charting

Flowcharts

• So let’s say we want to express the following algorithm:– Read in a number and print it out.

Page 5: Flow Charting

START

Page 6: Flow Charting

START

Read in A

Page 7: Flow Charting

START

Read in A

Print A

Page 8: Flow Charting

START

END

Read in A

Print A

Page 9: Flow Charting

Flowcharts

• So let’s say we want to express the following algorithm:– Read in a number and print it out double the number.

Page 10: Flow Charting

START

Page 11: Flow Charting

START

Read in A

Page 12: Flow Charting

START

Read in A

Print A*2

Page 13: Flow Charting

START

END

Read in A

Print A*2

Page 14: Flow Charting

Or alternatively...

Page 15: Flow Charting

START

Page 16: Flow Charting

START

Read in A

Page 17: Flow Charting

START

Read in A

B = A*2

Page 18: Flow Charting

START

Read in AB = A * 2

can be read as

“B gets the value of A

multiplied by 2”

B = A*2

Page 19: Flow Charting

START

Read in A

Print B

B = A*2

Page 20: Flow Charting

START

END

Read in A

Print B

B = A*2

Page 21: Flow Charting

Flowcharts

• So let’s say we want to express the following algorithm:– Read in a number, check if it is odd or even.

Page 22: Flow Charting

START

Page 23: Flow Charting

START

Read in A

Page 24: Flow Charting

START

Does A/2 give a

remainder?

Read in A

Page 25: Flow Charting

START

Does A/2 give a

remainder?

Read in A

YesPrint “It’s Odd”

Page 26: Flow Charting

START

Does A/2 give a

remainder?

No

Read in A

YesPrint “It’s Odd” Print “It’s Even”

Page 27: Flow Charting

START

END

Does A/2 give a

remainder?

No

Read in A

YesPrint “It’s Odd” Print “It’s Even”

Page 28: Flow Charting

Flowcharts

• So let’s say we want to express the following algorithm to print out the bigger of two numbers:– Read in two numbers, call them A and B. Is A is bigger

than B, print out A, otherwise print out B.

Page 29: Flow Charting

START

Page 30: Flow Charting

START

Read in A and B

Page 31: Flow Charting

START

A>B?

Read in A and B

Page 32: Flow Charting

START

A>B?

Read in A and B

YesPrint A

Page 33: Flow Charting

START

A>B?No

Read in A and B

YesPrint A Print B

Page 34: Flow Charting

START

END

A>B?No

Read in A and B

YesPrint A Print B

Page 35: Flow Charting

Flowcharts

• So let’s say we want to express the following algorithm to print out the bigger of three numbers:– Read in three numbers, call them A, B and C.

• If A is bigger than B, then if A is bigger than C, print out A, otherwise print out C.

• If B is bigger than A, then if B is bigger than C, print out B, otherwise print out C.

Page 36: Flow Charting

START

Page 37: Flow Charting

START

Read in A, B and C

Page 38: Flow Charting

START

A>B?

Read in A, B and C

Page 39: Flow Charting

START

A>B?

Read in A, B and C

YesA>C?

Page 40: Flow Charting

START

A>B?No

Read in A, B and C

YesA>C? B>C?

Page 41: Flow Charting

START

A>B?No

Read in A, B and C

YesA>C? B>C?

Print C

NoNo

Page 42: Flow Charting

START

A>B?No

Read in A, B and C

YesA>C? B>C?

Print A Print C

Yes

NoNo

Page 43: Flow Charting

START

A>B?No

Read in A, B and C

YesA>C? B>C?

Print A Print C Print B

Yes Yes

NoNo

Page 44: Flow Charting

START

END

A>B?

No

Read in A, B and C

YesA>C? B>C?

Print A Print C Print B

Yes Yes

No

No

Page 45: Flow Charting

Flowcharts

• So let’s say we want to express the following algorithm:– Print out the numbers from 1 to 5

Page 46: Flow Charting

START

Page 47: Flow Charting

START

Print 1

Page 48: Flow Charting

START

Print 1

Print 2

Page 49: Flow Charting

START

Print 1

Print 2

Print 3

Page 50: Flow Charting

START

Print 1

Print 2

Print 3

Print 4

Page 51: Flow Charting

START

Print 1

Print 2

Print 3

Print 4

Print 5

Page 52: Flow Charting

START

END

Print 1

Print 2

Print 3

Print 4

Print 5

Page 53: Flow Charting

Or alternatively...

Page 54: Flow Charting

Flowcharts

• If I say A = A + 1, that means “A gets the value of whatever is in itself, plus 1”

• If A is 14• It becomes 15

A(new)

15A(old)

14 + 1

A = A + 1

Page 55: Flow Charting

START

Page 56: Flow Charting

START

A = 1

Page 57: Flow Charting

START

Is A==6?

A = 1

Page 58: Flow Charting

START

Is A==6?No

A = 1

Print A

Page 59: Flow Charting

START

Is A==6?No

A = 1

Print A

A = A + 1

Page 60: Flow Charting

START

Is A==6?No

A = 1

Print A

A = A + 1

Page 61: Flow Charting

START

END

Is A==6?No

A = 1

Yes

Print A

A = A + 1

Page 62: Flow Charting

Flowcharts

• So let’s say we want to express the following algorithm:– Add up the numbers 1 to 5

Page 63: Flow Charting

Flowcharts

• But first a few points; • If I say T = 5, that means “T gets the value

5”

T = 5

Page 64: Flow Charting

Flowcharts

• But first a few points; • If I say T = 5, that means “T gets the value

5”

T

T = 5

Page 65: Flow Charting

Flowcharts

• But first a few points; • If I say T = 5, that means “T gets the value

5”

T

5

T = 5

Page 66: Flow Charting

Flowcharts

• If I say T = X, that means “T gets the value of whatever is in the variable X”

T = X

Page 67: Flow Charting

Flowcharts

• If I say T = X, that means “T gets the value of whatever is in the variable X”

• So if X is 14, then T will get the value 14.

T = X

Page 68: Flow Charting

Flowcharts

• If I say T = X, that means “T gets the value of whatever is in the variable X”

• So if X is 14, then T will get the value 14.

T

X14

14

T = X

Page 69: Flow Charting

Flowcharts

• If I say T = X+1, that means “T gets the value of whatever is in the variable X plus one”

T = X + 1

Page 70: Flow Charting

Flowcharts

• If I say T = X+1, that means “T gets the value of whatever is in the variable X plus one”

• So if X is 14, T becomes 15, and X stays as 14.

T = X + 1

Page 71: Flow Charting

Flowcharts

• If I say T = X+1, that means “T gets the value of whatever is in the variable X plus one”

• So if X is 14, T becomes 15, and X stays as 14.

T

X15

14+ 1

T = X + 1

Page 72: Flow Charting

Flowcharts

• If I say T = T + X, that means “T gets the value of whatever is in itself plus whatever is in the variable X”

T = T + X

Page 73: Flow Charting

Flowcharts

• If I say T = T + X, that means “T gets the value of whatever is in itself plus whatever is in the variable X”

• If T is 14 and X is 9• T becomes 23• X stays at 9

T = T + X

Page 74: Flow Charting

Flowcharts

• If I say T = T + X, that means “T gets the value of whatever is in itself plus whatever is in the variable X”

• If T is 14 and X is 9• T becomes 23• X stays at 9

T(new)

X23

9T(old)

14

T = T + X

Page 75: Flow Charting

Flowcharts

• So let’s say we want to express the following algorithm:– Add up the numbers 1 to 5

Page 76: Flow Charting

START

Page 77: Flow Charting

START

Total = 0

Page 78: Flow Charting

START

A = 1

Total = 0

Page 79: Flow Charting

START

Is A==6?

A = 1

Total = 0

Page 80: Flow Charting

START

Is A==6?No

A = 1

Total = Total + A;

Total = 0

Page 81: Flow Charting

START

Is A==6?No

A = 1

Total = Total + A;

A = A + 1

Total = 0

Page 82: Flow Charting

START

END

Is A==6?No

A = 1

Yes

Total = Total + A;

A = A + 1

Total = 0

Page 83: Flow Charting

Flowcharts

• So let’s say we want to express the following algorithm:– Read in a number and check if it’s a prime number.

Page 84: Flow Charting

Flowcharts

• So let’s say we want to express the following algorithm:– Read in a number and check if it’s a prime number.– What’s a prime number?

Page 85: Flow Charting

Flowcharts

• So let’s say we want to express the following algorithm:– Read in a number and check if it’s a prime number.– What’s a prime number?– A number that’s only divisible by itself and 1, e.g. 7.

Page 86: Flow Charting

Flowcharts

• So let’s say we want to express the following algorithm:– Read in a number and check if it’s a prime number.– What’s a prime number?– A number that’s only divisible by itself and 1, e.g. 7. – Or to put it another way, every number other than itself and 1

gives a remainder, e.g. For 7, if 6, 5, 4, 3, and 2 give a remainder then 7 is prime.

Page 87: Flow Charting

Flowcharts

• So let’s say we want to express the following algorithm:– Read in a number and check if it’s a prime number.– What’s a prime number?– A number that’s only divisible by itself and 1, e.g. 7. – Or to put it another way, every number other than itself and 1

gives a remainder, e.g. For 7, if 6, 5, 4, 3, and 2 give a remainder then 7 is prime.

– So all we need to do is divide 7 by all numbers less than it but greater than one, and if any of them have no remainder, we know it’s not prime.

Page 88: Flow Charting

Flowcharts

• So, • If the number is 7, as long as 6, 5, 4, 3, and

2 give a remainder, 7 is prime.• If the number is 9, we know that 8, 7, 6, 5,

and 4, all give remainders, but 3 does not give a remainder, it goes evenly into 9 so we can say 9 is not prime

Page 89: Flow Charting

Flowcharts

• So remember, – if the number is 7, as long as 6, 5, 4, 3, and 2

give a remainder, 7 is prime.• So, in general, – if the number is A, as long as A-1, A-2, A-3, A-

4, ... 2 give a remainder, A is prime.

Page 90: Flow Charting

START

Page 91: Flow Charting

START

Read in A

Page 92: Flow Charting

START

Read in A

B = A -1

Page 93: Flow Charting

START

Read in A

B = A -1

Is B = = 1?

Page 94: Flow Charting

START

Read in A

B = A -1

NoIs B = = 1?

Page 95: Flow Charting

START

Read in A

B = A -1

NoIs B = = 1?

Does A/B give a

remainder?

Page 96: Flow Charting

START

Read in A

B = A -1

NoIs B = = 1?

YesDoes

A/B give a remainder?

Page 97: Flow Charting

START

Read in A

B = A -1

NoB = B - 1 Is B = = 1?

YesDoes

A/B give a remainder?

Page 98: Flow Charting

START

Read in A

B = A -1

NoB = B - 1 Is B = = 1?

YesDoes

A/B give a remainder?

Page 99: Flow Charting

START

Read in A

B = A -1

NoB = B - 1 Is B = = 1?

YesDoes

A/B give a remainder?

No

Print “Not Prime”

Page 100: Flow Charting

START

Yes

Read in A

Print “Prime”

B = A -1

NoB = B - 1 Is B = = 1?

No

Print “Not Prime”

YesDoes

A/B give a remainder?

Page 101: Flow Charting

START

END

Yes

Read in A

Print “Prime”

B = A -1

NoB = B - 1 Is B = = 1?

No

Print “Not Prime”

YesDoes

A/B give a remainder?

Page 102: Flow Charting

Symbols

Page 103: Flow Charting

Symbols

Page 104: Flow Charting

Terminal

Input/Output Operation

Process

Decision

Connector

Module

Symbols