You are on page 1of 25

Department Information

Techonology
Subject:

Object Oriented programming

LAB MANUAL
Submitted to:

MS. SIDRA MUMTAZ

Submitted by:

Areej Musarat (219)

Namra Nisar (254)

Maham (217)

Kinza Arif (260)

Ayesha Arif (266)

Programe: BS(IT) Evening (B)


If Statement:.
If is a keyword in C++ language. If statement is a decision-making
statement. It is the simplest form of selection constructs. It is used to
execute or skip a statement or set of satements by checking a
condition.

Program 1:
Write a program that inputs marks and displays “congratulations! You
have passed.”if the marks are 40 or more.

Program 2:
Write a program that inputs two numbers and finds whether both are
equal.
Programe 3:
Write a program that inputs two numbers anf finds if second number
is square of first.

If –Else statement:
If else statement is another type of if statement .it execute one block
of statements ehen the condition is true and the other when itnis
false.in any situation, one block is executed and the other is skipped
in is else statement.

Program 1:
Write a program that inputs a number and finds whether it is even or
odd using if-else structur.

Program 2:
Write a program that inputs a year and finds whether it is a leap year
or not using if-else structure.
Program 3:
Write a program that inputs two integers. It determines and prints if
the firdt integer is a multiple of second integer.

Switch structure:
the switch statement is another conditional structure. It is a good
alternative of nested if-else. It can be used easily when there are many
choices available and only one should be executed. Nested if becomes
very diffult in such situation.

Program 1:
Write a program that inputs number of week’s day and displays the
name of the day.
Program 2:
Write a program that inputs a character from the user and checks
weather it is vowel or consonant.

Program 3:
Write a program that convert ASCII number to character and vice
versa.the program should display the following menu.
1. Convert ASCII value to character
2. Convert character to ASCII value.

Loops:
A types of control structure that repeats a statement or set of
statements is known as looping structure.
There are three types of loops available in C++ . these are as follows.

 While loop
 Do-while loop
 For loop

While loop:
While loop is the simplest loop of C++ language. This loop
executes one or more statement while the given condition remains
true. It is useful when the number of iterations is not known in
advance.
Program 1:
Write a program that displays “pakistan” for five times using while
loop.

Program 2:
Write a program that display counting from 1 to 10 using while
loop.
Program 3:
Write a program that displays first five numbers and their sum
using while loop.

Do-while loop:
Do-while is an iterative control in C++ language. This loop
executes one or more statements while the given condition is
true.in this loop, the condition comes after the body of the loop. It
is an important loop in a situation when the loop body must be
executed at least once.
Program 1:
Write a program that displays back-counting from 10 to 1 using
do-while loop.
Program 2:
Write a program that gets two numbers from the user and displays
the result of first number raise to the power of second number
using do-while loop.

Program 3:
Write a program that gets starting and ending point from the user
and display all odd numbers in the given range using do-while
loop.

For loop:
For loop executes one or more statements for a specified number of
times. This loop is also called counter-controlled loop.it is the most
flexible loop. That is why, it is the most frequently-used loop by
the programmers.
Program 1:
Write a program that displays counting from 1 to 5 using for loop.
Programe 2:
Write a program that displays product of all odd numbers from 1 to
10 using for loop.

Program 3:
Write a program that inputs table number and length of table and
then displays the table using for loop.
Continue statement:
The continue statement is used in the body of the loop. It is used to
move the control to the start of the loop body. When this statement
i executed in the loop body, the remaining statements of current
itreation are not executed.the control directly moves to the next
iteration.
Program 1:
write a program and print hello world atleast five time using
continue statement.
Program 2:
Write a program that inputs a number from the user using for
loop.it display the number if it is greater than 0 otherwise it inputs
next number using continue statement.

Program 3:
Write a program that displays the sum of the following series:
1+3+5+7+......100

Break statement:
The break statement is used in the body of the loopto exit from the
loop. When this control is executed in the loop body, the remaining
iterations of the loop are skipped. The control directly moves
outside the body and the statement that comes after the body is
executed.
Program 1:
Write a program that inputs number from the user using for loop.if
the number is greater than 0,it is displayed and the next number is
input. The program exits the loop if the number is 0 or negative
using break statement.
Program 2:
Write a program that inputs two numbers and displays the greatest
common divisor of both numbers.

Program 3:
Write a program if the value of x is less than or equal to 5 than
print questioning and bye otherwise gateway to knowledge.
One-Dimensional Array:
the process of input and output with arrays is similiar to the input
and output with simple variables. The cin object is used to input
values in the arrays. The cout object is used to display values of
arrays. However, the use of these objects with each individual
elements becomes very time-consuming because each elements is
treated as a simple variable.
Program 1:
Write a program that inputs five integers from the user and stores
them in an array.it then displays all values in the array without
using loops.
Program 2:
Write a program that inputs five integers from the user and stores
them in an array it then displays all values in the array using loops.

Program 3:
Write a program that inputs five values from the user, stores them
in an array and displays the sum and average of these values.
Two-Dimensional Arrays:
Two-dimensional array can be considered as a tabel that consists of
rows and column. Each element in 2-d array is refered with the help
of two indexes. one index is used to indicate the row and the second
index indicates the column of the element.
Program 1:
Write a program that stores integer values in array of 2 rows and 4
columns.
Program 2:
Write a program that initilizes a two dimensional array of 2 rows and
3 columns and then displays the value.

Program 3:
Write a program that initializes a two dimensional array of 2 rows and
4 columns and then displays the minimum and maximum number in
the array.

Pass by value:
A parameter passing mechanism in which the value of actual
parameter is copied to formal parameters of call function is known as
pass by value. If the function makes any change in formal parameter,
it does not affect the values of actual parameter. It is the default
mechanism for passing parameters to functions.
Program 1:
Write a program that inputs two numbers in main() function,passes
thesenumbers to a function. The function displays the maximum
number.
Program 2:
Write a program that inputs a number in main function and passes the
number to a function. The function displays table of that number.

Program 3:
Write a program that inputs a number and displays its precessor and
successor numbers using function.
Pass by reference:
A parameter passing mechanism in which the address of actual
parameter is passed to the called function is known as pass by
reference. The formal parameter is not created seprately in the
momory. Formal parameter becomes a second name of actual
parameter. It means that single memory location is shared between
actual parameter and formal parameter. If the called function makes
any change in formal parameter, the change is also available in calling
function.
Program 1:
Write a program that inputs two integers in main() function and
passes the integers to a function by reference. The function swaps the
values.the main() function should display the values before and after
swapping.