Professional Documents
Culture Documents
8.2 Problem Solving
8.2 Problem Solving
Problem Design a
Implementation Testing Documentation
Analysis Solution
•Find a logical sequence of precise steps that solve the problem Algorithm
Design a •Such a sequence of steps is called an algorithm •Pseudocode
•Every detail, including obvious steps, should appear in the algorithm
Solution •Flow chart
Problem Analysis:
Problem Analysis:
Flow line
Terminal
Input/output
Process
Decision
• General’s Problem
o Feeling thirsty
o Withdrawing money from an ATM machine.
• Mathematical Problem
o Finding an area of shape (rectangle, triangle)
o Mean for marks
Feeling thirsty
WALK
o Examples of Flow TO THE NEAREST SHOP
Chart
• a graphical
BUY
A DRINK
representation of
algorithm in DRINK
relation to its
sequence of HAPPY FACE
functions
END
• a graphical
representation of a ENTER
algorithm in relation to
PIN NUMBER
ENTER
AMOUNT
A
Footer Text 10/30/2015 22
8.2.3.1 Algorithm
Solve a problem using an Algorithm
A
• General’s Problem
Withdraw Money from COLLECT
• a graphical
representation of
algorithm in relation to
its sequence of
functions
Display total
END
Note:
** input/enter/key in/ read
** output / display / print
Footer Text 10/30/2015 26
8.2.3.1 Algorithm
Solve a problem using an Algorithm
• Math’s Problem START
Finding an Area of
Rectangle Input width, height
o Examples of Flow Chart
• a graphical representation of
algorithm in relation to its
sequence of functions
area of rectangle = width x height
Display area of
rectangle
END
END
END
Control Structures
Sequence • all examples from previous slide
series of statements have already shown a
that execute one sequence control structures.
after another
An arrow shows the
execution of every
block (in a flow chart),
one after another, this
is a SEQUENCE
control structure to
solve a problem.
Control Structures
• Example: How to make a tea drink
Start
Tea drink
End
Control Structures
Selection
statement is used to
determine which of A diamond (in this
two different case is a SELECTION)
statements to determine whether the
resulting process is
execute depending TRUE or FALSE – and
on certain it will flow to one
conditions direction
Control Structures
Selection
statement is used to
speed FALSE
determine which of
> 90
two different
statements to TRUE
execute depending
“ OVER LIMIT “
on certain
conditions
Control Structures
Selection
statement is used to
determine which of UPS FALSE
Control Structures
Selection If the program receive an input of UPS = 60 , then
the data flow is presented by the dotted line ..
statement is used to
determine which of
two different
statements to
execute depending
UPS FALSE
on certain
> 50
conditions
TRUE
“ PASS“ “ FAIL “
Control Structures
Selection If the program receive an input of UPS = 30 , then
the data flow is presented by the red line ..
statement is used to
determine which of
two different
statements to
execute depending
UPS FALSE
on certain
> 50
conditions
TRUE
“ PASS“ “ FAIL “
Control Structures
UPS FALSE UPS FALSE
> 50 > 50
TRUE TRUE
Control Structures
Repetition A diamond (in this case is
a REPETITION) if the
statement is used to value is TRUE, data will
repeat statements loop (in the loop body)
while certain and will out-of-loop when
the reach FALSE.
conditions are met
dashed line
show an area
of the Loop
Body
Control Structures
Repetition If water boil is FALSE (meaning not yet boil to 100
degree Celsius, temp < 100 ), keep it boiling until the
statement is used to water is boiled (temp = 100 deg. Celsius)
repeat statements
while certain
conditions are met
FALSE
WATER
BOILING
BOIL ?
Control Structures
Repetition If temp < = 100 is TRUE (meaning water still not
boil) keep it boiling until the temp reach 100, then it
statement is used to will stop.
repeat statements
while certain
conditions are met
TRUE
TEMP
BOILING
< = 100
FALSE
dashed line
show an area
of the Loop
now you can Body
make a coffee for
me !
Control Structures
START A
TURN ON
KETTLE
SUGAR ?
FALSE
WATER
BOILING
BOIL ?
ADD
SUGAR
TRUE
A END
Footer Text 10/30/2015 43
8.2.3.2 Apply Appropriate
Control Structures
START A
PUT WATER IN
SEQUENCE POUR WATER SEQUENCE
IN CUP
ELECTRIC KETTLE
ADD
TEA BAG
TURN ON
KETTLE
SELECTION
REPETITION
NO
SUGAR ?
FALSE
WATER
YES
BOILING
BOIL ?
ADD
SUGAR
TRUE
A END
Footer Text 10/30/2015 44
8.2.3.2 Apply Appropriate
Control Structures
START A
POUR WATER
PUT WATER IN IN CUP
ELECTRIC KETTLE
ADD
TEA BAG
TURN ON
KETTLE
NO
SUGAR ?
FALSE
WATER
YES
BOILING
BOIL ?
ADD
SUGAR
TRUE
A END
Footer Text 10/30/2015 45
EXERCISE
• 1. (a) Write a pseudocode to display “ Kolej
Matrikulasi Perak”.