Introduction to Multiple Inheritance in Object-Oriented Programming: 

Very often situations may arise in which a class has to derive features from more than one class. Multiple inheritances facilitate a class to inherit features from more than one class. The derived class can access two or more classes and can add properties of its own.




Write a program to explain multiple inheritances.

Algorithm:
step1: Take three classes student, employee, manager
step2: within a student, class Enter name and school, college data with the help of getdata() function and display this data using putdata() function.
step3: within the employee, class Enter and display company, age data with the help of getdata(),putdata() functions.
step4: within the manager class extends student and employee classes and using data and their functions to the manager class and Enter & display designation, salary of the manager using putdata(),getdata() functions
step5: within the main function create instance of manager class 'm' and call getdata() and putdata() functions.


Program implementation:
#include<iostream.h>
#include<conio.h>
const int MAX=50;
class student
{
private:
char name[MAX];
char school[MAX];
char college[MAX];
public:
void getdata()
{
cout<<”\n \t Enter name :”;
cin>>name;
cout<<”\t Enter school name:”;
cin>school;
cout<<”\n \t Enter College name:”;
cin>>college;
}
void putdata()
{
cout<<”\n \t Name :”<<name;
cout<<”\n \t School Name :”<<school;
cout<<”\n \t College Name :”<<college;
}
};
class employee
{
private
char company[MAX];
int age;
public :
void getdata()
{
cout<<”\n \t Enter the company name :”;
cin>>company;
cout<<”\n \t Enter age:”;
cin>>age;
}
void putdata()
{
cout<<”\n \t Company Name :”<<company;
cout<<”\t Age:”<<age;
}
};
class manager : private employee,private student



{
private:
char design[MAX];
float salary;
public :
void getdata()
{
student ::getdata();
employee ::getdata();
cout<<”\n \t Enter your Designation :”;
cin>>design;
cout<<”\n \t Enter salary:”;
cin>>salary;
}
void putdata()
{
Student ::putdata();
Employee::putdata();

cout<<”\n \t Designation :”<<design;
cout<<”\n \t Salary :“<<salary;
}
};
void main(0
{
manager m;
clrscr();
cout<<”\n Enter data for manager:”<<endl;
m.gatdata();
cout<<”\n The data for manager is :”<<endl;
m.putdata();
}

The output of the above program is:
Enter data for manager :
Enter name : Ram
Enter name of school: GMSS
Enter name of college :GCET
Enter name of company :CMC
Enter age :24
Enter designation :Analyst
Enter salary :10000
The data for manager is
Student Name :Ram
School Name :GMSS
College Name :GCET

Company Name :CMC
Age :24
Designation :Analyst
Salary:10000





Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: