Multiple Inheritance: 

Very often situations may arise in which a class has to derive features from more than one class. Multiple inheritance facilitates 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 classess student, employee, manager
step2:with in 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 Programmer class extends student and employee classess and using data and their functions to the Programmer class and Enter & display disegnation , salary of the Programmer using putdata(),getdata() functions
step5:within the main function create instance of Programmer class ‘m’ and call getdata() and putdata() functions.

Program Code:
#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 Programmer : 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
{
Programmer m;
cout<<”\n Enter data for Programmer:”<<endl;
m.gatdata();
cout<<”\n The data for Programmer is :”<<endl;
m.putdata();
}




Output:
Enter data for Programmer :
Enter name : Raja
Enter name of school: GSSCB
Enter name of college :GCH
Enter name of company :CU
Enter age :34
Enter designation : Programmer
Enter salary : 25000
The data for Programmer is
Student Name :Raja
School Name :GSSCB
College Name :GCH
Company Name :CU
Age :34
Designation :Programmer
Salary:25000



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: