Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
CHAPTER 2
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
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
TOTAL PRICE
CONTROL MODULE
0000
start
Print TotalPrice
end
3. DESIGN THE ALGORITHM TO SOLVE
THE PROBLEM
d) Pseudo code
START
Input WeightInKg, PricePerKg
TotalPrice = WeightInKg * PricePerKg
Print TotalPrice
END
4. IMPLEMENT THE ALGORITHM
#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
Type of errors
Logical Error