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

Representing Algorithm Using Pseudocode Part 2

The document discusses representing algorithms using pseudocode. It covers data types, control structures like selection and iteration, and the basic structure of a pseudocode including input, processing, and output sections. Common keywords, conventions, and examples of writing pseudocode are also explained.

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)
11 views

Representing Algorithm Using Pseudocode Part 2

The document discusses representing algorithms using pseudocode. It covers data types, control structures like selection and iteration, and the basic structure of a pseudocode including input, processing, and output sections. Common keywords, conventions, and examples of writing pseudocode are also explained.

Uploaded by

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

Representing Algorithm using

Pseudocode
Third Form
Data types
• A data type describes how data is processed and stored.
We group data with similar characteristics into data types because:
Grouping data gives the following advantages:
Makes it easier for the data tobe identified by the user and the computer.
Speeds up the time the computer takes to process and store these data.
Indicates the type of action that are applicable to the data.
Types of data types

✔ Number (Numeric)
✔ Text (String, Character)
Number (Numeric): means that we can perform a calculation on it.
Numeric data types can be divided into:
✔ Integer - are positive and negative whole numbers including 0..
(+65, -65)
✔ Real - are positive and negative fractional numbers. (+65.9, -
65.9)
✔ Text (Nonnumeric ): Include all letters of the alphabet, special
symbols such as #,%,@ and numbers that will never participate in
arithmetic calculations. For example, car licenses, telephone numbers
and so on.. Data that are text is enclosed in quotation marks.
Text can be further divided into:
✔ A character is a data type consisting of a single letter, symbols, or
digits.
✔ A string is a data type made up of more than one character enclosed
in quotation marks. The “computer” is a string made up of eight
characters. Telephone number “876 928-1584” is also a string.. A
string do not participate in arithmetic operations.
✔ Boolean is a data type that stores true or false value as its value.
Data types

✔ Real Eg. 16.0 , -67.456, 452.190


✔ Integer Eg.16, 309, -90, 567, -456
✔ Character Eg. “A”, “#”, “$”, “5”
✔ String Eg. “Hello”, “Kimani”
✔ Boolean Eg. True or False
Control Structures

Control structures specify the statements to be executed and


the order of execution of statements.
Sequential: A series of steps or statements that are executed
in the order they are written in an algorithm. For example,
following a recipe.
✔ Refers to the line-by-line execution by which statements
are executed sequentially, in the same order in which they
appear in the program
✔ Selection: A selection structure is a
programming feature that performs different
processes based on whether a boolean
condition is true or false.
✔ It defines two courses of action depending on
the outcome of a condition.
✔ A condition is an expression that is, when
computed, evaluated to either true or false.
This is where there is a choice of choosing
between 2 or more alternative paths. In C++,
these are the types of selection statements:
✔ if, if/else, Switch
✔ Iteration: Specifies a block of one or more statements
that are repeatedly executed until a condition is satisfied.
Used for looping, i.e. repeating a piece of code multiple
times in a row. In C++, there are three types of loops:
✔ while
✔ do/while
✔ for
Control structure Keyword

Keyword Purpose

If-Then-Else Helps the computer to make a choice


between one or several options

For, While Repeats a given task based on a


certain condition.
Basic Structure of a Pseudocode

Begin/Start
Input statement (s)
Process statement (s)
Output statement (s)
End/Stop
Input and Output
Keyword Purpose
The input and output
Read, Input Accepts data sections of a pseudocode are
Print, Write Outputs governed by statements that
information begin with special words
called keywords alongside
the relevant variable names.
Input-Output Keyword
Basic Conventions in using keywords

Read or Input
To use the “Read” or “Input” keyword, the word Read or Input must be followed
by a variable name. If more than one value needs to be inputted, then there will be
a need for more than one variables, each variable name separated by a comma.
For example, using ‘Read” to enter the value of a student’s score, you would
write:
Read Score
To input the value of two students’ scores you wouldd write: Read Score1, Score2
OR
Read Score 1
Read Score 2
Note: Each line of statement must begin with an appropriate
keyword.
Using “Input” to allow the user to enter the value of a student’s
score you would write:
Input Score1, Score2
OR
Input Score1
Input Score 2
How to write an input statement?

✔ Read variablename Eg. Read num1


✔ OR Input variablename Eg. Input num1
Output

✔ If you want to display or view the infmration then an output


instruction must be written.
Example of output keyword:
The “Print” or “Write” keywords
✔ To use the “Print” or “Write” keyowrds, the word “Print” or
“Write” must be followed by a A. variable name: - . Print Score
OR
B. A string then a variable name.: - Print “The Score is:”,Score
How to write an output statement?

✔ Print variablename Eg. Print num1 or Print num2


✔ OR Print “ Message” , Variablename Eg. Print “ This is the
first number”, Num1
✔ OR Print” Message” Eg. Print ” Hello Kimani”
Other words for output Statement:
✔ Display Eg. Display variblename Display num1
✔ Output Eg. Output variablename output num1
✔ Show Eg. Show variablename
✔ Write Eg. Write variablename
Processing Section of a computer instructions

The processing section of a pseudocode consists of the


following :
✔ Assignment and statements
✔ Arithmetic and logical symbols
✔ Construct (Control structures)
Assignment Operator

✔ Assignment Operator ( ) is used to give a value to a


variable. When it is used this way, the statement in which it
is being used is called an “Assignment statement”.
✔ The variable receiving the value is placed on the left of the
assignment operator while the variable (s) giving the values
(s) is placed on the right.
How to write processing/Assignment statements?

is the Assignment operator


Assignmentvariablename (Expression)

Eg. Square num1 * num1


NB: Square is referred to as your Lvalue(ie Location value)
num1 * num1 is referred to as your Rvalue(ie Result value)
Eg. Sum num1 + num2
Eg. Product num1 * num2
For example 1:
Add the value of two
test scores and store it in
a variable called Score.
✔ Score=test1 + test2
The value of test1 and
test2 is being totaled
and given to the variable
score.
Example 2
Add the value of two test scores, find their total and
their average.
Total=test1+test2
TestAverage=Total/2
Example 3 IPO CHART
Input Process Output
Write a program that Num 1 (a) Compute their total Total
will accept three Num 2 (Num1+Num2+Num3)
numbers and Num 3
compute and output (b) Assign total to a
variable e.g. Total
thier total.
IPO Chart (c) Print their total
Pseudocode
Start
Num1,Num2,Num3,:Integer
Num1 0, Num2 0, Num3 0
Read Num1,Num2,Num3
Total Num1,+Num2+Num3
Print Total
Stop
Flow chart Sart

Num1,Num2,Num3: Integer

Num1 0
Num2 0
Num3 0

Read Num1, Num2, Num3

Total Num1+Num2+Num3

Print Total

Stop
https://www.youtube.com/watch?v=eSYeHlwDCNA

https://www.youtube.com/watch?v=8AQcIdz8GQs

https://www.youtube.com/watch?v=mQ0VClVd31c

Video links!!!!

You might also like