0% found this document useful (0 votes)
29 views41 pages

Introduction To Flowcharting AND PSEUDO-CODE

Introduction to Flowcharting AND PSEUDO-CODE

Uploaded by

Savinu Gamage
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views41 pages

Introduction To Flowcharting AND PSEUDO-CODE

Introduction to Flowcharting AND PSEUDO-CODE

Uploaded by

Savinu Gamage
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

CHAPTER 05

INTRODUCTION TO FLOWCHARTING AND PSEUDO -CODE


WHAT IS A FLOWCHART? START

Display message
“How many
hours did you
work?”

A flowchart is a diagram Read Hours

that depicts the “flow” of Display message

a program. “How much do


you get paid per
hour?”

The figure shown here is


a flowchart for the pay- Read Pay Rate

calculating program Multiply Hours


by Pay Rate.
Store result in
Gross Pay.

Display Gross
Pay

END
Rounded

BASIC FLOWCHART SYMBOLS START

Display message
Rectangle

“How many
hours did you
work?”

Notice there are three Read Hours

types of symbols in this Display message

flowchart: “How much do


you get paid per Parallelogram
hour?”
 rounded rectangles
 parallelograms Read Pay Rate

 a rectangle
Multiply Hours
by Pay Rate.
Each symbol represents a Rectangle Store result in
Gross Pay.
different type of
operation. Rounded
Display Gross
Pay
Rectangle
END
BASIC FLOWCHART SYMBOLS START Terminal

Display message
“How many
hours did you
work?”

Terminals Read Hours

 represented by rounded Display message


rectangles “How much do
you get paid per
 indicate a starting or ending hour?”

point
Read Pay Rate

Multiply Hours
by Pay Rate.
START Store result in
Gross Pay.

Display Gross
Pay

END Terminal
END
BASIC FLOWCHART SYMBOLS START

Display message
“How many
hours did you
work?”

Input/Output Operations Read Hours

 represented by parallelograms Display message


 indicate an input or output “How much do
you get paid per
Input/Output
Operation
operation hour?”

Read Pay Rate

Multiply Hours
by Pay Rate.
Display message Store result in
Gross Pay.
“How many
Read Hours
hours did you Display Gross

work?” Pay

END
BASIC FLOWCHART SYMBOLS START

Display message
“How many
hours did you
work?”

Processes Read Hours

 represented by rectangles Display message


 indicates a process such as a “How much do
you get paid per
mathematical computation or hour?”

variable assignment
Read Pay Rate

Multiply Hours
by Pay Rate.
Process Store result in
Multiply Hours Gross Pay.
by Pay Rate.
Store result in Display Gross
Pay
Gross Pay.
END
Stepping
STEPPING Through
THROUGH THE START
Output

FLOWCHART
Display message Operation
the Flowchart “How many
hours did you
work?”

Read Hours
How many
hours did
you work?
Display message
“How much do
you get paid per
hour?”

Read Pay Rate

Multiply Hours
by Pay Rate.
Store result in
Variable Contents: Gross Pay.

Hours: ? Display Gross


Pay Rate: ? Pay

Gross Pay: ? END


Stepping
STEPPING Through
THROUGH THE START

FLOWCHART
Display message

the Flowchart “How many


hours did you
work?”

How many
Input Read Hours
hours did Operation
you work?
(User types Display message
40
40) “How much do
you get paid per
hour?”

Read Pay Rate

Multiply Hours
by Pay Rate.
Store result in
Variable Contents: Gross Pay.

Hours: 40
Display Gross
Pay Rate: ? Pay

Gross Pay: ? END


Stepping
STEPPING Through
THROUGH THE START

FLOWCHART
Display message

the Flowchart “How many


hours did you
work?”

Read Hours
How much
do you get
paid per
Display message
hour?
“How much do
Output you get paid per
Operation hour?”

Read Pay Rate

Multiply Hours
by Pay Rate.
Store result in
Variable Contents: Gross Pay.

Hours: 40
Display Gross
Pay Rate: ? Pay

Gross Pay: ? END


Stepping
STEPPING Through
THROUGH THE START

FLOWCHART
Display message

the Flowchart “How many


hours did you
work?”

Read Hours
How much
do you get
paid per
Display message
hour? 20
“How much do
you get paid per
hour?”

Input Read Pay Rate


Operation
(User types Multiply Hours
20) by Pay Rate.
Store result in
Variable Contents: Gross Pay.

Hours: 40
Display Gross
Pay Rate: 20 Pay

Gross Pay: ? END


STEPPING THROUGH THE START

FLOWCHART Display message


“How many
hours did you
work?”

Read Hours
How much
do you get
paid per
Display message
hour?
“How much do
you get paid per
hour?”

Read Pay Rate

Multiply Hours
Process: The by Pay Rate.
Store result in
Variable Contents: product of 40
times 20 is
Gross Pay.

Hours: 40 stored in
Gross Pay Display Gross
Pay Rate: 20 Pay

Gross Pay: 800 END


STEPPING THROUGH THE START

FLOWCHART Display message


“How many
hours did you
work?”

Read Hours
Your gross
pay is 800
Display message
“How much do
you get paid per
hour?”

Read Pay Rate

Multiply Hours
by Pay Rate.
Store result in
Variable Contents: Gross Pay.

Hours: 40
Output Display Gross
Pay Rate: 20 Operation Pay

Gross Pay: 800 END


FOUR FLOWCHART STRUCTURES
Sequence
Decision
Repetition
Case
SEQUENCE STRUCTURE

a series of actions are performed in sequence


The pay-calculating example was a sequence
flowchart.
DECISION STRUCTURE

One of two possible actions is taken, depending


on a condition.
DECISION STRUCTURE

A new symbol, the diamond, indicates a yes/no question.


If the answer to the question is yes, the flow follows one
path. If the answer is no, the flow follows another path

NO YES
DECISION STRUCTURE

In the flowchart segment below, the question “is x < y?” is


asked. If the answer is no, then process A is performed. If
the answer is yes, then process B is performed.

NO YES
x < y?

Process A Process B
DECISION STRUCTURE

The flowchart segment below shows how a decision


structure is expressed in Java as an if/else statement.
Flowchart Java 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.
DECISION STRUCTURE

The flowchart segment below shows a decision structure


with only one action to perform. It is expressed as an if
statement in Java code.
Flowchart Java Code

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

Calculate a
as x times 2.
REPETITION STRUCTURE

Notice the use of the diamond symbol. A loop tests a


condition, and if the condition exists, it performs an action.
Then it tests the condition again. If the condition still exists,
the action is repeated. This continues until the condition no
longer exists.
REPETITION STRUCTURE

In the flowchart segment, the question “is x < y?” is asked.


If the answer is yes, then Process A is performed. The
question “is x < y?” is asked again. Process A is repeated
as long as x is less than y. When x is no longer less than y,
the repetition stops and the structure is exited.

YES
x < y? Process A
CONTROLLING A REPETITION STRUCTURE

By adding an action within the repetition that changes the


value of x.

YES
x < y? Display x Add 1 to x
A PRE-TEST REPETITION STRUCTURE

In a pre-test repetition structure, if the condition does not


exist, the loop will never begin.

YES
x < y? Display x Add 1 to x
A POST-TEST REPETITION STRUCTURE

This flowchart segment shows a post-test


repetition structure. Display x
The condition is tested AFTER the actions
are performed.
Add 1 to x
A post-test repetition structure always
performs its actions at least once.
YES
x < y?
CASE STRUCTURE
CASE STRUCTURE

One of several possible actions is taken, depending on


the contents of a variable.

The structure below indicates actions to perform


depending on the value in years_employed.
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


CONNECTORS
Sometimes a flowchart will not fit on one page.
A connector (represented by a small circle) allows you to connect two
flowchart segments.

A
CONNECTORS

•The “A” connector


A
indicates that the second START

flowchart segment begins


where the first segment
ends.

END
A
ANSWER
What do each of the following symbols represent?

Decision
Terminal

Input/Output
Operation Connector

Process Module
INTRODUCTION TO PSEUDO CODE CHAPTER 05
Flowcharts and Pseudo-code
PSEUDO CODE AND FLOW CHARTS
There are two commonly used tools to help to document program logic
(the algorithm).
These are
 Flowcharts
 Pseudocode.

Generally, flowcharts work well for small problems but Pseudocode is


used for larger problems.

32
PSEUDO-CODE
Pseudo-Code is simply a numbered list of instructions to perform some task.
Statements are written in simple English without regard to the final programming
language.
Each instruction is written on a separate line.
The pseudo-code is the program-like statements written for human readers, not for
computers. Thus, the pseudo-code should be readable by anyone who has done a little
programming.
Implementation is to translate the pseudo-code into programs/software, such as “Java”
language programs.

33
BASIC ELEMENTS OF PSEUDO-CODE
A Variable
 Having name and value
 There are two operations performed on a
variable
 Assignment Operation: associate a value
to a variable.
 Read Operation : retrieve the value
previously assigned to the variable

34
BASIC ELEMENTS OF PSEUDO-CODE
Assignment Operation
 This operation associates a value to a
variable.
 Some of the possible syntaxes are:
 Assign 3 to x
 Set x equal to 3
 x=3

35
BASIC OPERATIONS OF PSEUDO-CODE
Read Operation
 In this operation we intend to retrieve the
value previously assigned to that variable.
x=5
y=10
m = x+y
Read the input from user
 This operation causes the algorithm to get the
value of a variable from the user.
 Get x
 Get a, b, c
36
BASIC OPERATIONS OF PSEUDO-CODE
Print the output to the user
 Print x (This will print value of variable x)
 Output “Your mileage is” x

37
EXAMPLE: PSEUDO-CODE OF CALCULATING AREA OF CIRCLE

1. Begin
2. Input value for radius
2
3. Calculate area (pi x radius )
4. Output radius and area
5. Quit

38
DECISION MAKING AND PSEUDO CODE

You might also like