Create Presentation
Download Presentation

Download Presentation
## Flow Charting, Structured English and PseudoCode

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

**Flow Charting, Structured English and PseudoCode**Damian Gordon**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**Structured English and Pseudocode**Structured English Pseudocode PROGRAM PrintNumber: Read A; Print A; END. PROGRAM PrintNumber: Read in a number and print it out. 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**Structured English and Pseudocode**Structured English Pseudocode PROGRAM DoubleNumber: Read A; Print A*2; END. PROGRAM DoubleNumber: Read in a number and print double the number out. 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**Structured English and Pseudocode**Structured English Pseudocode PROGRAM DoubleNumber: Read A; B = A*2; Print B; END. PROGRAM DoubleNumber: Read in a number and print double the number out. 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**Structured English and Pseudocode**Structured English Pseudocode PROGRAM OddOrEven: Read A; IF A/2 gives a remainder THEN Print “It’s Odd”; ELSE Print “It’s Even”; ENDIF; END. PROGRAM OddOrEven: Read in a number. Divide it by two. If there is a remainder, the number is odd, otherwise it’s even. 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?**START**Read in A and B A>B? Print A Yes**START**Read in A and B A>B? Print A Print B No Yes**START**Read in A and B A>B? Print A Print B No Yes END**Structured English and Pseudocode**Structured English Pseudocode PROGRAM BiggerOfTwo : Read A; IF (A>B) THEN Print A; ELSE Print B; ENDIF; END. PROGRAM BiggerOfTwo: Read in a number. Read in a second number. If the first number is bigger, then print out that number, otherwise print out the other number. END.**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.**START**Read in A, B and C**START**Read in A, B and C A>B?**START**Read in A, B and C A>C? A>B? Yes**START**Read in A, B and C A>C? A>B? B>C? No Yes**START**Read in A, B and C A>C? A>B? B>C? No Yes No No Print C**START**Read in A, B and C A>C? A>B? B>C? No Yes Yes No No Print A Print C**START**Read in A, B and C A>C? A>B? B>C? No Yes Yes Yes No No Print A Print C Print B**START**Read in A, B and C A>C? A>B? B>C? No Yes Yes Yes No No Print A Print C Print B END**Structured English and Pseudocode**Structured English Pseudocode PROGRAM BiggerOfThree: Read A; Read B; Read C; IF A>B THEN IF A>C THEN Print A ELSE Print C END IF; ELSE IF B>C THEN Print B ELSE Print C END IF; END IF; END. PROGRAM BiggerOfThree: Read in a number. Read in a second number. Read in a third number. If the first number is bigger than the second, then if the first number is bigger than the third, then print out the first number, otherwise print out the third number number. If the first number is smaller than the second, then if the second number is bigger than the third, then print out the second number, otherwise print out the third number. END.**Flowcharts**• So let’s say we want to express the following algorithm: • Print out the numbers from 1 to 5