C++一个管理系统,怎么样在类定义里增加一个工资,并在添加人员或统计里面显示
#include<iostream>#include<fstream>
#include<cstring>
#include<iomanip>
using namespace std;
int x;
class person
{
private:
char num[10];
char type[20];
char name[20];
char sex[10];
char age[10];
char zhiwu[20];
char zhichen[20];
char zzmm[20];
char zgxl[20];
char rzsj[20];
char lysj[30];
static int bianhao;
public:
void setperson(char *type1,char *name1,char *sex1,char *age1,char *zhiwu1,
char *zhichen1,char *zzmm1,char *zgxl1,char *rzsj1,char *lysj1);
//有设置有返回值
static int& getbianhao() {return bianhao;}
char * gettype() { return type;}
char * getname() {return name;}
char * getsex() {return sex;}
char * getage() {return age;}
char * getzhiwu() {return zhiwu;}
char * getzhichen() {return zhichen;}
char * getzzmm() {return zzmm;}
char * getzgxl() {return zgxl;}
char * getrzsj() {return rzsj;}
char * getlysj() {return lysj;}
char * getnum() {return num;}
//构造函数
void tjry();
void find();
void output();
void shanchu();
void xiugai();
void tongji();
};
person z[100];
person zz[100];
int x1;
int person::bianhao=0;
//
void person::setperson(char *type1,char *name1,char *sex1,char *age1,
char *zhiwu1,char *zhichen1,char *zzmm1,char *zgxl1,char *rzsj1,char *lysj1)
{
int static y=1;
strcpy(type,type1);
strcpy(name,name1);
strcpy(sex,sex1);
strcpy(age,age1);
strcpy(zhiwu,zhiwu1);
strcpy(zhichen,zhichen1);
strcpy(zzmm,zzmm1);
strcpy(zgxl,zgxl1);
strcpy(rzsj,rzsj1);
strcpy(lysj,lysj1);
bianhao++;
ofstream file("添加人员.txt",ios_base::app);//
file<<z[y].getbianhao()<<endl;
file<<z[y].gettype()<<endl;
file<<z[y].getname()<<endl;
file<<z[y].getsex()<<endl;
file<<z[y].getage()<<endl;
file<<z[y].getzhiwu()<<endl;
file<<z[y].getzhichen()<<endl;
file<<z[y].getzzmm()<<endl;
file<<z[y].getzgxl()<<endl;
file<<z[y].getrzsj()<<endl;
file<<z[y].getlysj()<<endl;
y++;
file.close();
}
void person::tjry ()
{
int v,l=1;
char type2[20];
char name2[20];
char sex2[10];
char age2[10];
char zhiwu2[20];
char zhichen2[20];
char zzmm2[20];
char zgxl2[20];
char rzsj2[20];
char lysj2[30];
cout <<"请输入需要添加的人数"<<endl;
cin>>x;
z[1].getbianhao()=zz[x1].getbianhao();
v=bianhao;
for(int i=v+1;i<=v+x;i++)
{
cout<<"请输入第"<<l<<"个人的信息"<<endl;
cout<<"人员类型"; cin>>type2;
cout<<"姓名:"; cin>>name2;
cout<<"性别:"; cin>>sex2;
cout<<"年龄:"; cin>>age2;
cout<<"职务:"; cin>>zhiwu2;
cout<<"职称:"; cin>>zhichen2;
cout<<"政治面貌:"; cin>>zzmm2;
cout<<"最高学历:"; cin>>zgxl2;
cout<<"任职时间:"; cin>>rzsj2;
cout<<"来院时间:"; cin>>lysj2;
z[i].setperson(type2,name2,sex2,age2,zhiwu2,zhichen2,zzmm2,zgxl2,rzsj2,lysj2);
l++;
}
}
void person::find()
{
cout<<"1:按编号查询--2:按姓名查询-请选择(1-2)"<<endl;
int m;
cin>>m;
while(m<1||m>2)
{
cout<<"请重新输入(1-2)"<<endl;cin>>m;
}
switch(m)
{
case 1:
{
char n[10];
cout<<"请输入要查找的编号:";
cin>>n;
ifstream filem("添加人员.txt",ios_base::in);
int x=1;
cout<<"编号"<<setw(9)<<"人员类型"<<setw(5)<<"姓名"<<setw(5)<<"性别"
<<setw(5)<<"年龄"<<setw(5)<<"职务"<<setw(5)<<"职称"
<<setw(9)<<"政治面貌"<<setw(10)<<"最高学历"<<setw(10)<<"任职时间"
<<setw(10)<<"来院时间"<<endl;
while(!filem.eof())
{
filem>>zz[x].getnum();
filem>>zz[x].gettype();
filem>>zz[x].getname();
filem>>zz[x].getsex();
filem>>zz[x].getage();
filem>>zz[x].getzhiwu();
filem>>zz[x].getzhichen();
filem>>zz[x].getzzmm();
filem>>zz[x].getzgxl();
filem>>zz[x].getrzsj();
filem>>zz[x].getlysj();
if(strcmp(zz[x].getnum(),n)==0)
{
cout<<zz[x].getnum()<<setw(9)<<zz[x].gettype()<<setw(5)<<zz[x].getname()
<<setw(5)<<zz[x].getsex()<<setw(5)<<zz[x].getage()
<<setw(5)<<zz[x].getzhiwu()<<setw(5)<<zz[x].getzhichen()
<<setw(9)<<zz[x].getzzmm()<<setw(10)<<zz[x].getzgxl()
<<setw(10)<<zz[x].getrzsj()<<setw(10)<<zz[x].getlysj()<<endl; break;}
x++;
if(filem.eof())
{
cout<<endl;
cout<<" 警告:没有要查找的人!!!!!!!!!!";
}
}
filem.close();} break;
case 2:
{
char nname[20];
cout<<"请输入要查找的姓名:";
cin>>nname;
ifstream filem("添加人员.txt",ios_base::in);
int x=1;
cout<<"编号"<<setw(9)<<"人员类型"<<setw(5)<<"姓名"<<setw(5)<<"性别"
<<setw(5)<<"年龄"<<setw(5)<<"职务"<<setw(5)<<"职称"
<<setw(9)<<"政治面貌"<<setw(10)<<"最高学历"<<setw(10)<<"任职时间"
<<setw(10)<<"来院时间"<<endl;
while(!filem.eof())
{
filem>>zz[x].getnum();
filem>>zz[x].gettype();
filem>>zz[x].getname();
filem>>zz[x].getsex();
filem>>zz[x].getage();
filem>>zz[x].getzhiwu();
filem>>zz[x].getzhichen();
filem>>zz[x].getzzmm();
filem>>zz[x].getzgxl();
filem>>zz[x].getrzsj();
filem>>zz[x].getlysj();
if(strcmp(zz[x].getname(),nname)==0)
{
cout<<zz[x].getnum()<<setw(9)<<zz[x].gettype()<<setw(5)<<zz[x].getname()
<<setw(5)<<zz[x].getsex()<<setw(5)<<zz[x].getage()
<<setw(5)<<zz[x].getzhiwu()<<setw(5)<<zz[x].getzhichen()
<<setw(9)<<zz[x].getzzmm()<<setw(10)<<zz[x].getzgxl()
<<setw(10)<<zz[x].getrzsj()<<setw(10)<<zz[x].getlysj()<<endl;break;}
x++;
if(filem.eof())
{
cout<<endl;
cout<<" 警告:没有需要查找的人!";}
}
filem.close();
}
break;
}
}
void person::shanchu()
{
int r;
ifstream filem("添加人员.txt",ios_base::in);
int x=1;
while(!filem.eof())
{
filem>>zz[x].getnum();
filem>>zz[x].gettype();
filem>>zz[x].getname();
filem>>zz[x].getsex();
filem>>zz[x].getage();
filem>>zz[x].getzhiwu();
filem>>zz[x].getzhichen();
filem>>zz[x].getzzmm();
filem>>zz[x].getzgxl();
filem>>zz[x].getrzsj();
filem>>zz[x].getlysj();
x++;
}
filem.close();
cout<<"请输入要被删除信息的人的编号:"<<endl;
cin>>r;
while(r<1||r>bianhao)
{
cout<<"没有找到你要删除的人,请重新输入:"<<endl;cin>>r;}
for(x=1;x<=bianhao;x++)
{
if(r==x)
continue;
ofstream file2("添加人员.txt",ios_base::trunc);
file2<<zz[x].getnum()<<endl;
file2<<zz[x].gettype()<<endl;
file2<<zz[x].getname()<<endl;
file2<<zz[x].getsex()<<endl;
file2<<zz[x].getage()<<endl;
file2<<zz[x].getzhiwu()<<endl;
file2<<zz[x].getzhichen()<<endl;
file2<<zz[x].getzzmm()<<endl;
file2<<zz[x].getzgxl()<<endl;
file2<<zz[x].getrzsj()<<endl;
file2<<zz[x].getlysj()<<endl;
file2.close();
}
cout<<"删除记录完毕"<<endl;
}
void person::xiugai()
{
int x=1;
ifstream filem("添加人员.txt",ios_base::in);
while(!filem.eof())
{
filem>>zz[x].getnum();
filem>>zz[x].gettype();
filem>>zz[x].getname();
filem>>zz[x].getsex();
filem>>zz[x].getage();
filem>>zz[x].getzhiwu();
filem>>zz[x].getzhichen();
filem>>zz[x].getzzmm();
filem>>zz[x].getzgxl();
filem>>zz[x].getrzsj();
filem>>zz[x].getlysj();
x++;
}
filem.close();
cout<<"请输入要修改的人的编号:"<<endl;
int o,p;
cin>>o;
cout<<"请输入编号为"<<o<<"的人需要修改的项目的代号:"<<endl;
cout<<"1:编号-2:人员类型-3:姓名-4:性别-5:年龄-6:职务-7:职称-8:政治面貌-9:最高学历-10:任职时间-11:来院时间"<<endl;
cin>>p;
switch(p)
{
case 1:
{cout<<"请输入新的编号"; cin>>zz[o].getnum() ;}
break;
case 2:
{cout<<"请输入新的人员类型"; cin>>zz[o].gettype();}
break;
case 3:
{cout<<"请输入新的姓名";cin>>zz[o].getname();}
break;
case 4:
{cout<<"请输入新的性别";cin>>zz[o].getsex();}
break;
case 5:
{cout<<"请输入新的年龄";cin>>zz[o].getage();}
break;
case 6:
{cout<<"请输入新的职务";cin>>zz[o].getzhiwu();}
break;
case 7:
{cout<<"请输入新的职称";cin>>zz[o].getzhichen();}
break;
case 8:
{cout<<"请输入新的政治面貌";cin>>zz[o].getzzmm();}
break;
case 9:
{cout<<"请输入新的最高学历";cin>>zz[o].getzgxl();}
break;
case 10:
{cout<<"请输入新的任职时间";cin>>zz[o].getrzsj();}
break;
case 11:
{cout<<"请输入新的来院时间";cin>>zz[o].getlysj();}
break;
ofstream file1("添加人员.txt",ios_base::trunc);
for(x=1;x<=bianhao;x++)
{
file1<<zz[x].getnum()<<endl;
file1<<zz[x].gettype()<<endl;
file1<<zz[x].getname()<<endl;
file1<<zz[x].getsex()<<endl;
file1<<zz[x].getage()<<endl;
file1<<zz[x].getzhiwu()<<endl;
file1<<zz[x].getzhichen()<<endl;
file1<<zz[x].getzzmm()<<endl;
file1<<zz[x].getzgxl()<<endl;
file1<<zz[x].getrzsj()<<endl;
file1<<zz[x].getlysj()<<endl;
}
file1.close();
cout<<"修改并保存完毕"<<endl;
}
void person::output()
{
ifstream filem("添加人员.txt",ios_base::in);
int x=1;
cout<<"编号"<<setw(9)<<"人员类型"<<setw(5)<<"姓名"<<setw(5)<<"性别"
<<setw(5)<<"年龄"<<setw(5)<<"职务"<<setw(5)<<"职称"
<<setw(9)<<"政治面貌"<<setw(10)<<"最高学历"<<setw(10)<<"任职时间"
<<setw(10)<<"来院时间"<<endl;
while(!filem.eof())
{
filem>>zz[x].getbianhao();
filem>>zz[x].gettype();
filem>>zz[x].getname();
filem>>zz[x].getsex();
filem>>zz[x].getage();
filem>>zz[x].getzhiwu();
filem>>zz[x].getzhichen();
filem>>zz[x].getzzmm();
filem>>zz[x].getzgxl();
filem>>zz[x].getrzsj();
filem>>zz[x].getlysj();
cout<<zz[x].getbianhao()<<setw(9)<<zz[x].gettype()<<setw(5)<<zz[x].getname()
<<setw(5)<<zz[x].getsex()<<setw(5)<<zz[x].getage()
<<setw(5)<<zz[x].getzhiwu()<<setw(5)<<zz[x].getzhichen()
<<setw(9)<<zz[x].getzzmm()<<setw(10)<<zz[x].getzgxl()
<<setw(10)<<zz[x].getrzsj()<<setw(10)<<zz[x].getlysj()<<endl;
x++;
}
x1=--x;
filem.close();
}
void person::tongji()
{
int a=0;int b=0;int c=0;int d=0;
int x=1;
ifstream filem("添加人员.txt",ios_base::in);
while(!filem.eof())
{
filem>>zz[x].getnum();
filem>>zz[x].gettype();
filem>>zz[x].getname();
filem>>zz[x].getsex();
filem>>zz[x].getage();
filem>>zz[x].getzhiwu();
filem>>zz[x].getzhichen();
filem>>zz[x].getzzmm();
filem>>zz[x].getzgxl();
filem>>zz[x].getrzsj();
filem>>zz[x].getlysj();
if(strcmp(zz[x].gettype(),"行政人员")==0||strcmp(zz[x].gettype(),"教师")==0||
strcmp(zz[x].gettype(),"一般员工")==0)
a++;
if(strcmp(zz[x].getzzmm(),"党员")==0)
b++;
if(strcmp(zz[x].getsex(),"nv")==0)
c++;
if(strcmp(zz[x].getzgxl(),"boshi")==0)
d++;
x++;
}
cout<<"在职人数"<<setw(12)<<"党员人数"<<setw(12)<<"女工人数"<<setw(12)<<"高学历人数"<<endl;
cout<<a<<setw(12)<<b<<setw(12)<<c<<setw(12)<<d<<endl;
filem.close();
}
void menu()
{
person zyx;
int c;
cout << endl;
cout << " 高校人事管理系统 "<<endl;
cout << " "<<endl;
cout << " 1 - 添加人员信息 "<<endl;
cout << " 2 - 删除人员信息 "<<endl;
cout << " 3 - 修改人员信息 "<<endl;
cout << " 4 - 查询人员信息 "<<endl;
cout << " 5 - 统计人员信息 "<<endl;
cout << " 6 - 保存人员信息 "<<endl;
cout << " 7 - 退出 "<<endl;
cout << " "<<endl;
cout << " 请选择(1-7) "<<endl;
cin>>c;
switch(c)
{
case 1: zyx.tjry();menu();break;
case 2:zyx.shanchu();menu(); break;
case 3:zyx.xiugai();menu(); break;
case 4:zyx.find() ;cout<<endl<<endl; menu();break;
case 5:zyx.tongji();menu(); break;
case 6:zyx.output();menu();break;
case 7:exit(1);break;
}
}
void main()
{
menu();
}
[此贴子已经被作者于2015-12-11 15:35编辑过]