#include<iostream.h>
#include<stdlib.h>
#include<fstream.h>
#include<iomanip.h>
#include<string.h>
class employee
{
public:
employee()
{
salary=0;
}
void pay(){}
void print(){}
void input()
{
cout<<"的编号:";
cin>>no;
cout<<" 其姓名:";
cin>>name;
cout<<" 性别(m/w):";
cin>>sex;
cout<<" 年龄:";
cin>>age;
}
protected:
int no;
char name[8];
float salary;
char sex;
int age;
};
class technician:virtual public employee
{
private:
float hourlyrate;
int workhours;
public:
technician(){hourlyrate=100;}
void pay()
{
cout<<name<<"本月工作时数:";
cin>>workhours;
salary=hourlyrate*workhours;
}
void input(){cout<<"技术工"<<endl;employee::input();}
void save()
{
fstream outfile;
outfile.open("f:flsdfj.txt",ios::app);
if(!outfile)
{
cout<<"f can't open.\n";
abort();
}
outfile<<"技术工"<<endl;
outfile<<"号码"<<no<<"名字"<<name<<"性别"<<sex<<"年龄"<<age<<"工资"<<salary<<endl;
}
void print()
{
cout<<setw(10)<<no<<setw(10)<<name<<setw(10)<<sex\
<<setw(10)<<age<<setw(10)<<salary<<endl;
}
};
class manager:virtual public employee
{
protected:
float monthlypay,sale;
public:
manager(){monthlypay=8000;}
void input(){cout<<"经理";employee::input();}
void save()
{
fstream outfile;
outfile.open("f:flsdfj.txt",ios::app);
if(!outfile)
{
cout<<"f can't open.\n";
abort();
}
outfile<<"经理"<<endl;
outfile<<"号码"<<no<<"名字"<<name<<"性别"<<sex<<"年龄"<<age<<"工资"<<salary<<endl;
}
void pay(){salary=monthlypay;}
void print()
{
cout<<setw(10)<<no<<setw(10)<<name<<setw(10)<<sex\
<<setw(10)<<age<<setw(10)<<salary<<endl;
}
};
class salesman:virtual public employee
{
protected:
float commrate;
float sales;
public:
salesman(){commrate=0.04;}
void input(){cout<<"销售员";employee::input();}
void save()
{
fstream outfile;
outfile.open("f:flsdfj.txt",ios::app);
if(!outfile)
{
cout<<"f can't open.\n";
abort();
}
outfile<<"技术工"<<endl;
outfile<<"号码"<<no<<"名字"<<name<<"性别"<<sex<<"年龄"<<age<<"工资"<<salary<<endl;
}
void pay()
{
cout<<name<<"本月销售额:";
cin>>sales;
salary=sales*commrate;
}
void print()
{
cout<<setw(10)<<no<<setw(10)<<name<<setw(10)\
<<sex<<setw(10)<<age<<setw(10)<<salary<<endl;
}
};
class salesmanager:virtual public manager,virtual public salesman
{
private:
float total;int no1,no2,no3,no4;char name1[8],name2[8],name3[8],name4[8];
float sale1,sale2,sale3,sale4;
public:
void salemanager()
{
monthlypay=5000;
commrate=0.005;
}
void input(){cout<<"销售经理";employee::input();}
void save()
{
fstream outfile;
outfile.open("f:flsdfj.txt",ios::app);
if(!outfile)
{
cout<<"f can't open.\n";
abort();
}
outfile<<"销售经理"<<endl;
outfile<<"号码"<<no<<"名字"<<name<<"性别"<<sex<<"年龄"<<age<<"工资"<<salary<<endl;
}
void savesale()
{
fstream outfile;
outfile.open("f:flsdfj.txt",ios::app);
if(!outfile)
{
cout<<"f can't open.\n";
abort();
}
outfile<<"销售经理所辖售员业绩及自己的工资"<<endl;
outfile<<"编号"<<no1<<"名字"<<name1<<"工资"<<sale1<<endl;
outfile<<"编号"<<no2<<"名字"<<name2<<"工资"<<sale2<<endl;
outfile<<"编号"<<no3<<"名字"<<name3<<"工资"<<sale3<<endl;
outfile<<"编号"<<no4<<"名字"<<name4<<"工资"<<sale4<<endl;
}
void pay()
{
cout<<name<<"所管部门月销售量:";
salary=monthlypay+commrate*total;
}
float totalsale(){total=sale1+sale2+sale3+sale4;return total;}
void printtotal()
{
cout<<" 销售额合计 "<<setw(10)<<total<<endl;
}
void sort(salesmanager p)
{
int tmp,i,j;
for(j=0;j<2;j++)
for(i=0;i<2;i++)
if(total<p.salary)
{
tmp=salary;
total=p.salary;
p.salary=tmp;
tmp=no;
no=p.no;
p.no=tmp;
}
}
void saler()
{
cout<<"职工编号:";
cin>>no1;
cout<<" 职工姓名:";
cin>>name1;
cout<<" 销售额:";
cin>>sale1;
cout<<"职工编号:";
cin>>no2;
cout<<" 职工姓名:";
cin>>name2;
cout<<" 销售额:";
cin>>sale2;
cout<<"职工编号:";
cin>>no3;
cout<<" 职工姓名:";
cin>>name3;
cout<<" 销售额:";
cin>>sale3;
cout<<"职工编号:";
cin>>no4;
cout<<" 职工姓名:";
cin>>name4;
cout<<" 销售额:";
cin>>sale4;
}
void saleprint()
{
cout<<setw(10)<<no1<<setw(10)<<name1<<setw(10)<<sale1<<endl;
cout<<setw(10)<<no2<<setw(10)<<name2<<setw(10)<<sale2<<endl;
cout<<setw(10)<<no3<<setw(10)<<name3<<setw(10)<<sale3<<endl;
cout<<setw(10)<<no4<<setw(10)<<name4<<setw(10)<<sale4<<endl;
}
void print()
{
cout<<setw(10)<<no<<setw(10)<<name<<setw(10)<<sex<<\
<<setw(10)<<age<<setw(10)<<salary<<endl;
}
};
void main()
{
manager m[4];
technician t[4];
salesman s[4];
salesmanager sm[4];
t[1].save();
int flag=1,operate;
do{
cout<<" 小型公司工资管理系统\n";
cout<<" 请选择您所需的操作 \n";
cout<<" 数据输入:1,并按回车键 \n";
cout<<" 数据统计:2,并按回车键 \n";
cout<<" 数据打印:3,并按回车键 \n";
cout<<" 数据备份:4,并按回车键 \n";
cout<<" 退出系统:5,并按回车键 \n";
cout<<"请选择数字代码进行操作: ";
cin>>operate;
switch(operate)
{
case 1:
cout<<"Waiting......."<<endl;
{
for(int i=0;i<4;i++)
{m[i].input();}
for(int j=0;j<4;j++)
{t[j].input();}
for(int k=0;k<4;k++)
{s[k].input();}
for(int l=0;l<4;l++)
{sm[l].input();}
};
{
for(int i=0;i<4;i++)
{m[i].pay();}
for(int j=0;j<4;j++)
{t[j].pay();}
for(int k=0;k<4;k++)
{s[k].pay();}
for(int l=0;l<4;l++)
{sm[l].pay();sm[l].saler();}
};break;
case 2:
cout<<"Waiting......"<<endl;
{
{
for(int l=0;l<4;l++)
sm[l].totalsale();
for(int i=0;i<4;i++)
for(int j=0;j<2;j++)
sm[j].sort(sm[j+1]);
};
cout<<"第一位经理的销售员"<<endl;
cout<<"│ 职工号 姓名 工资 "<<endl;
sm[0].saleprint();
sm[0].printtotal();
cout<<" 排序已经完成"<<endl;
cout<<"各销售经理的排名"<<endl;
cout<<" 职工号 姓名 性别 年龄 工资 "<<endl;
for(int k=0;k<4;k++)
sm[k].print();
};break;
case 3:
cout<<"Waiting......."<<endl;
{
cout<<" 职工基本情况一览表如下:"<<endl;
cout<<" 职工号 姓名 性别 年龄 工资 "<<endl;
for(int i=0;i<4;i++)
{m[i].print();}
cout<<" 职工号 姓名 性别 年龄 工资 "<<endl;
for(int k=0;k<4;k++)
{s[k].print();
};break;
case 4:
cout<<"Waiting......."<<endl;
{
for(int i=0;i<4;i++)
{m[i].save();}
for(int j=0;j<4;j++)
{t[j].save();}
for(int k=0;k<4;k++)
{s[k].save();}
for(int l=0;l<4;l++)
{sm[l].save();}
};cout<<" 信息保存成功! "<<endl;break;
case 5:exit(0);break;
default:cout<<"Error,请重新1-5间的输入"<<endl;
}
}while(flag=1); }