#include <iostream>
#include <string>
using namespace std;
//基类
class Emloyee{
public:
Emloyee(int no,string na)
{
number=no;
name=na;
}
protected:
int number; //编号
string name; //姓名
double Salary; //月工资
};
class Technican:public Emloyee{ //技术员类
public:
Technican(int no,string na):Emloyee(no,na)
{
hourlyrate=150;
}
void Print()
{
cout<<"技术员:"<<name<<" "<<"月小时:";
cin>>workhours;
Salary=hourlyrate*workhours;
cout<<"技术员:"<<name<<" "<<"编号:"<<number<<" "<<"月工资:"<<Salary<<endl;
}
private:
int hourlyrate;
double workhours;
};
class SalesPerson:virtual public Emloyee{ //销售员类(采用虚继承)
public:
SalesPerson(int no,string na):Emloyee(no,na)
{
ratio=0.007;
}
void Print()
{
cout<<"销售员:" <<name<<" "<<"月销售额:";
cin>>SalesVolume;
Salary=ratio*SalesVolume;
cout<<"销售员:"<<name<<" "<<"编号:"<<number<<" "<<"月工资:"<<Salary;
}
protected:
double ratio;
double SalesVolume;
};
class Manager:virtual public Emloyee{
public:
Manager(int no,string na):Emloyee(no,na){
monthpay=8500;
}
void Print()
{
Salary=monthpay;
cout<<"经理 :"<<name<<" "<<"编号:"<<number<<"月工资:"<<Salary<<endl;
}
protected:
double monthpay;
};
class SalesManager:public Manager,public SalesPerson{
public:
SalesManager(int no,string na):Emloyee(no,na)
{
ratio=0.0005;
monthpay=4000;
}
void Print()
{
cout<<"销售经理:"<<name<<" "<<"编号:"<<number<<" "<<"部门销售额:";
cin>>SalesVolume;
Salary=(monthpay+SalesVolume*ratio);
cout<<"销售经理:"<<name<<" "<<"编号:"<<number<<" "<<"月工资:"<<Salary<<endl;
}
};
int main()
{
Manager M(10009,"郭铁柱");
Technican T(10010,"王二狗");
SalesPerson S(10011,"田二妞");
SalesManager SM(10012,"高圆圆");
M.Print();
T.Print();
S.Print();
SM.Print();
return 0;
}
类SalesManager的构造函数错了
SalesManager(int no, string na) :Emloyee(no, na), Manager(no, na), SalesPerson(no, na)
{
ratio = 0.0005;
monthpay = 4000;
}