需要用c++的class和子函数编写,谢谢
1. 定义一个能够记录公司员工工资的类, 比如包括:员工号,姓名,基本工资,补贴金额,奖励金额,扣税,实发工资等),其中实发工资=基本工资+补贴金额+奖励金额-扣税。 要求:
1)新增功能,能输入10个员工信息并计算出实发工资,并且员工编号在生成员工信息时同时生成;(提示:使用构造函数生成员工编号)
2)要求对所有员工都能按照名称或编号进行显示、查找、增加和修改的功能;
3)统计出员工的平均工资。
以运行结果文本菜单的形式输出。
我只能编写出一部分正确的,就菜单的子函数,怎么编写都是错的,也不知道是思路不对,还是怎么的,就没发上来
#include <iostream>
#include <string>
#include <ctype.h>
#define N 10
using namespace std;
void menuline()
{
while(getchar()!='\n') continue;
}
class Work_menu
{private:
double price1,price2,price3,price4,price5;//price1基本工资,price2补贴金额,price3奖励金额,price4扣税,price5实发工资
string name;
int a[N];
public:
void set();
char showmenu();
};
Work_menu work1,work2,work3,work4,work5,work6,work7,work8,work9,work10;
void Work_menu::set()
{
int i;
for(i=0;i<N;i++)
{
cout<<"请输入第"<<i+1<<"位员工的信息:"<<endl;
cout<<"员工号:"<<endl;
cin>>a[i];
cout<<"姓名:"<<endl;
cin>>name;
cout<<"基本工资:"<<endl;
cin>>price1;
cout<<"补贴金额:"<<endl;
cin>>price2;
cout<<"奖励金额:"<<endl;
cin>>price3;
cout<<"扣税:"<<endl;
cin>>price4;
cout<<"实发工资:"<<endl;
price5=price1+price2+price3-price4;
cout<<price5<<endl;
}
}
char Work_menu::showmenu()
{
char ans;
cout<<"请选择菜单项:"<<endl;
cout<<"f)按名称显示员工信息: g)查找员工信息:"<<endl;
cout<<"h)增加员工信息: k)修改员工信息:"<<endl;
cout<<"p)返回菜单: q)退出程序"<<endl;
ans=tolower(getchar());
menuline();
while(strchr("fghkpq",ans)==NULL)
{ cout<<"请输入f,g,h,k,p or q:"<<endl;
ans=tolower(getchar());
menuline();
}
return ans;
}
int main()
{
work1.set();
work1.showmenu();
work2.set();
work2.showmenu();
work3.set();
work3.showmenu();
work4.set();
work4.showmenu();
work5.set();
work5.showmenu();
work6.set();
work6.showmenu();
work7.set();
work7.showmenu();
work8.set();
work8.showmenu();
work9.set();
work9.showmenu();
work10.set();
work10.showmenu();
return 0;
}