Partial Crash Course Booklet
Partial Crash Course Booklet
P2 Crash Course
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
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>
2) Counting TECHNIQUE
Count <-- 0 (Outside the loop)
Count <-- Count + 1 (Inside the loop)
Practice Question 2
Input 10 Numbers and Print the
sum of those 10 Numbers
Practice Question 3
Input 500 Numbers and print
how many numbers are Positive
Practice Question 3
Practice Question 4
Condition for a password to be correct is that first
digit should be capital
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
Declaration Of 2D Array
ROWS COLUMN
5 78
Practice Question 1
Construct An Array with the name StNames which have 200
rows and 500 columns and Initialize each Elements
Practice Question 2
Construct An Array with the name Number which have 150
rows and 238 columns and Initialize each Elements
Practice Question 3
There is an array StNames with 125 rows and 235 columns
which contains the name of Students but there are certain
Elements which are empty. Count how many elements are
empty.
Practice Question 4
There is an array StNames with 125 rows and 235 columns
which contains the name of Students. Search if there is
“Bano“. Output Found if there and Not Found if not there
Practice Question 5
There is an array Numbers with 125 rows and 235 columns
which contains the profit earned each day. Calculate the
sum of the profits.
Practice Question 6
There is an array Job with 129 rows and 289 columns which
contains salaries of Employees. Increase the salary of each
Employee by 12%.
Practice Question 7
There is an array Student with 129 rows and 2 columns. First
Columns Contains the Name of Students, The second
Column contains the Number of Days they were Present in
string format. Output the percentage of attendance of Bano
considering she was suppose to attend 180 Days.
Practice Question 8
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
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