Professional Documents
Culture Documents
Chapter 2 - Problem Solving Techniques (Part2) I
Chapter 2 - Problem Solving Techniques (Part2) I
Chapter 2 - Problem Solving Techniques (Part2) I
Computer
programmer
WHAT
Program ??
Prepared by Norhamreeza Abdul Hamid
Also known as
Software/ System
Development Life Cycle
(SDLC) or software
process
A development of a software/computer
program product.
Prepared by Norhamreeza Abdul Hamid
Specify problem
Steps
Analyze problem
Design algorithm
Implement algorithm
Test and verify program
Maintain and update program
Prepared by Norhamreeza Abdul Hamid
What
problem to
be solved?
STATE
What is the
problem?
Is it possible to solve
the problem with
programming?
Prepared by Norhamreeza Abdul Hamid
State the
problem
clearly
Gain a clear
understanding of
what are
required for its
solution.
Prepared by Norhamreeza Abdul Hamid
What is the
problem?
Given the value of x is 10 and a is 12,
find the result of the following equation:
y = 2x + a - 6
What to
solve?
Is it possible to
solve the problem
with
programming?
Prepared by Norhamreeza Abdul Hamid
IDENTIFY
Output
Input
Process
Input
Given the value of x is 10 and a is 12,
find the result of the following equation:
y = 2x + a - 6
Process
Output
Prepared by Norhamreeza Abdul Hamid
Value of x and a
Process
Output
Solve Problem
Develop a list of steps
called algorithm
Writing program
Convert algorithm into
programming
Also known as
CODING
Testing program
To verify the program can
works as desired
Modifying program
Remove undetected errors
and keep up-to-date
Specify problem
Steps
Analyze problem
Design algorithm
Implement algorithm
Test and verify program
Maintain and update program
Prepared by Norhamreeza Abdul Hamid
Algorithm
Pseudocode
Flowchart
Control
Structure
Making a delicious
chocolate cake.
Installing a software
into a pc.
Steps in
Computer program
for computer
to do its job
Famous muslim
scientist/
mathematician
Prepared by Norhamreeza Abdul Hamid
Procedure or formula
for solving problem
Sequence set of
steps taken to
solve a problem
Instructions for actions to be executed by computer
(input/process/output)
Prepared by Norhamreeza Abdul Hamid
Must have
input
Must produce
output
Efficiency
Algorithm
Requirements
Finiteness
Unambiguous
Correctness
Generality
Simple
codes
which
resembles program code that
will
be
written
during
implementation
phase
(program coding)
i.
ii.
Keyword?
START
IF student's grade is greater than or equal to 40
PRINT the statement "passed"
ELSE
PRINT the statement "failed"
ENDIF
END
print means
display on the
screen
monitor
show also
START
means
IF credit card number is valid
execute transaction based on number and
display on
order
the screen
ELSE
monitor
SHOW a generic failure message
ENDIF
Prepared by Norhamreeza Abdul Hamid
END
START
SET total to zero
SET grade counter to one
WHILE grade counter is less than or equal to
ten
INPUT the next grade
ADD the grade into the total
ENDWHILE
SET the class average to the total divided
by ten
PRINT the class average.
END
set means
assign the
value,e.g:
total = 0
while is used
whenever
the process is
to be
continued
Value of x and a
Process
Output
Write a
program!
y = 2x + a - 6
Keyword
Keyword
START
SET the value of x to 10
SET the value of a to 12
COMPUTE the value of y as y = 2x + a - 6
DISPLAY/PRINT the result (or the value of y)
END
Keyword
START
READ the student mark
IF mark is greater than 85 and mark is less than 100
set grade as A
ENDIF
DISPLAY/PRINT the grade Keyword
END
Test your
understanding!
START
INPUT/READ height, width, length
CALCULATE the volume = height * width * length
PRINT/DISPLAY volume
END
START
INPUT/READ salary per day
CALCULATE the salary= salary per day*30 days
PRINT/DISPLAY salary
END
Prepared by Norhamreeza Abdul Hamid
START
READ/INPUT pure volume, total rock
CALCULATE porosity = (pure volume / total
rock volume) x 100%
DISPLAY porosity
END
Schematic representation of an
algorithm or process
Start/End
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.
Prepared by Norhamreeza Abdul Hamid
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).
Prepared by Norhamreeza Abdul Hamid
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.
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.
y = 2x + a - 6
START
SET the value of x to 10
SET the value of a to 12
compute the value of y as y = 2x + a -6
DISPLAY/PRINT the result (or the value of y)
END
Prepared by Norhamreeza Abdul Hamid
Start
Set x = 10
Set a = 12
y = 2x + a - 6
Print y
End
Prepared by Norhamreeza Abdul Hamid
START
SET the amount of paint to 5
COMPUTE the total price as price per tin times by
amount of paint
DISPLAY/PRINT the result (or the total price)
Convert
END
to
flowchart
Start
End
Prepared by Norhamreeza Abdul Hamid
Convert to
flowchart
Start
Display volume
End
Prepared by Norhamreeza Abdul Hamid
Start
Display salary
End
Prepared by Norhamreeza Abdul Hamid
Start
Display porosity
End
Prepared by Norhamreeza Abdul Hamid
Sequential
Selection
Repetition
START
statement 1.
statement 2.
statement n.
END
statement 1
statement 2
statement n
end
start
Display age
end
Format:
No
IF (condition)
then-part
ELSE
else-part
ENDIF
elsestatement(s)
Condition?
Yes
thenstatement(s)
START
READ age
IF age is greater than 55
PRINT Pencen
ELSE
PRINT Kerja lagi
ENDIF
END
START
READ age
IF age > 55
PRINT Pencen
ELSE
PRINT Kerja lagi
ENDIF
END
start
Read age
yes
age > 55
no
print Pencen
End
Format:
WHILE (condition)
loop-body
ENDWHILE
yes
Condition?
Loop
Statement(s)
no
Counter
Can be used to control execution of the loop
(loop control variable)
It will increment or decrement each time a
loop repeats
Must be initialized before entering loop
Start
initialization
cnt=0
FALSE
condition
TRUE
body of loop
increment
FALSE
cnt<5
End
TRUE
Print whatever
cnt=cnt+1
Counter initialisation
START
number of users giving his age = 1
WHILE number of users giving his age <= 10
READ the age from the user.
Loop condition
PRINT the user age.
number of user giving his age + 1
ENDWHILE
Updating counter
END
START
users = 1
WHILE users <= 10
READ age
PRINT age.
users = users + 1
ENDWHILE
End
Prepared by Norhamreeza Abdul Hamid
Start
users = 1
NO
End
print age
users =users + 1
Prepared by Norhamreeza Abdul Hamid
START
users = 0
WHILE users < 10
READ age
PRINT age.
users = users + 1
ENDWHILE
END
Be
consistent