求助,我无法编译通过
代码如下:#include <iostream.h>
#include <fstream.h>
#include <ctype.h>
#include <string.h>
double ManagerSalary;
double SalesManagerSalary;
double SalesManagerPercent;
double SalesPercent;
double WagePerHour;
int ID;
class Person
{
protected:
int No;
char Name[20];
int Duty;
double Earning;
Person *next;
public:
Person(char ID,char *Name,int Duty)
{
this->Duty=Duty;
strcpy(this->Name,Name);
this->No=ID;
}
virtual void CalcSalary()=0;
virtual void Output()=0;
friend class Company;
};
class Manager:public Person
{
public:
Manager(char ID,char *Name,int Duty):Person(ID,Name,Duty){}
void CalcSalary(){Earning=ManagerSalary;}
void Output()
{
CalcSalary();
cout<<No<<"\t"<<Name<<"\t经理\t"<<Earning<<endl;
}
};
class SalesManager:public Person
{
private:
double Amount;
public:
SalesManager(char ID,char *Name,int Duty):Person(ID,Name,Duty){}
void SetAmount(double s)
{
Amount=s;
}
void CalcSalary()
{
Earning=SalesManagerSalary+Amount*SalesManagerPercent/100;
}
void Output()
{
CalcSalary();
cout<<No<<"\t"<<Name<<"\t销售经理\t"<<Earning<<endl;
}
};
class Technician:public Person
{
private:
double t;
public:
Technician(char ID,char *Name,int Duty,double T):Person(ID,Name,Duty)
{
this->t=T;
}
double GetT()
{
return t;
}
void SetT(double T)
{
this->t=T;
}
void CalcSalary()
{
Earning=WagePerHour*t;
}
void Output()
{
CalcSalary();
cout<<No<<"\t"<<Name<<"\t技术员\t"<<t<<"\t"<<Earning<<endl;
}
};
class Sales:public Person
{
private:
double Amount;
public:
Sales(char ID,char *Name,int Duty,double Amount):Person(ID,Name,Duty)
{
this->Amount=Amount;
}
double GetAmount()
{
return Amount;
}
void SetAmount(double Amount)
{
this->Amount=Amount;
}
void CalcSalary()
{
Earning=SalesPercent/100*Amount;
}
void Output()
{
CalcSalary();
cout<<No<<"\t"<<Name<<"\t销售员\t"<<Amount<<"\t"<<Earning<<endl;
}
};
class Company
{
private:
Person *Worker;
void Clear();
public:
Company()
{
Worker=0;
Load();
}
~Company()
{
Person *p;
p=Worker;
while(p)
{
p=p->next;
delete Worker;
Worker=p;
}
Worker=0;
}
void Add();
void Delete();
void Modify();
void Query();
void Set();
void Save();
void Load();
};
void Company::Clear()
{
Person* p=Worker;
while(p)
{
Worker=p->next;
delete p;
p=Worker;
}
}
void Company::Add()
{
Person *p;
int Duty;
char Name[20];
double Amount,T;
cout<<"\n** 新增员工 **\n";
ID++;
cout<<"输入岗位(1-经理2-销售经理3-销售员4-技术员):"; cin>>Duty;
cout<<"输入姓名:"; cin>>Name;
if(Duty==3)
{
cout<<"本月销售额:"; cin>>Amount;
}
else if(Duty==4)
{
cout<<"本月工作小时数(0-168):";
cin>>T;
}
switch(Duty)
{
case 1:p=new Manager(ID,Name,Duty); break;
case 2:p=new SalesManager(ID,Name,Duty); break;
case 3:p=new Sales(ID,Name,Duty,Amount); break;
case 4:p=new Technician(ID,Name,Duty,T); break;
}
p->next=0;
if(Worker)
{
Person *p2;
p2=Worker;
while(p2->next)
{
p2=p2->next;
}
p2->next=p;
}
else
{
Worker=p;
}
}
void Company::Delete()
{
int No;
cout<<"\n** 删除员工 **\n";
cout<<"ID:"; cin>>No;
Person *p1,*p2; p1=Worker;
while(p1)
{
if(p1->No==No)
break;
else
{
p2=p1;
p1=p1->next;
}
}
if(p1!=NULL)
{
if(p1==Worker)
{
Worker=p1->next;
delete p1;
}
else
{
p2->next=p1->next;
delete p1;
}
cout<<"找到并删除\n";
}
else
cout<<"未找到!\n";
}
void Company::Modify()
{
int No,Duty;
char Name[20];
double Amount,T;
cout<<"\n** 修改员工 **\n";
cout<<"ID:"; cin>>No;
Person *p1,*p2; p1=Worker;
while(p1)
{
if(p1->No==No)
break;
else
{
p2=p1;
p1=p1->next;
}
}
if(p1!=NULL)
{
p1->Output();
cout<<"调整岗位(1-经理2-销售经理3-销售员4-技术员):"; cin>>Duty;
if(p1->Duty!=Duty)
{
cout<<"输入姓名:"; cin>>Name;
if(Duty==3)
{
cout<<"本月销售额:"; cin>>Amount;
}
else if(Duty==4)
{
cout<<"本月工作小时数(0-168):";
cin>>T;
}
Person *p3;
switch(Duty)
{
case 1:p3=new Manager(p1->No,Name,Duty); break;
case 2:p3=new SalesManager(p1->No,Name,Duty); break;
case 3:p3=new Sales(p1->No,Name,Duty,Amount); break;
case 4:p3=new Technician(p1->No,Name,Duty,T); break;
}
p3->next=p1->next;
if(p1==Worker)
Worker=p3;
else
p2->next=p3;
delete p1;
}
else
{
cout<<"输入姓名:"; cin>>p1->Name;
if(Duty==3)
{
cout<<"本月销售额:";cin>>Amount; ((Sales *)p1)->SetAmount(Amount);
}
else if(Duty==4)
{
cout<<"本月工作小时数(0-168):";cin>>T; ((Technician *)p1)->SetT(T);
}
}
cout<<"修改成功!\n";
}
else
cout<<"未找到!\n";
}
void Company::Query()
{
cout<<"\n** 查询人员本月销售信息 **\n";
double sum=0;
Person *p=Worker;
while(p)
{
if(p->Duty==3)sum+=((Sales *)p)->GetAmount();
p=p->next;
}
p=Worker;
double sum2=0;
while(p)
{
if(p->Duty==2)((SalesManager *)p)->SetAmount(sum);
p->Output();
sum2+=p->Earning;
p=p->next;
}
cout<<"本月盈利:"<<sum*0.20-sum2<<endl;
cout<<"(按照20%利润计算)\n";
}
void Company::Set()
{
cout<<"\n** 设置基础数据 **\n";
cout<<"经理固定月薪["<<ManagerSalary<<"元]:";
cin>>ManagerSalary;
cout<<"销售经理固定月薪["<<SalesManagerSalary<<"元]:";
cin>>SalesManagerSalary;
cout<<"销售经理提成["<<SalesManagerPercent<<"%]:";
cin>>SalesManagerPercent;
cout<<"销售人员提成["<<SalesPercent<<"%]:";
cin>>SalesPercent;
cout<<"技术人员小时工资["<<WagePerHour<<"(元/小时)]:";
cin>>WagePerHour;
cout<<"员工标识[>="<<ID<<"]:";
cin>>ID;
}
void Company::Save()
{
ofstream fPerson,fBase;
char c;
cout<<"\n保存人员和基础数据,是否继续?[Y/N]:"; cin>>c;
if(toupper(c)!='Y')return;
fPerson.open("person.txt",ios::out);
Person *p=Worker;
while(p)
{
fPerson<<p->No<<"\t"<<p->Name<<"\t"<<p->Duty<<"\t";
if(p->Duty==3)
fPerson<<((Sales*)p)->GetAmount()<<"\t";
else if(p->Duty==4)
fPerson<<((Technician *)p)->GetT()<<"\t";
fPerson<<endl;
p=p->next;
}
fPerson.close();
fBase.open("base.txt",ios::out);
fBase<<"经理固定月薪\t"<<ManagerSalary<<endl;
fBase<<"销售经理固定月薪\t"<<SalesManagerSalary<<endl;
fBase<<"销售经理提成%\t"<<SalesManagerPercent<<endl;
fBase<<"销售人员提成%\t"<<SalesPercent<<endl;
fBase<<"技术人员小时工资\t"<<WagePerHour<<endl;
fBase<<"ID\t"<<ID<<endl;
fPerson.close();
cout<<"\n保存人员和基础数据已经完成...\n";
}
void Company::Load()
{
ifstream fBase;
char buf[80];
fBase.open("base.txt",ios::in);
fBase>>buf>>ManagerSalary;
fBase>>buf>>SalesManagerSalary;
fBase>>buf>>SalesManagerPercent;
fBase>>buf>>SalesPercent;
fBase>>buf>>WagePerHour;
fBase>>buf>>ID;
fBase.close();
Clear();
ifstream fPerson;
Person *p=Worker;
int No; char Name[20]; int Duty;
double Amount,T;
fPerson.open("person.txt",ios::in);
fPerson>>No>>Name>>Duty;
if(Duty==3)fPerson>>Amount;
else if(Duty==4)fPerson>>T;
while(fPerson.good())
{
switch(Duty)
{
case 1:p=new Manager(No,Name,Duty); break;
case 2:p=new SalesManager(No,Name,Duty); break;
case 3:p=new Sales(No,Name,Duty,Amount); break;
case 4:p=new Technician(No,Name,Duty,T); break;
}
p->next=0;
if(Worker)
{
Person *p2;
p2=Worker;
while(p2->next)
{
p2=p2->next;
}
p2->next=p;
}
else
{
Worker=p;
}
fPerson>>No>>Name>>Duty;
if(Duty==3)fPerson>>Amount;
else if(Duty==4)fPerson>>T;
}
fPerson.close();
cout<<"\n人员和基础数据已经装入...\n";
}
void main()
{
char c;
Company a;
do
{
cout<<"\n*** 公司人员管理系统 ***\n";
cout<<"1-增加人员\n";
cout<<"2-删除人员\n";
cout<<"3-修改人员\n";
cout<<"4-查询本月经营信息\n";
cout<<"5-基础数据设置\n";
cout<<"6-数据存盘\n";
cout<<"7-数据装入\n";
cout<<"8-退出\t请选择(1-8):";
cin>>c;
switch(c)
{
case '1': a.Add(); break;
case '2': a.Delete();break;
case '3': a.Modify();break;
case '4': a.Query(); break;
case '5': a.Set(); break;
case '6': a.Save(); break;
case '7': a.Load(); break;
}
}while(c!='8');
}
希望编译成功的大神 能将exe 发到我的邮箱里,jiao358@
拜谢不已!!!