Anda di halaman 1dari 25

Problem Solving Method

Introduction

Program Development Life Cycle


Selection and Looping/Iteration Structure Design
Problem Solving Examples

Introduction

Problem solving refer to a process which is used to


transform problem statement to solutions by using
knowledge that applicable to problem domains

Program Development Life Cycle


Program Development Life Cycle (PDLC) is a
framework for each steps that are used to developed
computer program.
There are 6 phase in PDLC which comprise of:
1. problem understanding
2. problem analysis
3. algorithm design
4. implementation
5. testing
6. maintenance

1. Problem Understanding
Before we can solved a given problem, we have to
carefully understand things that will be solved

2. Problem Analysis
Analyze the problem by determining 3 important things:
1. input for the program
2. processing steps to transform input to output (including
rules and constraint that will be considered and also all the
formula involved)
3. output produced

3. Algorithm Design
Algorithms refer to a procedure to solve problem that involved
steps/commands that has to be executed
Each algorithms has the following properties:
clear and unambiguousness lack of confusion)
Has a general characteristic which can accept all set of data
Accuracy in solving a problems as required
Have an ending
have input and produce output
Have 2 ways to represent algorithms
1. Pseudo code algorithm explanation in a wording form by using all
kind of language that can be understand by the programmer
2. Flow chart- a graphically program logic illustration that is
connected by using arrows

Example of Pseudo Code

PUT the purpose of the program


GET the age of the individual
GET the salary
Calculate the sum of the salaries in each age group
Calculate the number (count) of individuals in each
age group
PUT age, average
END

Flow chart basic symbol


Symbol

Meaning
Process command execution that transform input
to output
Input / output data entered or result displayed

Arrow connecting command sequence

Condition/testing rules that determine certain path


to follow
Start / End

Joint/Connecter connect flow chart to other page

4. Implementation
After designing algorithm, then we can write and type the program
code to computer. Here we can use a computer programming
language

5. Testing
Programs that has been developed must be tested first by using
several different input to ensure the needs of problem that being
solved is fulfill

6. Maintenances
In an organization that use a computer program, some programs
maybe need a change from time to time to fulfill current needs

HOW TO PRODUCE
THE PSEUDOCODE
& THE FLOW CHART
- CLASS DISCUSSION-

Problem Solving Example


Compute net salary of a worker after deducted by tax. If
gross salary of worker is greater than RM1000,he/she will
have tax deducted of 2% from gross salary. Worker who earn
gross salary of RM1000 and below will enjoy tax waive.

Solution Step
Understand the question, the determine input, output
and formulas that will be used
Algorithm design by developing pseudo code and flow
chart

Problem Solving Example


Compute net salary of a worker after deducted by tax. If
gross salary of worker is greater than RM1000,he/she will
have tax deducted of 2% from gross salary. Worker who earn
gross salary of RM1000 and below will enjoy tax waive.

Solution Step
Understand the question, the determine input, output
and formulas that will be used
Algorithm design by developing pseudo code and flow
chart

Problem Solving Example

Step 1: Analyze Problem


Input

gross salary

Process

Compute net salary from gross salary


net salary = gross salary - tax

Output

net salary

Problem Solving Example

Step 2: Pseudo code


Enter gross salary
If gross salary greater 1000
tax = 2/100 * gross salary
else
tax = 0
Compute net salary = gross salary - tax
Display output = net salary

Problem Solving Example

Step 2: Flow Chart


START
Gross Salary

No

Gross Salary
>= 1000

Tax = 0

Yes

Tax = 2/100 * Gross Salary


Net Salary = Gross salary - tax
Net salary

END

Selection and Looping Structure Design


1. Sequence Structure Control

Action 1

Action 2

Action 3

Sequence structure control is used to explain action arrangement by following


the given order

2. Selection Control Structure

Condition

Action 1

Action 2

Selection control structure is used when it involve conditions for example ifelse condition. This condition must be in 2 situation which is either yes/true if it
fulfill the condition and no/false if vice versa.

3. CASE Structure Control


Situation 1
yes
Condition /Case 1

Action 1

no
Condition /Case
2

Situation 2
yes

Action 2

no
Condition /Case 3

Situation 3
yes

Action 3

no

Case structure control is a kind of multiple selection structure

LETS DO IT TOGETHER...
Write the problem analysis and design the flow
chart.....
The Fantastic Floral Company sells to
wholesale buyers. The following are the
discounts to the wholesale buyer:
AMOUNT < RM1000
DISCOUNT=2%
AMOUNT >=RM1000 AND <RM5000 DISCOUNT=5%
AMOUNT >= RM5000
DISCOUNT=10%

Given the amount of purchase, compute the


nett amount which need to be paid by the
wholesale buyer to the company.
NOTE: THE SOLUTION WILL BE DISCUSSED IN THE CLASS

Exercise
Develop programs for the following problems: (you are
required to provide problem analysis and flow charts)
1. Compute money exchange rate from USD to RM
(1 USD = RM 3.80)
2. Compute average marks for 10 students from
Programming in Business Application course
3. Determine the least number from 3 number entered
4. Determine number entered by user is positive, negative or
null value
5. Compute the amount paid by user for petrol quantity
bought (user input is in liter quantity)
Note :

1 liter petrol = RM 1.53

Exercise
Develop programs for the following problems: (you are
required to provide problem analysis and flow charts)
6. Develop a program to display the status of current
temperature. Temperature status displayed is based on
the followings:
Temperature (Celsius)

Status

0-30

Cold

30-50

Medium

50-70

Hot

70-100

Very Hot

Exercise
Develop programs for the following problems: (you are
required to provide problem analysis and flow charts)
7. Develop an application to compute the payment of
electricity consumption. Input use early meter reader and
late meter reader. Payment rate required are as
followings:
First 100 unit

RM 20.00

Exceed 100 and less


than 300

RM 0.22 per unit

Greater 300 unit and


above

RM 0.28 per unit

Exercise
Develop programs for the following problems: (you are
required to provide problem analysis and flow charts)
8. Develop an application to calculate income zakat
payment that are required to pay by the user. Payment
rate are as followings:
Annual income less than
RM 4000

Income zakat waive

Annual income greater


than RM 4000

Zakat subjected : 2.5%


from annual income

Exercise
Develop programs for the following problems: (you are
required to provide problem analysis and flow charts)
9. Pos Malaysia have fixed the payment cost for every
posted parcel are as the following table. Develop an
application to compute posted payment cost based on
weight entered
Weight (kg)

Cost (RM)

0-2

2.50

2.1 - 5

3.80

5.1 - 10

6.00

10.1 - 20

10.00

Greater than 20

Void

Exercise
Develop programs for the following problems: (you are
required to provide problem analysis and flow charts)
10. Calculate average marks for every student from three
test. Determine the grade and status for average marks
produce. Grading table are as following
A

81 100

Distinction

61 80

Good

51 60

Satisfaction

40 50

Pass

0 39

Fail

Anda mungkin juga menyukai