Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
136 views

Programming - Pseudocode

Here are structured pseudo-codes for the examples: 1. Find Square of a Number SET pi TO 3.14 DECLARE num, square AS REAL PRINT "Enter a number: " READ num square ← num * num PRINT "The square of ", num, " is ", square 2. Calculate Total Cost of Item DECLARE unitCost, quantity, totalCost AS REAL PRINT "Enter unit cost: " READ unitCost PRINT "Enter quantity: " READ quantity totalCost ← unitCost * quantity PRINT "Total cost is ", totalCost 3. Calculate Difference of Two Numbers DECLARE num1, num2, difference

Uploaded by

Kadia Henry
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
136 views

Programming - Pseudocode

Here are structured pseudo-codes for the examples: 1. Find Square of a Number SET pi TO 3.14 DECLARE num, square AS REAL PRINT "Enter a number: " READ num square ← num * num PRINT "The square of ", num, " is ", square 2. Calculate Total Cost of Item DECLARE unitCost, quantity, totalCost AS REAL PRINT "Enter unit cost: " READ unitCost PRINT "Enter quantity: " READ quantity totalCost ← unitCost * quantity PRINT "Total cost is ", totalCost 3. Calculate Difference of Two Numbers DECLARE num1, num2, difference

Uploaded by

Kadia Henry
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

PROBLEM SOLVING

AND PROGRAM
DESIGN
Ms. Brown
Betty Williams had
quoted, “There’s no use
talking about the problem
unless you talk about the
solution”.
Pseudocodes

Objective 1.6: Represent algorithms in the


form of pseudocode.
► Watch a video that introduces psuedocode. What are
the three structures used in pseudocode?
► Video: 5 Minutes to Code: Programming Basics
“Pseudocode”
► https://www.youtube.com/watch?v=HhBrkpTqzqg
What is Pseudo-code?

► A pseudo-code is an imitation of a
computer written using mathematical
notations and English-like statements to
describe the logics to solve a problem or
carry out a procedure. The pseudo-code is
used as a guide to code the solution to
the problem in a high-level language such
as Pascal Programming.
Parts of a Pseudo-code
Algorithm
A pseudo-code contains one or more of
the following statements:
1. Input Statement
2. Assignment Statement
3. Output Statement
4. Control structure (sequence, selection,
repetition).
Input Statements
► The input statement is used to get data outside
the computer from a particular input device into a
variable for manipulation by the pseudo-code. The
key words we will use are ‘input’ or ‘read’. To
read data into a variable, you write the word
‘Input’ or ‘Read’ followed by the variable name
► Examples:
READ Score

Variable
Input
name
key word
Score
READ
Output Statements
► The output statement is used to get information to the
programmer or to the user.
► In pseudocode we use the keywords PRINT, DISPLAY AND
OUTPUT “ ” to achieve the output. They are used to
output strings, variable values or a combination of both.
► PRINT “Meaningful statement”
► PRINT “Meaningful statement” (variable)

Pseudocode User sees


PRINT “Today is a good day!” Today is a good day!
PRINT “Your name is” (name) Your name is Johnny
PRINT “Enter your age: ” Enter your age:
Prompt Statement
► We also have a statement called the prompt statement. A
prompt statement is actually an output statement which
displays on the screen, to the user, a message indicating what
actions to take based on the program written.
► For example, you may be asked to write a pseudo-code to
accept two numbers and prompt the user to enter the
numbers (this would be done via the keyboard).
Print “Please enter two numbers”
Read num1, num2
Output The prompt
Key word statement
written in
open and close
quotations
Assignment Statements
► An assignment statement is used to store a value
in a variable. The assignment statement has two
parts, the Left value and the Right value.
► An assignment statement is written as follows:
left value 🡨 right value
► The right value is a literal or an expression that
evaluates to a value that will be stored in the left
hand value which is a variable.
► Examples:
► area 🡨 pi*radius*radius
► Product num1 * num2
Pseudocode Program
Structure
Algorithm Name:
Purpose of Algorithm:
Declaration of constants
Declaration of variables

START
program statements

STOP
Declaration of Constants and
Variables
Recall: Variables and Constants MUST have
meaningful names.
► Constants are always declared before
variables.
Declaration of Constants and Variables
Structure
SET constant TO value
DECLARE variable1, variable2 as data type
DECLARE variable3, variable4 as data type

Example 1
SET pi TO 3.14
DECLARE radius, area as real
DECLARE count, sum as integer

Example 2
SET discp TO 0.25
DECLARE fname, lname as string
DECLARE code as character
Class Examples
1. Write a structured pseudo-code to find the square of a
number. Output the square of the number.
2. Write a structured pseudo-code to read the unit cost
and quantity of an item. Calculate and print the total
cost of the item.
3. Write a structured pseudo-code to read two numbers,
calculate and print their difference.
4. Write a structured pseudo-code to read three numbers,
calculate and print their average.
5. Write a structured pseudo-code that prompt the user to
input the ages of four of your friends. The program
should allow the user to input these ages, find their
average and print it with a suitable label.

You might also like