Practical -1 
Write a program in C++ that exchange data (Call by Value) using SWAP function i.e. void swap( int, 
int)to interchange the given two numbers.
// call by value
#include<iostream.h>
#include<conio.h>
void main ()
{
clrscr();
int a,b;
void swap(int,int);
cout<<"enter the value of two numbers:";
cin>>a>>b;
cout<<"before swapping A="<<a<<"b="<<b;
swap( a, b);
cout<<"after swapping A="<<a<<"b="<<b;
getch();
}
void swap(int x,int y)
{
int temp;
temp=x;
x=y;
y=temp;
}
Out Put 
enter the value of two numbers:55
66
before swapping A=55b=66
after swapping A=55 b=66
Practical - 2
Write a program in C++, that first initializes an array of given 10 integer numbers. The program must 
verify whether a given element belongs this array or not, using LINEAR SEARCH technique. The 
element (to be search) is to be entered at the time of execution. If the number is found, the program 
should print” The Number is Found” otherwise it should print “The number is not Found”.
//LINEAR SEARCH//
#include<iostream.h>
#include<conio.h>
void main ()
{
clrscr();
int num[10],n;
cout<<"enter the 10 numbers for the array.";
for(int i=0;i<10;i++)
cin>>num[i];
cout<<"enter the number for linear search:";
cin>>n;
for(i=0;i<=10;i++)
{
if(num[i]==n)
{
cout<<"the number is present search successful at position"<<i+1;
break;
}
}
if (i==10)
cout<<"the number is absent search unsuccessful";
getch();
}
Practical – 3
Write a program in C++, that first initializes an array of given 10 sorted integer numbers. The 
program must verify whether a given element belongs this array or not, using BINARY 
SEARCH technique. The element (to be search) is to be entered at the time of execution. If 
the number is found, the program should print” The Number is Found” otherwise it should 
print “The number is not Found”.
//Binary search//
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10],n,i,x,beg,end,mid;
cout<<"enter number of array elements"<<endl;
cin>>n;
beg=0;
end=n-1;
mid=(beg+end)/2;
cout<<"enter the elements";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"enter element to be search";
cin>>x;
while(a[mid]!=x&&beg<=end)
{
if(a[mid]>x)
end=mid-1;
beg=mid+1;
mid=(beg+end)/2;
}
if(a[mid]==x)
cout<<"element is present at position"<<mid+1;
else
cout<<"search unsuccessfull";
getch();
}
Practical – 4
Write a program in C++, that first initializes an array of given 10 integer numbers. The 
program must sort numbers in Ascending/Descending order using BUBBLE SORT method. It 
should print the given list of numbers as well as the sorted list.
//Bubble sort//
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,t,sort[10];
cout<<"enter the array element";
for(i=0; i<10;i++)
{
cin>>sort[i];
}
for(i=0;i<10;i++)
{
for(j=10;j>0;j--)
{
if(sort[j-1]>sort[j])
{
t=sort[j-1];
sort[j-1]=sort[j];
sort[j]=t;
}
}
}
cout<<"sorted array is-";
for(i=0;i<10;i++)
{
cout<<sort[i];
}
getch();
}
Practical – 5
Write a program in C++, that first initializes an array of given 5 integer numbers.
The program should perform summation of array elements using POINTER.
//sum of array
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num[5],i,*p,sum=0;
cout<<"enter array elements:=\n";
for(i=0;i<5;i++)
cin>>num[i];
p=num;
for(i=100;i<105;i++,p++)
{
sum=sum+*p;
}
cout<<"the sum of array is "<<sum;
getch();
}
Practical – 6
Write a program in C++, using OOP to demonstrating the implementation of SINGLE INHERITANCE, 
having two class viz. student and result
//Demonstrating inheritance//
#include<iostream.h>
#include<conio.h>
class student
{
private:
float rollno;
public:
float p,c,m,b,e;
void getdata()
{
cout<<"enter the marks of 5 subjects:-";
cin>>p>>c>>m>>b>>e;
}
};
class result : public student
{
private:
float total,per;
public:
void disdata();
};
void result::disdata()
{
getdata();
total=p+c+m+b+e;
per=total/500*100;
cout<<"total::"<<total<<"percentage::"<<per;
}
void main()
{
clrscr();
class result zl;
zl.disdata();
getch();
}
Practical – 7
Write a program in C++, using OOP to demonstrating the implementation of FUNCTION 
OVERLOADING having two classes.
//functional overloading//
#include<iostream.h>
#include<conio.h>
class ex
{
public:
void calc(int x,int y);
void calc(float a,float b);
};
void ex::calc(int x,int y)
{
int total;
total=x+y;
cout<<"\ntotal="<<total;
}
void ex::calc(float a,float b)
{
float sub;
sub=a-b;
cout<<"\nsub="<<sub;
}
void main()
{
ex ob;
clrscr();
int x,y;
float a,b;
cout<<"enter the value for x and y";
cin>>x>>y;
cout<<"enter the value for a and b";
cin>>a>>b;
ob.calc(a,b);
getch();
}
Practical 8.
Write a prof the in C++ using virtual function. The program must declare P to be a poin to 
object the base class Person. First, then the program met de pointaninstance xiname of the 
person for eg. BOB) of class Person. The program must then assign P to point at an instance y 
(name of the student og TOM) of derived class Student Define a print function in the base 
class to print the name of the Person. The second to the print function must print the name 
of the theme of student using derived class' print function.
Program:
#include<iostream.h>
#include<conio.h>
class person
{
public:
virtual void print()
cout<<"\n The Name of person is BOB";
}
};
class student:public person
{
public:
void print()
cout<<"\n The Name of the student is TOM";
}
};
void main()
{
clrscr();
Person *p;
Person p1;
p=&p1;
p->print();
student s1;
p=&s1;
p->print();
getch();
}
Output: The Name of person is BOB The Name of the student is
Practical 9.
Write a program in C++ that initializes the ratio class with no parameters as default 
constructor. The program must print the message "OBJECT IS BORN" during initialization. It 
should display the message "NOW X IS ALIVE" when the first member function of ratio class 
is called. The program must display "OBJECT DIES" when the class destructor is invoked for 
the object when it reaches the end of its scope.
Program:
#include <iostream.h>
#include <conio.h>
class Ratio
public:
void print()
{
cout<<"\nNow X is ALIVE";
}
Ratio()
cout<<endl<<"OBJECT IS BORN";
}
-Ratio()
{
cout<<endl<<"OBJECT DIES";
};
void main()
clrscr();
Ratio r1;
r1.print();
getch();
}
Output: OBJECT IS BORN 
Now X is ALIVE 
OBJECT DIES
******Factorial of given number*******
#include<iostream.h>
#include<conio.h>
class factorial
{
public:
void fact()
{
int f=1,n;
cout<<"\n\n Enter Number : ";
cin>>n;
while(n>0)
{
f=f*n;
n--;
}
cout<<"\n\n "<<f;
}
};
void main()
{
clrscr();
factorial fa;
fa.fact();
getch();
}
Practical - 11
Write a program in C++ to input the given string (including spaces) and reverse it using a 
function which locates the end of the string and swaps the first character with the last 
character, the second character with second last character and so on
#include<iostream.h>
#include<conio.h>
#include<string.h>
class revstring
{
public:
 char a[50],b[50];
 int i,j,n;
void get()
{
 cout<<"\n Please Give The STRING : ";
 cin>>a;
}
void disp()
{
for(j=strlen(a)-1;j>=0;j--)
cout<<a[j];
}
};
void main()
{
clrscr();
revstring r;
r.get();
r.disp();
getch();
}
Practical 12
#include<iostream.h>
#include<conio.h>
class student 
{
public:
int rno,m1,m2;
void get()
{
cout<<"Enter the Roll no :";
cin>>rno;
cout<<"Enter the two marks :";
cin>>m1>>m2;
}
};
class sports
{
public:
int sm; // sm = Sports mark
public:
void getsm()
{
cout<<"\nEnter the sports mark :";
cin>>sm;
}
};
class statement:public student,public sports
{
int tot;
double avg;
public:
void display()
{
tot=(m1+m2+sm);
avg=tot/3;
cout<<"\n\n\tRoll No:"<<rno<<"\n\tTotal:"<<tot;
cout<<"\n\tAverage:"<<avg;
}
};
void main()
{
clrscr();
statement obj;
obj.get();
obj.getsm();
obj.display();
getch(); 
}