Download Presentation
## Tutorial #7 Flowcharts (reprise)

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -

**Tutorial #7Flowcharts (reprise)**Program Design**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?**Symbols**Decision Terminal Input/Output Operation Connector Module Process**Flowcharts**• So we start the program as: START**Flowcharts**• Our program will finish with the following: END**Flowcharts**• When we write programs, we assume that the computer executes the program starting at the beginning and working its way to the end. • This is a basic assumption of all algorithm design.**Flowcharts**• When we write programs, we assume that the computer executes the program starting at the beginning and working its way to the end. • This is a basic assumption of all algorithm design. • We call this SEQUENCE.**START**Statement1 Statement2 END**Flowcharts**• What if we want to make a choice, for example, do we want to add sugar or not to the tea?**Flowcharts**• What if we want to make a choice, for example, do we want to add sugar or not to the tea? • We call this SELECTION.**START**Is Sugar required? Add Sugar Don’t Add Sugar No Yes END**Flowcharts**• What if we need to tell the computer to keep doing something until some condition occurs?**Flowcharts**• What if we need to tell the computer to keep doing something until some condition occurs? • Let’s say we wish to indicate that the you need to keep filling the kettle with water until it is full.**Flowcharts**• What if we need to tell the computer to keep doing something until some condition occurs? • Let’s say we wish to indicate that the you need to keep filling the kettle with water until it is full. • We need a loop, or ITERATION.**START**Keep Filling Kettle Kettle is not full? No Yes END**Flowcharts**• So let’s say we want to express the following algorithm: • Read in a number and print it out.**START**Read in A**START**Read in A Print A**START**Read in A Print A END**Flowcharts**• So let’s say we want to express the following algorithm: • Read in a number and print it out double the number.**START**Read in A**START**Read in A Print A*2**START**Read in A Print A*2 END**START**Read in A**START**Read in A B = A*2**START**B = A * 2 can be read as “B gets the value of A multiplied by 2” Read in A B = A*2**START**Read in A B = A*2 Print B**START**Read in A B = A*2 Print B END**Flowcharts**• So let’s say we want to express the following algorithm: • Read in a number, check if it is odd or even.**START**Read in A**START**Read in A Does A/2 give a remainder?**START**Read in A Does A/2 give a remainder? Print “It’s Odd” Yes**START**Read in A Does A/2 give a remainder? Print “It’s Odd” Print “It’s Even” No Yes**START**Read in A Does A/2 give a remainder? Print “It’s Odd” Print “It’s Even” No Yes END**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.**START**Read in A and B**START**Read in A and B A>B?