1.
Explain the Concepts of Programming
1.2.6. Pseudocode
This lesson covers the following objectives:
What is Pseudocode .
How to define
all data used by the program .
3main things to conceder when declaring data in
programs.(data type,data usage,data scope)
Structred Progrogrmming constructs with in
pseudocode
Procedures/Functions
Pseudocode
Pseudocode is Structured English like way of
representing the solution to a problem.
It is considered a “first draft” because
Pseudocode is like English and has some
precision to it ,
it does not have the very definite precision of a
programming language. A computer cannot
execute Pseudocode.
Pseudocode can be translated in to a variety of
programming language
Data Declaration
It is important to define all data used by a program
within the pseudo code as the following is one of the
fundamental concepts in programming.
Program = data + algorithm(logic)
There are 3main things to conceder when declaring
data in programs.
data type – specify the type of value that can be stored.
data usage – whether the data item is used as a variable or
a constant.
data scope – specify the limit of access within the program.
Data Types
Simple data:
Data items which can store single values
Name : string
Age : integer
Marks : real
Complex data:
Data item which allows you to store collection of
values.
Class marks(10): array of integer
Student data : record of
Name : string
Age : integer
Data Usage
Variables:
Variables are data items, of any type, whose contents
may change in value as the programs executes.
Counter = counter+1
Massage = “hello world”
Constants:
Constants are either literal values or data items whose
contents do not change as the program executes.
Counter = counter+1
Massage = “hello world”
pi : rea;l values 3.142
Data Scope
Global
Data which is accessible by the procedure in
which it is defined and by all procedures directly
subordinate to that procedure.
Local:
Data which is accessible only by the procedure in
which it is defined
Data Declaration Within A Program
Global data:
Pi : r e a l value3.142
Local data:
Counter,total:integer
constructs
sequence
A saris of instructions executed one after the
other
E.g.;
Input numberofitemspurchased
Input priceperitem
TotalCost=NumberOfitemsPurchased*PriceP
eritem
Display TotalCost
Selection
A selection control structure is the
presentation of a condition and the choice
between two actions, the choice depending on
whether the condition is true or false.
I F condition THEN
Command sequence 1
ELSE
Command sequence 2
ENDIF
Selection
e.g,
IF average >50
THEN
DISPLAY ”pass”
Else
DISPLAY ”fa i l ”
End I F
Selection
If the choice is between more than two
alternatives, then we need a multiple selector.
Case Statement
CASE of Variable
1 : Command sequence 1
2 : Command sequence 2
………….
………….
ELSE:
Defaul t command sequence
END CASE
Selection
I F condition THEN
Command sequence 1
ELSE I F cond it i o n 2 THEN
Command sequence 2
ELSE I F condition 3 THEN
…………….
…………….
ELSE
Defaul t command sequence
ENDIF
END I F
END I F
Selection
IF average>=80 THEN
Grade:=”A”
ELSE IF average>=65
THEN Grade:=”B”
ELSE IF average>=50
THEN Grade:=”C”
ELSE IF average>=35
THEN Grade:=”S”
ELSE
Grade:=”F”
ENDIF
ENDIF
ENDIF
ENDIF
Repetition
The repetition control structure can be defined as the
presentation of instructions to be performed rapidly as
long as the condition is true
While Loop:
WHILE cond i t io n P i s True
DO Statement block
END DO
Repetition
Repeat/Until Loop:
REPEAT
Statement block
UNTIL Cond i t io n P i s False
Repetition
For Loop:
FOR X = 1 to 10 DO
Statement block
END DO
Procedure/Function
Procedure: A selection of program that carries out
some well-defined operation on data specify by
parameter. It can be called from any ware in the
program and different parameters can be provided for
each call.
Procedure/Function
Procedure Swap ( Num1, Num2 : in te ger )
Local data
Temp : integer
BEGIN
Temp : =
Num 1
Num1: = Num 2
Num2: = Temp
END
Procedure/Function
Function: The program unit that, given values for input
parameters, computes the value.
FUNCTION average( Num1, Num2 : integer ) : r e a l
Local data
Total : integer
BEGIN
Total = Num1+Num2
Average = Total/2.0
END
Procedure/Function
The different between a Procedure and the function is
that the function is that the function will return a
single value after called, where as a procedure do a
particular task but not necessarily return a value,
Important points Regarding Functions/Procedures
To return a value from a function it should be assigned
to the function name.
Each module can define its own data.
The data item passed into the function at the time of
call are called parameters.
Parameters may be input or output based on their
role.
Input parameters only carry value into the
module.(e.g.Num1,Num2 in average function)
Output parameters take a result back to the
caller.(e.g.Num1,Num2 in swap procedure)
• Pseudocode • Local
• Algorithm • While Loop
• data type • Repeat/Until Loop
• data usage • For Loop
• data scope • Procedure
• Variables: • Function
• Constants:
• Global
http://en.wikipedia.org/wiki/Pseudocode
http://users.csc.calpoly.edu/~jdalbey/SWE/pdl_std.html