具体代码如下:
#include<iostream>
using namespace std;
class date
{public:
int year1;
int month1;
int day1;
date()=default;
date(int year,int month,int day):year1(year),month1(month),day1(day){}
};
class employee //员工类
{public:
string name;
string number;
int rank; //级别
double wage;
int age;
string title;
date date1;
void input1();
void output1(); //日期对象
employee()=default;
employee(string name,string number,int rank,int age,double wage,string title,int year,int month,int day):name(name),number(number),rank(rank),age(age),wage(wage),title(title),date1(year,month,day){}
// void output();
~employee();
string class1;
int n;
};
employee::~employee() //基类析构函数
{
}
void employee::input1() //经理输入函数
{
cout<<"请输入发薪时间"<<endl;
cout<<"年:"<<endl;
cin>>date1.year1;
getchar();
cout<<"月:"<<endl;
cin>>date1.month1;
cout<<"日:"<<endl;
cin>>date1.day1;
cout<<"名字:"<<endl;
cin>>name;
cout<<"编号:"<<endl;
cin>>number;
cout<<"年龄:"<<endl;
cin>>age;
}
void employee::output1()
{cout<<(date1).year1<<"年"<<(date1).month1<<"月"<<(date1).day1<<"日"<<endl;
}
class manager:virtual public employee //派生经理类
{public:
void input();
manager()=default;
//date date1;
manager(string name,string number,int rank,int age,double wage,string title,int year,int month,int day):employee(name,number,rank,age,wage,title,year,month,day){}
};
void manager::input() //经理输入函数
{
input1();
rank=4;
wage=8000;
class1="经理";
}
class technician:virtual public employee //派生技术人员类
{public:
void input();
double time;
date date1;
technician()=default;
technician(string name,string number,int rank,int age,double wage,string title,int year,int month,int day,double time):employee(name,number,rank,age,wage,title,year,month,day),date1(year,month,day),time(time){}
};
void technician::input()
{input1();
cout<<"工作时间:"<<endl;
cin>>time;
wage=time*100;
rank=3;
class1="技术人员";
}
class salesman:virtual public employee//派生类销售人员
{public:
void input();
salesman()=default;
date date1;
salesman(string name,string number,int rank,int age,double wage,string title,int year,int month,int day):employee(name,number,rank,age,wage,title,year,month,day),date1(year,month,day){}
};
void salesman::input()
{input1();
double b;
cout<<"请输入该销售员的销售额:"<<endl;
cin>>wage;
rank=1;
class1="销售员";
}
class salesmanager:virtual public salesman,virtual public manager //间接派生类 销售经理
{
public:
void input();
salesmanager()=default;
date date1;
salesmanager(string name,string number,int rank,int age,double wage,string title,int year,int month,int day):employee(name,number,rank,age,wage,title,year,month,day),date1(year,month,day){}
};
void salesmanager::input()
{input1();
rank=4;
class1="销售经理";
}
//类已结束
void output(manager *manager1,salesman *salesman1,technician *technician1,salesmanager *salesmanager1,int n,int j) //输出函数 //输出函数
{int i;
cout<<"各个段位的人的工资情况:"<<endl;
for(i=0;i<=n;i++)
{if(j==2)
{
cout<<"经理"<<"薪资情况"<<endl;
(*(manager1+i)).output1();
cout<<"名字:"<<(*(manager1+i)).name<<endl;
cout<<"编号:"<<(*(manager1+i)).number<<endl;
cout<<"级别:"<<(*(manager1+i)).rank<<endl;
cout<<"工资:"<<(*(manager1+i)).wage<<endl;
cout<<endl;
}
if(j==4)
{
cout<<"销售员"<<"薪资情况"<<endl;
(*(salesman1+i)).output1();
cout<<"名字:"<<(*(salesman1+i)).name<<endl;
cout<<"编号:"<<(*(salesman1+i)).number<<endl;
cout<<"级别:"<<(*(salesman1+i)).rank<<endl;
cout<<"工资:"<<(*(salesman1+i)).wage<<endl;
cout<<endl;
}
if(j==3)
{
cout<<"技术人员"<<"薪资情况"<<endl;
(*(technician1+i)).output1();
cout<<"名字:"<<(*(technician1+i)).name<<endl;
cout<<"编号:"<<(*(technician1+i)).number<<endl;
cout<<"级别:"<<(*(technician1+i)).rank<<endl;
cout<<"工资:"<<(*(technician1+i)).wage<<endl;
cout<<endl;
}
if(j==1)
{
cout<<"销售经理"<<"薪资情况"<<endl;
(*(salesmanager1+i)).output1();
cout<<"名字:"<<(*(salesmanager1+i)).name<<endl;
cout<<"编号:"<<(*(salesmanager1+i)).number<<endl;
cout<<"级别:"<<(*(salesmanager1+i)).rank<<endl;
cout<<"工资:"<<(*(salesmanager1+i)).wage<<endl;
cout<<endl;
}
}
}
double compute(salesman *p,int d) //通过销售员的销售额计算工资
{double wage=0;
int i;
for(i=0;i<=d;i++)
{
wage=wage+(*(p+i)).wage;
wage=5000+wage*5/100;}
return wage;}
double input(salesmanager *q,manager *m,technician *t,salesman *p,int &a,int &b,int &c,int &d) //输入函数
{here:
here1:
cout<<"1、经理 2、销售经理 3、技术人员 4、销售人员"<<endl;
int i;
int j1=0,j2=0,j3=0,j4=0;
cin>>i;
if(i<=0||i>=5)
goto here1;
if(i==2) //销售经理
{there1:
b++;
j1++;
(*(q+j1)).input();
cout<<"固定工资之外,提成由销售人员的销售总额决定"<<endl;
cout<<"1、继续 2、结束该类成员的录入"<<endl;
cin>>i;
if(i==1)
goto there1;
}
//销售员
if(i==4)
{
there2:
d++;
j2++;
(*(p+j2)).input();
cout<<"1、继续 2、结束该类成员的录入"<<endl;
cin>>i;
if(i==1)
goto there2;
if(i==2)
{cout<<"确定销售人员的销售额都输完了吗,这会影响到销售经理的工资哟"<<endl;
getchar();
}
}
if(i==1)//经理
{there3:
a++;
j3++;
(*(m+j3)).input();
cout<<"1、继续 2、结束该类成员的录入"<<endl;
cin>>i;
if(i==1)
goto there3;
}
if(i==3)//技术人员
{
there4:
c++;
j4++;
(*(t+j4)).input();
cout<<"1、继续 2、结束该类成员的录入"<<endl;
cin>>i;
if(i==1)
goto there4;
}
if(i==2)
{cout<<"是否录入其他成员 1、继续 2、结束录入"<<endl;
cin>>i;
if(i==1)
goto here;
}
} //输入函数结束
int main()
{salesmanager salesmanager1[100]{salesmanager("张三","123456",4,35,8500,"销售经理",2022,5,6)};
salesman salesman1[100]={salesman("李四","123453",1,25,6000,"销售人员",2022,5,6)};
manager manager1[100]={manager("王先生","123341",4,35,8000,"经理",2022,5,6)};
technician technician1[100]={technician("李先生","131213",3,30,6500,"技术人员",2022,5,6,10)};
salesmanager *q=&salesmanager1[0];
manager *m=&manager1[0];
technician *t=&technician1[0];
salesman *p=&salesman1[0];
int i;
int n1=0,n2=0,n3=0,n4=0;
int &a=n1;
int &b=n2,&c=n3,&d=n4;
input(q,m,t,p,a,b,c,d);
for(i=0;i<=b;i++)
salesmanager1[i].wage=compute(p,d);
output(m,p,t,q,b,1);
output(m,p,t,q,a,2);
output(m,p,t,q,c,3);
output(m,p,t,q,d,4);
return 0;
}