You are on page 1of 5

Topic: Problem Solving and Program Design

Sub-Topic: Algorithms (Pseudocode)


Specific objectives /learning outcomes:

1. State the purpose of a Pseudocode.


2. State the keywords used for input statements, output
statements and assignment statements
3. Identify the parts of a Pseudocode algorithm.
4. Represent algorithms in the form of Pseudocodes.

Pseudocode: Fake code


A pseudocode is not a programming code, but uses English-type words and phrases that
are clear enough to be easily converted into a programming code.

VARIABLES: are identifiers that can change. Place holders found in memory.

Statements and Keywords


A statement is a description of the processing that can be included in an action or condition.
Instruction within the statements are called keywords. Examples of keywords are INPUT,
READ, OUTPUT, DISPLAY, PRINT. The keyword normally tells the type of statement.

1. Input Statements
This is the way in which it will be written: Read variable_name
For example, if you were required to read two numbers, find the sum of the numbers and output
the sum of the numbers. The input statement would be:
Eg. Read num1
Read num2
2. Output Statements
This is the way in which it will be written:
Print “The average is ”, AVG Or Print AVG

For example, if you were required to read two numbers, find the sum of the numbers and output
the sum of the numbers. The output statement would be:

Print “The sum of the numbers is”, sum


or
Print sum

PROMPTING STATEMENT: Output statement. Tells the user what to enter.


Print “ Please enter your name here”
Print “ Please enter your age”

3. Assignment Statement
This is the way in which it will be written: variable_name = expression
An assignment statement may involve an arithmetic operation, such as:
sum num1 + num2

While some assignment statements just involve assigning values to variables, such as:

Count 1
Highest_Price 0
Parts of a Pseudocode Algorithm

Algorithm Header
Algorithm Name
Author
Date
Description: State what the code is about.
Declaration: State ALL the variables/constants and specify the data types.

Start
Body (Input, output and assignment statements)

Stop

Example one: Write the Pseudocode Algorithm for a program that is required to accept two
numbers. Calculate a print the sum.

Input Processing Output


Accept num1 Accept num1 Print “the sum is” Total
Accept num2 Accept num2
OR
Calculate sum
Total num1 + num2 Print Total

Print “the sum is” Total


Instruction:
1. Given three integers representing the age of three boys respectively, write a program to
find their average age.

2. A program is required to input the price of an item and quantity purchased. The program
should compute and print the amount due

Additional Notes
Arithmetic operators are symbols that allow you to perform mathematical processes.
ARITHMETIC OPERATORS EXAMPLES

Addition ( +) TotalPay= BasicPay+Bonus


Subtraction ( - ) NetPay=TotalPay-Tax
Multiplication ( * ) Days=Weeks*7
Division ( / ) Days=Hours/24
DIV- The operator DIV gives the result of integer Result =20 DIV 8
division, but not the remainder.
The variable “Result” would hold the
value 2.
MOD-The operator MOD gives the remainder. Remainder= 20 MOD 8
The variable “Remainder” would hold
the value 4.
Input Processing Output
Accept price and quantity Print “Your final cost is” Final_cost
Accept Price_1
Accept Price_1
Accept quantity
Accept quantity

Calculate final cost

Final_cost Price_1*quantity

Print “Your final cost is” Final_cost

Question 1

A program is required to prompt a user to enter the price and quantity of an item.
Calculate and print the final cost.

Write the corresponding Pseudocode algorithm for the above IPO chart.

To do.

Write a program that is required to calculate and print the cost of an item given the
price and quantity. Calculate a 5% discount of the item cost to produce the final
cost that the customer is required to pay.

You might also like