Sei sulla pagina 1di 37

PROBLEM SOLVING METHOD

CHAPTER 2

2.2 Demonstrate the understanding of


programming Life Cycle (PLC).
.
PROGRAMMING LIFE CYCLE

Please rearrange it in order..


-Analyze the problem
-Specify the Problem
- Documentation
-Design the algorithm to solve the problem
-Test and verify the completed program
-Maintain and update the program
-Implement the algorithm
R
A E
Y U
O
R E AD Y ?
ARE YOUR ANSWER CORRECT?
1- Specify
the Problem
7- Documentation
2 - Analyze the
problem
7 Phases
in
Programming
6 - Maintain and
3 - Design the Life Cycle
update the program
algorithm to solve
the problem

5 - Test and verify


4 - Implement the completed
the algorithm program
1. SPECIFY THE PROBLEM

 The first step in solving any problem is to understand it.


 Read the requirements statement carefully.
 State the problem clearly and unambiguously.
 Gain clear understanding of what is required for its solution.
1. SPECIFY THE PROBLEM
Example Problem Statement
Compute and display the total price apples
given the weight in kilograms
of apples purchased and the price
per kilogram of apples.
1. SPECIFY THE PROBLEM

 In problem requirement phase you may ask some question


like
a. What to compute?
b. What unit do they use?
c. Is it only for the apple or other fruit?
or any question for gaining understanding of what is
required.
2. ANALYZE THE PROBLEM

 Identify the problem inputs you have to work with and also
the problems outputs (results) desired.
 Check any additional requirements or constraints on the
solution.
 Determine the required format of the results to be displayed.
 Develop a list of variables.
2. ANALYZE THE PROBLEM

 To analyze the problem you may summarize the information


contained in it and find out the problem input and output.
Problem Inputs
a. weight in kilogram
b. price per kilogram ( in RM per kg)
Problem Output
a. Total price (in RM)
2. ANALYZE THE PROBLEM

 Develop a list of formulas that specify relationships between


the inputs and the outputs:

Total price = price per kilogram x weight in kilogram


2. ANALYZE THE PROBLEM

• Find a list of solution alternatives


Example:
1. Define price per kilogram as constant and
weight in kilogram as input value
2. Define price per kilogram and weight in
kilogram as input values
2. ANALYZE THE PROBLEM
• All the information gained from analyzing the
problem can be put into problem Analysis chart
(PAC)
Given Data Required Results
Weight in kilogram Total price
Price per kilogram

Processing Required Solution Alternatives


Total price = price per 1. Define price per kilogram as constant and
kilogram x weight in weight in kilogram as input value
kilogram *2. Define price per kilogram and weight in

kilogram as input values


3. DESIGN THE ALGORITHM TO SOLVE
THE PROBLEM

 Once you fully understand the problem and have clarified any
questions you have, you need to develop your solution.
 Algorithm is a set of instructions for the computer
 Setting up the algorithms is probably the hardest part of
problem solving on the computer
3. DESIGN THE ALGORITHM TO SOLVE
THE PROBLEM
 The instructions cannot assume anything, cannot skip
steps, must be executable one step at a time and must be
complete
 Example of algorithm:
1. Input the weight in kilograms of apples purchased and
the price per kilogram of apples
2. Calculate total price apples using the formula:
Total price = price per kilogram x weight in kilogram
3. Print Total Price
3. DESIGN THE ALGORITHM TO SOLVE
THE PROBLEM
 Tools which can be used to help you in this task:

• Structure Chart
a.

• IPO chart
b.

• Flow chart
c.

• Pseudo code
d.
3. DESIGN THE ALGORITHM TO SOLVE
THE PROBLEM
a) Structure Chart

 Depict the overall organization of a program, show how


program segment or modules are defined and how they
relate to one another.
 The module in the upper row serve as control functions
directing the program to process modules under them
as appropriate.
 It follows a top-down design philosophy.
3. DESIGN THE ALGORITHM TO SOLVE
THE PROBLEM
a) Example : Structure Chart

TOTAL PRICE
CONTROL MODULE
0000

READ CALC PRINT


1000 2000 3000
3. DESIGN THE ALGORITHM TO SOLVE
THE PROBLEM
b) IPO (Input-Processing-Output) chart

- shows in more detail what data items are


input, what processing takes place on that
data and what information will be the end
result, the output
3. DESIGN THE ALGORITHM TO SOLVE
THE PROBLEM
b) Example : IPO (Input-Processing-Output) chart

Input processing Module reference Output


number

Weight in kilogram 1. Enter Weight in 1000 Total price


Price per kilogram kilogram
2. Enter Price per 1000
kilogram
3. Calculate Total 2000
price
4. Print Total price 3000
5. End 0000
3. DESIGN THE ALGORITHM TO SOLVE
THE PROBLEM
c) Flow chart
- graphic representations of the algorithm
- shows the flow of processing from the beginning to the end
of a solution
- each block in a flowchart represents one instruction from
an algorithm
- flow lines indicate the direction of the data
flow
3. DESIGN THE ALGORITHM TO SOLVE
THE PROBLEM
c) Example : flow chart

start

Input WeightInKg, PricePerKg

TotalPrice = WeightInKg * PricePerKg

Print TotalPrice

end
3. DESIGN THE ALGORITHM TO SOLVE
THE PROBLEM
d) Pseudo code

 Uses English like statements in place of the


flowchart graphical symbols.
 It is easier to code a program from it than from
flowchart.
 It is not tied to any programming language.
 It is easy to modify but not graphical, difficult to use
for logically complex problems, and slower to create.
3. DESIGN THE ALGORITHM TO SOLVE
THE PROBLEM
d) Example : pseudo code

START
Input WeightInKg, PricePerKg
TotalPrice = WeightInKg * PricePerKg
Print TotalPrice
END
4. IMPLEMENT THE ALGORITHM

 This step involves writing the algorithm as a program.


 By using flow chart as the guideline, start writing a program
from the top of flow chart and work your way to the bottom.
4. IMPLEMENT THE ALGORITHM
 Example of program code in C++

#include <iostream.h>
int main()
{
float WeightInKg, PricePerKg, TotalPrice;
cout<<“ Enter weigh in Kg: “;
cin>> WeightInKg;
cout<<“ Enter price per kg: “;
cin>> PricePerKg;
TotalPrice= WeightInKg * PricePerKg;
cout<<“ Price of apples : RM “<<TotalPrice;
return 0;
}
5. TEST AND VERIFY THE COMPLETED
PROGRAM

 After writing the program, you must test it.


 Program testing can be a very tedious and time consuming.
 Run the program several times using the different sets of
data.
 Make sure that it works correctly for every situation
provided in the algorithm.

 Example: Blackbox Testing or Whitebox testing.


5. TEST AND VERIFY THE COMPLETED
PROGRAM

Blackbox Testing Whitebox Testing


Blackbox testing gets its name Whitebox testing assumes that the
from the concept of testing the tester knows everything about the
program without knowing what is program.
inside- without knowing how its
works.

By a user. It is a programmer’s responsibility.


5. TEST AND VERIFY THE COMPLETED
PROGRAM

 Errors are so common that they have a special name (BUGS).


Bugs must be identified and corrected.
 The process of identifying and correcting bugs is known as
debugging.
 When the compiler detects an error, the computer will
display an error message, which indicates that you have made
a mistake and what the cause of the error might be.
5. TEST AND VERIFY THE COMPLETED
PROGRAM

Type of errors

Syntax/Compile Run time Logical


5. TEST AND VERIFY THE COMPLETED
PROGRAM

 Syntax Error (Compilation Error)

 An error in the format of a statement in a


computer program that violates the rules of the
programming language employed.
 A program will not be executed until all syntax
errors are corrected
 Error can be traced at the event of compilation
5. TEST AND VERIFY THE COMPLETED
PROGRAM

 Run –time error

 Are detected by the computer and are displayed during


execution of a program.
 A run-time error occurs when the program directs the
computer to perform an illegal operation, such as dividing a
number by zero or
5. TEST AND VERIFY THE COMPLETED
PROGRAM

 Logical Error

 The hardest errors to find and fix.


 A logic error means although the language syntax was used
correctly, there was a misunderstanding: if you want a, where
b=c+a and you give a = b-a instead of a = b-c, then you will
get the wrong answer, but have used the correct language
syntax.
6. MAINTAIN AND UPDATE THE
PROGRAM

 Maintenance and update are the modification of a software


product after delivery to correct faults, to improve
performance or other attributes, or to adapt the product to a
modified environment.
6. MAINTAIN AND UPDATE THE
PROGRAM
 Types of maintenance
a) Corrective maintenance
- Reactive modification of a software product performed after
delivery to correct discovered problems. It deals with fixing
bugs in the code.
b) Adaptive maintenance
-Modification of a software product performed after delivery
to keep a software product usable in a changed or changing
environment. It deals with adapting the software to new
environments.
6. MAINTAIN AND UPDATE THE
PROGRAM
 Types of maintenance
c) Perfective maintenance
-Modification of a software product after delivery to
improve performance or maintainability. It deals with
updating the software according to changes in user
requirements.
d) Preventive maintenance
-Modification of a software product after delivery to detect
and correct latent faults in the software product before they
become effective faults. It deals with updating
documentation and making the software more maintainable.
7. DOCUMENTATION

 documentation should be concise so the person who


reads it doesn't have to spend too much time to find
what he or she is looking for.
 There are two types of documentation
a) Internal documentation
- The comments you put in your source code files should
be written to help other programmers navigate through
your code easily in order to find bugs or to determine
where to add new features.
7. DOCUMENTATION
 There are two types of documentation
b) External documentation
-is made up of the manuals written about the solution
-is written text that accompanies computer software. It
either explains how it operates or how to use it, and may
mean different things to people in different roles.

Potrebbero piacerti anche