Pseudocode ISL
Pseudocode ISL
Flow Charts:
Pictorial Representation of algorithms.
Structured English of an algorithm using proper syntax is pseudocode
Pseudocode:
Representation of an algorithm using keywords is pseudocode.
Lesson 1:
Pseudocode Basics.
2) Identifiers(Store Data)
i) Variables
Any storage locations where a value may change within the program.
ii) Constants
Any storage locations where a value will never change within the program.
iii) Arrays
Storage locations that can hold multiple data items of SAME DATA TYPE.
3)Arithmetic Operators:
i. +
ii. -
iii. *
iv. /
v. ^
vi. <
vii. >
viii. >=(greater than equal to)
ix. >=(Less than equal to)
x. <> (unequal to)
Logical operators
AND(Both conditions satisfied), OR(One Condition satisfied) , NOT
Built in Functions:
DIV(DIVIDER), MOD(REMINDER),
INT(it always removes the fractional part), ROUND, ROUNDUP,
7) Subroutines
i) Procedures (A procedure is a subroutine that performs a task but
does not return a value eg print statement)
ii) Functions (A function is a subroutine that performs a task and
returns a value. Eg operation performed)
8) File Handling
FLOWCHART:
Process Box(Rectangle): Any arithmetic operation or perform any assigned value to any
variable
Paralellogram (I/o Box): user ko store krna hai ya display krna hai we will use this box
Diamond/Rhombus (Decision Box) whenever you are using a comparison
operator(>,<.>=,<=) , you will use a decision box
All boxes are connected with each other through flow lines and they must be labelled (IT
IS IMP otherwise -1 srf yes or no sy label krni hai)
M<90 toh grading A* krdo agr no hai toh grade A krdo output grade
Lesson 2:
1) Variables
Any storage locations where a value may change within the program.
2) Constants
Any storage locations where a value will never change within the program.
Declaration:
Every identifier must be declared, have a suitable/understandable name followed by the
data type.
03-Oct-2023
IF CASE
Larger=num2 OTHERWISE
PRINT Larger
Largest of three numbers [nested if]
PRINT “please enter three numbers” PRINT “please enter three numbers”
ELSE ENDCASE
PRINT Larger
Grades Table
Students should not be able to enter invalid marks i.e., less than zero or greater
than 100
[Validation]
PRINT “please enter your marks” PRINT “please enter your marks”
IF marks < 0 OR marks > 100 THEN IF marks < 0 OR marks > 100 THEN
PRINT “invalid marks entered, please PRINT “invalid marks entered, please
re-enter” re-enter”
Grade=”B” Grade=”U”
ELSE ENDCASE
ENDIF
PRINT Grade
PRINT “please enter two numbers” PRINT “please enter two numbers”
PRINT “please select your choice” PRINT “please select your choice”
Result=num1*num2 ENDCASE
Result=num1/num2
ENDIF
PRINT Result
Pseudocode.pdf: Example 15 to 20
Topicals Topic 10: Question Number : 2,3,5,6,7,10,16,20
Lesson 4: Chap 11
Loops/Iteration/Repetition:
1) WHILE…ENDWHILE
2) REPEAT…UNTIL
3) FOR…TO…NEXT
TRUE
FALSE
=,>
<>,< 1 TO 10
1 TO 20
Count=5
Count=Count+1
6….
7….
8….
Total=0
0=0+10
10=10+30=40
40=40+10=50
Highest:
56>0…56
103>56…103
47>103…103
Lowest:
126<99999…126
11<126…11
65<11…11
Lesson 5
Print 1st 100 Whole Numbers (0-99)
count=count+1 count=count+1
There is no need to initialize the counter within for LOOP, as it is already given in range.
There is no need for increments of 1 within for loop, as NEXT acts as built in counter.
IMPORTANT IMPORTANT:
Take 50 numbers from user, and find out the average, highest and lowest of the numbers.
Pseudocode.pdf
Lesson 6
DECLARE count, total, num : INTEGER DECLARE count, total, num : INTEGER
PRINT avg
Lesson 6:
Loops Practice
Duration : 1 Year
Input Temperatures
totalDay=0
FOR readings=1 to 10
INPUT temp
totalDay=totalDaty+temp
totalYear=totalYear+temp
Next readings
AverageDay=totalDay/10
PRINT AverageDay
NEXT day
AverageYear=totalyear/3650
PRINT AverageYear,Highest,Lowest
fastest=0,slowest=999,totalspeed=0
INPUT time
FS=200/time
PRINT FS
totalspeed=totalspeed+FS
NEXT
avgspeed=totalspeed/500
PRINT fastest,slowest,avgspeed
totalcost=0
INPUT item,cost
IF item=1 THEN itemcost=cost*1.5
ELSE item=3
itemcost=cost*5.0
ENDIF
PRINT itemcost
totalcost=totalcost+itemcost
NEXT
avgcost=totalcost/1000
PRINT avgcost
best=0,worst=9999,total=0
INPUT distance,fuel
FEconomy=distance/fuel
PRINT FEconomy
total=total+FEconomy
average=total/1000
PRINT average,best,worst
Data Types:
INTEGER : whole numbers
REAL : fractional numbers
STRING : alphabets/name, alphanumeric/password, alphanumeric +
symbols/email, non-calculative data/IDs, Phone Numbers, Serial Numbers etc.
NOTE : Strings are encapsulated in double quotations. (“”)
CHAR : whenever there is a need to store one character only.
NOTE : Chars are encapsulated in single quotations.(‘’)
BOOLEAN : Two states/discrete behavior.
DATE & TIME : Data & Time.
Arrays and records are both data structures used to store multiple values, but they serve different
purposes and have distinct characteristics.
Lesson 7:
Arrays:
A list that can hold multiple data items of SAME DATA TYPE.
I want to store 10 numbers
10 variables : num1, num2, num3, num4, num5….num10
This is not a good approach, we can store these 10 numbers in only 1 data structure
DECLARE Nums: ARRAY[1:10] OF INTEGERS
1 REPRESNTS COLUMN AND 10 REPRESNTS ROWS
1 852
2 5250
3 0024
4 424
5 32543
6 041
7 04
8
9
10
Where the data item is being stored, The actual data being stored is the
that is the memory location, that’s dimension.
index. POSITION: INDEX
You may refer to dimensions as number of
YEH LOGICAL HOTA THEY DONOT columns.
EXIST PHYSICALLY
HAI(PROGRAMMING MEIN INDEX
STARTS FROM 0 BUT IN
PESUDOCODE IT DEPENDS UPON
US)
Variable aur array mein difference yehi hai k hum arrays k sath indexes detay hai to
manipulate
Declare Arrays:
1D ARRAYS:
Practice: Declare a 1D array named students of type integer to store marks of 200
students.
DECLARE Students : ARRAY[1:200] OF INTEGER
How to Input or Output Data from the Array : Programmer Defined Data:
Declare a 1D array named Games of type String to store 5 Game names into the array.
Populate the array with game names and output the game names stored at the 3rd and 5th
index of the array.
DECLARE Games : ARRAY[1:5] OF STRING
Games[1]=”COD”
Games[2]=”Tekken 7”
Games[3]=”FIFA”
Games[4]=”Unchartered 4”
Games[5]=”Cricket”
PRINT Games[3], Games[5]
How to Input or Output Data from the Array: User Defined Data:
Declare a 1D array named Games of type String to store 5000 Game names into the array.
Populate the array with game names given by the user and output the game names
stored from 100 to 367th index.
DECLARE Games : ARRAY[1:5000] OF STRING
FOR count = 1 TO 5000
PRINT “please enter game name”
INPUT Games[count]
NEXT
FOR count = 100 to 367
PRINT Games[count]
NEXT
Practice: Set up a 1D array Marks to store marks for 300 students, output the marks
stored from 215th index to 278th index.
Manipulating 1D Arrays:
Set up a 1D array Marks to store marks for 300 students, find out the average, highest
and lowest marks.
DECLARE Marks : ARRAY[1:300] OF INTEGER
DECLARE total,highest,lowest : INTEGER
DECLARE avg : REAL
total=0,highest=0,lowest=101
FOR count = 1 TO 300
total=total+Marks[count]
IF Marks[count]>highest THEN highest=Marks[count]
IF Marks[count]<lowest THEN lowest=Marks[count]
NEXT
avg=total/300
PRINT avg,highest,lowest
Please solve: Set up a 1D array Info to hold info about the salaries of 800 employees,
take all the values from user and populate the array, output the average salary, highest
and lowest salaries, do find out the range as well where range=highest salary paid –
lowest salary paid.
DECLARE Info : ARRAY[1:800] OF INTEGER
DECLARE highest,lowest,average,range,total : INTEGER
total=0,highest=0,lowest=9999
FOR count = 1 TO 800
PRINT “please enter salaries”
INPUT Info[count]
total=total+Info[count]
IF Info[count]>highest THEN highest=Info[count]
IF Info[count]<lowest THEN lowest=Info[count]
NEXT
average=total/800
range=highest-lowest
PRINT average,range,highest,lowest
Take 50 numbers, output the average of Take 50 numbers, store them and output
the numbers. the average.
DECLARE num,total,average : INTEGER DECLARE num : ARRAY[1:50] OF
INTEGER
total=0 DECLARE total,average : INTEGER
FOR count = 1 TO 50 total=0
PRINT “please enter a number” FOR count = 1 TO 50
INPUT num PRINT “please enter a number”
Total=total+num INPUT num[count]
NEXT Total=total+num[count]
average=total/50 NEXT
PRINT average average=total/50
PRINT average
An algorithm that searches through the array index after index, until the record being
searched is found, or the whole array has been searched through.
1) Take a search value from user.
2) Start searching from 1st index.
3) Compare the values.
4) If they match, break the loop.
5) If they don’t match, jump to the next index.
6) Keep repeating until the value is found, or whole
7) searched.
PSEUDOCODE:
Vb code for linear search: keep one thing in mind, that I populated the array myself.
Print : console.writeline
Input : console.readline
Ending : console.readkey()
Declare : dim
Module Module1
Sub Main()
Dim isl(4) As Integer
Dim found As Boolean
found = False
Dim index As Integer
index = 0
Dim searchvalue As Integer
For count = 0 To 4
Console.WriteLine("please enter isl numbers")
isl(count) = Console.ReadLine
Next
Console.WriteLine("please enter search value")
searchvalue = Console.ReadLine
Do
If isl(index) = searchvalue Then
found = True
Else
index = index + 1
End If
Loop Until found Or index > 4
If found Then
Console.WriteLine("value found at: " & index)
Else
Console.WriteLine("value not found")
End If
Console.ReadKey()
End Sub
End Module
Lesson 9:
BUBBLE SORT:
It is an algorithm to arrange the array in an order either ascending or descending
• Compare the first two elements of the list.
• If the first element is greater than the second, swap them.
• Move to the next pair and repeat the comparison and swap if necessary.
• Continue this process for the entire list.
• After the first pass, the largest element is at the end.
• Repeat the process for the remaining elements, excluding the last sorted ones.
• Continue until no swaps are needed.
PSEUDOCODE:
DECLARE Names : ARRAY[1:5] OF STRING
DECLARE swap : BOOLEAN
DECLARE temp,top : INTEGER
top=5
REPEAT
swap=False
FOR count = 0 to top-1
IF Names[count]>Names[count+1] THEN
temp=Names[count]
Names[count]=Names[count+1]
Names[count+1]=temp
Swap=TRUE
NEXT
top=top-1
UNTIL NOT swap OR top=0
Lesson 10:
Random Numbers:
Practice: There is a need to generate 100 random OTPs for a bank. (60-780)
Generate the OTPs and store them into array named password, output the contents of array.
DECLARE Password : ARRAY[1:100] OF INTEGER
FOR count = 1 TO 100
Password[count]=INT(RAND(720)+60))
PRINT Password[count]
NEXT
String Handlers:
DECLARE X : STRING
DECLARE Y,Z : INTEGER
X=”Programming is fun”
PRINT (Length(X))
Y=16
Z=3
PRINT(SubString(X,Y,Z))
Lesson 11: Array with more than one dimension. Datatypes should be same
2D Arrays:
(1,1)
(2,4)
(6,5)
(7,1)
Dimensions : 5
NOTE : To handle or manipulate 2D Arrays, you need to understand and have a good grip on co-
ordinates.
DECLARE:
DECLARE Students : ARRAY[1:7,1:5] OF STRING
example
Practice: A 2D array Data[] is required to store names, email, address and password for 500 employees.
Practice : A 2D array Info[] is required to store information about the clients, the information includes,
their name, address, city, country, occupation and martial status. Write pseudocode to set up an array
to store details for 2000 clients.
INPUT:
Store names and addresses of 200 students in a 2D array named students and output all the contents
as well.
DECLARE Students : ARRAY[1:200,1:2] OF STRING
DECLARE row,col : INTEGER
FOR row=1 TO 200
PRINT “please enter student names”
INPUT Students[row,1]
PRINT “please enter student addresses”
INPUT Students[row,2]
NEXT
OUTPUT:
FOR row = 1 TO 200
FOR col = 1 TO 2
PRINT (Students[row,col])
NEXT col
NEXT row
Practice : .
DECLARE Password : ARRAY[1:3000,1:4500] OF STRING
DECLARE row,col : INTEGER
FOR row= 1 TO 3000
FOR col=1 TO 4500
Password[row,col]=”Empty”
NEXT col
NEXT row
Lesson 12:
Manipulation of 2D arrays:
Validation:
Automatic checking by a program that data entered is reasonable before it is accepted into a computer
system.
Types:
1) Range Check
2) Length Check
3) Type Check
4) Presence Check
5) Format Check
6) Check Digits
Range Check:
Definition: Checks that the value of a number is in between an upper value and lower value.
Example: The marks entered by the student should be in between 0 and 100 incase max marks are 100.
Pseudocode:
While Repeat
Length Check:
Example: The password should be 8 characters in length, so the password less than 8 or greater than 8
would be rejected, i.e., password with 7 or less, 9 or more will be rejected.
Pseudocode:
While Repeat
PRINT “please enter your password” PRINT “please enter your password”
UNTIL Length(Password)=8
Type Check:
Example: Number of brothers or sisters should be an integer value i.e., Whole Number.
Pseudocode:
WHILE REPEAT
UNTIL Siblings=Div(Siblings,1)
Presence Check:
Definition: Checks that some data has been entered and field is not left blank.
Pseudocode:
WHILE REPRAT
PRINT “please enter your email” PRINT “please enter your email”
UNTIL Email<>””
Format Check:
Example: For an id, the 1st 4 character should be alphabets, last 4 should be numbers.
WHILE REPEAT
INPUT id INPUT id
ENDWHILE INPUT id
Definition: It is the final digit included in the code, it is calculated from all the other digits in the code.
Detection of Errors:
1) An incorrect digit entered. E.g., 5327 entered instead of 5307.
2) Transposition errors where two numbers have changed order E.g., 5037 instead of 5307.
3) Omitted or extra digits: 537 instead of 5037, 53107 instead of 5307.
4) Phonetic errors, E.g., 13, thirteen instead of 30 or thirty.
Verification:
Definition: Checks data has been accurately copied from one source to another, checks data entry
for errors.
Types;
1) Double Data Entry
2) Visual Check
Double Data Entry:
Definition: Data is entered twice and then both the sets of data are compared.
Example: Password Re-confirmation
Visual Check:
Definition: Physical or manual checking of data once it is entered from another source into a computer.
Example: Comparing the data entered in a computer from original document or a visual screen
appears when ordering online that contains address and phone number.
Subroutines :
Set of instructions that are used repeatedly in a program.
When required it can be called many times during the execution of a program.
1) Re-useable
Sum=num1+num2
PRINT Sum
END PROCEDURE
//Main Program
INPUT n1
INPUT n2
CALL Sum(n1,n2) //values being passed from the main program to the sub -routine are
called arguments
INPUT ISL,Grade11
CALL Sum(ISL,Grade11)
Sum=num1+num2
RETURN Sum
END PROCEDURE
//Main Program
INPUT n1
INPUT n2
Result=Sum(n1,n2) //values being passed from the main program to the sub -routine are
called arguments
PRINT Result
INPUT ISL,Grade11
Result2=Sum(ISL,Grade11)
PRINT Result 2
IF numbers>=90 THEN
Grade=”A*”
Grade=”A”
ELSE
Grade=”U”
ENDIF
PRINT Grade
END PROCEDURE
//Main Program
INPUT marks
INPUT marks
ENDWHILE
CALL Grade(marks)
NEXT
Global Variable : A variable that isn’t the part of any subroutine, and is declared outside all the
subroutines is global.
This variable can be used in any of the subroutines.
Local Variable: A variable that is a part of particular subroutine and can be used in only that
specific subroutine is local.
In this topic:
1) Subroutines
a) Procedures
b) Functions
c) Parameters
d) Arguments
e) Local and Global Variables/Identifiers
main()
myNumber = 5
result = doubleValue(myNumber)
PRINT "Result:", result // Output: Result: 10
PRINT "myNumber:", myNumber // Output: myNumber: 5 (unchanged)
END
//MAIN
def add_and_double(x, y):
x=x+5 # This change does not affect the original 'a'
y[0] = y[0] * 2 # Modifying an element in a list simulates 'ByRef'
return x
# Main program
a=3
b = [4] # Using a list to simulate 'ByRef' behavior for 'y'
result = add_and_double(a, b)
print("Result:", result) # Output: 8
print("a:", a) # Output: 3 (unchanged)
print("b[0]:", b[0]) # Output: 8 (changed)
Note: you always need an identifier to access the data from the file, either you want to read, write or
append, you always need identifier
1-variable
2- array
Write Operation : (I will take one line/sentence/record from the user and store it into the file)
DECLARE textline : STRING
PRINT “please enter a text line”
INPUT textline
OPEN “ISL.txt” FOR WRITE
WRITEFILE,textline
CLOSEFILE “ISL.txt”
Write Operation : (multiple text lines)
DECLARE textline : STRING
PRINT “please enter a text line, empty to stop”
INPUT textline
OPEN “isl.txt” FOR WRITE
WHILE NOT EOF //JB TK FILE END NA HOJAE TB TK RUN HOGA
WRITEFILE,textline
PRINT “please enter a text line, empty to stop”
INPUT textline
ENDWHILE
CLOSEFILE “isl.txt”
//APPEND AUR WRITE FILE SAME HAI BS JAHA WRITE HAI WAHA APPEND AJAIGA
Analysis:
Understanding the problem and looking for required solutions:
Two stages of analysis:
Abstraction and decomposition
Abstraction: That keeps the key elements for the solution and discards any unnecessary elements Example
Google Maps that shows the traveling required and type of vehicle being used
Decomposition: Diving a problem into smaller parts and then into sub parts till it can be solved easily.
Design:
Once done with analysis there is a need to develop the system that is making structured charts, flowcharts and
pseudocodes.
Coding:
Program is developed using a high-level language, that is coding.
Iterative testing: modules are tested, if required the code is amended and tests are repeated until the program
works as required.
Testing:
The program is run many times using different test adat to make sure the program is running fine.
Live data
Normal data
Extreme data
abnormal data