Define a class Employee with data members as empno, name and designation. Derive a class
Qualification from Employee that has data members UG, PG and experience. Create another class
Salary which is derived from both these classes to display the details of the employee and compute
their increments based on their experience and qualifications.
#include <iostream>
#include <string>
using namespace std;
class Employee{
protected:
int empno;
string name, designation;
public:
Employee(){
getDetails();
}
void getDetails(){
cout<<"Enter employee number: ";
cin>>empno;
cout<<"Enter employee name: ";
cin>>name;
cout<<"Enter employee designation: ";
cin>>designation;
}
};
class Qualification:public Employee{
protected:
bool UG, PG;
int experience;
public:
Qualification():Employee(){
Qualification::getDetails();
}
void getDetails(){
cout<<"Enter UG: (1 if true, 0 if false)";
cin>>UG;
cout<<"Enter PG: (1 if true, 0 if false)";
cin>>PG;
cout<<"Enter experience: ";
cin>>experience;
}
};
class Salary:public Qualification{
float salary;
public:
Salary(): Qualification(){
calcSal();
}
void calcSal(){
salary = 0;
if(UG){
salary = 500;
if(PG) salary += 300;
}
if(experience > 5) salary += 200;
}
void display(){
cout<<"Empno: "<<empno<<endl;
cout<<"Name: "<<name<<endl;
cout<<"Designation: "<<designation<<endl;
cout<<"UG: "<<UG<<endl;
cout<<"PG: "<<PG<<endl;
cout<<"Experience: "<<experience<<endl;
cout<<"Salary increment: "<<salary<<endl;
}
};
int main(){
Salary emp;
emp.display();
return 0;
}
Comments
Leave a comment