02 Introduction To Problem Solving
02 Introduction To Problem Solving
Reference:
Problem Solving and Programming Concepts 9th Edition
by Maureen Sprankle and Jim Hubbard
• Structure of Programs
• People make decisions every day to solve problems that affect their
lives
• Important problems
• Unimportant problem
• Bad/Good decision
Six Steps of Problem Solving
• There are six steps to follow to ensure the best decision.
• Most people use them without even knowing it:
1. Identify the problem.
2. Understand the problem.
3. Identify alternative ways to solve the problem.
4. Select the best way to solve the problem from the list of alternative
solutions.
5. List instructions that enable you to solve the problem using the selected
solution.
6. Evaluate the solution.
Six Steps of Problem Solving
1. Identify the problem
• The first step toward solving a problem is to identify the problem
Input
• What is the specific problem?
• This means you should determine what is that you want to change. Problem
• If you don’t know what the problem is, you cannot solve it.
Six Steps of Problem Solving
2. Understand the problem
• You must understand what is involved in the problem before you can continue
toward the solution.
• This includes understanding the knowledge base of the person or machine for
whom you are solving the problem.
• Also, you must know your own knowledge base., You cannot solve a problem if
you do not know the subject. For example, to solve a problem involving
accounting, you must know accounting.
Six Steps of Problem Solving
3. Identify alternative ways to solve the problem
• Generate as many potential solutions as possible.
• Use modules to break the whole problem into parts, with each part
having a particular function.
• Use the three logic structures to ensure that the solution flows
smoothly from one instruction to the next, rather jumping from one
point in the solution to another.
Structure of Programs
• Program Structures:
• The sequential Structure.
• Ex: Simple calculation.
• Computational problems
• involving some kind of mathematical processing
• Logical Problems
• involving relational or logical processing
• Repetitive Problems
• involving repeating a set of mathematical and/or logical instructions.
Beginning Computer Concepts for Problem
Solving
• Basic building programming blocks:
• Equations
• Consist of constant, variables and operators.
• Expressions
• Decisions and repeat control statements.
• Functions
Beginning Computer Concepts for Problem
Solving
• Constants:
• Does not change during the processing of all the instructions in a solution
• Examples
• 3, 5, 10, “Sara”, “+”, “-”, “/”
Beginning Computer Concepts for Problem
Solving
• Variables:
• May change during processing
• In many programming languages, variables are called identifiers.
• A name is assigned to each variable used in a solution and should be
consistent with what the value of the variable represents.
• The computer uses the variable name to find the location; it uses the value
found at the memory location to do the processing.
• Ex:
• Name=“Java”
• Test_Score=95
Beginning Computer Concepts for Problem
Solving
• Data Types:
• Data can come with different type:
• Numeric
• Character
• Logical
• Certain organizational tools will help you learn to how solve problems
on the computer.
• Flowchart
Algorithm
Output list
Writing the Algorithm
solution.
algorithm.
• Most block have one or more entrances and have only one exit .
Flowchart Symbol
entering another.
Flowchart Symbol
Flowchart Symbol Explanation
Start
• Flattened ellipses indicate the start and the end of a module. An
• A start has no flowlines entering it and only one exiting it; an end
calculations,
• An input/output (I/O) block has one entrance and only one exit.
Flowchart Symbol
Flowchart Symbol Explanation
False True • The diamond indicates a decision. It has one entrance and two
condition
Input
Hours & Pay rate
Problem
Output
Gross Pay
Example: Payroll System
• Problem: Calculate the gross pay of an employee given the hours
worked and the rate of pay. The gross pay is calculated by multiplying
the hours worked by the rate of pay.
Step 5 Start
3. Calculate Pay
4. Print Pay Print Gross Pay
5. End
End
Develop a flowchart
• Sarah is traveling from city A to city B. The distance between the two
cities is a variable because she would like to use the equation to use
for other cities. She knows that 50% of the time she will be traveling
50 kilometre an hour and the remaining 50% she will be traveling 100
kilometre per hour. Write an equation that will calculate the time it
will take to travel from one city to the next.
Solution
50 k/h 100 k/h
City A City B
Time=Distance??/Speed
Problem
Output
Time
Solution
Step 5
6. End
Solution
Step 5
Start
Read distance
Time 1= 0.5*distance/50
Time 2= 0.5*distance/100
Total time=Time1+Time2
End
Develop a flowchart & algorithm
• Ahmad would like to know the average of his test scores. Write an
equation that would calculate the average given five test scores.
4. Print average
5. End
Solution
Step 5
Start
Average=total/5
Print Average
End