Wednesday, March 28, 2018

Write a C+ Inheritance+ program to incorporate Multiple Inheritance


AIM: Write a C+ Inheritance+ program to incorporate Multiple Inheritance
THEORY:
Multiple inheritance is a feature of some  computer programming languages in which an object or class can inherit characteristics and features from more than one parent object or parent class. It is distinct from single inheritance, where an object or class may only inherit from one particular object or class.
Multiple Inheritance has been a sensitive issue for many years, with opponents pointing to its increased complexity and ambiguity in situations such as the "diamond problem", where it may be ambiguous as to which parent class a particular feature is inherited from if more than one parent class implements said feature. This can be addressed in various ways, including using virtual inheritance. Alternate methods of object composition not based on inheritance such as mixins and traits have also been proposed to address the ambiguity
SOURCE CODE:
#include<iostream>
using namespace std;
class A{
            protected:
            char name[20];
            int age;
};
class B{
            protected:
            int h,w;           
};
class C:public A,B{
    public:
    char g;
    void get_data()    {
            cout<<"\n enter name age:";
            cin>>name>>age;
            cout<<"\n enter weight and height:";
            cin>>w>>h;
            cout<<"enter gender:";
            cin>>g;
   }
   void show()   {
      cout<<"\n"<<name<<endl<<"\n"<<age;
      cout<<"\n"<<w<<endl<<"\n"<<h;
      cout<<"\n"<<g;
   }
};
int main(){
            C ob;
            ob.get_data();
            ob.show();
}

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home