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

Pseudocode Intro

The document discusses pseudocode and its use for developing algorithms to solve problems. Pseudocode uses English-like statements to present the logical steps to solve a problem. It also discusses variables, constants, input/output instructions, and basic calculations that can be used for processing data in pseudocode.

Uploaded by

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

Pseudocode Intro

The document discusses pseudocode and its use for developing algorithms to solve problems. Pseudocode uses English-like statements to present the logical steps to solve a problem. It also discusses variables, constants, input/output instructions, and basic calculations that can be used for processing data in pseudocode.

Uploaded by

nseaton
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

PSEUDOCODE

Information Technology
Grade: 9
An algorithm is a sequence of precise
instructions which result in a solution.

Developing an algorithm means


developing a method for arriving at a ALGORITHM
solution to a problem.

Algorithms may be written using special


statements and rules. The statements must
be written in prose. These statements are
called pseudocodes.
PSEUDOCODE

• Pseudocode is a language similar to a programming language, but the rules are not as
stringent. Each statement must have the correct syntax. The syntax is the arrangement of
words in an instruction.
• Pseudocode is a logic development tool that uses English-like statements or clauses to
present the logical steps necessary to solve a problem.
• Data is facts and figures that can be
categorized as:
• 1. Data that is always the same value and
does not change, for example:
DATA AND DATA
• The number of hours in a day
TYPES
• The number of metres in a kilometre
• The name of the 3rd month in the year
• The speed of light.
• Data is facts and figures that can be
categorized as:
• 2. Data that changes or varies, for example:
DATA AND DATA • The cost of a product/item
TYPES • The salary of an employee
• The age of a person
• The number of persons in a city
• Data that does not change is called a constant. Some
constants may be numbers, e.g., 10, 34, 67, 9, 22,
CONSTANTS may be calculated, while others may be a series of
characters, e.g., Kingston, David, Monday, April.
• Character Constants
• Characters that are not likely to be calculated must be
enclosed in quotation marks to distinguish them from
numeric data, Such data is called a string.
• E.g., “11th Avenue, Cave Hill”
• “Jones”
TYPES OF
CONSTANTS • Numeric Constants
• Numeric constants are numbers that can be calculated.
Two types of numbers are being considered. Integers,
which are whole numbers. E.g., 10, 6, -20, and Real
numbers, which are numbers with a decimal point. E.g.,
11.5, 8.34, -5.60.
• Data that varies is what we call variable data. Such data
is given a name to represent the data that is being stored
and processed.
• Use names that gives a good representation of the data.
The name used is called the variable name. VARIABLE
• Variable names cannot contain spaces or begin with a
digit. Letters and abbreviations may be used. However, it
is recommended to keep the name to a reasonable lenght
EXAMPLES OF VARIABLES

Variable Name Variable Type


SCORE Numeric
Quantity Numeric
Age Numeric
Address Character
Name Character
ADVANTAGES OF VARIABLES OVER
CONSTANTS

• The user of the program can vary the value by changing the input value when variables are
used, whereas the user cannot change the value when constants are used.
• There is no need to modify the program when changes of values are required if variables
are used, whereas there is a need to do so if constants are used.
DATA INPUT AND STORAGE
INPUT INSTRUCTION

• Data to be processed must be entered into the computer and stored. Such data
may be entered from they keyboard.
• When creating the pseudocode for solving a problem, the commands used to
permit the entry of data are the words READ or INPUT.
• After which you will put the variable name(s) to represent the data to be
entered and stored. When more that one variable is present, a comma is used
to separate each variable
• The syntax is: READ <variable name>, <variable name>
• Write an instruction to input the quantity and price of
an item.
• Solution: READ QUANTITY, PRICE

• Write a pseudocode to input the age of three (3)


INPUT INSTRUCTIONS students in a class
EXAMPLES
• Solution: READ AGE1, AGE2, AGE3

• Write an instruction to input the name and age of


your best friend.
• Solution: READ NAME, AGE
CLASS ACTIVITY

Write an instruction
Write an instruction
to read the name of
to input the cost of
two(2) persons in a
a Laptop.
class.
PROMPTS

• While in the process of entering data, messages may appear on the screen
notifying the user of what data is to be entered. These messages are called
prompts or captions.
• Prompt statements begin with the command PRINT, followed by the message
enclosed in quotation marks.
• Example:
PRINT “Enter the name”
• PRINT “Enter the first grade”
• A read statement usually follows the prompt statement to facilitate the entry of
data corresponding to the prompt.
PRINTING INFORMATION
In most programs output is needed. Output
and be sent to the screen or the printer. When
developing the pseudocodes for solving a
problem, the command that is used to
produce the output is PRINT.

PRINT can be used to output the value stored


in a variable or to output the data that is
OUTPUT
constant. INSTRUCTION

The syntax is PRINT <string>, <variable>


Write an instruction to
output the name of your
school

Solution: PRINT “The


School Name is”,
SchoolName EXAMPLES OF
OUTPUT
Write a structured algorithm STATEMENTS
to display the age of your
friend

Solution PRINT “My friend


age is”, Age
OUTPUTTING VALUE OF A
VARIABLE

• When a variable is printed, the content of the variable is


printed and not the same of the variable. The computer
locates the segment of memory the variable is stored in and
print the value stored in the variable.
• For example:
• B=5
• PRINT B
• In this example, the variable B is given a value 5 at the first
instruction, at the second instruction 5 is printed and not the
letter B
OUTPUTTING A CONSTANT

• The syntax is PRINT <string>


• For example:
PRINT “Name”
• In this example, the word “Name” is printed without the quotation marks.
OUTPUTTING A CONSTANT AND A
VARIABLE AT THE SAME TIME

• This is necessary in order to give a description of the value of the variable that
is being printed.
• The syntax is: PRINT <string>, <variable>
• Example:
• PRINT “Cost”, COST
• In this example ”Cost” is a constant and COST is a variable. The word cost is
printed, as well as the value that is stored in the variable COST.
OUTPUTTING A
CONSTANT AND A • Write a structured algorithm to accept the price
of a product, then output the price.
VARIABLE AT THE • Solution: READ PRICE
SAME TIME • PRINT “Price”, PRICE
EXAMPLE
PROCESSING INVOLVING
CALCULATIONS
C A L CU L ATI O N S
USED FOR
P R O CE S S I N G D ATA
Calculation Symbol

• Data that is to be processed


Addition +
could involve doing
calculations. Calculations Subtraction -
can be done by using the
mathematical operators:
Multiplication *
Division /
• When calculations are to be performed, numeric variables
and numeric constants are to be used.
• The results of the calculation must be stored in a variable
for future access, ie, for printing or calculations
CALCULATIONS
• The syntax is: <variable> = <what is to be calculated>
USED FOR
PROCESSING DATA • For example:
• AMTDUE = PRICE * QUANTITY
• INCHES = FEET * 12
• SUM = NUM1 + NUM2
CALCULATIONS USED FOR
PROCESSING DATA

• The result of the calculation is stored in the variable to the left of the equal (=)
sign also know as the assignment symbol. The variable is therefore assigned the
value resulting from the calculations.
• The value being assigned could be a constant or a variable or a calculation
• For example:
• SUM = 0 or STORE 0 TO SUM
• A = B. or STORE B TO A
• GRADE = “A” or STORE “A” TO GRADE
• TOTAL = A + B + C. or STORE A + B + C TO TOTAL
THE END

You might also like