标题:C++一个管理系统,怎么样在类定义里增加一个工资,并在添加人员或统计里面显 ...
只看楼主
流光溢彩丿
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2015-6-3
结帖率:25%
已结贴  问题点数:10 回复次数:5 
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编辑过]

搜索更多相关主题的帖子: 管理系统 private include person public 
2015-12-11 13:26
流光溢彩丿
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2015-6-3
得分:0 
c:\Program Files (x86)\Microsoft Visual Studio\MyProjects\4\4.cpp(176) : fatal error C1001: INTERNAL COMPILER ERROR
        (compiler file 'msc1.cpp', line 1786)
         Please choose the Technical Support command on the Visual C++
         Help menu, or open the Technical Support help file for more information
执行 cl.exe 时出错.

4.exe - 1 error(s), 0 warning(s)
这个是报错类型
2015-12-11 13:28
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:10 
重编译呗
2015-12-11 13:38
流光溢彩丿
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2015-6-3
得分:0 
回复 3楼 rjsp
百度了编译错误,还是调试不出来
2015-12-11 14:58
流光溢彩丿
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2015-6-3
得分:0 
就在类的定义里加加了一个工资,然后在后面的函数里面都加了一char gongzi[10],错误就出现了,调试也调试不不出来。
2015-12-11 15:16
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:0 
以下是引用流光溢彩丿在2015-12-11 14:58:15的发言:

百度了编译错误,还是调试不出来
听不懂你在说什么,你这是编译错误,哪来的编译错误?再者,就算编译错误吧,和“调试”又有什么关系?

我从来没提你的编译错误,因为我觉得你这代码吧,……,不排版的代码就是故意用于藏错误的。
如果这代码是别人用来害你的,你自己排版一下,轻易就会发现 void person::xiugai() 的实现部分缺少“右大括号”
2015-12-11 15:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-460114-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.220601 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved