Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Object Oriented ProgrammingRSS Feeds

Program to illustrate multiple inheritance

Posted By: Easy Tutor     Category: C++ Programming     Views: 4627

A C++ Program to illustrate multiple inheritance.

Code for Program to illustrate multiple inheritance in C++ Programming

 #include<iostream.h>
 #include<stdio.h>
 #include<conio.h>

 /*************************************************************************///------------------------------  item  ---------------------------------///*************************************************************************/class item
    {
       private:
        char part_name[20];
        float part_price;

       public:
        void get_data();
        void show_data();
    };

 /*************************************************************************///------------------------------  sales  --------------------------------///*************************************************************************/class sales
    {
       private:
        float sales_fig[3];

       public:
        void get_data();
        void show_data();
    };

 /*************************************************************************///---------------------------  hardware_item  ---------------------------///*************************************************************************/class hardware_item:public item,public sales
    {
       private:
        char category[10];
        char manufacturers[10];

       public:
        void get_data();
        void show_data();
    };

 /*************************************************************************///--------------------------  software_item  ----------------------------///*************************************************************************/class software_item:public item,public sales
    {
       private:
        char category[10];
        char operating_system[10];

       public:
        void get_data();
        void show_data();
    };


 /*************************************************************************///----------------------------  get_data( )  ----------------------------///*************************************************************************/void item::get_data()
    {
       cout<<"\t Enter part name = ";
       gets(part_name);

       cout<<"\t Enter part price = ";
       cin>>part_price;
    }

 /*************************************************************************///----------------------------  show_data( )  ---------------------------///*************************************************************************/void item::show_data()
    {
       cout<<"\t Part name = "<<part_name<<endl;
       cout<<"\t Part price = "<<part_price<<endl;
    }


 /*************************************************************************///----------------------------  get_data( )  ----------------------------///*************************************************************************/void sales::get_data()
    {
       cout<<"\n Enter the Sales figures for three months : "<<endl;

       for(int count=0;count<3;count++)
      {
         cout<<"\t Sales for month  "<<count+1<<" = ";
         cin>>sales_fig[count];
      }
    }

 /*************************************************************************///----------------------------  show_data( )  ---------------------------///*************************************************************************/void sales::show_data()
    {
       cout<<"\n Sales figures for three months : "<<endl;

       for(int count=0;count<3;count++)
       cout<<"\t Sales for month  "<<count+1<<" = "<<sales_fig[count]<<endl;
    }


 /*************************************************************************///----------------------------  get_data( )  ----------------------------///*************************************************************************/void hardware_item::get_data()
    {
       item::get_data();

       cout<<"\t Enter the category = ";
       gets(category);

       cout<<"\t Enter the manufacturers = ";
       gets(manufacturers);

       sales::get_data();
    }

 /*************************************************************************///----------------------------  show_data( )  ---------------------------///*************************************************************************/void hardware_item::show_data()
    {
       item::show_data();

       cout<<"\t Category = "<<category<<endl;
       cout<<"\t Manufacturers = "<<manufacturers<<endl;

       sales::show_data();
    }


 /*************************************************************************///----------------------------  get_data( )  ----------------------------///*************************************************************************/void software_item::get_data()
    {
       item::get_data();

       cout<<"\t Enter the category = ";
       gets(category);

       cout<<"\t Enter the operating system = ";
       gets(operating_system);

       sales::get_data();
    }

 /*************************************************************************///----------------------------  show_data( )  ---------------------------///*************************************************************************/void software_item::show_data()
    {
       item::show_data();

       cout<<"\t Category = "<<category<<endl;
       cout<<"\t Operating system = "<<operating_system<<endl;

       sales::show_data();
    }

 main()
    {
       clrscr();

       hardware_item h;
       software_item s;

       cout<<"\n ********* Hardware Item ********"<<endl;
       h.get_data();

       cout<<"\n ********* Software Item ********"<<endl;
       s.get_data();

       getch();
       clrscr();

       cout<<"\n ********* Hardware Item ********"<<endl;
       h.show_data();

       cout<<"\n ********* Software Item ********"<<endl;
       s.show_data();

       getch();
       return 0;
    }
  
Share: 


Didn't find what you were looking for? Find more on Program to illustrate multiple inheritance Or get search suggestion and latest updates.

Easy Tutor
Easy Tutor author of Program to illustrate multiple inheritance is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!