1/14/2015
Learning Outcomes
Explain the concepts of problem-solving and structured
programming.
Contents
Recognize 6 steps in problem solving1.
Types of problem1.
Difficulties with problem solving 1
Recognize 7 steps in program development process2.
Pseudocode and developing an Algorithm2
References:
Problem Solving and Programming Concepts (9th Edition) . Maureen Sprankle, Jim Hubbard, Pearson Education Limited 2012.
Simple Program Design. A step by step approach (5th Edition). Lesley Anne Robertson. Cengage Learning 2006.
References:
Problem Solving and Programming Concepts (9th Edition) . Maureen Sprankle, Jim Hubbard, Pearson Education Limited 2012.
Simple Program Design. A step by step approach (5th Edition). Lesley Anne Robertson. Cengage Learning 2006.
Problem Solving in Everyday Life
Problem-solving process (6 steps)
Identify the problem
What to do?
Understand the problem
Knowledge base required
Identify alternatives
Other acceptable methods
Select the best way to solve the problem
List the instructions
All steps required
Evaluate the solution
Check to see if result is correct
Problem Solving in Everyday Life
Example : You are doing assignment at home, and you
are hungry
Identify problem : you are hungry
Understand the problem : you need food
Identify Alternatives :
1.) look for mum
2.) go to kitchen and look for some food
3.) go to kitchen and prepare food yourself
4.) make a food delivery order
5.) go out to have a meal in restaurant / hawker center
1/14/2015
Problem Solving in Everyday Life
Example (continued)
Select the best way
Method 1 : you arent kid anymore
Method 2 : might be a good idea
Method 3 : you might not have time since you are
doing assignment.
Method 4 : might be expensive
Method 5 : you might not have time since you are
doing assignment.
After some consideration, let say you choose method 2
Types of problem
Algorithmic solutions
Can be solved with a series of actions (the algorithm)
Log on to an e-mail account
Withdraw cash from ATM machine
Problem Solving in Everyday Life
Example (continued)
List out the instruction
Go out from the room
Go to kitchen
Search the table, cabinet, refrigerator for food
Consume the food
evaluate the solution
Is the solution help to solve the problem?
Is the solution solve the problem efficiently?
Should we follow the same solution next time?
Types of problem (cont)
6-steps can be used for both problems
But step 6 (for heuristic solutions)
Correctness and appropriateness far less certain
May need to iterate (repeat) many times
Same solution may not work all the time
Heuristic solutions (rule of thumb)
Based on knowledge & experience
Requires a process of trial and error
Add Salt to food (during cooking)
Buying the best stock
Problem solving with computers
Computers built for dealing with algorithmic solutions
Write instruction step by step
Heuristic solutions requires (Artificial) intelligence
The program can make decision like human when for
each situation base on previous solution
Need to transform into algorithmic format
Most problems require a combination of the two kinds
of solutions
Driving a vehicle
Fix a malfunction computer
Difficulties with problem solving
Why?
One or more steps in Problem solving process are not
completed adequately.
Problem-solving process requires time and practice
Problem solving on the computer.
Problem with writing the instruction
E.g. List 5 numbers and pick the largest one.
(Can you explain/list all the steps required?)
The computer is a tool that will perform only tasks that the
user can explain.
All steps must be in proper order
1/14/2015
7 Steps of Program Development Process
7 Steps of Program Development Process
Programming can be defined as the development of a
solution to an identified problem, and the setting up
of a related series of instructions that will produce
the desired results
1.
Define the Problem
To help with initial analysis, the problem should be
divided into three separate components:
the inputs
the outputs
the processing steps to produce the required outputs
4. Test the algorithm (for correctness)
1 Define the Problem
To help with initial analysis, the problem should be
divided into three separate components:
the inputs
the outputs
the processing steps to produce the required outputs
Use IPO chart (Input Process Output chart)
2 Outline the Solution
This initial outline is usually a rough draft of the
solution and may include:
The major processing steps involved
The major subtasks (if any)
The user interface (if any)
The major control structures (e.g. repetition loops)
Define the problem
2. Outline the solution
3.
Develop an algorithm (based on the outline)
5. Code the algorithm (into a specific programming language)
6. Run the program (on the computer)
7. Document & Maintain the program
1 Define the Problem
Example:
Shop A is offering a 20% discount for all products.
Calculate the payment for the customers.
Input
Discount rate, original price of the products
Output
payment
Process
Calculate payment
2 Outline the Solution
Example (step by step to solve the problem) :
Get the price of product purchase by the customer
Get the discount rate
Calculate the discount amount
Calculate the payment after discount
Display the payment amount to the customer
The major variables and record structures
The mainline logic
1/14/2015
3 Develop the Outline into an Algorithm
4 Test the Algorithm for Correctness
The solution outline developed in Step 2 is expanded
into an algorithm: a set of precise steps that describe
exactly the tasks to be performed and the order in
which they are to be carried out
This step is one of the most important in the development
Develop flow chart and pseudocode from IPO chart
to identify major logic errors early, so that they may be
of a program, and yet it is the step most often forgotten
The main purpose of desk checking (test the algorithm) is
easily corrected
Early error identification is better because will save time
and cost
5 Code the Algorithm into a Specific
Programming Language
6 Run the Program on the Computer
Only after all design considerations have been met
This step uses a program compiler and programmer-
should you actually start to code the program into your
designed test data to machine test the code for syntax
chosen programming language (e.g c++, c , Java)
errors and logic errors
Syntax error any violation of rules of the language
results in syntax error
Logic errors these errors are related to logic of the
program execution
7 Document and Maintain the Program
Program documentation should not be listed as the
last step in the program development process, as it is
really an ongoing task from the initial definition of the
problem to the final test result
Documentation involves both external documentation
and internal documentation that may have been coded
in the program
Algorithms
A program must be systematically and properly
designed before coding begins
This design process results in the construction of an
algorithm
1/14/2015
What Is an Algorithm?
An algorithm is like a recipe: it lists the steps involved
in accomplishing a task
It can be defined in programming terms as a set of
detailed, unambiguous and ordered instructions
developed to describe the process necessary to
produce the desired output from a given input
Tools to build algorithm
From algorithm, we also can uses:
Pseudocode (more English-like)
Flowcharts
Nassi-Schneiderman diagrams
As all above are all popular ways of representing
algorithms
Summary
The steps in program development were introduced
and briefly described below:
1. Define the problem
2. Outline the solution
3. Develop the outline into an algorithm
4. Test the algorithm for correctness
5. Code the algorithm into a specific programming
language
6. Run the program on the computer
7. Document and maintain the program