Anda di halaman 1dari 5

try

{
throw exceptions;
}
catch(arguments)
{
}

pgm:
#include<iostream.h>
#include<conio.h>

int main()
{
int a,b;
cout<<Enter the value of A & B.\n;
cin>>a>>b;
int x = (a-b);

try
{
if(x!=0)
{
cout<<result=<<(a/(a-b));
}
else
{
throw(x);
}
}

catch(int i)
{
cout<<Division by zero \n;
}
getch();
return 0;
}

SINGLE INHERITANCE
#include<iostream.h>
#include<conio.h>
class A // CLASS A ONE CLASS
{
private:
int a;
public:
void getdata();
};
void A::getdata()
{
cout<<"Enter the value of a...\n";
cin>>a;
}

class B:public A //CLASS B IS THE BASE CLASS


{
private:
int b;
public:
void setdata();
};
void B::setdata()
{
cout<<"Enter the value of B....\n";
cin>>b;
}; //AFTER THE CLASS JUST CLOSE THE CLASS WITH SEMICOLON

void main()
{
clrscr();
B obj; //WE SHOULD CREATE THE OBJ FOR THE BASE CLASS
obj.getdata();
obj.setdata();
getch();
}

MULTIPLE INHERITANCE:
#include<iostream.h>
#include<conio.h>
class A
{
private:
int a;
public:
void getdata();
};
void A::getdata()
{
cout<<"Enter the value of a...\n";
cin>>a;
}
class B
{
private:
int b;
public:
void setdata();
};
void B::setdata()
{
cout<<"Enter the value of B....\n";
cin>>b;
} //AFTER THE CLASS JUST CLOSE THE CLASS WITH SEMICOLON
class C:public A,public B
{
private:
int x;
public:
void display();
};
void C::display()
{
cout<<"Enter the value of x....\n";
cin>>x;
}
void main()
{
clrscr();
C obj;
obj.getdata();
obj.setdata();
obj.display();
getch();
}
MULTILEVEL INHERITANCE:
#include<iostream.h>
#include<conio.h>
class A
{
private:
int a;
public:
void getdata();
};
void A::getdata()
{
cout<<"Enter the value of a...\n";
cin>>a;
}
class B:public A
{
private:
int b;
public:
void setdata();
};
void B::setdata()
{
cout<<"Enter the value of B....\n";
cin>>b;
} //AFTER THE CLASS JUST CLOSE THE CLASS WITH SEMICOLON
class C:public B
{
private:
int x;
public:
void display();
};
void C::display()
{
cout<<"Enter the value of x....\n";
cin>>x;
}
void main()
{
clrscr();
C obj;
obj.getdata();
obj.setdata();
obj.display();
getch();
}
virtual function in c++
#include<iostream.h>
#include<conio.h>
class eee
{
public:
virtual void display()
{
cout<< ;
}
};
class eee2:public eee
{
public:
void display()
{
cout<< ;
}
};

void main()
{
clrscr();
eee *p, o;
eee2 k;
p=&o;
p->display();
p=&k
p->display();
getch();

Anda mungkin juga menyukai