新手求助,local function definitions are illegal
#include<iostream>#include<stdlib.h>
#include<string>
using namespace std;
//基类
class employee{
public:
employee(string Name="XXX",string Num="0000",int Lev=0,float Pay=0.0){
name=Name;
num=Num;
lev=Lev;
pay=Pay;
}
void getname()
{ cout<<"输入姓名:"<<endl;
cin>>name;
}
void getnum()
{ cout<<"输入编号:"<<endl;
cin>>num;
}
void getlev(){
cout<<"输入等级:"<<endl;
cin>>lev;
}
virtual void showpay();
char *showname()
{return (&name[0]);}
char *shownum(){
return (&num[0]);
}
int showlev(){
return lev;
}
void show(){
showname();
shownum();
showlev();
}
employee::~employee(){}
private:
string name;
string num;
int lev;
float pay;
};
//派生
class jingli:public employee{
public:
jingli(string Name="XXX",string Num="0000",int Lev=0,float Pay=0.0,int t=0){
this->t=t;
employee(Name,Num,Lev,Pay);
}
void gett(){
cout<<"输入薪水:"<<endl;
cin>>t;}
int showt(){
return t;
}
void showpay(){
cout<<"t"<<endl;
}
private:
int t;
};
class technicist:public employee{
public:
technicist(string Name="XXX",string Num="0000",int Lev=0,float Pay=0.0,int t=0){
this->t=t;
employee(Name,Num,Lev,Pay);
}
void gett(){
cout<<"输入工作小时数:"<<endl;
cin>>t;}
int showt(){
return t;
}
void showpay(){
t=t*100;
cout<<t<<endl;
}
private:
int t;
};
class sale:public employee{
public:
sale(string Name="XXX",string Num="0000",int Lev=0,float Pay=0.0,int t=0,float p=0.0){
this->t=t;
this->p=p;
employee(Name,Num,Lev,Pay);
}
void gett(){
cout<<"输入销售额:"<<endl;
cin>>t;}
void getp(){
cout<<"输入底薪:"<<endl;
cin>>p;}
int showt(){
return t;
}
int showp(){
return p;
}
void showpay(){
p=t*0.04;
cout<<p<<endl;
}
private:
int t;
float p;
};
class xiaoshoujingli:public employee{
public:
xiaoshoujingli(string Name="XXX",string Num="0000",int Lev=0,float Pay=0.0,int t=0,float p=0.0){
this->t=t;
this->p=p;
employee(Name,Num,Lev,Pay);
}
void gett(){
cout<<"输入销售额:"<<endl;
cin>>t;}
int showt(){
return t;
}
void showpay(){
p=5000+t*0.05;
cout<<p<<endl;
}
private:
int t;
float p;
};
//显示
//void jingli::showpay()
//void technicist::showpay()
//void sale::showpay()
//void xiaoshoujingli::showpay()
//添加成员
void addemployee(int&flag1,int&flag2,int&flag3,int&flag4,jingli A[20],technicist B[20],sale C[20],xiaoshoujingli D[20])
{ system("cls");
int n1,n2,n3,n4;
int i,k,j;
cout<<"添加经理请输入1"<<endl;
cout<<"添加兼职技术人员请输入2"<<endl;
cout<<"添加销售人员请输入3"<<endl;
cout<<"添加销售经理请输入4"<<endl;
cout<<"返回上层菜单输入0"<<endl;
cin>>i;
system("cls");
switch(i){
case 1:{ cout<<"请输入添加人数"<<endl;
cin>>n1;
jingli *q;
while(1)
{ for(k=flag1,j=flag1;k<=n1+j-1;k++)
{q=&A[k];
q->getname();
q->getlev();
q->getnum();
}
}
}
case 2:{cout<<"请输入添加人数"<<endl;
cin>>n2;
technicist *q;
while(1){
for(k=flag2,j=flag2;k<=n2+j-1;k++)
{ q=&B[k];
q->getname();
q->getlev();
q->getnum();
q->gett();
}
}
}
case 3:{cout<<"请输入添加的人数:"<<endl;
cin>>n3;
sale *q;
while(1){
for(k=flag3,j=flag3;k<=n3+j-1;k++)
{ q=&C[k];
q->getname();
q->getlev();
q->getnum();
q->gett();
q->getp();
}
}
}
case 4:{ cout<<"请输入添加的人数:"<<endl;
cin>>n4;
xiaoshoujingli *q;
while(1){
for(k=flag4,j=flag4;k<=n4+j-1;k++)
{ q=&D[k];
q->getname();
q->getlev();
q->getnum();
q->gett();
}
}
}
}
}
//删除成员函数
void delemployee(int&flag1,int&flag2,int&flag3,int&flag4,jingli A[20],technicist B[20],sale C[20],xiaoshoujingli D[20])
{ system("cls");
int i,j;
string target;
cout<<"删除经理请输入1"<<endl;
cout<<"删除兼职技术人员请输入2"<<endl;
cout<<"删除销售人员请输入3"<<endl;
cout<<"删除销售经理请输入4"<<endl;
cout<<"返回上层菜单输入0"<<endl;
cin>>j;
system("cls");
switch(j){
case 1:{
cout<<"输入想要删除人员的名字:"<<endl;
cin>>target;
for(i=0;i<=flag1;i++)
if(target==A[i].showname())
{ for(;i<=flag1-1;i++)
// {A[i].name=A[i+1].showname;
// A[i].lev=A[i+1].showlev();
// A[i].t=A[i+1].showt();
// A[i].num=A[i+1].shownum();
{A[i]=A[i+1];}flag1--;
break;}
}
case 2:{ cout<<"输入想要删除人员的名字:"<<endl;
cin>>target;
for(i=0;i<=flag2;i++)
if(target==B[i].showname())
{ for(;i<=flag2-1;i++)
// {B[i].name=A[i+1].showname();
// B[i].lev=B[i+1].showlev();
// B[i].num=B[i+1].shownum();
// B[i].t=B[i+1].showt();
// }
{B[i]=B[i+1];}
flag2--;
break;}
}
case 3:{ cout<<"输入想要删除人员的名字:"<<endl;
cin>>target;
for(i=0;i<=flag3;i++)
if(target==C[i].showname())
{ for(;i<=flag3-1;i++)
// {C[i].name=C[i+1].showname();
// C[i].lev=C[i+1].showlev();
// C[i].p=C[i+1].showp();
// C[i].num=C[i+1].shownum();
// C[i].t=C[i+1].showt();
{C[i]=C[i+1];}flag3--;
break;}
}
case 4:{ cout<<"输入想要删除人员的名字:"<<endl;
cin>>target;
for(i=0;i<=flag4;i++)
{ if(target==D[i].showname())
{ for(;i<=flag1-1;i++)
// {D[i].name=D[i+1].showname();
// D[i].lev=D[i+1].showlev();
// D[i].num=D[i+1].shownum();
// D[i].t=D[i+1].showt();
{D[i]=D[i+1];
}
flag4--;
break;}
}
}
}
//修改成员函数
void changedata(int&flag1,int&flag2,int&flag3,int&flag4,jingli A[20],technicist B[20],sale C[20],xiaoshoujingli D[20])
{
system("cls");
int j,k;
string target;
cout<<"修改经理请输入1"<<endl;
cout<<"修改兼职技术人员请输入2"<<endl;
cout<<"修改兼职技术人员请输入3"<<endl;
cout<<"修改销售经理请输入4"<<endl;
cout<<"返回上层菜单输入0"<<endl;
cin>>j;
system("cls");
switch(j){
case 1:{cout<<"输入被修改成员的姓名"<<endl;
cin>>target;
for(k=0;k<=flag1;k++)
if(target==A[k].showname())
{A[k].getname();
A[k].getnum();
A[k].getlev();
A[k].gett();
}break;
}break;
case 2:{cout<<"输入被修改成员的姓名"<<endl;
cin>>target;
for(k=0;k<=flag2;k++)
if(target==B[k].showname())
{B[k].getname();
B[k].getnum();
B[k].getlev();
B[k].gett();
}break;
}break;
case 3:{cout<<"输入被修改成员的姓名"<<endl;
cin>>target;
for(k=0;k<=flag3;k++)
if(target==C[k].showname())
{C[k].getname();
C[k].getnum();
C[k].getlev();
C[k].gett();
C[k].getp();
}break;
}break;
case 4:{cout<<"输入被修改成员的姓名"<<endl;
cin>>target;
for(k=0;k<=flag1;k++)
if(target==D[k].showname())
{D[k].getname();
D[k].getnum();
D[k].getlev();
D[k].gett();
}break;
}break;
}
}
//显示成员函数
void showdata(int&flag1,int&flag2,int&flag3,int&flag4,jingli A[20],technicist B[20],sale C[20],xiaoshoujingli D[20])
{ system("cls");
int j,k;
cout<<"查看经理请输入1"<<endl;
cout<<"查看兼职技术人员请输入2"<<endl;
cout<<"查看销售人员请输入3"<<endl;
cout<<"查看销售经理请输入4"<<endl;
cout<<"返回上层菜单输入0"<<endl;
cin>>j;
system("cls");
switch(j){
case 1:{for(k=0;k<=flag1;k++)
{A[k].show();
A[k].showpay();
}
}break;
case 2:{for(k=0;k<=flag2;k++)
{B[k].show();
B[k].showpay();
}
}break;
case 3:{for(k=0;k<=flag3;k++)
{C[k].show();
C[k].showpay();
}
}break;
case 4:{for(k=0;k<=flag4;k++)
{D[k].show();
D[k].showpay();
}
}break;
}
}
//主函数
void main()
{
int a;
int flag1=0,flag2=0,flag3=0,flag4=0;
jingli A[20];
technicist B[20];
sale C[20];
xiaoshoujingli D[20];
cout<<"欢迎使用公司成员管理系统,按任意键继续!"<<endl;
getchar();
while(1)
{ system("cls");
cout<<"请输入编号选择功能:"<<endl<<"添加输入1"<<endl<<"删除输入2"<<endl<<"查看输入3"<<endl<<"修改输入4"<<endl<<"结束操作请输入0"<<endl;
cin>>a;
switch(a)
{case 1:addemployee(flag1,flag2,flag3,flag4,A,B,C,D);
case 2:delemployee(flag1,flag2,flag3,flag4,A,B,C,D);
case 3:showdata(flag1,flag2,flag3,flag4,A,B,C,D);
case 4:changedata(flag1,flag2,flag3,flag4,A,B,C,D);
case 0: exit(0);
}
}
}
}