以下是针对该问题的代码实现:
```cpp
#include<iostream>
#include<vector>
#include<ctime>
using namespace std;
class Date { //日期类
private:
int year, month, day;
public:
Date(int y, int m, int d) : year(y), month(m), day(d) {}
int getMonth() const { return month; }
};
class Employee { //雇员类(抽象类)
private:
string name;
int id;
Date birthDate;
public:
Employee(string n, int i, Date b) : name(n), id(i), birthDate(b) {}
virtual double earnings() const = 0; //纯虚函数,计算工资
virtual void print() const = 0; //纯虚函数,输出信息
int getID() const { return id; }
string getName() const { return name; }
Date getBirthDate() const { return birthDate; }
};
class SalariedEmployee : public Employee { //周薪雇员类
private:
double weeklySalary;
public:
SalariedEmployee(string n, int i, Date b, double w) : Employee(n, i, b), weeklySalary(w) {}
double earnings() const override {
return weeklySalary;
}
void print() const override {
cout << "Salaried Employee: " << getName() << " (ID: " << getID() << ")" << endl;
cout << "Birth Date: " << getBirthDate().getMonth() << "/xx/xxxx" << endl;
cout << "Weekly Salary: $" << earnings() << endl;
}
};
class HourlyEmployee : public Employee { //时薪雇员类
private:
double wage;
double hours;
public:
HourlyEmployee(string n, int i, Date b, double w, double h) : Employee(n, i, b), wage(w), hours(h) {}
double earnings() const override {
if (hours <= 40)
return wage * hours;
else
return 40 * wage + (hours - 40) * wage * 1.5;
}
void print() const override {
cout << "Hourly Employee: " << getName() << " (ID: " << getID() << ")" << endl;
cout << "Birth Date: " << getBirthDate().getMonth() << "/xx/xxxx" << endl;
cout << "Hours Worked: " << hours << endl;
cout << "Hourly Wage: $" << wage << endl;
cout << "Total Earnings: $" << earnings() << endl;
}
};
class CommissionEmployee : public Employee { //佣金雇员类
private:
double commission;
int sales;
public:
CommissionEmployee(string n, int i, Date b, double c, int s) : Employee(n, i, b), commission(c), sales(s) {}
double earnings() const override {
return commission * sales;
}
void print() const override {
cout << "Commission Employee: " << getName() << " (ID: " << getID() << ")" << endl;
cout << "Birth Date: " << getBirthDate().getMonth() << "/xx/xxxx" << endl;
cout << "Sales: " << sales << endl;
cout << "Commission: $" << commission << endl;
cout << "Total Earnings: $" << earnings() << endl;
}
};
class BasePlusCommissionEmployee : public CommissionEmployee { //带底薪佣金雇员类
private:
double baseSalary;
public:
BasePlusCommissionEmployee(string n, int i, Date b, double c, int s, double bs) : CommissionEmployee(n, i, b, c, s), baseSalary(bs) {}
double earnings() const override {
return baseSalary + CommissionEmployee::earnings();
}
void print() const override {
cout << "Base Plus Commission Employee: " << getName() << " (ID: " << getID() << ")" << endl;
cout << "Birth Date: " << getBirthDate().getMonth() << "/xx/xxxx" << endl;
cout << "Sales: " << CommissionEmployee::sales << endl;
cout << "Commission: $" << CommissionEmployee::commission << endl;
cout << "Base Salary: $" << baseSalary << endl;
cout << "Total Earnings: $" << earnings() << endl;
}
};
int main() {
vector<Employee*> employees; //创建雇员指针容器
employees.push_back(new SalariedEmployee("John Doe", 1, Date(2000, 1, 1), 1000));
employees.push_back(new HourlyEmployee("Jane Smith", 2, Date(1995, 5, 15), 20, 45));
employees.push_back(new CommissionEmployee("Bob Johnson", 3, Date(1980, 10, 27), 0.05, 1000));
employees.push_back(new BasePlusCommissionEmployee("Mike Brown", 4, Date(1978, 2, 3), 0.03, 2000, 2000));
time_t now = time(0);
tm* local_time = localtime(&now);
int month = local_time->tm_mon + 1; //获取当前月份
for (Employee* e : employees) {
e->print();
if (e->getBirthDate().getMonth() == month)
cout << "Birthday Bonus: $100" << endl;
if (dynamic_cast<BasePlusCommissionEmployee*>(e))
dynamic_cast<BasePlusCommissionEmployee*>(e)->earnings() *= 1.1; //提高带底薪佣金雇员的基本工资
cout << endl;
}
for (Employee* e : employees)
delete e; //释放内存
return 0;
}
```
上述代码中,我们定义了一个抽象类 `Employee`,它包含了雇员的基本信息(姓名、工号、生日)以及两个纯虚函数 `earnings()` 和 `print()`。不同类型的雇员分别继承了 `Employee` 类,并实现了自己的计算工资和输出信息的函数。主函数中创建了一个雇员指针容器 `employees`,并向其中添加不同类型的雇员对象。在输出每个雇员的信息时,如果该雇员的生日在本月,就奖励100元。同时,对于带底薪佣金雇员,将其基本工资提高10%。最后,释放内存并结束程序。