Professional Documents
Culture Documents
DECLARE AN ARRAY:
Identifiers.
1) Constants
2) Variables
3) Arrays
CONST pi=3.14.16 : REAL
DECLARE num : INTEGER
1D:
DECLARE Names[1:10] : STRING
1 “Haseeb” “Gilani”
2
3
4
5
6
7 Kazmi
8
2D:
DECLARE Names[1:2,1:8] : STRING
Set up an array and put some programmer defined data and then I wanna output the data.
1) Set up a data structure to store 500 marks of students. Take all values from the user and store
them into your 1D array. Output only the Marks those which were greater than 90. Put a
validation check to ensure the marks are between 1 to 100 only.
P2 Pseudocode
1) Basics
2) Selection
3) Repetition (Max, Min, Average)
4) Arrays
i) Input Prog defined
ii) Output Prog defined
iii) Input User defined
iv) Output User defined
v) Array manipulation (output selective data)
vi) Validation
vii) Linear Search
viii) Global Subroutines
ix) Bubble Sort
1) DIV
2) MOD
3) Round
4) Random
5) String Handlers
i) Left
ii) Right
iii) Mid (Sub String)
iv) Length
v) Ucase
vi) Lcase
6) Array Handling
7) 2D Arrays
8) Validation (Pseudocode)
9) Filing
10) Structured Charts
11) Program Development Life Cycle
12) Test Data
13) Validation & Verification
14) Sub routines (Procedures & Functions)
15) Local & Global Variables
Global Subroutines:
1) Length
2) Left
3) Right
4) Mid (Sub String)
5) UCase
6) LCase
Let’s Try 😊
Length(Haseeb)=6
Left(Haseeb,3)=Has
Right(Haseeb,4)=seeb
Mid(Haseeb,3,3)=see
UCASE(Haseeb)=HASEEB
LACASE(HASEEB)=Haseeb
9DIV2=4
17MOD3=2 (Remainder)
Round(7.9,0)=8
Round(7.9,2)=8.00
INT(7.9)=7
Bubble Sort:
Array has been set/declared, data is stored. Array contains 500 Numbers and there is a need to
arrange that array in ascending order.
DECLARE Nums[1:500] : INTEGER
DECLARE count,upperbound,lowerbound,top,temp : INTEGER
DECLARE swap : BOOLEAN
lowerbound=1, upperbound=500, top=upperbound
REPEAT
FOR count= lowerbound TO Top-1
Swap=False
IF Nums[count]>Nums[count+1] THEN
Temp=Nums[count]
Nums[count]=Nums[count+1]
Nums[count+1]=temp
Swap=TRUE
ENDIF
NEXT
Top=top-1
UNTIL (NOT swap) OR top=0
Generate 500 Random Numbers and store them in an array. (random numbers should be in
between 1 TO 2000)
DECLARE Random[1:500] : INTEGER
FOR count = 1 TO 500
Random[count]=INT(RAND(2000)+1)
NEXT
Set an array to store 500 numbers. Generate 500 random numbers in between 7500 to 8500 and
store in that array.
Output the numbers those between 8000 to 8200.
IF a number is in between 7500 to 8000 output accepted.
IF a number is in between 8000 to 8300 output okay.
IF a number is in between 8300 to 8500 output rejected.
Find the average of the numbers.
The highest and lowest number as well.
Sort the numbers into ascending order. [25]
Validation:
An automatic check that makes sure data entered by the user is reasonable before it is accepted
by the system.
i) Range Check:
The value being entered is within a specific range i.e., it is between a lower and upper
value.
PRINT “Please enter marks” PRINT “Please enter marks”
INPUT Marks INPUT Marks
WHILE Marks < 0 AND Marks > 100 REPEAT
PRINT “please enter valid marks” IF Marks < 0 OR Marks > 100 THEN
INPUT Marks PRINT “please re-enter your marks”
ENDWHILE INPUT Marks
UNTIL Marks>=0 OR Marks <=100
ii) Length Check:
Data contains exact number of characters.
PRINT “Please enter your password of 8 PRINT “Please enter your password of 8
chars” chars”
INPUT Password INPUT Password
WHILE LENGTH(Password) <> 8 REPEAT
PRINT “please enter valid password” IF LENGTH(Password) <> 8 THEN
INPUT Password PRINT “please re-enter your password”
ENDWHILE INPUT Password
UNTIL LENGTH(Password)=8
v) Format Check:
Data entered should be equal to pre-defined structure e.g., A school ID ISL123 based 3
alphabets and 3 numbers should follow the same pattern.
vi) Check Digit:
Final Digit of a code that is calculated from other digits within a code.
E.g., Barcodes, product codes, ISBN, VIN
Error Detections of Check Digits:
1) Incorrect Digit. E.g., 45094589
2) Transposition Errors. E.g., 45094590
3) Omitted Digits. E.g., 4509450/459
4) Extra Digits. E.g., 450945009/45091
5) Phonetic Errors. E.g., 13Thirty/30
Test Data:
Data to check the system responds/outputs correctly.
1) Normal data(within the range and acceptable)
2) Abnormal/Erroneous Data (outside the rage and rejected)
3) Extreme (highest and lowest acceptable values)
4) Live (with known outcomes)
Range 10-200
Normal Abnormal Extreme
10 ok
0 Ok
9 Ok
19 Ok
21 ok
Thirteen ok
13 Ok
200 ok
197 Ok
2D ARRAYS:
1,1 1,2 1,3 dgahgdaw ajds@ BGTL ISL LGS KAI BTSC
2,1 2,2
Structure Charts:
Pictorial representation/Decomposition of a system into sub-systems(Modules) until one system
performs its own task.
Module is :
Sub Routine :
1) Function (it returns a value)
2) Procedure (never returns a value)
2D Continued:
Set up a 2D array to hold 100 names and emails.
Take data from the user and store that in your array.
DECLARE Data[1:100,1:2] : STRING
//SEPERATELY
Col=1
FOR row= 1 TO 100
PRINT “please enter names”
INPUT Data[row,col]
NEXT
Col=2
FOR row= 1 TO 100
PRINT “please enter emails”
INPUT Data[row,col]
NEXT
//together
Col=1
FOR row = 1 TO 100
PRINT “please enter names and emails”
INPUT Data[row,col]
INPUT Data[row,col+1]
NEXT
Subroutines:
Structured Programming:
PROCEDURE
KGS TO GRAMS:
FUNCTION MyConverter(X:REAL) RETURNS REAL
DECLARE Grams : REAL
Grams=X*1000
RETURNS Grams
END FUNCTION
DECLARE KGS : REAL
PRINT “please enter weight in kgs”
INPUT KGS
CALL MyConverter(KGS)
Gram is a part of a sub routine i.e., MyConverter, so its user is restricted to that particular sub routine, it
can’t be used within the actual program.
On the other hand KGS is Declared within actual program, so it can be used anywhere required.
Gram : Local Variable
(scope restricted to MyConverter)
KGS : Global variable
(scope not restricted)
File Handling:
3 Modes:
1) Write (overwrites)
2) Read (to read)
3) Append (to add data at the end of the file)
NOTE: For every mode you’ve to open and close the file.
Up to you if you want to directly use the file name or you want to save the file name in an identifier and
then use that identifier in rest of your program.