Following is the a simple diagram for a class hierarchy of an employee, you are required to map the
diagram to C++ Code , Each class should have a default and an overloaded constructor and a function
named as SalaryCalculator() which calculates the pay according to the employee the employer have.
Parent class :Employee
Employee child classes:
1)SalariedEmployee
2)CommissionEmployee
3)HourlyEmployee
Employee and CommissionEmployee child class:
1)Base plus Commission Employee
Implement:
Inheritance
Dynamic Polymorphism
A main( ) which can test all the classes
#include <iostream>
using namespace std;
class Employee {
private:
string name;
public:
Employee()
{
this->name = "unknown";
}
Employee(string name)
{
this->name = name;
}
virtual double SalaryCalculator();
};
class SalariedEmployee : Employee {
public:
SalariedEmployee() : Employee()
{}
SalariedEmployee(string name) : Employee(name)
{}
double SalaryCalculator()
{
// method impl...
return 0.0;
}
};
class CommistionEmployee : Employee {
public:
CommistionEmployee() : Employee()
{}
CommistionEmployee(string name) : Employee(name)
{}
double SalaryCalculator()
{
// method impl...
return 0.0;
}
};
class HourlyEmployee : Employee {
public:
HourlyEmployee() : Employee()
{}
HourlyEmployee(string name) : Employee(name)
{}
double SalaryCalculator()
{
// method impl...
return 0.0;
}
};
int main()
{
return 0;
}
Comments
Leave a comment