0% found this document useful (0 votes)
37 views

Multiple Inheritance

This C++ code defines three classes - Employee, Student, and Manager. Employee stores an employee ID and name. Student stores an educational degree. Manager inherits privately from both Employee and Student and additionally stores a due amount and job title. The Manager class overrides the getdata() and showdata() methods to collect and display data from the Employee, Student, and additional Manager fields. The main function creates a Manager object, collects its data, and displays it.

Uploaded by

Michelle JR
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Multiple Inheritance

This C++ code defines three classes - Employee, Student, and Manager. Employee stores an employee ID and name. Student stores an educational degree. Manager inherits privately from both Employee and Student and additionally stores a due amount and job title. The Manager class overrides the getdata() and showdata() methods to collect and display data from the Employee, Student, and additional Manager fields. The main function creates a Manager object, collects its data, and displays it.

Uploaded by

Michelle JR
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

using namespace std;


/// Multiple Inheritance

class Employee
{
private:
int id;
string name;
public:
Employee(): id(0), name("n/a"){}
Employee(int i, string na): id(i), name(na){}
void getdata()
{
cout<<"Enter Id ";
cin>>id;
cout<<"Enter Name ";
cin>>name;
}
void showdata()
{
cout<<"Id "<<id<<endl;
cout<<"Name "<<name<<endl;
}
};

class Student
{
private:
string degree;
public:
Student(): degree("n/a"){}
Student(string de): degree(de){}
void getedu()
{
cout<<"Enter degree Title ";
cin>>degree;
}
void showedu()
{
cout<<"Degree "<<degree<<endl;
}
};
class Manager : private Employee, private Student
{
private:
float dues;
string jobtitle;
public:
Manager(): Employee(), Student(), dues(0.0f), jobtitle("n/a"){}
Manager(int i, string na, string de, float du, string title): Employee(i,
na), Student(de), dues(du), jobtitle(title){}
void getdata()
{
Employee::getdata();
Student::getedu();
cout<<"Enter Dues ";
cin>>dues;
cout<<"Enter Job Title ";
cin>>jobtitle;
}
void showdata()
{
Employee::showdata();
Student::showedu();
cout<<"Dues "<<dues<<endl;
cout<<"Job Title "<<jobtitle<<endl;
}
};

int main()
{
Manager m1;
m1.getdata();
m1.showdata();
return 0;
}

You might also like