0% found this document useful (0 votes)
22 views35 pages

P2 - Level 1

The document outlines the Program Development Life Cycle, which includes five stages: Analysis, Design, Coding, Testing, and Maintenance. It details techniques for each stage, such as abstraction and decomposition in Analysis, the use of structure charts and pseudo codes in Design, and various testing methods. Additionally, it covers computer system components, algorithms, data validation, verification, and the use of arrays in programming.

Uploaded by

Muhammad Mehroz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views35 pages

P2 - Level 1

The document outlines the Program Development Life Cycle, which includes five stages: Analysis, Design, Coding, Testing, and Maintenance. It details techniques for each stage, such as abstraction and decomposition in Analysis, the use of structure charts and pseudo codes in Design, and various testing methods. Additionally, it covers computer system components, algorithms, data validation, verification, and the use of arrays in programming.

Uploaded by

Muhammad Mehroz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Handouts of Paper 2 [ Level 1 ]

Program Development Life Cycle:


It has following five stages:

• Analysis
• Design
• Coding
• Testing
• Maintenance

➢ Analysis
o It means to identify the problems in the existing system and set the clear objectives of
the new system. Requirement specification of the new system is defined.
Analysis is done with two tools one is abstraction and other is decomposition.

Abstraction: It means to keep the key elements to develop new system and discard the
unnecessary details

Decomposition: It means to break up complex problem into smaller parts which can
further be subdivided into smaller parts so that smaller portions can be solved easily.

Top down design: It means the problem is solved in modular approach or procedural
approach. A major problem is solve in hierarchical way.
➢ Design:
o It involves
▪ structure charts
▪ flow charts
▪ pseudo codes

➢ Coding:
o On the basis of design work a programmer can do coding to get new application using
any programming language/tool

Page 1 of 35
Handouts of Paper 2 [ Level 1 ]

➢ Testing:
o Once the coding is done the software is tested to make sure it is working properly.
Testing is done with
▪ Normal set of data
▪ Abnormal set of data
▪ Extreme data e.g. lower extreme or upper extreme
▪ Boundary data e.g. if 1 is the lower possible value then check with 0 and 1. 0
will be rejected and 1 is accepted
Iterative Testing: It means that modular tests are conducted, code amended, and tests repeated
until the module performs as required.

Age can be from 10 to 20 years

Type of test : Normal


Example: 15
Expected Result: should be accepted
Reason: to make sure data is accepted without any problem

Type of test : Abnormal


Example : 7 or 25
Expected Result: Should be rejected
Reason: to make sure out of range or abnormal values are not accepted.

Type of test : Extreme


Example : 10 or 20
Expected Result: Should be Accepted
Reason: minimum and maximum possible values are entered. If these are accepted rest will be
accepted as well.

Type of test : Boundary data can be just below the minimum possible value or one point less
than minimum
For example. 0 to 100 is accepted If more than 9 characters are allowed then 9
Boundary data will be 0 or -1 characters’ value is boundary data
0 is accepted / -1 is rejected

Boundary data can be 100 or 101

100 is accepted and 101 is rejected

Dry Run: Trace the pseudo code or flow chart with dummy data is known as Dry Run.

Page 2 of 35
Handouts of Paper 2 [ Level 1 ]

Maintenance:

It means how the program written in any high level language will be easy to understand for
further updating for another programmer? For this purpose following techniques can be used:

i. Meaningful Identifier Names:


All variables/identifiers should be given meaningful names so that it wont be difficult
for other programmer to understand the purpose of these identifiers

ii. Add Comments:


Each programming line or part of code can be added with comments that will
explain the purpose of each piece of code. It will also help in future for further
improvements

iii. Procedural Approach:


It is good skilled approach to used procedures or modules for different parts of the
program. It will provide easy way for further development.

Computer System: a computer system is made up of software, data , hardware,


communications and people. Each computer system can be divided into a set of sub-
systems and each sub system is further divided into sub system until each sub system
performs a single action which can’t be further divided.

Components parts of any Computer System:

Input: the data used by system needs to be entered

Process: Tasks needs to be performed using input data and previously stored data

Output: information that needs to be displayed on screen or printer paper

Storage: data that needs to be stored for future use

Page 3 of 35
Handouts of Paper 2 [ Level 1 ]

Structure Diagrams: It shows the design of a computer system in hierarchical way.

Example:

Question from Specimen Paper:

Page 4 of 35
Handouts of Paper 2 [ Level 1 ]

Algorithm: an ordered or series of steps to solve a problem.

Stages of writing and amending an algorithm

i. Make sure that the problem is clearly specified


ii. Break the problem down in to sub problems
iii. Decide on how any data is to be obtained
iv. Design the structure of algorithm
v. Decide on how you are going to construct your algorithm either using flowchart or
pseudo.
vi. Construct your algorithm
vii. Use sets of test data
viii. Correct any errors found

State Two techniques to build an algorithm:


Algorithm can be design using two techniques:

1. Pseudocodes:

It is a simple method of shown an algorithm. It describes that the algorithm does by using
English key words similar to those used in high level language.

Rules of pseudocodes:

i. All keywords are written in capital format


ii. All names given to data items and subroutines start with capital letters
iii. Repeated or selected statements are indented by two spaces

2. Flow Charts:

A diagram that shows the steps required for a task and the order in which the steps are to be
performed.

Symbols:

Input/Output Condition/Selection

Start and Stop

Process

Use of procedure or library routine

Data flow (direction) get external data

Page 5 of 35
Handouts of Paper 2 [ Level 1 ]

Sequence, Selection and Iteration:


Sequence: It means all instructions are given in right order in proper sequence for example in
order to calculate area of triangle we need to get input of base and height then we can apply
formula for area e.g.

Input base

Input height

Area = ½ x base x height

Output Area

All instructions are given in proper sequence to get accurate results.

Selection:

There are two selection/conditional statements are used

i. If …. Then…else (these are used for one or two conditions with either or solutions

ii. Case… otherwise … EndCase (these can be used for multiple conditions and
solutions , multiple outcomes

Iterations:

It means the loop. Repeat set of instructions for given number of times

Three loops are used in programming:

i. For…. Next loop (count controlled loop)


a. It is used for fixed number of iterations e.g. from 1 to 10 etc
b. It cannot be used in situations where loop has to terminate on certain condition
ii. Repeat…. Until
a. This loop is known is post conditional loop it can be used in situations in which loop will
run for one time at least because condition is given at the end
b. This loop can also be used in which loop terminates on certain condition
iii. While…Do…EndWhile
a. This loop is known as pre-conditional loop. It can be used in situation where loop will
not run for one time if condition which is given in the beginning is false
b. This can also be used in situation where loop terminates on certain condition

Page 6 of 35
Handouts of Paper 2 [ Level 1 ]

Operators used in programming


Mathematical operators:

• + Add
• - Subtract
• * Multiply
• / Division
• DIV - Mod
• ^ Exponent (Raise the power)
• ( ) Group

Example: X x+y

Logical/Comparison Operator:

• >
• >=
• <
• <=
• <>

Example: If X > Y THEN Output “ the Value of X is greater than Y”

Boolean/Relational Operators:

• AND
• OR
• NOT

Example: IF (A > B AND B > C) THEN Output “True” (It means if both conditions are true )

Page 7 of 35
Handouts of Paper 2 [ Level 1 ]

STATE the difference between Variable and Constant along with methods of declaring both?

Variables: These are named memory locations whose value can change during execution of the program

Declare StudentName : String

Declare Student : Integer

Constants: These are named memory locations whose value remains the same during execution of the
program

Constant SalePrice 500

TYPES OF VARIABLES

Local Variable: These can be used within subroutine or procedure where they have been
declared

Global Variables: These can be used anywhere in the program. Defined out of the procedure or
subroutine

Data Types of variables:

o Number/Integer It stores whole numbers that can be positive or negative


o Real It means to hold numbers with decimals
o Char It means to hold a single character
o String It means to hold a complete string
o Boolean It means to hold True or False/ Yes or No

DECLARE X : INTEGER

DECLARE Y : REAL

DECLARE Z : CHAR

DECLARE Q : STRING

DECLARE R : BOOLEAN

Page 8 of 35
Handouts of Paper 2 [ Level 1 ]

EXAMPLE OF TOTALLING:

For Count = 1 to 10

Input Number

Sum = sum + Number (//Totalling)

Next Count

Average = Sum / 10

Print Sum, Average

EXAMPLE OF COUNTING

Negative, positive,percentage = 0 (Example of counting)

For Count = 1 to 20

Input number

If number >=0 then positive = positive + 1

If number < 0 then negative = negative +1

Next count

Percentage = negative/20* 100

Print positive, negative, percentage

MOD (Modulus Operator): It returns the remainder value when one number is divided by another

for example 5 mod 2 will return 1.

DIV : It returns quotient or whole number part when one number is divided by another

for example 5 DIV 2 will return 2.

Page 9 of 35
Handouts of Paper 2 [ Level 1 ]

Validation : It means data is valid according to given standard. It is done automatically through
programming code. Validation checks:

o Range check (It means the values are in specific range for example age can be from 5
years to 10 years )
Repeat

Input age

Until age>=5 and age<=10

o Length check (It means data contains exact number of characters for example
password can be of 8 characters long)

Repeat

Input password

Until length(password) = 8

o Presence check (It means no important field is left blank)

Repeat

Input CNIC

Until CNIC < > “ ”

o Type Check (It means data entered is of given type for example numbers are required
only numbers should be entered no text or characters)

Repeat

Input Num

IF Num < > DIV (Num , 1) Then output “Invalid value”

Until Num = DIV (Num,1)

o Format Check (It means characters entered should be in pre-defined format for example
every bank code will have BAH followed by any 4 number e.g. “BAH0009”

Repeat

Input Code

IF SUBSTR(Code,1.3) < > “BAH” Then “Error….”

Until SUBSTR (Code,1,3)= “BAH”

Page 10 of 35
Handouts of Paper 2 [ Level 1 ]

o Check Digits: it is the final digit included in a code. It is calculated from all the other
digits in the code.

Verification: It means checking of data when copied from one source to another. It is done with two
techniques:

- Visual Checking/Proof reading (It means a manual check completed by the user who is
entering the data.

- Double entry (It means the same data is entered twice if both are same accepted
otherwise rejected)1

- Example of Double entry

Repeat
Input Measurement
Input Measurement1

IF Measurement < > Measurement1 Then output “Both are not equal”

Until Measurement = Measurement

Procedure and Function

Define following:

i. Subroutine/procedure: Set of programming statements grouped together under single


name that can be called to perform a task anywhere in the program. It may not return a
value
Call NameofProcedure( )

ii. Function: It is also set of programming statements grouped under single name that can be
called to perform a task but it returns a value at the ends. It requires assignment statement

Declare result : Integer


Result = sqrt(5)

iii. Parameters: these are the variables that stores the value of the arguments passed to the
procedure or function e.g. Function Sqrt(Number : Integer) return integer
Number is parameter in this example

Page 11 of 35
Handouts of Paper 2 [ Level 1 ]

iv. Library routine: These can hold subroutines which can be reused in many programs. Library
routines can be included into a program and are called when required. DIV, Round, Random
are examples of library routines.

These are fully tested.


These are immediately ready to use.

Examples of library routines (MOD , DIV, ROUND, RANDOM)

A = 5 mod 2 (It returns remainder)


A = 5 DIV 2 (It returns quotient)
A = round (5/2 , 0) (It rounds to the nearest decimal place given
A = random (It returns a random number that can be from 0 to 1)

# Header of any procedure or function contain the following:


• Name of procedure or function
• Parameters and their types
• Data type of return value

Page 12 of 35
Handouts of Paper 2 [ Level 1 ]

1D (Single dimensional arrays): An array is a data structure containing several


elements of the same data type. It requires array name and index.

How to declare an 1D array:

Declare StudentName : Array ( 1: 10) of String

Declare Marks : Array (1 : 10) of Integer

Insert Values in a 1D Array:

For Index = 1 to 10 For Index = 1 to 10


INPUT N
INPUT Marks (Index )
Marks ( Index ) = N
Next Index Next Index

Display Values stored in a 1D Array:

FOR Index = 1 to 10

OUTPUT Marks ( Index )

NEXT Index

Q1 : Display the 50 names stored in 1D array St_Name

A: For count = 1 to 50

Output St_Name (count)

Next count

Q2 : Display the 50 averages stored in 1D array Average

A: For count = 1 to 50

Output Average (count)

Next count

Page 13 of 35
Handouts of Paper 2 [ Level 1 ]

Linear Search:

An algorithm that inspects each item in list (array) in turn to see if the item
matches the value searched for.

Q: Write a program that will ask user to enter RollNumber of his choice stored in
1D array RollNumbers[ ] and Display the marks of that roll number stored in
another 1D array name Marks [ ]. Both arrays contain 1000 values in all.

Ans:

INPUT RollNum

For count = 1 to 1000

IF RollNum = RollNumbers [ Count ]

Then Output Marks [ count]

END IF

Next count

Page 14 of 35
Handouts of Paper 2 [ Level 1 ]

2D array can be defined as table with rows and columns


How to declare a 2D array:

DECLARE Tests : Array ( 1:30 , 1:3) of INTEGER

=======
Bubble Sort:

An algorithm that makes multiple passes through a list comparing each element
with the next element and swapping them.

Page 15 of 35
Handouts of Paper 2 [ Level 1 ]

String Handling:

• Substring()
• Length()
• UCASE()
• LCASE()

Print substring(“Pakistan”,4,2) // it will display “is” from Pakistan


Print length(“Pakistan”) // It will display 8 (number of characters in pakistan)
Print UCase(“Pakistan”) // It will display PAKISTAN
Print LCase(“PAKISTAN”) // It will display pakistan

Declare X : String
Declare Y : Integer
Declare Z : Integer

X “Programming is fun”
Output Length(X)
Y 16
Z 3
Output Substring(X,Y,Z)

Page 16 of 35
Handouts of Paper 2 [ Level 1 ]

P Computer Science
Q 16
R Science
S 7
T Sci

F Substring(P, 1, 8)

Page 17 of 35
Handouts of Paper 2 [ Level 1 ]

File Handling

Declare TextLine: String


Declare MyFile: String

MyFile = “MyText.txt”
OpenFile MyFile for Write
Output “Please enter a line of text”
Input TextLine
WriteFile, TextLine
CloseFile MyFile

OpenFile MyFile for Read


ReadFile, TextLine
Output TextLine
CloseFile MyFile

// Copy a string written in one file to another file

Declare TextLine

OpenFile FileA.Txt for Read


ReadFile, TextLine
CloseFile FileA.Txt

Open file FileB.txt for write


WriteFile, TextLine
CloseFile FileB.txt

Page 18 of 35
Handouts of Paper 2 [ Level 1 ]

CHAPTER 9

Page 19 of 35
Handouts of Paper 2 [ Level 1 ]

Page 20 of 35
Handouts of Paper 2 [ Level 1 ]

Page 21 of 35
Handouts of Paper 2 [ Level 1 ]

Page 22 of 35
Handouts of Paper 2 [ Level 1 ]

======================================================

Page 23 of 35
Handouts of Paper 2 [ Level 1 ]

Page 24 of 35
Handouts of Paper 2 [ Level 1 ]

Page 25 of 35
Handouts of Paper 2 [ Level 1 ]

Page 26 of 35
Handouts of Paper 2 [ Level 1 ]

Page 27 of 35
Handouts of Paper 2 [ Level 1 ]

Page 28 of 35
Handouts of Paper 2 [ Level 1 ]

Page 29 of 35
Handouts of Paper 2 [ Level 1 ]

Page 30 of 35
Handouts of Paper 2 [ Level 1 ]

Page 31 of 35
Handouts of Paper 2 [ Level 1 ]

Page 32 of 35
Handouts of Paper 2 [ Level 1 ]

Page 33 of 35
Handouts of Paper 2 [ Level 1 ]

Page 34 of 35
Handouts of Paper 2 [ Level 1 ]

Page 35 of 35

You might also like