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

Multiple inheritance

The document presents a C++ program that demonstrates multiple inheritance using two base classes, 'basicInfo' and 'deptInfo', and a derived class 'employee'. The 'employee' class combines the functionalities of both base classes to gather and display employee information, including basic details and department specifics. The program utilizes standard input/output for data entry and retrieval.

Uploaded by

gmranuj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Multiple inheritance

The document presents a C++ program that demonstrates multiple inheritance using two base classes, 'basicInfo' and 'deptInfo', and a derived class 'employee'. The 'employee' class combines the functionalities of both base classes to gather and display employee information, including basic details and department specifics. The program utilizes standard input/output for data entry and retrieval.

Uploaded by

gmranuj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

//Multiple inheritance

#include <iostream>
#include <stdio.h>
using namespace std;
//Base Class - basicInfo
class basicInfo
{
protected:
char name[30];
int empId;
char gender;
public:
void getBasicInfo(void)
{
cout << "Enter Name: ";
cin.getline(name,30);
cout << "Enter Emp. Id: ";
cin >> empId;
cout << "Enter Gender: ";
cin >> gender;
}
};

//Base Class - deptInfo


class deptInfo
{
protected:
char deptName[30];
char assignedWork[30];
int time2complete;
public:
void getDeptInfo(void)
{
cout << "Enter Department Name: ";
cin.ignore(1);
cin.getline(deptName,30);
cout << "Enter assigned work: ";
fflush(stdin);
cin.getline(assignedWork,30);
cout << "Enter time in hours to complete work: ";
cin >> time2complete;
}
};

/*final class (Derived Class)- employee*/


class employee:private basicInfo, private deptInfo
{
public:
void getEmployeeInfo(void){
cout << "Enter employee's basic info: " << endl;
//call getBasicInfo() of class basicInfo
getBasicInfo(); //calling of public member function
cout << "Enter employee's department info: " << endl;
//call getDeptInfo() of class deptInfo
getDeptInfo(); //calling of public member function
}
void printEmployeeInfo(void)
{
cout << "Employee's Information is: " << endl;
cout << "Basic Information...:" << endl;
cout << "Name: " << name << endl; //accessing protected data
cout << "Employee ID: " << empId << endl; //accessing protected data
cout << "Gender: " << gender << endl << endl;//accessing protected data

cout << "Department Information...:" << endl;


cout << "Department Name: " << deptName << endl; //accessing protected data
cout << "Assigned Work: " << assignedWork << endl; //accessing protected data

cout << "Time to complete work: " << time2complete<< endl; //accessing protected data

}
};

int main()
{
//create object of class employee
employee emp;

emp.getEmployeeInfo();
emp.printEmployeeInfo();

return 0;
}

You might also like