Flowchart
Flowchart
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
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.
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.
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
13
Connectors
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?
Input/Output
Operation Connector
Process Module
17
Review
• Name the four flowchart structures.
19
Review
• What type of structure is this?
21
Review
• What type of structure is this?
23
Review
• What type of structure is this?
25
Review
• What type of structure is this?
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.
Sequence Action
Selection Decision
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
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
IF,THEN,ELSE,ENDIF IF-THEN-ELSE
WHILE,DO,ENDWHILE LOOP
CASE,OF,OTHERS,ENDCASE A CASE
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
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