Download presentation
Presentation is loading. Please wait.
1
Flow Charting Damian Gordon
2
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?
4
Flowcharts So let’s say we want to express the following algorithm: – Read in a number and print it out.
5
START
6
Read in A
7
START Read in A Print A
8
START END Read in A Print A
9
Flowcharts So let’s say we want to express the following algorithm: – Read in a number and print it out double the number.
10
START
11
Read in A
12
START Read in A Print A*2
13
START END Read in A Print A*2
14
Or alternatively...
15
START
16
Read in A
17
START Read in A B = A*2
18
START Read in A B = A * 2 can be read as “B gets the value of A multiplied by 2” B = A*2
19
START Read in A Print B B = A*2
20
START END Read in A Print B B = A*2
21
Flowcharts So let’s say we want to express the following algorithm: – Read in a number, check if it is odd or even.
22
START
23
Read in A
24
START Does A/2 give a remainder? Read in A
25
START Does A/2 give a remainder? Read in A Yes Print “It’s Odd”
26
START Does A/2 give a remainder? No Read in A Yes Print “It’s Odd”Print “It’s Even”
27
START END Does A/2 give a remainder? No Read in A Yes Print “It’s Odd”Print “It’s Even”
28
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.
29
START
30
Read in A and B
31
START A>B? Read in A and B
32
START A>B? Read in A and B Yes Print A
33
START A>B? No Read in A and B Yes Print APrint B
34
START END A>B? No Read in A and B Yes Print APrint B
35
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.
36
START
37
Read in A, B and C
38
START A>B? Read in A, B and C
39
START A>B? Read in A, B and C Yes A>C?
40
START A>B? No Read in A, B and C Yes A>C?B>C?
41
START A>B? No Read in A, B and C Yes A>C?B>C? Print C No
42
START A>B? No Read in A, B and C Yes A>C?B>C? Print APrint C Yes No
43
START A>B? No Read in A, B and C Yes A>C?B>C? Print APrint CPrint B Yes No
44
START END A>B? No Read in A, B and C Yes A>C?B>C? Print APrint CPrint B Yes No
45
Flowcharts So let’s say we want to express the following algorithm: – Print out the numbers from 1 to 5
46
START
47
Print 1
48
START Print 1 Print 2
49
START Print 1 Print 2 Print 3
50
START Print 1 Print 2 Print 3 Print 4
51
START Print 1 Print 2 Print 3 Print 4 Print 5
52
START END Print 1 Print 2 Print 3 Print 4 Print 5
53
Or alternatively...
54
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) 15 A (old) 14 + 1 A = A + 1
55
START
56
A = 1
57
START Is A==6? A = 1
58
START Is A==6? No A = 1 Print A
59
START Is A==6? No A = 1 Print A A = A + 1
60
START Is A==6? No A = 1 Print A A = A + 1
61
START END Is A==6? No A = 1 Yes Print A A = A + 1
62
Flowcharts So let’s say we want to express the following algorithm: – Add up the numbers 1 to 5
63
Flowcharts But first a few points; If I say T = 5, that means “T gets the value 5” T = 5
64
Flowcharts But first a few points; If I say T = 5, that means “T gets the value 5” T T = 5
65
Flowcharts But first a few points; If I say T = 5, that means “T gets the value 5” T 5 T = 5
66
Flowcharts If I say T = X, that means “T gets the value of whatever is in the variable X” T = X
67
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
68
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 14 T = X
69
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
70
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
71
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 15 14+ 1 T = X + 1
72
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
73
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
74
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) X 23 9 T (old) 14 T = T + X
75
Flowcharts So let’s say we want to express the following algorithm: – Add up the numbers 1 to 5
76
START
77
Total = 0
78
START A = 1 Total = 0
79
START Is A==6? A = 1 Total = 0
80
START Is A==6? No A = 1 Total = Total + A; Total = 0
81
START Is A==6? No A = 1 Total = Total + A; A = A + 1 Total = 0
82
START END Is A==6? No A = 1 Yes Total = Total + A; A = A + 1 Total = 0
83
Flowcharts So let’s say we want to express the following algorithm: – Read in a number and check if it’s a prime number.
84
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?
85
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.
86
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.
87
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.
88
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
89
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.
90
START
91
Read in A
92
START Read in A B = A -1
93
START Read in A B = A -1 Is B = = 1?
94
START Read in A B = A -1 No Is B = = 1?
95
START Read in A B = A -1 No Is B = = 1? Does A/B give a remainder?
96
START Read in A B = A -1 No Is B = = 1? Yes Does A/B give a remainder?
97
START Read in A B = A -1 No B = B - 1 Is B = = 1? Yes Does A/B give a remainder?
98
START Read in A B = A -1 No B = B - 1 Is B = = 1? Yes Does A/B give a remainder?
99
START Read in A B = A -1 No B = B - 1 Is B = = 1? Yes Does A/B give a remainder? No Print “Not Prime”
100
START Yes Read in A Print “Prime” B = A -1 No B = B - 1 Is B = = 1? No Print “Not Prime” Yes Does A/B give a remainder?
101
START END Yes Read in A Print “Prime” B = A -1 No B = B - 1 Is B = = 1? No Print “Not Prime” Yes Does A/B give a remainder?
102
Symbols
104
Terminal Input/Output Operation Process Decision Connector Module Symbols
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.