#include <iostream>
#include <cstring>
using namespace std;
class Employee
{
public:
virtual void pay(){ } // 第一题 这一行不要
string name;
float salary;
};
class Technician : public Employee
{
public:
Technician(float day_){ name = "技术员"; day = day_; }
void pay(){ salary = 100 * 8 * day; }
float day;
};
class Manager : virtual public Employee
{
public:
Manager(){ name = "经理"; }
void pay(){ salary = 7000; }
};
class Salesman : virtual public Employee
{
public:
Salesman(float sale){ name = "销售员"; saleMoney = sale; }
void pay(){ salary = saleMoney *0.05f; }
float saleMoney;
};
class SalesManager : public Manager, public Salesman
{
public:
SalesManager(float sale) :Salesman(sale){ name = "销售经理"; }
void pay(){ salary = saleMoney * 0.005f + 400; }
};
int main1()
{
Employee* ep = 0;
Technician m1(30); m1.pay();
Manager m2; m2.pay();
Salesman m3(30000); m3.pay();
SalesManager m4(80000); m4.pay();
cout << m1.name << "月薪:" << m1.salary << endl;
cout << m2.name << "月薪:" << m2.salary << endl;
cout << m3.name << "月薪:" << m3.salary << endl;
cout << m4.name << "月薪:" << m4.salary << endl;
return 0;
}
int main2()
{
Employee* ep = 0;
Technician m1(30); ep = &m1; ep->pay();
Manager m2; ep = &m2; ep->pay();
Salesman m3(30000); ep = &m3; ep->pay();
SalesManager m4(80000); ep = &m4; ep->pay();
cout << m1.name << "月薪:" << m1.salary << endl;
cout << m2.name << "月薪:" << m2.salary << endl;
cout << m3.name << "月薪:" << m3.salary << endl;
cout << m4.name << "月薪:" << m4.salary << endl;
return 0;
}