c2_problemsolvingandalgorithm
c2_problemsolvingandalgorithm
PROGRAMMING COMPONENT
HISTORY
Maintai
Proble
n&
Update m
Implem
ent Design
DEVELOPMENT LIFECYCLE
Gain a clear understanding of what are
required for its solution.
Problem
State the problem clearly
PROBLEM
Is it possible to solve the
problem with
programming?
EXAMPLE 1
Problem
Input
data
Analyze
IPO Process
requirements/constraints
problem
Output
desired results
EXAMPLE 1
Given the value of x is 10 and a is 12,
find the result of the following equation: Analysis
y = 2x + a - 6
Input
data x = 10, a =
12
Process
Requirements/
Replace x and a
Analyze constraints y = 2x + a - 6
problem
Output
Value of
Desired results
y
Uncle Chen wants to buy 5 cans of paint from
Linda’s shop. The price for each of the paint can is
RM 15.60. Calculate the total price of all Example 2
the paint cans.
PROBLEM ANALYSIS
Problem What is the Input 1 can paint =
price for 5 cans RM 15.60
of paint? No. of cans = 5
Data 1 can paint = Process Total price cans of
RM 15.60 paint = RM 15.60 x
5
Solution Calculate the Output Total price 5
total price cans of paint
Madam Sue needs to determine her students grade for
Example 3
programming subject based on the mark scored during final
examination. The ‘A’ grade will be given if the mark scored is
between 85 to 100. If a student has scored 90 marks, what is the
grade should Madam Sue give to the student?
PROBLEM ANALYSIS
Problem What is the grade Input Mark = 90
for student who
scored 90 marks
Data Process A = if 85 < mark
Student marks
< 100
Solution Determine Output Grade for
grade based students with 90
on marks marks
Exercise 1
Solve
Algorith List of problem
Design m steps
algorithm
List of steps
• Insert ATM card
• Select language
Pseudocode Flowchart
Simple codes which
A text-based
resembles program
design tool that
code that will be
Natural Language helps programmers
written during
to develop
implementation phase
algorithm
(program coding)
Pseudocode
Consists of a statement of instructions in sequence.
Pseudocod
Every steps should be written in different steps, if continued,
the next row must be indented.
e Rules Can use if/else for conditional statement and while, do/while
and for repetition statement
Input Pseudocod
data
e?
x = 10, a = 12
Process
start
Requirements/ read the value of x
constraints
read the value of a
Replace x and a
y = 2x + a - 6 compute the value of y as y = 2x + a -6
display/print the value of y
Output
Desired results
end
Value of y
Uncle Chen wants to buy 5 cans of paint from
Linda’s shop. The price for each of the paint can is
RM 15.60. Calculate the total price of all Example 2
the paint cans.
Pseudocod
ANALYSIS e?
Input 1 can paint = start
RM 15.60
set price as 15.60
No. of cans = 5
read the number of cans
Process
Total price cans of compute the total price as price per can
paint = RM 15.60 x times by number of cans
5
Output display/print the total price
Total price 5
cans of paint end
Madam Sue needs to determine her students grade for
Example 3
programming subject based on the mark scored during final
examination. The ‘A’ grade will be given if the mark scored is
between 85 to 100. If a student has scored 90 marks, what is the
grade should Madam Sue give to the student?
Pseudocod
ANALYSIS e?
Input Mark = 90
start
read the student mark
Process if mark is greater than 85 and mark
A = if 85 < mark is less than 100, then
< 100 set grade as A
Output display/print the grade
Grade for
students with 90 end
marks
Given the following formula, calculate the porosity of rock if the pure
volume = 12.5 while total rock volume = 55:
Pseudocod
ANALYSIS e?
Input Pure volume = start
12.5 total rock read the number of pure volume
volume = 55 read the total rock volume
Process Porosity = (pure compute the value of total porosity as
volume/total rock total porosity = (number of
volume) x 100%
pure volume divided by total rock volume)
Output Porosity of the given
pure volume and
times by 100%
total rock volume display/print the total porosity
end
Compute and display the total cost of apples,
if given the number of pounds of apples
purchased and the cost of apples per pound
Exercise 2
Pseudocod
ANALYSIS e?
Input No. of pounds of start
apples read the number of apples purchased
purchased and read the cost of apples per pound
Process costcost
Total perof
pound
apples compute the total cost as number of
= no. of pounds x apples purchased
cos per pound
times by cost of apples per pound
Output Total cost of apples for the
given no. of pounds of display/print the total cost
apples and the cost per
pounds
end
A box has height, width and length.
Write the pseudo code to calculate the volume
of a box.
Exercise 3
Pseudocod
ANALYSIS e?
Input height start
width read the height
length read the width
Process Box volume = read the length
height x width x compute the box volume as height
length
times by width times by length
Output Total volume of display/print the total volume of box
box end
Write the pseudo code to calculate salary of
an employee for a month. Exercise 4
Pseudocod
ANALYSIS e?
Input Salary per day
start
No of day per
month read the salary per day
read the no. of day per month
Process Salary = salary per
day x no. of day per compute the total salary as salary per day
month times by no. of day per month
Output Total salary display/print the total salary
end
1. Helps to visualize
the content/steps
better or to find flaws Schematic
in process Symbol representation of an
algorithm or process
2. Illustrate the steps in
the process
Flowchart
Start/Stop
The terminator symbol marks
the starting or ending point of
the system. It usually contains
the word "Start" or "End."
Action or Process
A box can represent a single
step ("add two cups of flour"), or
and entire sub-process ("make
bread") within a larger process.
Flowchart Symbols
Decision
A decision or branching point.
Lines representing different
decisions emerge from
different points of the diamond.
Input/Output
Represents material or
information entering or leaving
the system, such as customer
order (input) or a product
(output).
Flowchart Symbols
Flow Line
Lines indicate the sequence of
steps and the direction of flow.
Connector
Indicates that the flow
continues where a matching
symbol (containing the same
letter) has been placed.
Flowchart Symbols
Off Page
Indicates that the process
continues off page.
Database
Indicates a list of information with
a standard structure that allows
for searching and sorting.
Flowchart Symbols
Example
Flowchar
t
Given the value of x is 10 and a is 12,
find the result of the following equation: Example 1
y = 2x + a - 6
Pseudocod
e?
start
read the value of x
read the value of a
compute the value of y as y = 2x + a -6
display/print the value of y
end
Uncle Chen wants to buy 5 cans of paint from
Linda’s shop. The price for each of the paint can is
RM 15.60. Calculate the total price of all Example 2
the paint cans.
Pseudocod
e?
start
set price as 15.60
read the number of cans
compute the total price as price per can
times by number of cans
display/print the total price
end
Madam Sue needs to determine her students grade for
Example 3
programming subject based on the mark scored during final
examination. The ‘A’ grade will be given if the mark scored is
between 85 to 100. If a student has scored 90 marks, what is the
grade should Madam Sue give to the student?
Pseudocod
e?
start
read the student mark
if mark is greater than 85 and mark
is less than 100, then
set grade as A
display/print the grade
end
Given the following formula, calculate the porosity of rock if the pure
volume = 12.5 while total rock volume = 55:
Pseudocod
e?
start
read the number of pure volume
read the total rock volume
compute the value of total porosity as
total porosity = (number of
pure volume divided by total rock volume)
times by 100%
display/print the total porosity
end
Compute and display the total cost of apples,
if given the number of pounds of apples
purchased and the cost of apples per pound
Exercise 2
Pseudocod
e?
start
read the number of apples purchased
read the cost of apples per pound
compute the total cost as number of
apples purchased
times by cost of apples per pound
display/print the total cost
end
A box has height, width and length.
Write the pseudo code to calculate the volume
of a box.
Exercise 3
Pseudocod
e?
start
read the height
read the width
read the length
compute the box volume as height
times by width times by length
display/print the total volume of box
end
Write the pseudo code to calculate salary of
an employee for a month. Exercise 4
Pseudocod
e?
start
read the salary per day
read the no. of day per month
compute the total salary as salary per day
times by no. of day per month
display/print the total salary
end
REFERENCES