C++编写的简单工资管理系统,还有一个错误,求教!
还有一个问题:fatal error C1083: Cannot open include file: 'empfunc.cpp': No such file or directory头文件:
#include<iostream>
#include <string>
using namespace std;
class Employee //声明抽象类
{
protected:
char name[10]; //姓名
int no; //编号
float salary; //月工资
static int maxno; //编号基数
public:
Employee(); //构造函数
virtual void Pay()=0; //纯虚函数,为其派生类计算月工资
virtual void Display()=0; //纯虚函数,为其派生类显示信息
static double totalsalary;
};
class Technician:public Employee //派生兼职技术人员类
{
public:
Technician(std::string p,int w);
void Pay();//派生类虚函数,计算兼职技术人员月工资
void Display();
private:
int workhours; //工作时数
};
class Salesman:virtual public Employee //销售员类虚拟继承Employee
{
public:
Salesman(std::string p,float s);
void Pay();//派生类虚函数,计算销售员月工资
void Display();
protected:
//销售提成比例
float sales; //销售额
};
class Manager:virtual public Employee //经理类虚拟继承Employee
{
public:
Manager(std::string p,float m);
void Pay();//派生类虚函数,计算经理月工资
void Display();
protected:
float monthlypay;
float level;
};
class SalesManager:public Manager,public Salesman//多继承销售经理类
{
public:
SalesManager(std::string p,float m,float c,float s)
:Manager(p,m),Salesman(p,s){} //初始化基类数据
void Pay();//派生类虚函数,计算销售经理月工资
void Display();
protected:
float level;
};
类成员函数:
#include <iostream>
#include <string.h>
#include "employee1.h"
using namespace std;
int Employee::maxno=1000;//员工编号基数
double Employee::totalsalary=0;
Employee::Employee() //构造函数
{
salary=0;
no=++maxno;
}
Technician::Technician(string p,int w)
{
strcpy(name,"p");
workhours=w;
}
void Technician::Pay()//派生类虚函数,计算兼职技术人员月工资
{
salary=100*workhours;
totalsalary +=salary;
}
void Technician::Display()
{ cout<<"请输入技术人员名字"<<endl;
cin>>name;
cout<<"名字:"<<name<<endl;
cout<<"工时:"<<workhours<<endl;
cout<<"编号:"<<no<<endl;
cout<<"薪水:"<<salary<<endl;
cout<<"总薪水:"<<totalsalary<<endl;
}
Salesman::Salesman(string p,float s)
{
strcpy(name,"p");
sales=s;
}
void Salesman::Pay()//派生类虚函数,计算销售员月工资
{
salary=sales*0.04;
totalsalary +=salary;
}
void Salesman::Display()
{
cout<<"请输销售人员名字"<<endl;
cin>>name;
cout<<"名字:"<<name<<endl;
cout<<"销售量:"<<endl;
cin>>sales;
cout<<"编号:"<<no<<endl;
cout<<"薪水:"<<salary<<endl;
cout<<"总薪水:"<<totalsalary<<endl;
}
Manager::Manager(string p,float m)
{
strcpy(name,"p");
monthlypay=m;
}
void Manager::Pay()//派生类虚函数,计算经理月工资
{
salary=5000+(level-1)*2000;
salary=monthlypay;
totalsalary +=salary;
}
void Manager::Display()
{
cout<<"请输入经理名字、级别"<<endl;
cin>>name>>level;
cout<<"名字: "<<name<<endl;
cout<<"等级: "<<level<<endl;
cout<<"编号: "<<no<<endl;
cout<<"薪水: "<<salary<<endl;
cout<<"总薪水: "<<totalsalary<<endl;
}
void SalesManager::Pay()//派生类虚函数,计算销售经理月工资
{
salary=3000+(level-1)*1000+(sales*0.05);
totalsalary += salary;
}
void SalesManager::Display()
{
cout<<"请输入销售经理的名字、级别"<<endl;
cin>>name>>level;
cout<<"销售量"<<endl;
cin>>sales;
cout<<"名字: "<<name<<endl;
cout<<"级别: "<<level<<endl;
cout<<"编号:"<<no<<endl;
cout<<"薪水: "<<salary<<endl;
cout<<"总薪水: "<<totalsalary<<endl;
}
主函数:
#include <empfunc.cpp>
void main()
{
Employee *p;
Technician a;
p=&a;
p->Display();
Salesman b;
p=&b;
p->Display();
Manager c;
p=&c;
p->Display();
SalesManager d;
p=&d;
p->Display();
}