Introduction To Flowcharting AND PSEUDO-CODE
Introduction To Flowcharting AND PSEUDO-CODE
Display message
“How many
hours did you
work?”
Display Gross
Pay
END
Rounded
Display message
Rectangle
“How many
hours did you
work?”
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?”
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?”
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?”
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?”
Multiply Hours
by Pay Rate.
Store result in
Variable Contents: Gross Pay.
FLOWCHART
Display message
How many
Input Read Hours
hours did Operation
you work?
(User types Display message
40
40) “How much do
you get paid per
hour?”
Multiply Hours
by Pay Rate.
Store result in
Variable Contents: Gross Pay.
Hours: 40
Display Gross
Pay Rate: ? Pay
FLOWCHART
Display message
Read Hours
How much
do you get
paid per
Display message
hour?
“How much do
Output you get paid per
Operation hour?”
Multiply Hours
by Pay Rate.
Store result in
Variable Contents: Gross Pay.
Hours: 40
Display Gross
Pay Rate: ? Pay
FLOWCHART
Display message
Read Hours
How much
do you get
paid per
Display message
hour? 20
“How much do
you get paid per
hour?”
Hours: 40
Display Gross
Pay Rate: 20 Pay
Read Hours
How much
do you get
paid per
Display message
hour?
“How much do
you get paid per
hour?”
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
Read Hours
Your gross
pay is 800
Display message
“How much do
you get paid per
hour?”
Multiply Hours
by Pay Rate.
Store result in
Variable Contents: Gross Pay.
Hours: 40
Output Display Gross
Pay Rate: 20 Operation Pay
NO YES
DECISION STRUCTURE
NO YES
x < y?
Process A Process B
DECISION STRUCTURE
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
NO YES if (x < y)
x < y? a = x * 2;
Calculate a
as x times 2.
REPETITION STRUCTURE
YES
x < y? Process A
CONTROLLING A REPETITION STRUCTURE
YES
x < y? Display x Add 1 to x
A PRE-TEST REPETITION STRUCTURE
YES
x < y? Display x Add 1 to x
A POST-TEST REPETITION 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
A
CONNECTORS
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.
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