0% found this document useful (0 votes)
81 views25 pages

Ditp 1113 - Programming I SEMESTER 1 - 2014/2015: Problem Solving

This document discusses problem solving and system development. It explains the four steps to problem solving: 1) understand the problem, 2) develop the solution, 3) write the program, and 4) test the program. It provides examples of using pseudo code and flowcharts to develop solutions. Structured programming techniques like top-down design and stepwise refinement are recommended. The waterfall model of system development is described. Examples are given to demonstrate applying the four steps of problem solving to convert between miles and kilometers and calculate purchase costs with discounts.

Uploaded by

Hanani Idris
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views25 pages

Ditp 1113 - Programming I SEMESTER 1 - 2014/2015: Problem Solving

This document discusses problem solving and system development. It explains the four steps to problem solving: 1) understand the problem, 2) develop the solution, 3) write the program, and 4) test the program. It provides examples of using pseudo code and flowcharts to develop solutions. Structured programming techniques like top-down design and stepwise refinement are recommended. The waterfall model of system development is described. Examples are given to demonstrate applying the four steps of problem solving to convert between miles and kilometers and calculate purchase costs with discounts.

Uploaded by

Hanani Idris
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Lecture 2

PROBLEM SOLVING
DITP 1113 PROGRAMMING I
SEMESTER 1 2014/2015
System Development
Definition: The critical process determines the
overall quality and success of the program.
If any program is design carefully using good structured
development techniques, the program will be efficient,
error-free and easy to maintain.
Most programming projects are built using System
Development Life Cycle (SDLC).
One of the popular development life cycle is known as the
waterfall model.
Waterfall model
Identify
program
components.
Looks at
different
alternatives
from a
system
viewpoint.
Review program specification
(input, output, process).
Analyst meet with the users.
Read and understand the question.
Algorithm a list of steps to solve the
problem.
Top-down design divide & conquer.
Algorithm refinement improvised the
algorithm
Flowchart graphically shows the
logic in a solution algorithm.
Pseudo code describe a program
using English-like technique.
Write programs
(coding).
Compile and
execute.
Update
program/system
from time to
time.
Fix errors &
enhance the
system.
Verify tasks as desired.
Run the programs repeatedly using
different data sets.
Errors type: syntax, run-time or logic
Development of program
A multi-step process that requires you understand the
problem, develop a solution, write the program, and test it.
To determine how to take the inputs given and then
convert them into the specified output (program design).
4 steps involve in solving problems:
1. Understand the problem
2. Develop the solution
3. Write the program
4. Test the program
Example of the problem:
A user can read a map in kilometers but the map shows
distances in miles.
Development of program (coding)
Problem: Convert distance in miles (m) to kilometers (km).
4 steps involve in solving problems:
1. Understand the given problem
Carefully read the requirements statement.
Ask few clarifying questions even for the simplest problem
statements.
Determines I.P.O. (input, process, output)
Input the distances in miles (m)
Process conversion formula
1 mile = 1.609 kilometers
kms = miles x 1.609
Output the distance in kilometers, (km)
1. Understand the problem
2. Develop the solution
3. Write the program
4. Test the program
Development of program (coding)
Problem: Convert distance in miles (m) to kilometers (km).
4 steps involve in solving problems:
2. Develop the solution
Tools to solve problems
Structure chart to design the whole program
Pseudo-code to design the individual parts of a program
(eg. module / function)
Flowchart to design the individual parts of a program
(eg. module / function)
1. Understand the problem
2. Develop the solution
3. Write the program
4. Test the program
Development of program
Problem: Convert distance in miles (m) to kilometers (km).
4 steps involve in solving problems:
2. Develop the solution
Structure chart
To design the whole program
- The functional flow through
your program.
- Shows the breakdown of a
program to its lowest
manageable levels.
- Shows your program divided
into logical steps each step as
separate module
- The interaction between
modules of your program.
Distance
Conversion
Get miles
Calculate
Conversion
Print
kilometers
1. Understand the problem
2. Develop the solution
3. Write the program
4. Test the program
Development of program
Problem: Convert distance in miles (m) to kilometers (km).
4 steps involve in solving problems:
2. Develop the solution
Pseudo code
To design individual parts of the
program
(eg. module/function)
- Precise algorithmic description
of program logic
- Precisely describe the
algorithm detail, what the
program being design.
- Requires to define, in sufficient
detail, the steps to accomplish
the task so that can be
converted into a computer
program.
Algorithm Calculate Distance Conversion
received units in miles, ms
convert to kilometers using kms = ms * 1.609
return kms in kilometers unit
End Algorithm
1. Understand the problem
2. Develop the solution
3. Write the program
4. Test the program
Development of program
Problem: Convert distance in miles (m) to kilometers (km).
4 steps involve in solving problems:
2. Develop the solution
Flowchart
To design individual parts of the
program
(eg. module/function)
- A graphical or symbolic
representation of a process.
- Each step in the process is
represented by a different
symbol and contains a short
description of the process
step.
- Use standardised symbols
and linked together with
arrows showing the process
flow direction.
1. Understand the problem
2. Develop the solution
3. Write the program
4. Test the program
Start
kms ms * 1.609
Receive units
in miles (ms)
End
Return result
(kms)
Development of program
Problem: Convert distance in miles (m) to kilometers (km).
4 steps involve in solving problems:
3. Write a program
Remember:
Syntax
; {} () >> << etc
Declare variable(s)
Initialise variable(s)
#include <iostream>
using namespace std;
const float m2km = 1.609;
float ms, kms;
void getMiles()
{ cin >> ms; }
void printKilometers()
{ cout << kms; }
float convertM2KM()
{ return ms * m2km; }
void main()
{
getMiles();
kms = convertM2KM();
printKilometers();
}
1. Understand the problem
2. Develop the solution
3. Write the program
4. Test the program
Development of program
Problem: Convert distance in miles (m) to kilometers (km).
4 steps involve in solving problems:
4. Test a program two types of testing:-
Blackbox Testing
Whitebox Testing
Differences?
Blackbox Whitebox
Test by the system engineer and
the user.
Test by the programmer.
Testing without knowing how does
the program works.
Testing with the tester that knows
everything about the program.
Test by looking only at the
requirements statement.
Test to ensure that every single
instruction and possible situation
have been tested.
1. Understand the problem
2. Develop the solution
3. Write the program
4. Test the program
Examples of problem solving
Problem Statement #1:
Compute and display the total cost of apples by
receiving the number of kilograms of apples
purchased and the cost per kilogram of apples.
Step 1: Understand the problem
Input number of apples purchased (numKiloApples), cost per kilogram
of apples (costPerkg)
Process formula total cost = cost per kilogram of apples x number of
apples kilograms (totalCost= numKiloApples x costPerkg)
Output Total cost of purchased apples (totalCost)
Examples of problem solving
Problem Statement #1:
Step 2: Develop the solution
(pseudo code)
Algorithm cost of apples purchased
Get number of kilogram of
apples purchased
Get cost per kilogram of apples
Compute the total cost of apples
The total cost of apples is number of kilogram of
apples purchased multiply/times cost per kilogram
Display the total cost
End algorithm
Step 1: Understand the problem
Input number of apples
purchased (numKiloApples), cost
per kilogram of apples
(costPerkg)
Process formula total cost = cost
per kilogram of apples x number
of apples kilograms (totalCost=
numKiloApples x costPerkg)
Output total cost of purchased
apples (totalCost)
Examples of problem solving
Problem Statement #1:
Step 2: Develop the solution (flowchart)
Step 3: Write the program(C++ codes)
Start
Read kilograms of apples
(numKiloApples)
Compute the total cost of apple purchased,
totalCost= numKiloApples x costPerkg
Print
Total cost of apples
in RM (totalCost)
End
Get cost per kilogram of
apples (costPerkg)
void main()
{
int numKiloApples;
int costPerkg;
int totalCost;
cout << Give number of kilograms of apples purchased: ";
cin >> numKiloApples;
cout << Enter cost per kilograms of apples: ";
cin >> costPerkg;
totalCost = numKiloApples * costPerkg;
cout >> The total cost of apples is >> totalCost;
}
Examples of problem solving
Problem Statement #2:
During the promotion of Ummies Boutique, 30%
discount is given to every item purchased. Write a
program to compute and display the price after
discount for every item purchased by the customers.
Step 1: Understand the problem
Input Price of the item, priceBefore
Process
formula discount = priceBefore x 0.3
formula priceAfter = priceBefore - discount
Output Price after discount, priceAfter
Examples of problem solving
Problem Statement #2:
Step 2: Develop the solution
(pseudo code)
Algorithm price after discounted
get the price of the item (priceBefore)
compute the price of the item after discount
compute discount = priceBefore x 0.3
compute priceAfter = priceBefore - discount
display the the price after discount, priceAfter
End algorithm
Step 1: Understand the problem
Input Price of the item,
priceBefore
Process
discount = priceBefore x 0.3
priceAfter = priceBefore discount
Output Price after discount,
priceAfter
Examples of problem solving
Problem Statement #2:
Step 2: Develop the solution (flowchart)
Step 3: Write the program(C++ codes)
Start
Get Items price (priceBefore)
Compute the price after discount
priceAfter = priceBefore discPrice
Display the price after
discount, priceAfter
End
Compute the discount
discPrice = priceBefore x 0.3
void main()
{
float priceBefore;
float discPrice;
float priceAfter;
cout << Key in the price of item: ";
cin >> priceBefore;
discPrice = priceBefore * 0.3;
priceAfter = priceBefore discPrice;
cout >> The price after 30% discount is >> priceAfter;
}
Flowchart with different structure
If/else double-selection structure:
Pseudo code:
If students grade is greater than or equal to 60
Print Passed
Else
Print Failed
Flowchart with different structure
If/else double-selection structure:
Pseudo code:
While product is less than or equal to 1000
Multiply product by two
Examples of problem solving
Problem Statement #3:
SHN Enterprise is given 10% discount for every item
with price of above RM100 only. Write a program that
compute and display the price after discount for
every item purchased by the customers.
Step 1: Understand the problem
Input Price of the item, priceBefore
Process
formula discount = priceBefore x 0.1
formula priceAfter = priceBefore discount
Output Price after discount, priceAfter
Examples of problem solving
Problem Statement #3:
Step 2: Develop the solution
(pseudo code)
Algorithm price after discounted
get the price of the item, priceBefore
compute the item discount
if priceBefore > 100
compute discount = priceBefore x 0.1
else
discount = 0
compute priceAfter = priceBefore discount
display the price after discount, priceAfter
End algorithm
Step 1: Understand the problem
Inputs Price of the item,
priceBefore
Process
discount = priceBefore x 0.1
priceAfter = priceBefore discount
Output Price after discount,
priceAfter
Examples of problem solving
Problem Statement #3:
Step 2: Develop the solution (flowchart)
Start
Discount = priceBefore x 0.1
Get Items price, priceBefore
Display price after
discount, priceAfter
End
Compute the price after discount
priceAfter = priceBefore - discount
priceBefore > 100?
discount = 0
Yes No
Examples of problem solving
Problem Statement #3:
Step 3: Write the program(C++ codes)
void main()
{
float priceBefore;
float discPrice;
float priceAfter;
cout << Key in the price of item: ";
cin >> priceBefore;
if (priceBefore > 100)
{
discPrice = priceBefore * 0.1;
}
else
{
discPrice = 0;
}
priceAfter = priceBefore discPrice;
cout >> The price after 10% discount is >> priceAfter;
}
Indent program properly
Use a good indentation style to enhance the readability of a
program.
The layout of a program should make it easy for a reader to
identify the program's modules.
Use blank lines to offset each function.
Also, within both functions and the main program, you should
offset with blank lines and indent individual blocks of code visibly.
These blocks are generally - but are not limited to - the actions
performed within a control structure, such as a while loop or an if
statement.
Any questions..?
End of Lecture 2..

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy