Showing posts with label Inheritance. Show all posts
Showing posts with label Inheritance. Show all posts

Multiple Inheritance

#include<iostream.h>
#include<constream.h>
class A { protected : int a;};
class B { protected : int b;};
class C { protected : int c;};
class D { protected : int d;};
class E : public A,B,C,D
 {
 int e;
public:
 void getdata()
  {
cout<<"\n Enter values of a,b,c,d,e:\n";
cin>>a>>b>>c>>d>>e;
  }
 void showdata()
  {
cout<<"\n a="<<a<<"\n b="<<b<<"\n c="<<c<<"\n d="<<d;               cout<<"\n e="<<e;
  }
 };
void main()
 {
clrscr();
E X;
X.getdata();
X.showdata();
getch();
 }

Multilevel Inheritance

#include<iostream.h>
#include<constream.h>
class A1
 {
protected:
     char name[15];
     int age;
 };
class A2: public A1
 {
protected:
float height;
float weight;
 };
class A3: public A2
 {
protected:
char sex;
public:
void get()
 {
cout<<"name :";
cin>>name;
cout<<"age :"; cin>>age;
cout<<"sex :"; cin>>sex;
cout<<"height :"; cin>>height;
cout<<"weight :"; cin>>weight;
 }
void show()
 {
cout<<"\n Name :"<<name;
cout<<"\Age :"<<age<<"years";
cout<<"\Sex :"<<sex;
cout<<"\Height :"<<height<<"feets";
cout<<"\Weight :"<<weight<<"kg.";
 }
 };
void main()
 {
clrscr();
A3 X;
X.get();
X.show();
getch();
 }

Single Inheritance

#include<iostream.h>
#include<constream.h>
class ABC
 {
protected:
     char name[15];
          int age;
 };
class abc: public ABC
 {
Protected:
     float height;
     float weight;
public:
  void getdata()
   {
cout<<"\n Enter Name and Age:";
cin>>name>>age;
cout<<"\n Enter Height and Weight:";
cin>>height>>weight;
   }
  void show()
   {
cout<<"\n Name:"<<name<<"\n Age:"<<age<<"years";
cout<<"\n Height:"<<height<<"feets";    
cout<<”\n weight:"<<weight<<"kg";
   }
 };
void main()
 {
clrscr();
abc x;
x.getdata();
x.show();
getch();
 }
Related Posts with Thumbnails