DC024
Topic 1: Problem Solving
1
SEMESTER II SESSION 2018/2019
1.0 Problem Solving
1.1 Steps in Problem Solving
1.2 Problem Analysis
1.3 Design a Solution
2
Learning Outcome:
At the end of this topic, students should be able to:
(a) List five steps in problem solving.
(b) Identify input, process and output from a
given problem.
(c) Define pseudocode and flowchart.
(d) Solve a given problem using pseudocode -
Sequence
(e) Solve a given problem using flowchart - 3
Sequence
Learning Outcome:
At the end of this topic, students should be able to:
(e) Solve a given problem using pseudocode -
Selection
(f) Solve a given problem using flowchart -
Selection
(g) Solve a given problem using pseudocode -
Repetition
(h) Solve a given problem using flowchart - 4
Repetition
[ Introduction ]
This subtopic introduces
you to the process
that programmers
follow when solving
problems that require
a computer solution.
5
[ Introduction ]
Thing to Ponder....
Computers are NOT intelligent or telepathic
Computers do what we tell them to do.
They don't do anything by themselves.
We must clearly tell a computer what to do in a
step by step manner using a programming language.
Computers are just electronic devices that have the
power to perform difficult tasks but they do not
'KNOW' what to do.
Programmers tell the computers what to do by
writing programs. 6
[ Intro – Solving Everyday Problems ]
Scenario:
You are taking a test and your
friend behind you asks
you for help.
He/She wants to know what
you put
for question number two.
What could you do?
7
[ Steps in Problem Solving ]
Five (5) steps in problem solving:
(1) Problem Analysis
(2) Design a Solution
(3) Implementation
(4) Testing
(5) Documentation
8
[ Steps in Problem Solving ]
(1) Problem Analysis
• State the problem clearly.
• Identify input, process and output based
on the problem.
(2) Design a Solution
• Prepare an algorithm (pseudocode &
flowchart) for its solution.
• Write step-by-step procedure and then
verify that the algorithm solves the
problem as intended.
9
[ Steps in Problem Solving ]
(3) Implementation
• Coding/Programming is the process of
translating the algorithm into the
syntax of a given programming
language.
(4) Testing
• Testing means running the program,
executing all its instructions/functions,
and testing the logic by entering sample
data to check the output.
10
[ Steps in Problem Solving ]
(5) Documentation
• All of the flowcharts, messages,
algorithms, lines of code, and the user
manuals are part of this documentation.
• Internal documentation is used by other
programmers to help them know why
you did something a certain way or tell
them how you wrote a program.
11
[ Steps in Problem Solving ]
(5) Documentation
External documentation includes user
manuals and anything that is not the
actual code or is art of the listing.
This should also include materials
that are placed on a website such as
FAQs (frequently asked questions).
12
[ Problem Analysis ]
• Input Process Output (IPO) analysis is
used to analyze problems and develop
algorithms.
• Used to organize and summarize the
results of a problem analysis.
• It shows where in the solution the
processing takes place. 13
[ Problem Analysis ]
It can also be represent using IPO chart
Input Process Output
Information that How the input Information to be
displayed to the
must be acquired allows the user indicating the
result of the
from the user determination of problem.
before the problem the output. List names for the
output items.
can be solved.
How to compute
List names for the the output
input items. information.
Each instruction 14
begins with a verb.
2 [ IPO Analysis ] 1
Input 3 Output
Process
Input typically Process: Output typically
is stated as Look for verb is stated as
nouns and use. nouns.
adjectives in
problem
specification.
15
[ IPO Analysis – Tips ]
• Underline all the inputs values that must be
entered by the user.
• Underline all the outputs values that should
be generated by the program.
• Underline all the nouns, verbs and adjective.
• Write the output variable names in the output
column.
• Write the input variable names in the input
column.
• Write the processing steps in the processing
column.
16
[ Analyze the Problem – Example#1 ]
Problem Statement 1:
Calculate the area of a rectangle
width
height
We can summarize the information contained
in the problem statement as follows....
17
[ Analyze the Problem – Example#1 ]
Problem Analysis:
2 Input: width, height
3 Process: Calculate rectangle area
1 Output: rectangle area
18
[ IPO Chart - Example#1 ]
Input Process Output
width, Calculate rectangle area rectangle
height area
19
[ Analyze the Problem – Example#2 ]
Problem Statement 2:
Find the average of three numbers input by
user.
20
[ Analyze the Problem – Example#2 ]
Problem Analysis:
2 Input: num1, num2, num3
3 Process: Calculate average
1 Output: average
21
[ IPO Chart - Example#2 ]
Input Process Output
num1, Calculate average average
num2,
num3
22
[ Analyze the Problem – Example#3 ]
Problem Statement 3:
Berjaya Concept Corporation gives a bonus to
Roy based on his sales. The bonus is 5% of the
sales. Calculate Roy's bonus.
23
[ Analyze the Problem – Example#3 ]
Problem Analysis:
2 Input: sales
3 Process: Calculate bonus
1 Output: bonus
24
[ IPO Chart - Example#3 ]
Input Process Output
sales Calculate bonus bonus
25
[ Analyze the Problem – Question#1 ]
Problem Statement 1:
Given sides a, b, and c, finding the
perimeter of a triangle.
26
[ Analyze the Problem – Question#1 ]
Problem Analysis:
Input:
Process:
Output:
27
[ Analyze the Problem – Question#2 ]
Problem Statement 2:
Find the surface area of a sphere.
SA = 4 × pi × r × r
28
[ Analyze the Problem – Question#2 ]
Problem Analysis:
Input:
Process:
Output:
29
[ Analyze the Problem – Question#3 ]
Problem Statement 3:
Convert a measurement in millimeter
(mm) to meter (m)
30
[ Analyze the Problem – Question#3 ]
Problem Analysis:
Input:
Process:
Output:
31
[ Analyze the Problem – Question#4 ]
Problem Statement 4:
A government tax of 10% and service tax
of 5% will be added to the price of a set of
meal bought at MFC. Calculate the total
price that Ali has to pay for a set of meal.
32
[ Analyze the Problem – Question#4 ]
Problem Analysis:
Input:
Process:
Output:
33
[ Analyze the Problem – Question#5 ]
Problem Statement 5:
Calculates the Body Mass Index (BMI) for
a person.
BMI = weight / (height x height)
34
[ Analyze the Problem – Question#5 ]
Problem Analysis:
Input:
Process:
Output:
35
[ Analyze the Problem – Question#6 ]
Problem Statement 6:
Calculate and print the area and circumference
of a circle.
area = pi x radius x radius
circumference = 2 x pi x radius
where pi = 3.14
36
[ Analyze the Problem – Question#6 ]
Problem Analysis:
Input:
Process:
Output:
37
[ Analyze the Problem – Question#7 ]
Problem Statement 7:
Calculate and display the area of shaded
region in the diagram below.
A
B
C
38
[ Analyze the Problem – Question#7 ]
Problem Analysis:
Input:
Process:
Output:
39
[ Analyze the Problem – Question#8 ]
Problem Statement 8:
Calculate and display the overtime pay
received by an employee. Overtime rate is
RM500 per hour.
40
[ Analyze the Problem – Question#8 ]
Problem Analysis:
Input:
Process:
Output:
41
[ Analyze the Problem – Question#9 ]
Problem Statement 9:
Convert the temperature in Fahrenheit (F)
to Celsius (C) using the formula:
C 5 (F 32)
9
42
[ Analyze the Problem – Question#9 ]
Problem Analysis:
Input:
Process:
Output:
43
[ Analyze the Problem – Question#10 ]
Problem Statement 10:
Calculate the salary of an employee
who works by hourly basis.
The formula to be used is
Salary = Hours worked * Pay rate
44
[ Analyze the Problem – Question#10 ]
Problem Analysis:
Input:
Process:
Output:
45
1. Five (5) steps in problem solving.
- Problem Analysis
- Design a Solution
- Implementation
- Testing
- Documentation
2. Identify input, process and output from
a given problem (sequence).
46