3 ProblemSolving PDF
3 ProblemSolving PDF
FUNDAMENTALS
WEEK # 3 PROBLEM SOLVING
CASE STUDY
1 Marriam Daud
Dept of Computer Science & IT
The University of Lahore
[email protected]
INTRODUCTION TO PROBLEM SOLVING
Programming is a problem solving activity. When
you write a program, you are actually writing an
instruction for the computer to solve something
for you.
2
CASE STUDY: YUMMY CUPCAKE
3
SOFTWARE DEVELOPMENT METHOD (SDM)
For programmer, we solve problems using Software
Development Method (SDM), which is as follows:
1. Specify the problem requirements.
2. Analyze the problem.
3. Design the algorithm to solve the problem.
4. Implement the algorithm.
5. Test and verify the completed program.
6. Documentation
4
1. REQUIREMENT SPECIFICATION
Specifying the problem requirements requires you to state
the problem clearly and to gain the understanding of what
to be solved and what would be the solution.
When specifying problem requirement, we ask ourselves
the following questions:
What the problem is?
What the solution should provide?
What is needed to solve it?
If there are constraints and special conditions?
5
YUMMY CUPCAKE
6
2. PROBLEM ANALYSIS
Analyzing the problem require us to identify the following:
Input(s) to the problem, their form and
the input media to be used
Output(s) expected from the problem,
their form and the output media to be
used
Special constraints or conditions (if any)
Any formulas or equations to be used
7
YUMMY CUPCAKE
Input?
Quantity of the cupcake purchased (integer)
Price per cupcake (RM, float)
Output?
Total amount to be paid by the customer (float)
Constraint/condition?
Quantity purchased must be more than zero
Price per cupcake must be more than zero (it is not free)
We assume that the price given is the standard price to all
cupcakes
Formula/equation?
Amount to pay = quantity of cupcake x price per cupcake
8
3. DESIGNING ALGORITHM
10
YUMMY CUPCAKE
Major Task:
1. Read the quantity of cupcake purchased
2. Read the price per cupcake
3. Calculate total amount to pay
4. Display the total amount to pay
However, looking at the above algorithm, we can still further refine step 3,
by introducing the formula to calculate the amount to pay.
After Refinement:
1. Read the quantity of cupcake purchased
2. Read the price per cupcake
3. Total amount to pay = quantity of cupcake x price per cupcake
4. Display the total amount to pay
11
4. IMPLEMENTATION
The
process of implementing an algorithm by writing a
computer program using a programming language (for
example, using C language)
Theoutput of the program must be the solution of the
intended problem
Theprogram must not do anything that it is not
supposed to do
(Think of those many viruses, buffer overflows, trojan horses,
etc. that we experience almost daily. All these result from
programs doing more than they were intended to do)
12
5. TESTING AND VERIFICATION
Program testing
is the process of executing a
program to demonstrate its correctness
Program verification is
the process of ensuring
that a program meets user-requirement
After theprogram is compiled, we must execute
the program and test/verify it with different inputs
before the program can be released to the public
or other users (or to the instructor of this class)
13
6. DOCUMENTATION
Writing description that explain what the program
does.
Can be done in 2 ways:
Writing comments between the line of codes
Creating a separate text file to explain the program
14
DOCUMENTATION CONT…
Documentation is so important because:
You may return to this program in future to use the whole of
or a part of it again.
Other programmer or end user will need some information
about your program for reference or maintenance
You may someday have to modify the program, or may
discover some errors or weaknesses in your program
Although documentation is listed as the last stage of
software development method, it is actually an
ongoing process which should be done from the very
beginning of the software development process.
15