// 主函数,保存为:main.cpp
#include <cstdlib>
#include <iostream>
#include "employee.h"
using namespace std;
int main(int argc, char *argv[])
{
employee e2= employee("lz","bh007",4,6666); //底薪6666,旷工4天
employee e1 = e2; // 复制构造函数
cout << e1.pay() << endl;
system("PAUSE");
return 0;
}
// 下面这些保存为:employee.h
#ifndef EMPLOYEE_H_
#define EMPLOYEE_H_
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
class employee{
private:
string name;
string id;
int level;
float salary;
public:
employee(string n,string i,int l,float s){
name = n;
id = i;
level = l;
salary = s;
};
employee(const employee& e)
{
name = e.name;
id = e.id;
level = e.level;
salary = e.salary;
};
virtual ~employee(){};
virtual float pay();
};
class technician:virtual public employee{
private:
float extra;
int hours;
float schedule;
public:
technician(string n,string i,int l,float s,float e=0,int h=0,float s2=0)
:employee(n,i,l,s),extra(e),hours(h),schedule(s2) {};
float pay()
{
return employee::pay() + extra*hours*schedule;
};
};
class salesman:virtual public employee{
private:
float sales;
float rate;
public:
salesman(string n,string i,int l,float s,float s2 = 0,float r=0)
:employee(n,i,l,s),sales(s2),rate(r) {};
float pay()
{
return employee::pay() + sales*rate;
};
};
class manager:virtual public employee{
private:
float extra;
float rate;
public:
manager(string n,string i,int l,float s,float e,float e2 = 0,float r=0)
:employee(n,i,l,s),extra(e2),rate(r) {};
float pay()
{
return employee::pay() + extra*rate;
};
};
class developermanager:public manager, public technician{
public:
developermanager(string n,string i,int l,float s,float e,int h,float s2,float e2,float r)
:employee(n,i,l,s),technician(n,i,l,s,e,h,s2),manager(n,i,l,s,e2,r) {};
float pay()
{
return ( technician::pay() + manager::pay())/2;
};
};
class salesmanager:public manager, public salesman{
public:
salesmanager(string n,string i,int l,float s,float s2 ,float r,float e2,float r2)
:employee(n,i,l,s),salesman(n,i,l,s,s2,r),manager(n,i,l,s,e2,r2) {};
float pay()
{
return (manager::pay()-employee::pay())/2 + salesman::pay();
};
};
float employee::pay()
{
int absent=0;
cout << "Input total absent days This Month:"<< endl;
cin >> absent;
return salary - absent*100;
}
#endif
温馨提示:内容为网友见解,仅供参考