Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

01 2 Introduction To Flowcharting

18,153 views

Published on

Published in: Technology, Spiritual
  • Be the first to comment

01 2 Introduction To Flowcharting

  1. 1. Introduction To Flowcharting by Jumail Bin Taliba Faculty of Computer Science & Information System
  2. 2. Today’s Topics <ul><li>Flowchart Symbols </li></ul><ul><li>Control Structures </li></ul><ul><li>Some examples </li></ul>
  3. 3. Flowchart: Represents an algorithm in graphical symbols Example: Algorithm for multiplying two numbers
  4. 4. Flowchart Symbols Flow line: Used to indicate the direction of flow of control. Comment: Used to add descriptions or clarification. Off-page Connector: Used to connect remote flowchart portion on different pages. One flow line enters and one flow line exits. On-page Connector: Used to connect remote flowchart portion on the same page. One flow line enters and one flow line exits. Function / Subroutine: Used to identify an operation in a separate flowchart segment (module). One flow line enters and one flow line exits. Decision: Used to represent operations in which there are two possible selections. One flow line enters and two flow lines (labeled as “Yes” and “No”) exit. Input/Output: Used whenever data is entered (input) or displayed (output). One flow line enters and one flow line exits. Process: Used whenever data is being manipulated. One flow line enters and one flow line exits. Terminal: Used to indicates the start and end of a flowchart. Single flow line. Only one “Start” and “Stop” terminal for each program. The end terminal for function/subroutine must use “Return” instead of “Stop”.
  5. 5. Example: Start Terminal. Program starts here Stop Terminal Program ends here Input. Enter values for A and B Process Output
  6. 6. Comments or description
  7. 7. Connectors on the same page 1- connection on the same flowchart portion 2- connection on the different flowchart portion
  8. 8. Connectors on a different page Page 1 Page 2
  9. 9. F unction The detail of how the function works is put in another flowchart. This is known as Function-Definition This flowchart calculates the average of three numbers Page 1 Page 2 End terminal must be a “Return” Start terminal for a Function is different. Do not use “Start” At this point, we only focus on what to do. How to do it, it comes later. This part is known as Function-Call Body of a function is the same with normal flowchart
  10. 10. Related terms and concepts This flowchart calculates the average of three numbers Page 1 Page 2 AVRG is the function name Objects enclosed by ( ) – result, n1, n2, n3 - are called parameters Parameters used in a function-call are called actual parameters result, n1, n2, n3 are actual parameters Parameters used in a function-definition are called formal parameters R, a, b, c are formal parameters <ul><li>Each formal parameter represents </li></ul><ul><li>an actual parameter according </li></ul><ul><li>to its order : </li></ul><ul><ul><li>R represents result , </li></ul></ul><ul><ul><li>a represents n1 , </li></ul></ul><ul><ul><li>b represents n2 , </li></ul></ul><ul><ul><li>c represents n3 </li></ul></ul><ul><li>The name of an actual parameter may be </li></ul><ul><li>different from its formal parameter </li></ul>
  11. 11. Related terms and concepts (cont.) In a function-definition, you should only use formal parameters – R, a, b, c You shouldn’t use actual parameters Page 1 Page 2 This is wrong! n1, n2, n3 are actual parameters. Should use a, b, c instead. This is wrong! R is an formal parameters. Should use result instead.
  12. 12. Page 1 Related terms and concepts (cont.) This flowchart calculates the average of three numbers Page 2 A function may be called more than once At this time: R represents average1 , a represents n1 , b represents n2 , c represents n3 When comes to this: R represents average2 , a represents n4 , b represents n5 , c represents n6
  13. 13. Related terms and concepts (cont.) <ul><li>A function parameter may act as: </li></ul><ul><ul><li>Input </li></ul></ul><ul><ul><ul><li>Data of the function </li></ul></ul></ul><ul><ul><li>Output </li></ul></ul><ul><ul><ul><li>The result of the function </li></ul></ul></ul><ul><ul><li>Both </li></ul></ul>
  14. 14. Related terms and concepts (cont.) This flowchart calculates the average of three numbers Page 1 Page 2 Function call: result is the output parameter . n1, n2, n3 are the input parameters. Function definition: R is the output parameter a, b, c are input parameters
  15. 15. Related terms and concepts (cont.) Page 1 Page 2 This flowchart exchanges or swaps the value of x and y each other Function call: p and q act as both input and output parameters. Function definition: x and y act as both input and output parameters
  16. 16. Related terms and concepts (cont.) If there is only one output parameter, the flowchart may “RETURN” the result Example: let take a look again at the function that calculates the average of three numbers. Original function flowchart: Since it has only one output, the output is “RETURN” Page 2 Page 2 The output parameter (R) is removed from the formal parameter list and the result is return
  17. 17. Related terms and concepts (cont.) Since the function flowchart has been modified, the way of the function to be called will also be changed Original main flowchart: Modified main flowchart: Page 1 Page 1 Now , result is not anymore a parameter of the function-call
  18. 18. Control Structure <ul><li>Describe the flow of execution. </li></ul><ul><li>In flowcharts, flow of execution is represented by the arrow line . </li></ul><ul><li>Types of control structure: </li></ul><ul><ul><li>Sequential </li></ul></ul><ul><ul><li>Selection </li></ul></ul><ul><ul><li>Repetition </li></ul></ul>
  19. 19. Sequential Structure statement statement Multiple statements considered as one statement  statement A statement means a command or an instruction
  20. 20. Selection Structure If (one-choice) condition statement ° FALSE If set condition is true, execute the statement, else do nothing “ do it or don’t” condition TRUE  statement
  21. 21. If-else (two-choices) Selection Structure ( cont.. ) condition Statement 2 Statement 1 ° If set condition is true, execute the first statement, else execute second statement TRUE FALSE “ do this one or the other one” condition  statement
  22. 22. Nested if (if within if) Selection Structure ( cont.. )  Considered as one statement test1 test2 statement ° ° FALSE FALSE TRUE TRUE test1 ° ° FALSE TRUE it is an “one-choice” if
  23. 23. Complex if-else & if Statements ° x condition statement condition statement ° statement TRUE TRUE FALSE FALSE Considered as one statement Selection Structure ( cont.. )
  24. 24. Repetition Structure while Loop It is a pre-test loop  While a set condition is true, repeat statement (body of loop) TRUE FALSE ° condition statement condition body of loop
  25. 25. do-while Loop It is a post-test loop Repetition Structure ( cont… )  FALSE TRUE Do the statement (body of loop) while a condition is true statement ° condition statement
  26. 26. for Loop It is a pre-test loop x initialization ° condition body of loop increment y FALSE TRUE Repetition Control Structure ( cont… )
  27. 27. Example: Input: Length <- 5 Width <- 3 Process: Area = 5 * 3 = 15 Process: Perimeter = 2* (5+3) = 16 Output Area: 15 Perimeter: 16
  28. 28. Example: What is the output of the following flowchart when the input Num= 10 Category A Num = 10 10 > 0 ? => YES Input: Num <- 10 Enter a Number >> 1 0 Output: “ Category A”
  29. 29. Example: What is the output of the following flowchart when the input is Num= 0 Category B Category A Num = 0 0 > 0 ? => NO Output: “ Category B” Input: Num <- 0 Enter a Number >> 0 Output: “ Category A”
  30. 30. Example: What is the output of the following flowchart when the input is Num= 4 <ul><li>Variables (in memory) : </li></ul><ul><ul><li>Num [ ] </li></ul></ul><ul><ul><li>Result [ ] </li></ul></ul><ul><ul><li>Count [ ] </li></ul></ul><ul><li>Variables (in memory) : </li></ul><ul><ul><li>Num [ 4 ] </li></ul></ul><ul><ul><li>Result [ 0 ] </li></ul></ul><ul><ul><li>Count [ 4 ] </li></ul></ul>Count: 4 <ul><li>Variables (in memory) : </li></ul><ul><ul><li>Num [ 4 ] </li></ul></ul><ul><ul><li>Result [ 4 ] 0 + 4 </li></ul></ul><ul><ul><li>Count [ 3 ] 4 - 1 </li></ul></ul>Count: 3 <ul><li>Variables (in memory) : </li></ul><ul><ul><li>Num [ 4 ] </li></ul></ul><ul><ul><li>Result [ 7 ] 4 + 3 </li></ul></ul><ul><ul><li>Count [ 2 ] 3 - 1 </li></ul></ul>Count: 2 <ul><li>Variables (in memory) : </li></ul><ul><ul><li>Num [ 4 ] </li></ul></ul><ul><ul><li>Result [ 9 ] 7 + 2 </li></ul></ul><ul><ul><li>Count [ 1 ] 2 - 1 </li></ul></ul>Count: 1 <ul><li>Variables (in memory) : </li></ul><ul><ul><li>Num [ 4 ] </li></ul></ul><ul><ul><li>Result [ 10 ] 9 + 1 </li></ul></ul><ul><ul><li>Count [ 0 ] 1 - 1 </li></ul></ul>Count: 0 Result: 10 Input: Num <- 4 Enter a Number => 4 <ul><li>Variables (in memory) : </li></ul><ul><ul><li>Num [ 4 ] </li></ul></ul><ul><ul><li>Result [ ] </li></ul></ul><ul><ul><li>Count [ ] </li></ul></ul>Count = 4 4 > 0 ? => YES Count = 3 3 > 0 ? => YES Count = 2 2 > 0 ? => YES Count = 1 1 > 0 ? => YES Count = 0 0 > 0 ? => NO
  31. 31. Page 1 Page 2 Example: What is the output of the following flowchart when the input is N = 6 average 10 5 N=6 Sum = 10 + 5 + 6 average = 21/3 Output: Average: 7

×