0% found this document useful (0 votes)
33 views

The Problem Solving Process & Algorithms

Here are the pseudocode, narrative and flowchart for the problem: Pseudocode: Start Declare length1, width1, length2, width2, area, time as real Write "Enter length and width of block" Read length1, width1 Write "Enter length and width of house" Read length2, width2 area <- (length1 * width1) - (length2 * width2) time <- area / 2 Write "Mowing time required is", time Stop Narrative: 1. Prompt user to enter length and width of block 2. Accept values and store in variables 3. Prompt user to enter length

Uploaded by

DeJeanae Lewis
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

The Problem Solving Process & Algorithms

Here are the pseudocode, narrative and flowchart for the problem: Pseudocode: Start Declare length1, width1, length2, width2, area, time as real Write "Enter length and width of block" Read length1, width1 Write "Enter length and width of house" Read length2, width2 area <- (length1 * width1) - (length2 * width2) time <- area / 2 Write "Mowing time required is", time Stop Narrative: 1. Prompt user to enter length and width of block 2. Accept values and store in variables 3. Prompt user to enter length

Uploaded by

DeJeanae Lewis
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

The Problem Solving Process &

Algorithms

Mr Allen
Immaculate Conception High School
Objectives
By the end of the lesson students should be
able to:

Differentiate among the three ways of


representing algorithms.
State the properties of a good algorithm.
Represent Algorithms using flow charts,
Pseudocodes and narratives.
What is Problem Solving?
Problem Solving
Problem solving is the process of finding solutions
to problems, whether difficult or simple.
What are the stages in the
Problem Solving Process?
Stages in the problem solving process
• Problem definition
• Problem analysis
• Identify and evaluate possible solutions
• Select and justify optimal solutions
• Implementation and review.
Defining Diagrams
Defining diagrams are tables that are utilized to aid
in the decomposition of a programming problem.
They allow for the programmer to see clearly the
requirements that he/she will need to implement to
reach a solution. A properly done defining diagram
can make a great difference to a properly designed
program.
Example
Design a program solution that will read two
numbers from the user, calculate the sum of those
two numbers and output the result to the user.
Defining Diagram/IPO Chart Example
Inputs Processing Outputs
num1 Read num1, num2 sum
num2 Calculate Sum:
sum  num1 + num2
Display sum
What is an algorithm?
What is an Algorithm?
An algorithm is a sequence of steps devised with the
purpose of solving a problem. A
computer program can be viewed as an elaborate
algorithm.

What role does an algorithm play in the


problem solving process?
What are the properties of a
good algorithm?
Properties of a good Algorithm
1. A general solution to the problem.
2. Clearly defined and unambiguous steps.
3. Flow of control from one process to another.
4. A finite number of instructions /steps.
What are the three ways of
representing an algorithm?
Ways of Representing algorithms

The three main ways of representing algorithms


are:
• Narratives
• Flow Charts
• Pseudocodes
Pseudocodes
 Pseudocodes are an informal way of
programming description that does not require any
strict programming language syntax but resemble .
It is used for creating an outline or a rough draft of a
program.
Pseudocode Example
START
DECLARE num1, num2, sum as INTEGER

num1 0
num2 0
sum 0

WRITE “Please enter two numbers”


READ num1, num2

sum num1 + num2


WRITE “The sum is: ” sum

STOP
Narratives
This representation of an algorithm is the closest
in nature to English. You will simply need to state
the main steps to solve your problem in English
statements. In simpler terms a narrative is a
summary of the steps of a program. A narrative
should be void of technical terms, its main purpose
is to explain an algorithm to stake holders such as a
client.
Example
Pseudocode Narrative
Algorithm: Sum of Two Numbers Algorithm: Sum of Two Numbers
Developer: Developer:
Date: Date:
START
Declare variables num1, num2 and START
sum AS INTEGER Step 1: Prompt user to enter two numbers
Step 2: Accept the two numbers and store
num1 num2 sum  0 them
Print “Enter two numbers” Step 3: Add the two numbers
Step 4: Display the sum of the two numbers.
Read num1, num2.
sum num1 + num2 STOP
Print sum
STOP
Flow Charts
A flowchart is a type of diagram that represents
an algorithm or process, showing the steps as boxes
of various kinds, and their order by connecting them
with arrows.
Flow Chart Symbols
Other Flow Chart Symbols
START

DECLARE first_name, middle_name, last_name as string

DECLARE Bet, Amt_won, Amt_lost, Total_win as real

Flow Chart Example WRITE “Please type your full name including middle name:”

READ first_name, middle_name, last_name


START A
WRITE “Please input your bet amount:”
DECLARE first_name, middle_name, last_name as string

READ Bet

DECLARE Bet, Amt_won, Amt_lost, Total_win as real


(LET) Amt_won <-- (Bet * Bet) / ( (Bet * Bet) - ( 100 * Bet ) )* 25000

WRITE “Please type your full name including middle name:”


(LET) Amt_lost <-- (35 / 100) * bet

READ first_name, middle_name, last_name


(LET) Total_win <-- Amt_won - Amt_lost

WRITE “Please input your bet amount:”


WRITE first_name, middle_name, last_name

READ Bet
WRITE “"Total Winnings: JA$", Total_win

A
(LET) Amt_won <-- (Bet * Bet) / ( (Bet * Bet) - ( 100 * Bet ) )* 25000
STOP

(LET) Amt_lost <-- (35 / 100) * bet


BREAK TIME
Class Activity 1
Explain briefly the stages in the Problem Solving
Process
Class Activity 2
Create a Pseudocode, Narrative and flow chart to
solve the following problem.

1. A program is required to read from the screen the


length and width of a rectangular house block and
the length and width of the rectangular house
that has been built on the block. The program
should then compute and display the mowing
time required to cut the grass around the house at
the rate of two square meters per minute.

You might also like