Flow Charting, Structured English and PseudoCode

Slides:



Advertisements
Similar presentations
Understanding the Three Basic Structures
Advertisements

Lab #6 Program Design.
Prime Numbers and Prime Factorization
Prime Numbers and Prime Factorization
Prime Numbers and Prime Factorization. Factors Factors are the numbers you multiply together to get a product. For example, the product 24 has several.
4.2 Factors and Divisibility
Tutorial #6 PseudoCode (reprise)
5 Minute Check Complete in your notebook.
Flowcharts So let’s say we want to express the following algorithm to print out the sum of the biggest and smallest of three numbers.
Tutorial #7 Flowcharts (reprise) Program Design. Introduction We mentioned it already, that if we thing of an analyst as being analogous to an architect,
Flow Charting Damian Gordon. Introduction We mentioned it already, that if we thing of an analyst as being analogous to an architect, and a developer.
Developing logic (Examples on algorithm and flowchart)
(BASIC MATH) QUIZ. START!! Click Here!! 1. What is Addition? a. The act or process of adding numbers. The act or process of adding numbers. b. The act.
Factors Terminology: 3  4 =12
division algorithm Before we study divisibility, we must remember the division algorithm. r dividend = (divisor ⋅ quotient) + remainder.
ALGORITHMS AND FLOWCHARTS
Algebra Notes.
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
Python: Modularisation Damian Gordon. Modularisation Remember the prime checker program:
Selection: IF Statement Damian Gordon. adsdfsdsdsfsdfs dsdlkmfsdfmsdl kfsdmkfsldfmsk dddfsdsdfsd.
Prime Numbers and Prime Factorization. Factors Factors are the numbers you multiply together to get a product. For example, the product 24 has several.
Objectives The student will be able to: 7A: Find the prime factorization of a number, the greatest common factor (GCF) for a set of monomials and polynomials.
Iteration: WHILE Loop Damian Gordon. WHILE Loop Consider the problem of searching for an entry in a phone book with only SELECTION:
Solving Linear Equations To Solve an Equation means... To isolate the variable having a coefficient of 1 on one side of the equation. Examples x = 5.
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
Variables Damian Gordon. Variables We know what a variable is from maths. We’ve all seen this sort of thing in algebra: 2x – 10 = 0 2x = 10 X = 5.
Solving Equations Using Multiplication and Division 4 A.4f Apply these skills to solve practical problems. 4 A.4b Justify steps used in solving equations.
Basic Control Structures
Prime Factorization. Prime Numbers A Prime Number is a whole number, greater than 1, that can be evenly divided only by 1 or itself.
Modularisation Damian Gordon. Modularisation Let’s imagine we had code as follows:
Prime Numbers and Prime Factorization. Factors Factors are the numbers you multiply together to get a product. For example, the product 24 has several.
Sequence Damian Gordon. Pseudocode When we write programs, we assume that the computer executes the program starting at the beginning and working its.
Prime Numbers & Prime Factorization. Factors Factors are the numbers you multiply together to get a product. For example, the product 24 has several factors.
Fractions Shelby Ferreira. Vocabulary Numerator Denominator Proper fraction Improper fraction Mixed number.
One-Step Equations I can show that solving an equation leads to finding the value that makes the equation true.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding the Three Basic Structures Structure: a basic unit of programming logic Any program.
Drill #4 Evaluate the following if a = -2 and b = ½. 1. ab – | a – b | Solve the following absolute value equalities: 2. |2x – 3| = |5 – x | + 4.
Divisibility Tests How can you tell quickly whether a number can be divided exactly by another?
Prime Numbers Damian Gordon. Prime Numbers So let’s say we want to express the following algorithm: – Read in a number and check if it’s a prime number.
Division by 2 Any number that ends is 0, 2, 4, 6, or 8 is evenly divisible by 2.
CSCI 125 & 161 Lecture 12 Martin van Bommel. Prime Numbers Prime number is one whose only divisors are the number 1 and itself Therefore, number is prime.
Pseudocode Skill Area Materials Prepared by Dhimas Ruswanto, BMm.
Lecture Notes 1/20/05 Pseudocode.  Pseudocode standard which we will follow in this class: - Statements are written in simple English; - Each instruction.
Python: Structured Programming Damian Gordon. Structured Programming Remember the modularised version of the prime number checking program:
Prime and Composite Numbers A prime number is a natural number greater than 1 whose only factors are 1 and itself. The first few prime numbers are 2,
Exam practice. Exam 1  Describe how a Boolean expression can control the operation of a loop  Describe the difference between a while loop and for loop.
Prime Numbers and Prime Factorization
Prime Numbers and Prime Factorization
3x + 2 6x3 - 5x2 – 12x – 4 2x2 – 3x – 2 6x3 + 4x2 -9x2 – 12x -9x2 – 6x
Introduction to Python
ALGORITHMS AND FLOWCHARTS
Solving One-Step Equations
Prime Numbers and Prime Factorization
Prime Numbers.
Prime Numbers and Prime Factorization
ALGORITHMS AND FLOWCHARTS
Review Basic Math Divisibility tests Prime and Composite Numbers
Prime Numbers and Prime Factorization
Dr. Joe Anderson September 6, 2017
ALGORITHMS AND FLOWCHARTS
Python: Algorithms Damian Gordon.
Prime Numbers and Prime Factorization
Chapter 5: Control Structure
Prime Numbers and Prime Factorization
Bell work Week 20.
Structured Programming
Some Common Issues: Common Algorithms
Prime Factorization FACTOR TREE.
Prime Numbers and Prime Factorization
Prime Numbers and Prime Factorization
Presentation transcript:

Flow Charting, Structured English and PseudoCode Damian Gordon

We will recall...

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

START

START Read in A

START Read in A Print A

START Read in A Print A END

Structured English and Pseudocode PROGRAM PrintNumber: Read in a number and print it out. END. PROGRAM PrintNumber: Read 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

START Read in A

START Read in A Print A*2

START Read in A Print A*2 END

Structured English and Pseudocode PROGRAM DoubleNumber: Read in a number and print double the number out. END. PROGRAM DoubleNumber: Read A; Print A*2; END.

Or alternatively...

START

START Read in A

START Read in A B = A*2

“B gets the value of A multiplied by 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 PROGRAM DoubleNumber: Read in a number and print double the number out. END. PROGRAM DoubleNumber: Read 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

START Read in A

Does A/2 give a remainder? START Read in A Does A/2 give a remainder?

Does A/2 give a remainder? START Read in A Does A/2 give a remainder? Print “It’s Odd” Yes

Does A/2 give a remainder? START Read in A Does A/2 give a remainder? Print “It’s Odd” Print “It’s Even” Yes No

Does A/2 give a remainder? START Read in A Does A/2 give a remainder? Print “It’s Odd” Yes No Print “It’s Even” END

Structured English and Pseudocode PROGRAM OddOrEven: Read in a number. Divide it by two. If there is a remainder, the number is odd, otherwise it’s even. END. PROGRAM OddOrEven: Read A; IF A/2 gives a remainder THEN Print “It’s Odd”; ELSE Print “It’s Even”; ENDIF; 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

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 Yes No

START Read in A and B A>B? Print A Yes No Print B END

Structured English and Pseudocode 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. PROGRAM BiggerOfTwo : Read A; IF (A>B) THEN Print A; ELSE Print B; ENDIF; 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

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? Yes No

START Read in A, B and C A>C? A>B? B>C? Yes No No No Print C

A>C? A>B? B>C? START Read in A, B and C Yes Yes No No No Print A Print C

A>C? A>B? B>C? START Read in A, B and C Yes Yes No Yes No No Print A Print C Print B

A>C? A>B? B>C? START Read in A, B and C Yes Yes No Yes No No Print A Print C Print B END

Structured English and 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 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

START

START Print 1

START Print 1 Print 2

START Print 1 Print 2 Print 3

START Print 1 Print 2 Print 3 Print 4

START Print 1 Print 2 Print 3 Print 4 Print 5

START Print 1 Print 2 Print 3 Print 4 Print 5 END

Structured English and Pseudocode PROGRAM Print1to5: Print out 1. Print out 2. Print out 3. Print out 4. Print out 5. END. PROGRAM Print1to5: Print 1; Print 2; Print 3; Print 4; Print 5; END.

Or alternatively...

Flowcharts 14 + 1 A(old) 15 A(new) A = A + 1 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 14 + 1 A(old) 15 A(new)

START

START A = 1

START A = 1 Is A==6?

START A = 1 Is A==6? No Print A

START A = 1 A = A + 1 Is A==6? No Print A

START A = 1 A = A + 1 Is A==6? No Print A

START A = 1 A = A + 1 Is A==6? No Print A Yes END

Structured English and Pseudocode PROGRAM Print1to5: Keep printing out numbers until you reach 5. END. PROGRAM Print1to5: A = 1; WHILE (A != 6) DO Print A; A = A + 1; ENDWHILE; END.

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

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

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

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

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

T = X 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 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. 14 X 14 T

T = X + 1 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 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 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. + 1 14 X 15 T

T = T + X 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 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

Flowcharts 14 9 T(old) X 23 T(new) T = T + X 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 14 9 T(old) X 23 T(new)

Flowcharts So let’s say we want to express the following algorithm: Add up the numbers 1 to 5 and print out the result

START

START Total = 0

START Total = 0 A = 1

START Total = 0 A = 1 Is A==6?

START Total = 0 A = 1 Is A==6? No Total = Total + A;

START Total = 0 A = 1 A = A + 1 Is A==6? No Total = Total + A;

Is A==6? START Total = 0 A = 1 A = A + 1 No Total = Total + A; Yes Print Total

Is A==6? START Total = 0 A = 1 A = A + 1 No Total = Total + A; Yes Print Total END

Structured English and Pseudocode PROGRAM PrintSum1to5: Keep adding the numbers from 1 to 5. END. PROGRAM PrintSum1to5: Total = 0; A = 1; WHILE (A != 6) DO Total = Total + A; A = A + 1; ENDWHILE; Print Total; END.

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

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?

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.

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.

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.

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

Flowcharts So remember, So, in general, 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.

START

START Read in A

START Read in A B = A -1

START Read in A B = A -1 Is B = = 1?

START Read in A B = A -1 Is B = = 1? No

START Read in A B = A -1 Is B = = 1? No Does A/B give a remainder?

START Read in A B = A -1 Is B = = 1? No Does A/B give a remainder? Yes

START Read in A B = A -1 No B = B - 1 Yes Does A/B give a remainder? Is B = = 1? B = B - 1 No Does A/B give a remainder? Yes

START Read in A B = A -1 No B = B - 1 Yes Does A/B give a remainder? Is B = = 1? B = B - 1 No Does A/B give a remainder? Yes

START Read in A B = A -1 No B = B - 1 Yes Does A/B give a remainder? Is B = = 1? B = B - 1 No Does A/B give a remainder? Yes No Print “Not Prime”

START Read in A B = A -1 B = B - 1 No Yes Print “Prime” Does Is B = = 1? B = B - 1 No Yes Print “Prime” Does A/B give a remainder? Yes No Print “Not Prime”

START Read in A B = A -1 B = B - 1 No Yes Print “Prime” Does Is B = = 1? B = B - 1 No Yes Print “Prime” Does A/B give a remainder? Yes No Print “Not Prime” END

Structured English and Pseudocode PROGRAM Prime: Read A; B = A - 1; IsPrime=True; WHILE (B != 1) DO IF (A/B gives no remainder) THEN IsPrime= False; ENDIF; B = B – 1; ENDWHILE; IF (IsPrime == true) THEN Print “Prime”; ELSE Print “Not Prime”; END. PROGRAM Prime: Read in a number Divide that number by every number less than it, but greater than one. If any of them divide in evenly, then it’s not prime, otherwise it is prime. END.