0% found this document useful (0 votes)
4 views

Flowchart

Python Flowchart

Uploaded by

PPTV
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Flowchart

Python Flowchart

Uploaded by

PPTV
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 41

Introduction to

Flowcharting

1
Flowchart
•A flow chart is a diagrammatic representation that illustrates the
sequence of operations to be performed to arrive at the solutions.
•Each step in the process is represented by a different symbol and
contains a of the process step.
•The flowchart symbols are linked together with arrows showing the flow
of directions.

2
3
Rules for drawing a flowchart

•The standard symbols should only be used.


•The arrowheads in the flowchart represent the direction of flow in
the problem.
•The direction of the flow from top to bottom (or) left to right.
•The flow lines should not cross each other.
•Keep flowchart as simple as possible.
•Words in the flowchart should be common and easy to understand.
•More than one flowcharts connected by using connectors.

4
Advantages of flowchart.

•Communication.
•Effective analysis.
•Proper documentation.
•Efficient coding.
•Proper Testing and Debugging.
•Efficient Program Maintenance.

5
Four Flowchart Structures
• Sequence
• Decision
• Repetition
• Case

6
Sequence Structure
• A series of actions are performed in sequence
• The pay-calculating example was a sequence
flowchart.

7
Decision Structure
• The flowchart segment below shows how a decision
structure is expressed in C++ as an if/else statement.

Flowchart C++ Code

NO YES if (x < y)
x < y? a = x * 2;
else
Calculate a Calculate a a = x + y;
as x plus y. as x times 2.

8
Decision Structure
• The flowchart segment below shows a decision structure
with only one action to perform. It is expressed as an if
statement in C++ code.
Flowchart C++ Code

NO YES if (x < y)
x < y? a = x * 2;

Calculate a
as x times 2.

9
Repetition Structure
• The flowchart segment below shows a repetition structure
expressed in C++ as a while loop.

Flowchart C++ Code

while (x < y)

YES x++;
x < y? Add 1 to x

10
Controlling a Repetition
Structure
• The action performed by a repetition structure must
eventually cause the loop to terminate. Otherwise, an
infinite loop is created.
• In this flowchart segment, x is never changed. Once the
loop starts, it will never end.
• QUESTION: How can this
YES
flowchart be modified so x < y? Display x
it is no longer an infinite
loop?

11
Controlling a Repetition
Structure
• ANSWER: By adding an action within the repetition that
changes the value of x.

YES
x < y? Display x Add 1 to x

12
Case Structure

If years_employed = 2, If years_employed = 3,
bonus is set to 200 bonus is set to 400
If years_employed = 1, If years_employed is
CASE
bonus is set to 100 years_employed any other value, bonus
is set to 800

1 2 3 Other

bonus = 100 bonus = 200 bonus = 400 bonus = 800

13
Connectors

•The “A” connector


indicates that the second START A

flowchart segment begins


where the first segment
ends.

END
A

14
Combining Structures
• This flowchart segment
shows two decision NO YES
structures combined. x > min?

Display “x is NO YES
outside the limits.”
x < max?

Display “x is Display “x is
outside the limits.” within limits.”

15
Review
• What do each of the following symbols
represent?

(Answer on next slide)


16
Answer
• What do each of the following symbols
represent?
Decision
Terminal

Input/Output
Operation Connector

Process Module

17
Review
• Name the four flowchart structures.

(Answer on next slide)


18
Answer
• Sequence
• Decision
• Repetition
• Case

19
Review
• What type of structure is this?

(Answer on next slide)


20
Answer
• Repetition

21
Review
• What type of structure is this?

(Answer on next slide)


22
Answer
• Sequence

23
Review
• What type of structure is this?

(Answer on next slide)


24
Answer
• Case

25
Review
• What type of structure is this?

(Answer on next slide)


26
Answer
• Decision

27
28
Examples ???

29
BUILDING BLOCKS OF ALGORITHMS
Statements
A statement is a command given to the computer that instructs the computer to
take a specific action, such as display to the screen, or collect input. A computer
program is made up of a series of statements.
State
State is information your program manipulates to accomplish some task. It is data
or information that gets changed or manipulated throughout the runtime of a
program.
Control Flow Statements
– if statements
– for loops
– while loops
Functions
•A function is a block of organized, reusable code that is used to perform a single, related action.
Functions provide better modularity for your application and a high degree of code reusing.
•Other Terms: methods, sub-routines, procedure
30
The three building blocks are Sequence, Selection, and Iteration.
An Action is one or more instructions that the computer performs in sequential order (from
first to last).
Example: Compute 10 plus 30.
A Decision is making a choice among several actions.
Example: If value of A is greater than B, then print “A is Greater” otherwise
print “B is Greater”
A Loop is one or more instructions that the computer performs repeatedly.
Example: Print "HAVE A GOOD DAY" 50 times.

Building Block Common name

Sequence Action

Selection Decision

Iteration Repetition or Loop

31
Example 1:Even or odd
•Step 1: Start
•Step 2: [ Take Input ] Read: N
•Step 3: Check: If N%2 == 0 Then
•Print : N is an Even Number.
•Else
•Print : N is an Odd Number.
•Step 4: Exit

32
NOTATION

• A series or system of written symbols used to represent


numbers, amounts, or elements in something such as music
or mathematics.
• A notation can be a pseudo code, flow chart or any
programming language.

33
Pseudocode
•An alternative method of representing program logic is a pseudocode.
•A narrative description of the flow and logic of the intended program, written in plain
language that expresses each step of the algorithm
•Instead of using symbols to represent the program logic steps, a pseudocode uses
statements which act as ab ridge between actual programming and ordinary english.
•In a pseudocode, a designer describes system characteristics using simple english language
phrases with the help of keywords like while,if.else,end,etc..

34
Advantages of Pseudo Code
•Since it is independent of any language, it can be used by most programmers.
•It is easy to develop a program from pseudo code than with a flowchart.
•It is easy to translate pseudo code into a programming language.
•Pseudo code is compact and does not tend to run over many pages.
Disadvantages of Pseudo Code
•It does not provide visual representation of the program’s logic.
•There are no accepted standards for writing pseudo codes.
•It cannot be compiled nor executed.

35
Keywords for using
Input
Pseudocode
STATEMENTS

READ,OBTAIN,GET
KEYWORDS

Output PRINT,DISPLAY,SHOW

Compute COMPUTE,CALCULATE,DETERMINE

Initialize SET,INIT

Add one INCREMENT,BUMP

Input,Output,Compute,Initialize,Add one SEQUENCE

IF,THEN,ELSE,ENDIF IF-THEN-ELSE

Sequence one THEN--IF

Sequence two ELSE—IF

End of IF conditional ENDIF

WHILE,DO,ENDWHILE LOOP

CASE,OF,OTHERS,ENDCASE A CASE

Multi-way branch based on conditions CASE


36
REPEAT,UNTIL loop REPEAT-UNTIL

REPEAT Sequence REPEAT

determines the ending point of a REPEAT Sequence UNTIL

FOR loop FOR,TO,DOWNTO,ENDFOR,DO


Iterate with index i from n to m DOWNTO

Iterate with index i from m to n TO

FOR Conditional followed by command FOR

End of FOR loop ENDFOR

The use of conditional statements inside of other conditional


NESTED CONSTRUCTS
statements

INVOKING SUBPROCEDURES CALL,RETURN

Calls in and executes a command CALL

returns desired information RETURN

EXCEPTION HANDLING BEGIN,EXCEPTION,WHEN,END

identifies start of BEGIN block BEGIN

identifies start of exception construct EXCEPTION

individual condition precedence for each exception type WHEN

End of the BEGIN block END

RETURN A--Procedure returns value A and ends its


return statement example execution
37
Example for Pseudocode
Accept two numbers,add them and display
the result.
•START
•ACCEPT N1
•ACCEPT N2
•SUM=N1+N2
•DISPLAY SUM
•END

38
Programming Language

39
Definition of programming language
A programming language is a set of commands, instructions, and other
syntax that are used to create a software program
COMPILER

INTERPRETER

40
Interpreter Compiler

Scans the entire program and translates it as a whole into


Translates program one statement at a time.
machine code.

It takes less amount of time to analyze the source code but It takes large amount of time to analyze the source code but the
the overall execution time is slower. overall execution time is comparatively faster.

No intermediate object code is generated, hence are Generates intermediate object code which further requires
memory efficient. linking, hence requires more memory.

Continues translating the program until the first error is It generates the error message only after scanning the whole
met, in which case it stops. Hence debugging is easy. program. Hence debugging is comparatively hard.

Programming language like Python, Ruby use interpreters. Programming language like C, C++ use compilers.

41

You might also like