继承与派生的应用3

/*编写一个程序实现小型公司的工资管理。人员:经理、技术人员、销售员、销售经理。
信息:编号、姓名、月工资信息。经理拿固定工资8000;技术人员每小时100元;
销售员按当月销售额的4%提成;销售经理既拿固定工资5000,又拿销售提成,
销售提成为所在部门销售额的0.5%。
*/

#include
using namespace std;

class employee
{
protected:
	int ID;
	char name[10];
	double salary;
	static int ID_NUM;
public:
	employee(){salary=0;ID=ID_NUM++;}
	void pay(){}
	void Setname(char *name){strcpy(this->name,name);}
	int GetID(){return ID;}
	char *Getname(){return name;}
	double GetSalary(){return salary;}	
};

int employee::ID_NUM=1000;
class technician:public employee
{
private:
	int hours;
	double hour_rate;
public:
	technician(){hour_rate=100;}
	void GetHours(int hours){this->hours=hours;}
	void pay(){salary=hours*hour_rate;}
};
class manager:virtual public employee
{
protected:
	double month_pay;
public:
	manager(){month_pay=8000;}
    void pay(){salary=month_pay;}
};

class salesman:virtual public employee
{
protected:
	double CommRate;
	double sales;
public:
	salesman(){CommRate=0.04;}
	void GetSales(double sales){this->sales=sales;}
    void pay(){salary=sales*CommRate;}
};

class salesmanager:public manager,public salesman
{
public:
	salesmanager(){month_pay=5000;CommRate=0.005;}
    void pay(){salary=month_pay+CommRate*sales;}
};

int main()
{
	int wt,sale1,sale2;
    manager P1;
	technician P2;
	salesman P3;
	salesmanager P4;
	
	P1.Setname("TOM");
	P2.Setname("MARY");
	P3.Setname("JACK");
	P4.Setname("BOB");
    P1.pay();
	
	cout<<"请输入技术人员的工作时间:";
	cin >> wt;
	P2.GetHours(wt);
	P2.pay();
	
	cout<<"请输入销售员的销售额:";
    cin >> sale1;
	P3.GetSales(sale1);
    P3.pay();
	
	cout<<"请输入销售经理管辖的部门的销售额:";
	cin >> sale2;
	P4.GetSales(sale2);
	P4.pay();
	
	cout<<"WorkNum  Name   Salary   Positon"<


你可能感兴趣的:(c++)