0% found this document useful (0 votes)
12 views25 pages

Program Design Tools: Algorithms & Pseudocode

Design Tools

Uploaded by

Ann Kingori
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views25 pages

Program Design Tools: Algorithms & Pseudocode

Design Tools

Uploaded by

Ann Kingori
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PROGRAM DESIGN TOOLS

- ALGORITHMS
2

Program Design Tools - Algorithm


• An Algorithm is a limited number of logical steps that a
program follows in order to solve a problem
• Algorithms take little or no account of the programming
language.
• They must be precise/ accurate, unambiguous/clear and
should guarantee a solution
• Algorithm is illustrated using:
- Pseudocode
- Flowchart
3

PSEUDOCODE
• A pseudocode is a method of documenting a program logic
in English-like statements to describe the processing steps.

Guidelines for designing a good pseudocode.

• A pseudocode must have a Begin and end.

• The input, output and processing statements should be


clearly stated using keywords such as Output: PRINT,
OUTPUT, DISPLAY and Input: READ, INPUT, SCAN etc.
Pseudocode of a program to calculate area of a 4

triangle
Begin
INPUT base
INPUT height
Area= 0.5 * base * height
OUTPUT area
End
Pseudocode of a program to calculate area & 5

perimeter of a rectangle

Begin
Scan length, width
Area = length * width
Perimeter = 2*(length +width)
Print area, perimeter
End
6

Pseudocode of a program to input 3


subject marks then calculates and displays
total and average marks
Pseudocode of a program to input subject marks then 7

calculates and displays total and average marks


Start
INPUT subj1, subj2, subj3
Total = subj1 + subj2 + subj3
Average=total/3
OUTPUT total, average
Stop
8
Pseudocode to convert degrees Celsius to
degrees Fahrenheit

Begin
9
•F = 𝐶 + 32 Scan C
5
9
F= ( ∗ 𝐶) + 32
5
Display F
End
Pseudocode to calculate and display diameter area and
9
circumference of a circle
Way 1 Way 2
• Begin • Start
• Read radius
• Read radius
• Set pi=3.14
• Diameter = radius *2
• Diameter = radius *2
• Area= 3.14* radius * radius
• Area=pi * radius * radius
• Circumference = 2 * 3.14 * radius • Circumference = 2 * pi * radius
• Print area, circumference • Print area, circumference
• End • Stop
10
Write a pseudocode of a program to solve the equation
of a straight line given by the expression: Y = MX + C.

Start
Input m, x, c
Y=(m*x) + c
Output y
Stop
11

Write a pseudocode for a program that


prompts the user to enter their age. If the
age entered is below 18, it should display
“you’re a young person”, otherwise it
should display “you’re an adult”
Begin 12

Read age
If age < 18 then
Output “you are a young person”
Else
Output “you are an adult”
Stop
13
FLOWCHART
 A Flowchart is a diagrammatic or
pictorial representation of a
program’s algorithm.
 It is a chart that demonstrates the
logical sequence of events that
must be performed to solve a
problem.
14

Flowchart Symbols
• A Flowchart is constructed using a set of special shapes (or
symbols) that have specific meaning.
• Each symbol contains information (short text) that describes
what must be done at that point.
• The symbols are joined by arrows to obtain a complete
Flowchart. The arrows show the order in which the
instruction must be executed.
Flowchart Symbols 15

Symbol Meaning
Start/Stop - Indicate the start and end of a
flowchart

Input / Output symbol

Process symbol

Decision symbol

Flow
Connector
16
Flowchart of a program to START

solve the equation of a


Input m, x ,
straight line given by the c
expression: Y = mx + c.
Y=(m*x) + c

Output Y

STOP
Diameter, circumference and area of a
17
Start circle
• Begin
Input radius
• Read radius
Pi=3.14 • Diameter = radius * 2
Diameter= radius *2
Area = Pi * radius * radius • Pi = 3.14
Circumference = 3.14 * 2* radius
• Area= Pi* radius * radius
Output area, • Circumference = 2 * Pi * radius
circumference, diameter • Print area, circumference,
Diameter
Stop
• End
Start 18

Diameter, circumference and area of a circle


Input radius
Begin
Read radius
Set pi=3.14 Set pi = 3.14
Diameter= radius *2
Diameter = radius * 2 Area = pi* radius * radius
Area=pi * radius * radius Circumference =pi* 2* radius
Circumference = 2 * pi * radius
Print area Output area,
circumference,
Print circumference
diameter
End
Stop
19
Start

Input C Convert degree celsius


to degrees fahrenheit
F = (9/5)*C+ 32 𝟗
F= 𝑪 + 32
𝟓

Output F

Stop
20
Start

Input height,
Flowchart of a base

program to calculate
Area = 0.5*height*
area of a triangle base

Output Area

Stop
Start 21

Flowchart of a Input length, width


program to calculate
area & perimeter of a Area = length * width
Perimeter = 2*(length +width)
rectangle

Print area, perimeter

Stop
A program that prompts the user to enter their
22
age and then it displays “you’re a young STAR
person”, if age is less than 18 otherwise it T
should display “you’re an adult”
Input age
• Begin
• Input age
If age No Output “You are
• If age<18 then < 18 an adult”

• Output “you are a young


person” Yes

Output “You are a


• Else young person”
• Output “You are an adult”
• End
STOP
Write a pseudocode that prompts the user to enter weight in kgs23
and height in meters. The program then calculates the body mass
index (BMI) of the user. It checks the BMI using the table below and
displays the remarks accordingly.
Hint BMI= weight/height2

BMI Remarks
Below 18 You are underweight
Between 18 and 25 Your weight is normal
Between 25 and 30 You are overweight
Above 30 You are obese
PSEUDOCODE 24

• Begin  Output “you are normal”


• Input weight • Else if BMI > 25 and BMI <=30
• Input height  Output “you are overweight”
• BMI = weight/(height*height) • Else
• If BMI <18  Output “you are obese
 Output “You are • End
underweight”
25

Stop

You might also like