You are on page 1of 76

CHAPTER 10

PROBLEM
SOLVING AND
PROGRAM DESIGN
PROBLEM

• Is a discrepancy between what is required and what


exists.

• Problems can be:


• very simple – Only one main task, adding tax to an
item
• very complex – As the number of tax increase so
does the complexity.
PROBLEMS

Simple problems More complex problems


• Find the average of a • Performing a linear
set of integers search ( for example
searching an ID number
• Calculating tax in a list of ID numbers)
payable
• Determining which
• Computing surface persons qualify for
area and perimeter something based on a
• Generating a list of particular set of criteria
prime numbers
SOLUTION

• A procedure consisting of a set of


instructions that, if followed in order, will
achieve the desired results.
PROBLEM SOLVING PROGRESS

• Problem
• Develop an idea, make a program to solve
problem?????
• Solution
5 STEPS IN PROBLEM SOLVING

• Define the problem


• Propose and analyze multiple solution
• Determine the most efficient solution
• Develop and represent the algorithm
• Test and validate the solution
CASE SCENARIOS
IN CLASS

• Write a case scenario that is associated


with a problem. Ensure to include all
necessary details to explain the problem.
At the end, address a solution for the
problem.
REVIEW PROBLEM SOLVING STEPS
DATA TYPE
• A category that states the values that can
be taken, how they are stored and what
range of operations are allowed on them.
DATA TYPES
1.INTEGER: Any whole number. Ex: 0, -27, 54
2.REAL: Any decimal number. Ex:13.5, -5.6
3.CHARACTER: A single value. Ex: D,K, #
4.STRING: Multiple characters. Ex: John, Eve
5.BOOLEAN: Two possible values. Ex: Yes/No
Data type Possible values that can Examples
be taken
Integer Any whole number 0
-27 -
540
Real Any decimal number 13.5
3.1472
-8.0

Character A single value from the ASCII ‘D’


character set ‘K’
‘#’

String Multiple characters ‘Frank’


‘Ruth’
‘955-0000’
Boolean Two possible values True/false
Yes/no
ACTIVITY: 01
1. A person’s age. ________________
2. A student monthly report average. ________________
3. The number of coins in a piggy bank. ________________
4. A person Name ____________
5. The number of items purchased. ________________
6. Math is your favourite subject True or False___
7. # can also be categorized as an ________
PROBLEM SOLVING

• Is the thought process that


requires a critical analysis of the
situation (the problem) and careful
consideration of possible ways of
overcoming the problem.
ALGORITHM

• Is a set of instructions that followed in


sequence will lead to a solution for the
problem.

• All Algorithm
1.Have a set of steps
2.Are precise
3.Are unambiguous
4.Have instructions that flow
5.Eventually terminate
IPO CHART
Input Processing Output
ALL the
What is given instructions The
that must be expected
executed to results
transform
what is given
into the
expected
results.
GRADED ASSIGNMENT (PPT, BRISTOL
BOARD)
1.Represent a real life example using an IPO chart.
2.Construct an Algorithm and represent in an IPO
chart.
3.What is pseudocode, ways of presenting
pseudocode. Give example.
4.what is flow chart, correct use of it, give
example.
CLASSWORK
PROBLEMS WITH SUM
1.Find the sum of three numbers.

INPUT PROCESSING
OUTPUT
START STORE (Num 1 +Num 2+ Num3)
SUM
INPUT Num 1 TO SUM
END
INPUT Num 2
INPUT Num 3
EXAMPLE IN REAL LIFE

Input Processing Output


Flour Prepare yeast and mix Bread
ingredients

Water Form the dough into a ball


and let rise

Yeast Form dough into a loaf,


place into the loaf pans

Salt Bake in the oven at 350


degrees F until loaf is
golden brown

Margarine
Given the price and taxes paid for an item. Calculate
the taxes to be paid and total price to be paid with
tax.
PROBLEM SOLVING: USE AN IPO CHART

1. Find the sum of five numbers.


2. Find the product of three numbers.
3. Find the average of four numbers.
REMEMBER:

• A computer accepts data, processes it and


outputs the result.
• Programs are stored in main memory
• Programs use variables and constants to
store data in RAM
NEW TERMS
• Constants- named location in memory
whose values remain the same during
program execution

• Variables- a named location in memory


whose values can change

• Identifiers- is the name given to variable or


a constant by the programmer.
USE APPROPRIATE DATA TYPES
1. The option in going to a field trip to the zoo.
2. The length of a baby.
3. The number of fruits purchased for a Christmas event.
4. The ID Number to access your online banking.
5. The Value of two unknowns in an equation.
6. The number of planets in our solar system.
7. The total value of money in the world.
8. The symbolic representation for items.
9. A series of numbers, letters or signs.
10.The choice of playing football over basketball.
ALGORITHM

• Is a set of instructions that followed in


sequence will lead to a solution for the
problem.

• All Algorithm
1.Have a set of steps
2.Are precise
3.Are unambiguous
4.Have instructions that flow
5.Eventually terminate
Representing Algorithm
An Algorithm may be represented in one of two ways: by
using FLOWCHARTS OR PSEUDOCODE.

PSEUDOCODE - is a way of documenting the solution to


a problem using simple structure instructions.

FLOWCHART - is a pictorial way of representing an


algorithm using a set of standard symbols.
FLOW CHART SYMBOLS

TERMINAL

DECIISION INPUT/
PROCESS OUTPUT
Symbols Meaning

> Greater than


>= Greater than or equal to

<> Not equal to


< Less than
<= Less than equal rto
IF<BOOLEAN> THEN <action 1>
ELSE < action 2>
Using Both
PSEUDOCODE FLOWCHART

Yes No
Mark >60
IF(>=60) THEN
WRITE ( You have pass)
END You have pass

END
Representation
IF….THEN….ESLE
PSEUDOCODE FLOWCHART

TRUE FALSE
Mark >=60
IF(score>=60) THEN
PRINT ( Julian Cho)
ELSE Well done Try harder
PRINT (NEED TO TRY HARDER)
ENDIF

END
FLOWCHART
ADDING TWO NUMBERS USING A FLOWcHART
PRACTISE

• Find the sum of Price A and Price B


• Find the sum of number 6 and
number 5
EXTENDED ACTIVITY
• Find the sum of three books. These books are
labelled as x, y and z.
• Find the sum of sales of four companies. These
companies are A,B, C and D.
WORD PROBLEMS

• Find the sum of four numbers


• Find the sum of two variables x
and y.
ADDING TWO VARIABLES

END
AVERAGE
FIND THE AVERAGE OF THREE NUMBERS
AVERAGE EXERCISE

• Find the average of sales 1, sales 2 and sales


3
• Find the average of x, y and z
• Input num 1, num2 and num 3. Compute
their average and give their output
• Input price A and price B. Find their product
FINDING THE AVERAGE OF THREE NUMBERS
PRACTISE

• Input three prices, compute their sum and


average
• Input letter A and letter B, find their sum and
product
• Read cost 1, cost 2 and cost 3. Find their product
and average
FINDING THE LARGEST NUMBER
FIND THE MIN AND MAX OF TWO NUMBERS
FINDING THE AREA OF A CIRCLE
AREA OF A CIRCLE
AREA OF RECTANGLE
AREA OF A SQUARE
ALGORITHM FOR BAKING BREAD
• Directions
• In a large bowl, dissolve yeast in warm water. Add the
sugar, salt, oil and 3 cups flour. Beat until smooth. Stir in
enough remaining flour, 1/2 cup at a time, to form a soft
dough.
• Turn onto a floured surface; knead until smooth and
elastic, 8-10 minutes. Place in a greased bowl, turning
once to grease the top. Cover and let rise in a warm place
until doubled, about 1-1/2 hours.
• Punch dough down. Turn onto a lightly floured surface;
divide dough in half. Shape each into a loaf. Place in two
greased 9x5-in. loaf pans. Cover and let rise until doubled,
30-45 minutes.
• Bake at 375° for 30-35 minutes or until golden brown and
bread sounds hollow when tapped. Remove from pans to
IT IS NOW AN ALGORITHM BECAUSE THE INSTRUCTIONS ARE SO SPECIFIC.
ALL ALGORITHMS

• Have a set number of steps


• Are precise
• Are unambiguous/accurate
• Have instructions that flow from one process
to another
• Eventually terminate
WAYS OF REPRESENTING ALGORITHMS

• Pseudocode and flowcharts are two ways of


representing algorithms
• Written using pseudocode
• Drawn as a flowchart
ENSURE YOU HAVE THE BASIC SYMBOLS USED WHEN DRAWING FLOW CHARTS
WHAT IS A FLOWCHART?

•A flowchart is a pictorial way


of representing an algorithm
using a set of standard
symbols.
FLOWCHART
EXAMPLE
WHAT DO YOU THINK THE FLOWCHART ABOVE REPRESENTS?
FLOWCHART RULES

• You draw and read a flowchart from top to bottom


and left to right.
• A flow chart should have only TWO terminal
symbols one labelled START and the other labelled
END or STOP.
INPUT/OUTPUT SYMBOL

• A data input/output symbol must


be labelled with either INPUT OR
OUTPUT.
PROCESS SYMBOL

• Pge 144 in Textbook


• Each symbol has one flow line
entering and one leaving.
DECISION SYMBOL

• Label with a question and has two


arrows leaving it. The task sequence
flows to the right if the decision is a NO
or down is the decision is a YES. The
flow lines leaving the symbol MUST be
labelled, one with YES and the other
with NO.
FLOWCHARTS SHOULD NOT HAVE:

• TWO ENDS. WHY?


• MULTIPLE FLOW LINES MAY COME TOGETHER
BUT ONLY ONE SHOULD LEAD TO A
TERMINAL SYMBOL. (end)
TURN TO THE HANDOUT FOR NOTES ON FLOWCHARTS AND AN EXAMPLE.
PRACTICE DRAWING A FLOWCHART
DEVELOPING ALGORITHMS TO SOLVE SIMPLE PROBLEMS

• In the 1960’s mathematicians prove that


any program could be constructed using
only three program flow control
structures: SEQUENCE, SELECTION
(DECISION) AND ITERATION(LOOPING).
SEQUENCE

• Instructions are executed one after the


other, in sequence.
• In pseudocode, it is represented as a set
of statements, written one after the
other, in a top to bottom fashion.
IF……THEN……ELSE
STATEMENT
Read in the original price of the goods
IF the cost is less than $500 THEN the discount price = .99
ELSE the discount price = .50
Print out the discount price.

Represent you answer using both a PSEUDOCODE and FLOWCHART.

You might also like