Download presentation
Presentation is loading. Please wait.
Published bySucianty Muljana Modified over 5 years ago
1
Faculty of Computer Science & Information System
Introduction To Flowcharting by Jumail Bin Taliba Faculty of Computer Science & Information System
2
Today’s Topics Flowchart Symbols Control Structures Some examples
3
Flowchart: Represents an algorithm in graphical symbols Example: Algorithm for multiplying two numbers
4
Flowchart Symbols 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”. Process: Used whenever data is being manipulated. One flow line enters and one flow line exits. Input/Output: Used whenever data is entered (input) or displayed (output). 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. Function / Subroutine: Used to identify an operation in a separate flowchart segment (module). 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. Off-page Connector: Used to connect remote flowchart portion on different pages. One flow line enters and one flow line exits. Comment: Used to add descriptions or clarification. Flow line: Used to indicate the direction of flow of control.
5
Example: Process Output Start Terminal. Program starts here Input.
Enter values for A and B Process Output Stop Terminal Program ends here
6
Comments or description
7
Connectors on the same page
1- connection on the same flowchart portion 2- connection on the different flowchart portion
8
Connectors on a different page
9
Function The detail of how the function works
is put in another flowchart. This is known as Function-Definition Function Page 1 Start terminal for a Function is different. Do not use “Start” Page 2 Body of a function is the same with normal flowchart At this point, we only focus on what to do. How to do it, it comes later. This part is known as Function-Call End terminal must be a “Return” This flowchart calculates the average of three numbers
10
Related terms and concepts
Parameters used in a function-definition are called formal parameters R, a, b, c are formal parameters Related terms and concepts Page 1 Page 2 AVRG is the function name Objects enclosed by ( ) – result, n1, n2, n3 - are called parameters Each formal parameter represents an actual parameter according to its order: R represents result, a represents n1, b represents n2, c represents n3 The name of an actual parameter may be different from its formal parameter Parameters used in a function-call are called actual parameters result, n1, n2, n3 are actual parameters This flowchart calculates the average of three numbers
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
Related terms and concepts (cont.)
Page 1 Page 2 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 A function may be called more than once This flowchart calculates the average of three numbers
13
A function parameter may act as: Input
Related terms and concepts (cont.) A function parameter may act as: Input Data of the function Output The result of the function Both
14
Related terms and concepts (cont.)
Function definition: R is the output parameter a, b, c are input parameters Related terms and concepts (cont.) Page 1 Page 2 Function call: result is the output parameter. n1, n2, n3 are the input parameters. This flowchart calculates the average of three numbers
15
Related terms and concepts (cont.)
Function definition: x and y act as both input and output parameters Related terms and concepts (cont.) Page 1 Page 2 Function call: p and q act as both input and output parameters. This flowchart exchanges or swaps the value of x and y each other
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
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
Control Structure Describe the flow of execution.
In flowcharts, flow of execution is represented by the arrow line. Types of control structure: Sequential Selection Repetition
19
Sequential Structure Multiple statements considered as one statement
A statement means a command or an instruction statement statement statement
20
If set condition is true, execute the statement, else do nothing
Selection Structure If (one-choice) “do it or don’t” statement condition condition TRUE FALSE statement If set condition is true, execute the statement, else do nothing
21
If-else (two-choices)
Selection Structure (cont..) If-else (two-choices) “do this one or the other one” TRUE condition condition FALSE statement Statement 1 Statement 2 If set condition is true, execute the first statement, else execute second statement
22
Nested if (if within if)
Selection Structure (cont..) Nested if (if within if) test1 test2 statement FALSE TRUE test1 FALSE TRUE it is an “one-choice” if Considered as one statement
23
Complex if-else & if Statements
Selection Structure (cont..) Complex if-else & if Statements x FALSE condition TRUE statement TRUE statement condition FALSE statement Considered as one statement
24
° Repetition Structure while Loop It is a pre-test loop
condition body of loop condition FALSE statement TRUE While a set condition is true, repeat statement (body of loop)
25
do-while Loop It is a post-test loop
Repetition Structure (cont…) do-while Loop It is a post-test loop statement statement condition TRUE FALSE Do the statement (body of loop) while a condition is true
26
for Loop It is a pre-test loop
Repetition Control Structure (cont…) for Loop It is a pre-test loop x initialization FALSE condition TRUE body of loop increment y
27
Example: Output Area: 15 Perimeter: 16 Input: Length <- 5
Width <- 3 Process: Area = 5 * 3 = 15 Process: Perimeter = 2* (5+3) = 16 Output Area: 15 Perimeter: 16
28
Example: What is the output of the following flowchart when the input Num= 10 Input: Num <- 10 Enter a Number >> 10 Category A Num = 10 10 > 0 ? => YES Output: “Category A”
29
Example: What is the output of the following flowchart when the input is Num= 0 Input: Num <- 0 Enter a Number >> 0 Category B Category A Num = 0 0 > 0 ? => NO Output: “Category B” Output: “Category A”
30
Variables (in memory): Variables (in memory): Variables (in memory):
Example: What is the output of the following flowchart when the input is Num= 4 Variables (in memory): Num [ 4 ] Result [ ] Count [ ] Variables (in memory): Num [ ] Result [ ] Count [ ] Variables (in memory): Num [ 4 ] Result [ 4 ] 0 + 4 Count [ 3 ] 4 - 1 Variables (in memory): Num [ 4 ] Result [ 0 ] Count [ 4 ] Variables (in memory): Num [ 4 ] Result [ 7 ] 4 + 3 Count [ 2 ] 3 - 1 Variables (in memory): Num [ 4 ] Result [ 10] 9 + 1 Count [ 0 ] 1 - 1 Variables (in memory): Num [ 4 ] Result [ 9 ] 7 + 2 Count [ 1 ] 2 - 1 Input: Num <- 4 Enter a Number => 4 Count = 4 4 > 0 ? => YES Count = 3 3 > 0 ? => YES Count = 2 2 > 0 ? => YES Count: 4 Count = 0 0 > 0 ? => NO Count = 1 1 > 0 ? => YES Count: 3 Count: 2 Count: 1 Count: 0 Result: 10
31
Example: What is the output of the following flowchart when the input is N = 6 10 5 average Page 1 Page 2 N=6 Sum = average = 21/3 Output: Average: 7
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.