C++实现高校人事管理系统

功能介绍

\quad 使用 C + + C++ C++实现高校人事管理系统,主要功能为人员输入,查询,编辑,删除,统计功能。

C++程序

#include <iostream>
#include<string.h>
#include<stdlib.h>
#include<windows.h>
#include<fstream>

#define n 10
using namespace std;
int check=0;
int number;
int m;
int postnum=0;//在职人数
int stanum=0;//党员人数
int womennum=0;//女性人数
int counts=0;
class person
{
    
    

public:
    person(char *NUM,char *NAME,char *SEX,char *AGE,char *STATUS,char *EDUCATION);
    ~person(){
    
    }
    void  set_num(char *NUM);
    void  set_name(char *NAME);
    void  set_sex(char *SEX);
    void  set_age(char *AGE);
    void  set_status(char *STSTUS);
    void  set_education(char *EDUCATION);
    void show();
    char *num;//编号
    char *name;//名字
    char *sex;//性别
    char *age;//年龄
    char *status;//政治面貌
    char *education;//学历
    //static int counts;

};
//int person::counts=0;
person::person(char *NUM=" ",char *NAME=" ",char *SEX=" ",char *AGE=" ",char *STATUS=" ",char *EDUCATION=" ")
{
    
    
    if(NUM)
    {
    
    
       num=new char[strlen(NUM)+1];
        strcpy(num,NUM);
    }
    else num=0;
    //*****如果num是数组形式*****//
    //if(num)
    //strcpy(num,NUM);
    //else strcpy(num," ");
    if(NAME)
    {
    
    
       name=new char[strlen(NAME)+1];//并不知道name能否装下NAME
        strcpy(name,NAME);//故必须动态申请空间
    }
    else name=0;

    if(SEX)
    {
    
    
       sex=new char[strlen(SEX)+1];
        strcpy(sex,SEX);
    }
    else sex=0;
    if(AGE)
    {
    
    
       age=new char[strlen(AGE)+1];
        strcpy(age,AGE);
    }
    else age=0;

    if(STATUS)
    {
    
    
       status=new char[strlen(STATUS)+1];
        strcpy(status,STATUS);
    }
    else status=0;

    if(EDUCATION)
    {
    
    
       education=new char[strlen(EDUCATION)+1];
        strcpy(education,EDUCATION);
    }
    else education=0;

    counts++;

}
void person::set_num(char *NUM)
{
    
    
   strcpy(num,NUM);
}
void person::set_name(char *NAME)
{
    
    
   strcpy(this->name,NAME);
}
void person::set_sex(char *SEX)
{
    
    
    strcpy(this->sex,SEX);

}
void person::set_age(char *AGE)
{
    
    
   strcpy(this->age,AGE);

}
void person::set_status(char *STATUS)
{
    
    
    strcpy(this->status,STATUS);
}

void person::set_education(char *EDUCATION)
{
    
    
   strcpy(this->education,EDUCATION);
}

void person::show()
{
    
    
    cout<<"编号:"<<this->num<<endl;
    cout<<"姓名:"<<this->name<<endl;
    cout<<"性别:"<<this->sex<<endl;
    cout<<"年龄:"<<this->age<<endl;
    cout<<"政治身份:"<<this->status<<endl;
    cout<<"学历:"<<this->education<<endl;
}


class teacher:public person
{
    
    

public:
    teacher(char *NUM=" ",char *NAME=" ",char *SEX=" ",char *AGE=" ",char *STATUS=" ",char *EDUCATION=" ",char *POST=" ",char *TITLE=" ",char *POSTTIME=" ",char *TIME=" ");
    ~teacher(){
    
    }
    void show_teacher();
    friend ostream& operator << (ostream &,  teacher&);
    friend istream& operator >> (ostream &,  teacher&);
    char *post;
    char *title;
    char *post_time;
    char *time;
    void edit1();
    //istream& operator >>(char *);
    //ostream& operator <<(char *);
};

teacher T[10*n];
void display()
{
    
    
    cout<<"********"<<"高校人事管理系统"<<"********"<<endl;
    cout<<endl;
    cout<<"********"<<"   1 删除功能   "<<"********"<<endl;
    cout<<endl;
    cout<<"********"<<"   2 查询功能   "<<"********"<<endl;
    cout<<endl;
    cout<<"********"<<"   3 编辑功能   "<<"********"<<endl;
    cout<<endl;
    cout<<"********"<<"   4 统计功能   "<<"********"<<endl;
    cout<<endl;
    cout<<"********"<<"   5 保存功能   "<<"********"<<endl;
    cout<<endl;
    cout<<"********"<<"   6 输入人员   "<<"********"<<endl;
    cout<<endl;
    cout<<"********"<<"   0 退出系统   "<<"********"<<endl;
    cout<<endl;
    cout<<"***"<<"输入相应数字,进入相应功能"<<"***"<<endl;


}
teacher::teacher(char *NUM,char *NAME,char *SEX,char *AGE,char *STATUS,char *EDUCATION,char *POST,char *TITLE,char *POSTTIME,char *TIME):person(NUM,NAME,SEX,AGE,STATUS,EDUCATION)
{
    
    
        if(POST)
        {
    
    
         post=new char[strlen(POST)+1];
        strcpy(post,POST);
        }
        else post=0;
        if(TITLE)
        {
    
    
         title=new char[strlen(TITLE)+1];
         strcpy(title,TITLE);
        }
        else title=0;
        if(POSTTIME)
        {
    
    
         post_time=new char[strlen(POSTTIME)+1];
         strcpy(post_time,TITLE);
        }
        else post_time=0;
        if(TIME)
        {
    
    
         time=new char[strlen(TIME)+1];
         strcpy(time,TIME);
        }
        else time=0;

    }


void teacher::show_teacher()
{
    
    
    show();
    cout<<"职位:"<<this->post<<endl;
    cout<<"职称:"<<this->title<<endl;
    cout<<"任职时间:"<<this->post_time<<endl;
    cout<<"来校时间:"<<this->time<<endl;

}
istream& operator >> (istream& input,  teacher&c)
{
    
    
	cout<<"输入人员信息:"<<endl;
	cout<<"编号:";
	//cin>>c.num;
	input>>c.num;
	//if(*c.num=='*')//****" "与' '的区别
	/*if(!strcmp(c.num,"退出"))//**字符串判断相等
	{
    
    
        cout<<"输入停止!"<<endl;
        while(1);
	}*/
	cout<<endl;
	cout<<"姓名:";
	input>>c.name;
	cout<<endl;
	cout<<"性别:";
	input>>c.sex;
	cout<<endl;
	cout<<"年龄:";
	input>>c.age;
	cout<<endl;
	cout<<"职务:";
	input>>c.post;
	cout<<endl;
	cout<<"职称:";
	input>>c.title;
	cout<<endl;
	cout<<"政治面貌:";
	input>>c.status;
	cout<<endl;
	cout<<"学历:";
	input>>c.education;
	cout<<endl;
	cout<<"任职时间:";
	input>>c.post_time;
	cout<<endl;
	cout<<"来校时间:";
	input>>c.time;
	cout<<endl;
	return input;
}
ostream& operator << (ostream& output,  teacher&c)
{
    
    
	output<<"人员信息:";
	output<<"编号:";
	//cout<<c.num;
	output<<c.num;
	output<<endl;
	output<<"姓名:";
	output<<c.name;
	output<<endl;
	output<<"性别:";
	output<<c.sex;
	output<<endl;
	output<<"年龄:";
	output<<c.age;
	output<<endl;
	output<<"职务:";
	output<<c.post;
	output<<endl;
	output<<"职称:";
	output<<c.title;
	output<<endl;
	output<<"政治面貌:";
	output<<c.status;
	output<<endl;
	output<<"学历:";
	output<<c.education;
	output<<endl;
	output<<"任职时间:";
	output<<c.post_time;
	output<<endl;
	output<<"来校时间:";
	output<<c.time;
	return output;
}

void edit();
void start();
void cinin();
void statics();
void store();
void teacher::edit1()
{
    
    
        int z,s,d;
        char *SEX1=new char[100];
        cout<<"请重新输入员工信息:"<<endl;
        cout<<"编号:";
        cin.sync();//先清除缓冲区
        cin>>num;
        cin.get();
        cout<<"姓名:";
        cin.sync();
        cin>>name;
        cin.get();
        cout<<"性别:";
        cin.sync();
        if(strcmp(this->sex,"女性")==0||strcmp(this->sex,"女")==0)
            s=1;
        cin>>sex;
        if(((!strcmp(this->sex,"女性")||!strcmp(this->sex,"女")))&&s!=1)
        womennum++;
        cin.get();
        //strcmp(sex,SEX1);
        cout<<"年龄:";
        cin.sync();
        cin>>age;
        cin.get();
        cout<<"职务:";
        cin.sync();
        cin>>post;
        cin.get();
        cout<<"职称:";
        cin.sync();
        cin>>title;
        cin.get();
        cout<<"政治面貌:";
        cin.sync();
        if(strcmp(this->status,"党员")==0)
            d=1;
        cin>>status;
        if(!strcmp(this->status,"党员")&&s!=1)
        stanum++;
        cin.get();
        cout<<"学历:";
         cin.sync();
        cin>>education;
        cin.get();
        cout<<"任职时间:";
        cin.sync();
        cin>>post_time;
        cin.get();
        cout<<"来校时间:";
        cin.sync();
        cin>>time;
        cin.get();
        cout<<"继续编辑请输入1,退出编辑请输入0"<<endl;
        cin.sync();//清除缓冲区,不然直接执行case 6
        cin>>z;
        switch(z)
        {
    
    
            case 1:edit();
            case 0:start();
        }


}

void cinin()
{
    
    
    int j;
    ofstream outfile;
    outfile.open("D:\\teacher.txt");
    cout<<"请输入人员数量:"<<endl;
    cin>>number;
    postnum=number;
    for(j=0;j<=number-1;j++)
    {
    
    
        cout<<"请输入第"<<j+1<<"个员工信息:"<<endl;
        cin>>T[j];
       // if(strcmp(T[j].num,"\n"))
        //T[j].num=(T[j-1].num)+1;
        if(!strcmp(T[j].status,"党员"))
        stanum++;
        if(!strcmp(T[j].sex,"女性")||!strcmp(T[j].sex,"女"))
        womennum++;
        outfile<<T[j];//((char *)&temp,sizeof(temp));
    }
    outfile.close();
}

void delete_teacher()
{
    
    
    cout<<"请输入删除第几位员工"<<endl;
    int i,a,z;
    cin.sync();//清除缓冲区
    cin>>a;
    if(!strcmp(T[a].status,"党员"))
        stanum--;
    if(!strcmp(T[a].sex,"女性")||(strcmp(T[a].sex,"女")))
        womennum--;
    for(i=a-1;i<number;i++)
       T[i]=T[i+1];
       T[number]=0;
    cout<<"删除成功!"<<endl;
    delete &T[number];
    postnum--;
    cout<<"继续删除请输入1,退出删除请输入0"<<endl;
    cin.sync();//清除缓冲区,不然直接执行case 6
    cin>>z;
        switch(z)
        {
    
    
            case 1:delete_teacher();
            case 0:start();
        }

}

void inquiry()
{
    
    
    int i,z;//必须要动态申请空间,char,数组大小是固定的,所以小面可以比较
    char *s=new char[100];//为什么可以用数组*********为什么不能用char *//
    cout<<"请输入要查询员工编号或名字:"<<endl;
    cin>>s;
    cin.get();
    for(i=0;i<number;i++)
    {
    
    
       if((strcmp(s,(T[i].num))==0||strcmp(s,(T[i].name))==0))
      // if(s==*T[i].num||s==*T[i].name)
        {
    
    
            cout<<"您查询的员信息:";
            cout<<T[i]<<endl;
            counts++;
        }
    }
        if(counts==0)
            cout<<"查询失败!"<<endl;
        cout<<"继续查询请输入1,退出查询请输入0"<<endl;
        cin.sync();//清除缓冲区,不然直接执行case 6
        cin>>z;
        switch(z)
        {
    
    
            case 1:inquiry();
            case 0:start();
        }

}

void start()
{
    
    
    while(1)
    {
    
    
    system("cls");
    display();
    cout<<"请输入:"<<endl;
    cin>>m;
    system("cls");
    switch(m)
    {
    
    
        case 0: exit(0);
        case 1: delete_teacher();
        case 2: inquiry();
        case 3: edit();
        case 4: statics();
        case 5: store();
        case 6: cinin();
    }
   }
}


void edit()
{
    
    
    cout<<"请输入编辑员工的编号或名字:"<<endl;
    char s;
    cin>>s;
    cin.sync();
    int i,z;
    for(i=0;i<10*n;i++)
    {
    
    
         if(s==*T[i].num||s==*T[i].name)
         T[i].edit1();
    }
       cout<<"继续编辑请输入1,退出编辑请输入0"<<endl;
        cin.sync();//清除缓冲区,不然直接执行case 6
        cin>>z;
        switch(z)
        {
    
    
            case 1:edit();
            case 0:start();
        }

}
void statics()
{
    
    
    int z;
    cout<<"在职人数:"<<endl;
    cout<<postnum<<endl;
    cout<<"党员人数:"<<endl;
    cout<<stanum<<endl;
    cout<<"女性人数:"<<endl;
    cout<<womennum<<endl;
        cout<<"继续统计请输入1,退出统计请输入0"<<endl;
        cin.sync();//清除缓冲区,不然直接执行case 6
        cin>>z;
        switch(z)
        {
    
    
            case 1:statics();
            case 0:start();
        }
}
void store()
{
    
    
        int i,z;
        fstream infile;
        infile.open("D:\\teacher.txt");
        for(i=0;i<postnum;i++)
        infile<<T[i];
        infile.close();
        cout<<"已保存!"<<endl;
        cout<<"退出保存请输入0"<<endl;
        cin.sync();//清除缓冲区,不然直接执行case 6
        cin>>z;
        switch(z)
        {
    
    

            case 0:start();
        }
}

int main()
{
    
    

    void display();
    void cinin();
    void inquiry();
    void returns();
    void start();
    void edit();
    void statics();
    void store();
    start();

    return 0;
}

实验结果

主界面

在这里插入图片描述

人员查询

在这里插入图片描述

人员统计

在这里插入图片描述

人员编辑

在这里插入图片描述

人员查询

在这里插入图片描述

参考文献

  1. 王珊珊, 臧冽, 张志航.《C++程序设计教程》. 机械工业出版社, 2010.
  2. 谭浩强.《C++面向对象程序设计》. 清华大学出版社, 2014.

猜你喜欢

转载自blog.csdn.net/qq_41982200/article/details/109258699