Prasad Sawant MIT Pune India FLOW CHART Chapter

  • Slides: 27
Download presentation
Prasad Sawant MIT Pune India FLOW CHART Chapter 1: Introduction To Flowchart | Introduction

Prasad Sawant MIT Pune India FLOW CHART Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 1

Figure 1 -11: Process of system development Building programs • Edit • Compile •

Figure 1 -11: Process of system development Building programs • Edit • Compile • Link • Run Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 2

Figure 1 -11: Process of system development Understand the problem: • Input • Output

Figure 1 -11: Process of system development Understand the problem: • Input • Output • Process Develop the solution (Algorithm): • Structure chart • Pseudocode • Flowchart Converting design to computer codes. e. g: Flowchart -> C program Algorithm is the steps to solve problems Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 3

Figure 1 -12: Structure chart example Chapter 1: Introduction To Flowchart | Introduction to

Figure 1 -12: Structure chart example Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 4

Pseudocode: Describe an algorithm in English-like statements Example: Algorithm for multiplying two numbers 1.

Pseudocode: Describe an algorithm in English-like statements Example: Algorithm for multiplying two numbers 1. 2. 3. 4. Get the first number, let say A Get the second number, let say B Calculate the result let say C, C= A * B Display the result, C Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 5

Today’s Topics • Flowchart Symbols • Control Structures Chapter 1: Introduction To Flowchart |

Today’s Topics • Flowchart Symbols • Control Structures Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 6

Flowchart: Represents an algorithm in graphical symbols Example: Algorithm for multiplying two numbers Chapter

Flowchart: Represents an algorithm in graphical symbols Example: Algorithm for multiplying two numbers Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 7

Flowchart Symbols Terminal: Used to indicates the start and end of a flowchart. Single

Flowchart Symbols Terminal: Used to indicates the start and end of a flowchart. Single flowline. 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 flowline enters and one flowline exits. Input/Output: Used whenever data is entered (input) or displayed (output). One flowline enters and one flowline exits. Decision: Used to represent operations in which there are two possible selections. One flowline enters and two flowlines (labelled as “Yes” and “No”) exit. Function / Subroutine: Used to identify an operation in a separate flowchart segment (module). One flowline enters and one flowline exits. On-page Connector: Used to connect remote flowchart portion on the same page. One flowline enters and one flowline exits. Off-page Connector: Used to connect remote flowchart portion on different pages. One flowline enters and one flowline exits. Comment: Used to add descriptions or clarification. Flowline: Used to indicate the direction of flow of control. Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 8

Example: Start Terminal. Program start here Input. Enter values for A and B Process

Example: Start Terminal. Program start here Input. Enter values for A and B Process Output Stop Terminal Program end here Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 9

Example: Use of comments/description Chapter 1: Introduction To Flowchart | Introduction to Programming and

Example: Use of comments/description Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 10

Example: Use of connectors on the same page. 1 - connection on the same

Example: Use of connectors on the same page. 1 - connection on the same flowchart portion 2 - connection on the different flowchart portion Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 11

Example: Use of connectors on the different page. Page 2 Page 1 Chapter 1:

Example: Use of connectors on the different page. Page 2 Page 1 Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 12

The details (how the function works) we put in another flowchart. This also known

The details (how the function works) we put in another flowchart. This also known as Function-Definition Example: Function-call example. Note: Module = function = subroutine Page 1 Page 2 Start terminal for a Function is different. Do not use “Start” Body of a function is the same with normal flowchart At this part, we only know what we want to do. But we don’t know how to do it This part also known as Function-Call End terminal must be “Return” Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 13

Control Structures • Describe the flow of execution • Basic types of control structure:

Control Structures • Describe the flow of execution • Basic types of control structure: • Sequential • Selection • Repeatition Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 14

Sequential Structure Multiple statements considered as one statement Statement simply means command or instruction

Sequential Structure Multiple statements considered as one statement Statement simply means command or instruction statement Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 15

Selection Structure If (one-choice) “do or don’t” condition TRUE FALSE statement ° If set

Selection Structure If (one-choice) “do or don’t” condition TRUE FALSE statement ° If set condition is true, execute the statement, else do nothing Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 16

Selection Structure (cont. . ) If-else (two-choices) “do this or do that” TRUE FALSE

Selection Structure (cont. . ) If-else (two-choices) “do this or do that” TRUE FALSE condition Statement 1 Statement 2 statement ° If set condition is true, execute the first statement, else execute second statement Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 17

Selection Structure (cont. . ) Nested if (if within if) FALSE test 1 TRUE

Selection Structure (cont. . ) Nested if (if within if) FALSE test 1 TRUE FALSE test 2 TRUE ° ° statement Considered as one statement ° ° it is an “one-choice” if Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 18

Selection Structure (cont. . ) Complex if-else & if Statements x FALSE condition TRUE

Selection Structure (cont. . ) Complex if-else & if Statements x FALSE condition TRUE statement TRUE condition FALSE statement ° ° Chapter 1: Introduction To Flowchart Considered as one statement | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 19

Repeatition Structure while Loop (pre-test loop) ° condition conditio n TRUE body of loop

Repeatition Structure while Loop (pre-test loop) ° condition conditio n TRUE body of loop FALSE statement While a set condition is true, repeat statement (body of loop) Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 20

Repeatition Structure (cont…) do-while Loop (post-test loop) ° statement condition statement TRUE FALSE Do

Repeatition Structure (cont…) do-while Loop (post-test loop) ° statement condition statement TRUE FALSE Do the statement (body of loop) while a condition is true Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 21

Repeatition Control Structure (cont…) for Loop (pre-test loop) x initialization ° FALSE condition TRUE

Repeatition Control Structure (cont…) for Loop (pre-test loop) x initialization ° FALSE condition TRUE body of loop increment y Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 22

Example: Input: Length <- 5 Width <- 3 Process: Area = 5 * 3

Example: Input: Length <- 5 Width <- 3 Process: Area = 5 * 3 = 15 Process: Perimeter = 2* (5+3) = 16 Output Area: 15 Perimeter: 16 Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 23

Example: What is the Output of the following flowchart when the input Num= 10

Example: What is the Output of the following flowchart when the input Num= 10 Enter a Number >> 10 Input: Num <- 10 Category A Num = 10 10 > 0 ? => YES Output: “Category A” Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 24

Example: What is the Output of the following flowchart when the input is Num=

Example: What is the Output of the following flowchart when the input is Num= 0 Enter a Number >> 0 Category B Category A Input: Num <- 0 Num = 0 0 > 0 ? => NO Output: “Category B” Output: “Category A” Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 25

Example: What is the Output of the following flowchart when the input is Num=

Example: What is the Output of the following flowchart when the input is Num= 4 Variables (in memory): Variables(in (inmemory): Input: Num <- 4 Num [[[ 444 ]]] Num Result 0710] 9 ]]] 0497 +++ 4312 Result [[[ 4 Count [[[ 4 1 ]]] 4312 --- 111 320 Enter a Number => 4 Count= Count ===4 132 0 4 => =>YES YES 132> 0 >>>0 000? ? => => YES NO Chapter 1: Introduction To Flowchart Count: 4 Count: 3 Count: 2 Count: 1 Count: 0 Result: 10 | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 26

Example: What is the Output of the following flowchart when the input is N

Example: What is the Output of the following flowchart when the input is N = 6 Page 1 average 10 Page 2 5 N=6 Sum = 10 + 5 + 6 average = 21/3 Output: Average: 7 Chapter 1: Introduction To Flowchart | Introduction to Programming and Prog in C | Prof. Prasad Sawant | Slide 27