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

Pseudocode pt1

The document outlines the objectives and fundamentals of problem-solving and program design, focusing on pseudocode as a tool for representing algorithms. It covers basic program constructs such as input/output statements, assignment statements, and control structures like sequencing, selection, and iteration. Additionally, it provides examples of pseudocode for calculating age and electricity bills, along with exercises for students to practice writing their own algorithms.

Uploaded by

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

Pseudocode pt1

The document outlines the objectives and fundamentals of problem-solving and program design, focusing on pseudocode as a tool for representing algorithms. It covers basic program constructs such as input/output statements, assignment statements, and control structures like sequencing, selection, and iteration. Additionally, it provides examples of pseudocode for calculating age and electricity bills, along with exercises for students to practice writing their own algorithms.

Uploaded by

jonae.jumpp
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Problem-Solving & Program

Design
Specific Objectives
Students should be able to:
 Represent algorithms in the form of
• pseudocode

Prepared by Ms A. Cole
Pseudocode algorithm
 Pseudocode is similar to real programming language

 Pseudocode helps to familiarize you with the syntax


and structure of a program
Basic program construct

 Input and Output statements

 Assignment statements

 Control structure

o Sequencing

o Selection

o Iteration/Repetition
Input & output statement

Output statement allows a program Input statement allows for the


to communicate with the user by
user to interact with the
outputting information to them. Uses
program by allowing them to
commands such as: Print, Display,
enter data into it. Uses
Output, Write
commands such as: Read, input
• Example: Print “What is your

name” Example: Read name


Assignment statement

Assignment statement this is used to store data in a


variable or constant or to change data in a variable.
Example: sum 0
average sum/5
Sequence

 This structure sees that to it that instructions are


executed line by line, one after the other, in the
order which they were written.
 Example the following algorithm accepts the your
year of birth and current year, compute your age
then display you age.
Operators

 Arithmetic (use when performing mathematical operations):

+, -, *, /, %

 MOD (6 MOD 2 = 0)…gives the remainder of a division

 DIV (6 DIV 2 = 3) …tells how many 2s we can get out of 6


 Example the following algorithm accepts the your year of birth
and current year, compute your age then display you age.

• START

PRINT “Enter your year of birth”

READ yob

PRINT “Enter the current year”

READ currentyear

age currentyear – yob

PRINT “You age is:”, age

STOP
Example
Write an algorithm in pseudocode to prompt for and accept the customer’s
previous and current meter readings. The algorithm should compute the
units of electricity consumed this month and also compute the amount to
pay. The fuel charge is fixed at $12.50 per kWh and the customer charge at
$125. The bill is computed using the formula:
amount_to_pay = (units_used * fuel charge) + customer_charge

The program should print the words “Please pay this amount =>” followed
by the amount to be paid, print the farewell statement “National
Electricity….Reliable service since 1975” as the last line of the bill.
START
PRINT “Enter the customer’s current meter reading”
READ current_reading
PRINT “Enter the customer’s previous reading”
READ previous_reading

units_used  current_reading – previous_reading


amount_to_pay  (units_used *12.50)+125

PRINT “Please pay this amount = $”, amount_to_pay


PRINT “National Electricity……Reliable service since 1975”

STOP
Put your brain to
work!!
Write pseudocode algorithms to solve the following:

• James would like to secure his pool from public access. He was encouraged by

his friends to use diamond fence around it. James gave you the length and the

width of the pool and ask you to compute and print the length of fencing

required.

• Kara wants to buy a $350 costume for the upcoming carnival. She decides to

sell some cakes in order to raise the funds for the costume. Kara’s friend

ordered some cakes. Accept the quantity of cakes ordered, then calculate and

output the total, at $5 per cake.


In class activity
Pseudocode Pt 2

You might also like