Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Information Technology

January 11, 2022


Problem Solving and Programme Design

Objectives
 Define the terms problem and problem solving
 Outline and explain correctly each step in the problem-solving phase
 Illustrate by decomposing large everyday problems into smaller tasks by using the dive and
conquer approach.

A problem is anything that needs to be solved or a task that needs to be accomplished. The steps in
problem solving

Groupwork Activity
Your younger sister is having her 16th birthday party and the caterer is unable to complete the order due
to being sick. You volunteer to help out with the cake.

1. Decide on the cake you want to bake


2. Find a cake recipe
3. Gather the ingredients, tools and decorations for the cake
4. Preheat the oven
5. Mix the ingredients to make batter
6. Grease the pan
7. Pour the batter in the pan
8. Put the pan in the oven and let it bake
9. Take the cake out the oven the oven and make it cool
10. Decorate the cake

OR

1. Find a reputable bakery


2. Choose a cake to order
3. Order the cake you want
4. Wait for the cake to be delivered
Information Technology H/W
January 11, 2022

1. Define algorithm
It is a finite sequence of well-defined instructions typically used to solve a class of specific
problems.

2. Identify the three ways in which you can represent an algorithm.


Three ways an algorithm can represented in natural language, flow charts and pseudocode.

3. What are the characteristics of a good algorithm?


→ Well Ordered- The exact order of operations performed should be concretely defined
→ Input: It should be able to accept a well-defined set of inputs
→ Outputs- It should produce some result as an output, so that its correctness can be
reasoned.
→ Finiteness- It should terminate after a finite number of instructions

Should always give the correct solution


Part 2

Input Processing Output


Accept num1, num2 IF num1>num2 lnum
THEN lnum←num1
ELSE lnum←num2
ENDIF
PRINT lnum

Or
If num1>num2 then
Lnum1←num1
Endif

If num2>num1 then
lnum←num2

Eg) num1←5
num2←23
IF 5>23 then
lnum←5
endif

IF 23>5 then
lnum←23
endif
PRINT 23

2. To calculate the discount price of a computer. If the computer costs more than $2,000, the discount
is 17%. If not, it is 14%. Print the original price, discount and the price after the discount.

Input Processing Output


Read price IF PRICE >2000 then Print Price, Discount, Total
Discount ← Price*0.17
Total ← Price - Discount
ELSE
Discount ← Price*0.14
Total ← Price ← Discount
ENDIF
Print Total, Discount, Price

4. A customer pays a monthly fee of $37.50 for telephone service and $3.50 per minute for long
distance calls. Input the number of minutes for long distance calls. Calculate and print the total
bill.

Input Processing Output


ACCEPT LDC mins IF mf ← 37.50 Total
LDC ← LDC mins*3.50
Total ← mf + LDC
Print total
Information Technology
January 18, 2022
Defining Diagrams- IPO Charts
Variables are data values that can change when the user is asked a question, for example their age.
Variables may change during programme execution.

 Can include digits but shouldn’t start with digits


 Shouldn’t include special characters
 Cannot used reserved words relating to that particular language
Information Technology
January 20, 2022
Problem Solving and Programme Design
Defining Diagrams

1. To read a number P. If the number is greater than 50. It should add 20 to P. If not, it
should subtract 20 from P. Print the result.

Input Processing Output


Read P IF P>50 THEN Result
Result ← P + 20
ELSE
Result ← P – 20
ENDIF
Display Result
Information Technology
January 20, 2022
Problem Solving and Programme Design
Defining Diagrams

The “IF Statement” is also called Selection, Conditional or Decision-Making. There are some examples
which we will use.

IF [condition] THEN IF [condition] THEN IF [condition] THEN

Statement Statement Statement

ELSE ENDIF ELSIF [condition] THEN

Statement IF [condition] THEN Statement

ENDIF Statement ELSIF [condition] THEN

ENDIF Statement

ELSE [condition] THEN

Statement

ENDIF

IF A>B THEN

Lnum ← A

ELSEIF B>A THEN

Lnum ← B

ELSEIF C ← Lnum

ENDIF
Information Technology
February 1, 2022
Problem Solving and Programme Design
Literals
Literals are constants that are written literally as itself rather than a value.
Examples- “The average is”, “The smallest number is”, “The highest grade is”.

Literals are normally used with the input/output instructions that appear as a message for the
user (prompt). The messages /prompts make the programme user friendly.

Data Type
Data type indicate or tells the type of data a variable can store. A variable can store the
following Data Types:

 Integer- Are negative or positive whole numbers (without decimal places)


 Floating Point/Real Number- Are positive or negative numbers with decimal places
 Characters- Are single letters or symbols (asterisks, hashtag, dollar sign and etcetera)
 String- A collection of characters (“I love you <3”)
 Boolean- Can only store one of two values (True or False, Yes or No). This is ideal for
storing the result of an operation that can either be true or false.

Information Technology
February 3, 2022
Problem Solving and Programme Design
Algorithm Pseudocode
This algorithm closely resembles the language instructions that computers follow.’

Algorithm Student’s_Data

This algorithm will display the student’s name and age

Start

Display “Please enter your name

Accept Name

Display “Enter age”

Accept age

Display “Hello”, Name,

“Your age is”, Age, “years old”

Stop

Write an algorithm pseudocode to prompt a user to enter their first and last names. Output a
welcome message that says “Welcome to our world!” with the names after it. The message must be a
constant.
Algorithm Greetings
Const
Message= “welcome to our world”
Var
Firstname, Lastname as string
Start
Print (“Please enter your first name”)
Imput (Firstname)
Print (“please enter your last name”)
Input (Lastname)
Print
Print(message,”sp”, firstname, “sp”, lastname)

Write a pseudocode to find and print the total of three numbers.

Algorithm TotalOfNumbers
{Finding the total of 3 numbers}
Var
Num1, Num2, Num3, Total as integer

Start
Total = 0
Print (”Please enter 3 numbers”)
Input (Num1, Num2, Num3)
Total= Num1 + Num2 + Num3
Print (“The answer is:”, Total)
Stop

Initialization Of Variables
Variables that are used as counters or to store totals should always be assigned an initial value of 0
before being incremented. This ensures that the variables are cleared of any values may have been
assigned in a previous execution of the programme. Initialization usually comes right after Start.

Algorithm TotalOfNumbers
{Finding the total of 3 numbers}

Var
Num1, Num2, Num3, Total as real

Start
Total = 0
Print (”Please enter 3 numbers”)
Input (Num1, Num2, Num3)
Total= Num1 + Num2 + Num3
Print (“The answer is:”, Total:6:2)
Stop

Information Technology
February 3, 2022
Problem Solving and Programme Design
Algorithm Pseudocode
(9 × c)
Calculate a temperature in Celsius to Fahrenheit using the formula F= + 32.
5
Algorithm Celcius_to_Fahrenheit

{This algorithm will convert a temperature in Celsius to Fahrenheit.}

Var

CelTemp, FarTemp as real

Start

FarTemp = 0

Print (“Please enter temperature in Celsius”)

Input CelTemp

FarTemp= (9*CelTemp/5) + 32

Print

Print (“The temperature in Fahrenheit is”, FarTemp:5:2)

GCT is 15% . Read the prices of three items. Calculate the total price of the items before tax. Calculate the tax
payable. Output the total price before tax, tax payable and overall price (all inclusive). Use prompts.

Prices_Algorithm
{To calculate the tax payable, the total price of items before tax and the overall price}
Const
GCT= 0.15
Var
PBTax, Tax, OPrice, Price1, Price2, Price3 as real

Start
Tax  0
PBTax  0
OPrice  0

Print (Please enter the prices of the items.”)


Accept Price1, Price2, Price3
PBTax  Price1 + Price2 + Price3
Tax PBTax * GCT
OPrice  Tax + PBTax
Print (“The price before the tax is “), PBTax, (“ “) , (“, the tax payable is”), Tax, (“ and the overall price
is”), OPrice

Information Technology
February 24, 2022
Problem Solving and Programme Design
Algorithm Flowchart

Objectives
 Define the term flow chart
 State the rules for creating flow charts
 Identify flow chart symbols
 Explain the purpose of the flowchart symbols
 Create flowchart algorithms for given problems

A flowchart is a diagrammatic representation of an algorithm. A flowchart can be helpful for both writing
programmes and explaining the programme to others.

To make sure the flowchart works, you need to follow a few basic construction rules
 Each flowchart must have and only one subject
 The flow of control must always enter an object from the top
 The flow of control must always leave an object from the bottom (except for decision objects,
which allow the flow of control to leave the side)
 The flow of control must not split. You can use decision objects to give the flow of control a
choice of paths to flow, but it can only follow one of these paths
 The no-go cursors used to show you where you cannot drop objects or complete links.

Start

Variables N1, N2 as real

You might also like