CPP Pranit
CPP Pranit
1
Date: / /
Roll No:140
Output :
Experiment No.2
Date: / /
Roll No:140
#include<conio.h>
#include<iostream.h>
void add(int a,int b);
void add(int a,int b,int c);
void main()
{
clrscr();
add(5,8);
add(10,99,12);
getch();
}
void add(int a,int b)
{
cout<<"Addition:"<<a+b<<endl;
}
void add(int a,int b,int c)
{
cout<<"Addition:"<<a+b+c<<endl;
}
Output:
Experiment No.3
Date: / /
Roll No:140
Output :
Experiment No
4 Date: / /
Roll No:140
#include<iostream.h>
#include<conio.h>
class XYZ;
class ABC{
int X;
public:
void getdata();
friend void AOpertn(ABC,XYZ);
};
class XYZ{
int Y;
public:
void getdata();
friend void AOpertn(ABC,XYZ);
};
void ABC::getdata()
{ cout<<"Enter 1st number:";
cin>>X;
}
void XYZ::getdata()
{ cout<<"Enter 2nd Number:";
cin>>Y;
}
void AOpertn(ABC aa,XYZ bb){
cout<<"Addition:"<<aa.X+bb.Y;
}
void main()
{
ABC aa;
XYZ bb;
aa.getdata();
bb.getdata();
AOpertn(aa,bb);
getch();
}
Output :
Experiment No.5
Date: / /
Roll No:140
Output:
2) Parameterized Constructor:
#include<iostream.h>
#include<conio.h>
class abc{
int a;
public:
abc(int x)
{
a=x;
}
void putdata()
{
cout<<"
}
};
void main()
{
int b;
clrscr();
cout<<"Enter value: ";
cin>>b;
abc aa(b);
aa.putdata();
getch();
}
Output :
3) Copy Constructor
: #include<iostream.h>
#include<conio.h>
class abc{
int x,y;
public:
abc()
{ x=
7;
}
abc(abc &aa)
{
y=aa.x;
}
void putdata1()
{
cout<<"Value in first object: "<<x<<endl;
}
void putdata2()
{
cout<<"Value in second object: "<<y<<endl;
}
};
void main()
{
clrscr();
abc aa;
aa.putdata1();
abc bb(aa);
bb.putdata2();
getch();
}
Output:
4) Destructor :
#include<iostream.h>
#include<conio.h>
int x=0;
class abc{
public:
abc()
{
x=x+1;
cout<<"Constructor created: "<<x<<endl;
}
~abc()
{
x=x-1;
cout<<"Constructor destroyed: "<<x<<endl;
}
};
void main()
{
clrscr();
{
abc aa,bb,cc;
{
abc dd;
}
}
getch();
}
Output:
Experiment No.6
Date: / /
Roll No:140
Output:
2)Multiple Inheritance:
#include<iostream.h>
#include<conio.h>
class A
{protected:
int x;
public:
void getdata1()
{cout<<"Enter First Number:";
cin>>x;
}};
class B
{protected:
int y;
public:
void getdata2()
{cout<<"Enter second Number:";
cin>>y;
}};
class c: public A,public B
{public:
void add(){
cout<<"Addition="<<x+y;
}};
void main()
{c zz;
zz.getdata1();
zz.getdata2();
zz.add();
getch();
}
Output:
3)Multilevel Inheritance:
#include<iostream.h>
#include<conio.h>
class A{
protected:
int x;
public:
void getdata1()
{cout<<"Enter First value:";
cin>>x;
}};
class B:public A
{protected:
int y;
public:
void getdata2()
{cout<<"Enter second value:";
cin>>y;
}};
class c: public B
{public:
void mult()
{cout<<"Multiplication is="<<x*y;
}};
void main()
{c zz;
zz.getdata1();
zz.getdata2();
zz.mult();
getch();
}
Output:
4) Hirarchical
Inheritance:
#include<iostream.h>
#include<conio.h>
class
A{ public:
void msg1()
{cout<<"This is class A"<<endl;
}};
class B: public A
{ public:
void msg2()
{cout<<"This is class B"<<endl;
}};
class C: public A
{ public:
void msg3()
{cout<<"This is class c";
}};
void main()
{clrscr();
B bb;
C cc;
bb.msg1();
bb.msg2();
cc.msg1();
cc.msg3();
getch();
}
Output:
5)Hybrid Inheritance:
#include<iostream.h>
#include<conio.h>
class A{
public:
void msg1()
{cout<<"This is class A"<<endl;
}};
class B: public A
{ public:
void msg2()
{cout<<"This is class B"<<endl;
}};
class C
{ public:
void msg3()
{cout<<"This is class C"<<endl;
}};
class D: public B,public C
{ public:
void msg4()
{cout<<"This is class D"<<endl;
}};
void main()
{clrscr();
D dd;
dd.msg1();
dd.msg2();
dd.msg3();
dd.msg4();
getch();
}
Output:
Experiment No.8
Date: / /
Roll No:140
#include<iostream.h>
#include<conio.h>
void main()
{
float
A,r;
clrscr();
cout<<"Enter Radius: ";
cin>>r;
A=r*r*3.14;
cout<<"Area: "<<A;
getch();
}
Output:
Experiment No.10
Date: / /
Roll No:140
#include<iostream.h>
#include<conio.h>
class akash{
int a,b,c;
public:
void getdata()
{cout<<"Enter 1st value:";
cin>>a;
cout<<"Enter 2nd value: ";
cin>>b;
}
void putdata()
{
c=a*b;
cout<<"MUltiplication is:"<<c;
}};
void main()
{
clrscr();
akash obj;
obj.getdata();
obj.putdata();
getch();
}
Output: