Faculty of Computer Science & Information System

Slides:



Advertisements
Similar presentations
Introduction to Flowcharting
Advertisements

Introduction to Flowcharting
Flow Control Analysis & Design Tool: Flowcharts
Introduction to Flowcharting
Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Published by Addison-Wesley.
ME 142 Engineering Computation I Fundamentals of Procedural Computer Programming.
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
Program Design and Development
Algorithm & Flowchart Credit: Mr Ainullotfi.
(C)opyright 2003 Scott/Jones Publishers Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Scott/Jones Publishers.
ALGORITHMS AND FLOWCHARTS
CSC103: Introduction to Computer and Programming
Programming Techniques I SCJ1013
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
Chapter 2 - Algorithms and Design
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
Visual Basic Programming
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
(C)opyright 2000 Scott/Jones Publishers Introduction to Flowcharting.
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
Introduction to Computing Dr. Nadeem A Khan. Lecture 2.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
1 Introduction to Flowcharting Computer Science Principles ASFA.
FLOWCHARTING AND ALGORITHMS
Sesi 0607EKT120/4 Computer Programming Week 5 – Repetition / Loops.
Algorithm & Flowchart.
ALGORITHMS AND FLOWCHARTS
INTRODUCTION TO PROBLEM SOLVING
REPETITION CONTROL STRUCTURE
Lecture 7: Repeating a Known Number of Times
Python: Control Structures
GC211Data Structure Lecture2 Sara Alhajjam.
Introduction to Computing
CHAPTER 5A Loop Structure
Introduction to Flowcharting
Flowcharting: Decision Structure
Lecture 4 - Loops UniMAP EKT120 Sem 1 08/09.
Week 4 – Repetition Structures / Loops
Lecture 2 Introduction to Programming
Introduction To Flowcharting
ALGORITHM Basic CONCEPTS of Basic Concepts of Algorithm
Numbering System TODAY AND TOMORROW 11th Edition
Chapter 5: Loops and Files.
Chapter 5: Looping Starting Out with C++ Early Objects Seventh Edition
Introduction to Flowcharting
Flow Charts What are they good for?.
Chapter 5: Looping Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
ALGORITHMS AND FLOWCHARTS
Print slides for students reference
Control Structure Senior Lecturer
Control Structure Senior Lecturer
How to develop a program?
ALGORITHMS AND FLOWCHARTS
SME1013 PROGRAMMING FOR ENGINEERS
Introduction to Algorithms and Programming
` Structured Programming & Flowchart
ME 142 Engineering Computation I
SME1013 PROGRAMMING FOR ENGINEERS
Let’s all Repeat Together
More Loops Topics Counter-Controlled (Definite) Repetition
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Based on slides created by Bjarne Stroustrup & Tony Gaddis
More Loops Topics Counter-Controlled (Definite) Repetition
Basic Concepts of Algorithm
More Loops Topics Counter-Controlled (Definite) Repetition
More Loops Topics Counter-Controlled (Definite) Repetition
Introduction to Flowcharting
More Loops Topics Counter-Controlled (Definite) Repetition
More Loops Topics Counter-Controlled (Definite) Repetition
Presentation transcript:

Faculty of Computer Science & Information System Introduction To Flowcharting by Jumail Bin Taliba Faculty of Computer Science & Information System

Today’s Topics Flowchart Symbols Control Structures Some examples

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

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.

Example: Process Output Start Terminal. Program starts here Input. Enter values for A and B Process Output Stop Terminal Program ends here

Comments or description

Connectors on the same page 1- connection on the same flowchart portion 2- connection on the different flowchart portion

Connectors on a different page

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

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

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.

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

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

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

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

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

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

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

 Sequential Structure Multiple statements considered as one statement A statement means a command or an instruction statement statement  statement

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

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

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 

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

 ° 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)

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

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

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

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”

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”

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

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 = 10 + 5 + 6 average = 21/3 Output: Average: 7