1738576707-Paper 2 Pseudocode Basics-1
1738576707-Paper 2 Pseudocode Basics-1
TahaAli
Taha Ali
Selection Statement
Selection statements are programming constructs that allow
the execution of certain blocks of code based on conditions.
IF ...........THEN..........ELSE..........ENDIF
CASE.......OF..........OTHERWISE.........ENDCASE
Syntax Of IF Statement
IF statements may or may not have an ELSE clause.
IF statements without an else clause are written as follows:
IF <condition> THEN
<statement(s)>
ENDIF
IF <condition> THEN
<statement(s)>
ELSE
<statement(s)>
ENDIF
Logical Operators
AND OR
Both Condition Any one Condition
Should Be True Should Be True
Relational Operators
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
= Equal to
<> Not equal to
Practice Question
Write a pseudocode of a program in which Input
three numbers and print the Largest Number
Syntax Of CASE Statement
CASE statements allow one out of several branches of code
to be executed, depending on the value of a
variable.
CASE OF <identifier>
<value 1> : <statement1>
<statement2>
CASE OF <identifier>
<value 1> : <statement1>
<statement2>
OTHERWISE : <statement1>
<statement2>
ENDCASE
Practice Question
There are Certain Conditions for a password to be
correct
FOR LOOP
FOR <identifier> ← <value1> TO <value2>
<statement(s)>
NEXT <identifier>
Practice Question
Input One Name and then Output “Good Morning”
23 Times concatenated with the Name
Repetition Known
The identifier must be an INTEGER variable.
No condition
Fixed Loops and will always execute
Values must evaluate to integers.
The loop runs from value1 to value2 inclusive.
Statements inside the loop execute for each assigned
value.
If value1 = value2, the loop runs once.
If value1 > value2, the loop does not execute.
WHILE <condition>
<statement(s)>
ENDWHILE
REPEAT
<statement(s)>
UNTIL <condition>
Practice Question
Input 500 Names and Print in the
format "Hello Name" and Prompt the user aswell
PROGRAMMING TECHNIQUES
1) SUM TECHNIQUE
SUM <-- 0 (Outside the loop)
SUM <-- Sum + Number (Inside the loop)
2) Counting TECHNIQUE
Count <-- 0 (Outside the loop)
Count <-- Count + 1 (Inside the loop)
QUESTION
Input 10 Numbers and Print the
sum of those 10 Numbers
QUESTION
Input 500 Numbers and print
how many numbers are Positive
PRACTICE QUESTION
Input 499 and print how many
number are positive , negative
and zero with a suitable message
Flag Looping
QUESTION
Condition for a password to be correct is that first
digit should be capital
2 11
19 DIV 3
19 MOD 3
27 DIV 4
27 MOD 4
PRACTICE QUESTION
3 "Pappu"
2 "Ahmed"
Lower
Bound 1 "Taha"
Names
What Is Array ?
Arrays stores multiple values of same datatype and
the data is stored on position known as index
5 "Pappan"
4 "Banto"
Names[3] "Bano" 3 "Bano"
Names[0] "Taha"
2 "Pappu"
Names[4]
1 "Ahmed"
Names[5]
0 "Taha"
Names
How to Declare the Array
DECLARE NameOfArray : ARRAY [ LowerBound : UpperBound ] OF DataType
Practice Question
Create an array with the name "FoodItems" with
the Lower Bound (1) and Upper Bound (6) Of
DataType String
Question
Construct an array of 10 Elements and store
Names in it which User Will Input.
Practice Question
construct an array of 100 Elements and store
"No Data" in all the elements and the
name of Array is " ResultArray"
Linear Searching
In this each element of an array is compared with
the value to be found in order from lower bound to
upper bound until the item is found or upper
bound is reached
Question
There is an Array which contains names of 500
students. Search at which index position "Bano" is
stored
Declaration Of 2D Array
ROWS COLUMN
5 78
Question
Write Mode
Writing to a text file means Creating a text file.
All the previous data would be deleted and a file
will be written from scratch
Pseudocode For Writing
Question
Input 5 names and store them in a new file
“Names.txt”
Practice Question
Store all the names which are present in an Array
with the name "School" and contains 700 elements
into a new file "SchoolNames.txt'
Practice Question
There are 54 employee and they will input their ID
numbers with the names. ID will be the first 4
characters. Store only the ID number in the text file
"New.txt"
E.g : "2675Bano"
Append Mode
Sometimes we want to add data to an existing file
rather than creating a new file.
Append Mode adds the new data to an existing file
Question
There is already a File with the name "New.txt"
add one more ID into the file.
The ID "2356"
Read Mode
Whenever you want to search something from an
existing file we use Read Mode
Question
There is an existing file known as sample.txt, Print
all of its content and the file contains 500 line
Practice Question
There is a file “Student.txt” and contains 300 lines.
Search the whole file and output found if “Bano” is
in the file and Not Found if not in the file
Concept Of EOF ( End Of File)
If you want to read a file from begining to end and
you don't know how much lines a file contains, we
can use a conditional loop in this scenario
Header Of Function
FUNCTION Name ( Parameter : Datatype, Parameter : Datatype ) RETURNS Datatype
ENDFUNCTION
ENDPROCEDURE
Question
Write a program code for module named square
that takes an integer value as a parameter and
returns the square value of the number
Practice Question
Write a program code for module named Greeting
that takes a name as a parameter and outputs Good
Morning concatenated with the name 10 times.