定义一个员工类Employee,有数据成员姓名,编号。定义一个销售员继承自员工类Sales,工资为销售额的提成10%,定义一个经理类Manager,固定工资8000,定义一个销售经理类,继承自销售员类和经理类,工资为固定工资5000加销售额的提成5%。每个类均有display()函数输出信息,编写主函数测试。主函数中定义一个销售经理对象,销售额为100000,输出信息。
题目已给的代码:
#include <iostream>
using namespace std;
class Employee
{
public:
Employee(string id,string name):id(id),name(name)
{}
void display()
{
cout<<"ID:"<<id<<endl;
cout<<"Name:"<<name<<endl;
}
protected:
string id,name;
};
int main()
{
string id,name;
float sale;
cout<<"Input id name and sale:"<<endl;
cin>>id>>name>>sale;
if(sale<0)
{
cout<<"Input Error!"<<endl;
return 0;
}
SalesManager sm(id,name,sale);
sm.display();
return 0;
}
我写的中间部分的代码:
-
//定义一个销售员继承自员工类Sales,工资为销售额的提成10%, class Sales : virtual public Employee { public: Sales(string id, string name) { this->id = id; this->name = name; } void display() { cout << "ID:" << id << endl; cout << "Name:" << name << endl; cout << "salary:" << sale*1.1 << endl; } protected: float sale; }; //定义一个经理类Manager固定工资8000 class Manager :virtual public Employee { public: void display() { } protected: float salary=8000; }; //定义一个销售经理类继承自销售员类和经理类工资为固定工资5000加销售额的提成5%。 class SalesManager : public Manager, public Sales { public: //SalesManager() //{ // salary = 5000; //} SalesManager(string id, string name, float sale) { this->id = id; this->name = name; this->salary = salary + sale*0.5; } void display() { cout << "ID:" << id << endl; cout << "Name:" << name << endl; cout << "Salary:" << salary << endl; } };
错误代码:
请问应该怎么改才对呀??