你思路有问题,一直在定义,重复的定义干嘛,最后你注释完全可以不用,看看你的整体吧,思路的事情。
啦啦啦德玛西亚!
#include <iostream> #include <string> #include <ctype.h> #define N 3 using namespace std; /* void menuline() { wh(getchar()!='\n') continue; } */ class Work_menu {private: double price1,price2,price3,price4,price5; string name; public: static int num; void set(); void show(); //char showmenu(); void re_show(); void rer_show(int n); void fun1(int k); void fun2(int k); void fun3(int k); void fun4(int k); }; int Work_menu::num=0; void Work_menu::set() { cout<<"姓名:"; cin>>name; cout<<"基本工资:" ; cin>>price1; cout<<"补贴金额:" ; cin>>price2; cout<<"奖励金额:" ; cin>>price3; cout<<"扣税:" ; cin>>price4; cout<<"实发工资:" ; price5=price1+price2+price3-price4; cout<<price5<<endl; } void Work_menu::show() { num++; cout<<"员工号:"<<num<<endl; cout<<"姓名:"<<name<<endl; cout<<"基本工资:"<<price1<<endl; cout<<"补贴金额:"<<price2<<endl; cout<<"奖励金额:"<<price3<<endl; cout<<"扣税:"<<price4<<endl; cout<<"实发工资:"<<price5<<endl; } void Work_menu::rer_show(int n) { num=n; cout<<"员工号:"<<num<<endl; cout<<"姓名:"<<name<<endl; cout<<"基本工资:"<<price1<<endl; cout<<"补贴金额:"<<price2<<endl; cout<<"奖励金额:"<<price3<<endl; cout<<"扣税:"<<price4<<endl; cout<<"实发工资:"<<price5<<endl; } char showmenu() { char ans; cout<<"请选择菜单项:"<<endl; cout<<"g)查找员工信息: k)修改员工信息:"<<endl; cout<<"h)增加员工信息: m)显示员工信息"<<endl; cout<<"p)返回菜单: q)退出程序"<<endl; //ans=tolower(getchar()); //menuline(); cin>>ans; return ans; } void Work_menu::re_show() { int i; // Work_menu work[N]; // for(i=0;i<N;i++) //{ cout<<"----------------------------"<<endl; // work[i]. show(); //} cout<<"--------------------------------------------------------------------"<<endl; } void Work_menu::fun1(int k)//查找员工信息 { // char showmenu(); // void rer_show(int n); //int n; // cout<<"请输入您需要查找的员工号:"<<endl; // cin>>n; rer_show(k); //showmenu(); } void Work_menu::fun2(int k)//修改员工信息 { // char showmenu(); // void rer_show(int n); // void re_show(); //int n; // cout<<"请输入您需要修改的员工号:"<<endl; // cin>>n; cout<<"请重新录入该员工信息:"<<endl; rer_show(k-1); cout<<"----------------------修改员工信息后,整理的信息如下-----------------------------"<<endl; re_show(); num=k-2; //showmenu(); } void Work_menu::fun3(int k)//增加员工信息 { //char showmenu(); // void set(); // void re_show(); //int n; cout<<"请输入您要增加的员工信息:"<<endl; // cin>>n; set(); cout<<"----------------------增加员工信息后,整理如下-----------------------------"<<endl; re_show(); // showmenu(); } void Work_menu::fun4(int k)//显示员工信息 { //char showmenu(); // void rer_show(int n); // int n; // cout<<"请输入您需要显示的员工信息的员工号:"<<endl; // cin>>n; rer_show(k); // showmenu(); } int main() { //Work_menu a; int i; //char showmenu(); Work_menu work[N]; for(i=0;i<N;i++) { cout<<"请输入第"<<i+1<<"位员工的信息:"<<endl; work[i].set(); } cout<<"----------------------您录入的信息如下-----------------------------"<<endl; for(i=0;i<N;i++) { cout<<"----------------------------"<<endl; work[i].show(); } cout<<"--------------------------------------------------------------------"<<endl; char choice; choice=showmenu(); while(choice!='q') { cout<<"请输入要查找,修改,增加,显示的员工号:"<<endl; int k; cin>>k; //work[k-1].showmenu(); switch(choice) {case 'g': work[k-1].fun1(k); break; case 'k': work[k-1].fun2(k); break; case 'h': work[k-1].fun3(k); break; case 'm': work[k-1].fun4(k); break; case 'p':break; } showmenu(); } // if(choice=='q') // break;//break只能用于循环语句和switch语句,该如何加上 //这里是想退出程序,但是用了break之后又不合法,不知道怎么办,能帮忙想个办法么 return 0; }