求一段C++程序,内容是职工信息管理系统,不用复杂,尽可能的简单。作为期末作业交的,QQ369349929

2024年11月17日 16:25
有1个网友回答
网友(1):

#include
#include
using namespace std;

class employee
{
public:
virtual void display()=0;
protected:
int num;
string name;
string sex;
float income;
int birthday;
int workday;
int age;
};

class teacher:public employee
{
public:
void getdata()
{
cout<<"请输入编号:"< cin>>num;
cout<<"请输入姓名:"< cin>>name;
cout<<"请输入姓别:"< cin>>sex;
cout<<"请输入薪水:"< cin>>income;
cout<<"请输入生日:"< cin>>birthday;
cout<<"请输入工作年龄:"< cin>>workday;
age=workday-birthday;
}
void display()
{
cout<<"编号:"< cout<<"姓名:"< cout<<"姓别:"< cout<<"薪水:"< cout<<"生日:"< cout<<"参加工作时间:"< cout<<"年龄:"< }
int getage()
{
age=workday-birthday;
return age;
}
int getnum()
{
return num;
}
string getname()
{
return name;
}
};

class worker:public employee
{
public:
void getdata()
{
cout<<"请输入编号:"< cin>>num;
cout<<"请输入姓名:"< cin>>name;
cout<<"请输入姓别:"< cin>>sex;
cout<<"请输入薪水:"< cin>>income;
cout<<"请输入生日:"< cin>>birthday;
cout<<"请输入工作年龄:"< cin>>workday;
}
void display()
{
cout<<"编号:"< cout<<"姓名:"< cout<<"姓别:"< cout<<"薪水:"< cout<<"生日:"< cout<<"参加工作时间:"< cout<<"年龄:"< }
int getage()
{
age=workday-birthday;
return age;
}
int getnum()
{
return num;
}
string getname()
{
return name;
}
};

void menu(int &choice)
{
cout<<"\t\t\t 职工信息管理系统"< cout<<"\t\t\t1、增加一位教师记录"< cout<<"\t\t\t2、增加一位工人记录"< cout<<"\t\t\t3、显示全部职工记录"< cout<<"\t\t\t4、计算教师平均年龄"< cout<<"\t\t\t5、计算工人平均年龄"< cout<<"\t\t\t6、删除一个教师"< cout<<"\t\t\t7、删除一个工人"< cout<<"\t\t\t8、按姓名检索所有信息"< cout<<"\t\t\t0、结束程序运行"< cout<<"\t\t 请输入你的选择:";
cin>>choice;
}

int main()
{
int choice=0;
int indx1=0,indx2=0;
bool flag=false;
teacher t[50];
worker w[50];
while (1)
{
int i=0;
int average=0;
int temp;
string tname;
menu(choice);
switch (choice)
{
case 1:
t[indx1++].getdata();
break;
case 2:
w[indx2++].getdata();
break;
case 3:
cout<<"显示所有教师信息:"< for (i=0;i!=indx1;++i)
{
t[i].display();
}
cout<<"显示所有工人信息:"< for (i=0;i!=indx2;++i)
{
w[i].display();
}
break;
case 4:
cout<<"教师平均年龄:"< for (i=0;i!=indx1;++i)
{
average+=t[i].getage();
}
cout< break;
case 5:
cout<<"工人平均年龄:"< for (i=0;i!=indx2;++i)
{
average+=w[i].getage();
}
cout< break;
case 6:
cout<<"请输入要删除教师的编号"< cin>>temp;
for (i=0;i!=indx1;++i)
{
if (temp==t[i].getnum())
{
do
{
t[i]=t[i+1];
++i;
} while (i!=indx1);
cout<<"已删除"< --indx1;
break;
}
}
break;
case 7:
cout<<"请输入要删除工人的编号"< cin>>temp;
for (i=0;i!=indx2;++i)
{
if (temp==w[i].getnum())
{
do
{
w[i]=w[i+1];
++i;
} while (i!=indx2);
cout<<"已删除"< --indx2;
break;
}
}
break;
case 8:
cout<<"请输入姓名:"< cin>>tname;
for (i=0;i!=indx1;++i)
{
if (tname==t[i].getname())
{
cout<<"这位是教师"< t[i].display();
}
}
for (i=0;i!=indx2;++i)
{
if (tname==w[i].getname())
{
cout<<"这位是工人"< w[i].display();
}
}
break;
case 0:
flag=true;
break;
}
if (flag)
{
break;
}
}
return 0;
}