📄 renshiguanli.cpp
字号:
#include<iostream.h>
#include<string.h>
#include<iomanip.h>
#include<fstream.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int k=1,i; //定义一个标志变量
class birthday{ //定义出生年月日类
public:
int year;
int month;
int day;
};
class people{ //声明人员基类,以后在这个基础上派生出其它类
public:
people(){}
virtual void enter(); //虚基函数,搭成一个框架,以后在此基础上扩充
virtual void display();
virtual int get_no(){return number;}
virtual char * get_name(){return name;}
virtual void change_infor(){} //信息修改函数
virtual void readfile(){} //从文件中读
virtual void write(){} //将信息写入文件
people operator = (people p1); //运算符重载
int operator == (people p1);
virtual ~people(){};
protected:
char name[12];
int number;
char sex;
birthday bir;
char id[15];
};
people people::operator =(people p1){ //定义运算符重载
strcpy(name,p1.name); number=p1.number; sex=p1.sex; bir.day=p1.bir.day;
bir.month=p1.bir.month; bir.year=p1.bir.year;
strcpy(id,p1.id);
return p1;
}
int people::operator ==(people p1){
if(id==p1.id) return 1;
else return 0;
}
void people::enter(){ //定义信息输入函数
cout<<"输入姓名:"; cin>>name;
cout<<"输入编号:"; cin>>number;
cout<<"输入性别:"; cin>>sex;
cout<<"生日是(年 月 日):"; cin>>bir.year>>bir.month>>bir.day;
cout<<"身份证号:";cin>>id;
}
void people::display(){ //定义信息显示函数
cout<<setw(8)<<"姓名"<<setw(8)<<"编号"<<setw(8)<<"性别"<<setw(8)<<"出生日期"<<setw(8)<<"身份证号"<<endl;
cout<<setw(8)<<name<<setw(8)<<number<<setw(8)<<sex<<setw(8)<<bir.year<<setw(8)<<bir.month<<setw(8)<<bir.day<<setw(8)<<id<<endl;
}
class student:virtual public people{ //以公有方式派生出学生类
protected:
char classnumber[20];
public:
student(){}
virtual void enter(){people::enter();cout<<"输入班级名称:";cin>>classnumber;}
virtual void display();
virtual void readfile();
virtual void write();
virtual void change_infor();
virtual ~student(){};
};
class teacher:virtual public people{ //以公有方式派生出老师类
protected:
char principalship[16];
char department[16];
public:
teacher(){}
virtual void enter(){people::enter();cout<<"输入老师的职务:";cin>>principalship;cout<<"\n输入老师所在的部门:";cin>>department;}
virtual void display();
virtual void readfile();
virtual void write();
virtual void change_infor();
virtual ~teacher(){}
};
class graduate:virtual public student{ //以公有方式派生出研究生类
protected:
char subject[16];
teacher adviser;
public:
graduate(){};
virtual void enter(){student::enter();cout<<"输入研究生的专业:";cin>>subject;cout<<"输入导师的情况:"<<endl;adviser.enter();}
virtual void display();
virtual void readfile();
virtual void write();
virtual void change_infor();
virtual ~graduate(){};
};
class teacher_asistant:public teacher,public graduate{ //以公有方式派生出助教类
public:
teacher_asistant(){};
virtual void enter(){graduate::enter();cout<<"请输入助教生所在职务:";cin>>principalship;cout<<"请输入所在部门:";cin>>department;}
virtual void display();
virtual void readfile();
virtual void write();
virtual void change_infor();
virtual ~teacher_asistant(){}
};
void student::display(){ //定义派生类学生的信息显示函数
cout<<setw(8)<<"姓名"<<setw(8)<<"编号"<<setw(5)<<"性别"<<setw(12)<<"出生日期"<<setw(12)<<"身份证号"<<setw(12)<<"班级名称"<<endl;
cout<<setw(8)<<name<<setw(8)<<number<<setw(5)<<sex<<setw(4)<<bir.year<<setw(4)<<bir.month<<setw(4)<<bir.day<<setw(10)<<id<<setw(12)<<classnumber<<endl;
}
void student::write(){ //定义派生类学生的信息写入文件函数
student stu;
char ch;
ofstream myfile("student.txt",ios::app);
do{
stu.enter();
myfile.write((char *)&stu,sizeof(stu));
cout<<"还需要输入下个学生的信息吗(y/n):";
cin>>ch;}while(ch=='y'||ch=='Y');
myfile.close();
}
void student::readfile(){ //定义派生类学生的读文件函数
ifstream myfile("student.txt",ios::nocreate);
while(myfile){
student stu;
if(myfile.read((char*)&stu,sizeof(stu))){
if(stu.number!=-1) //删除一个学生的信息,通过不显示来定义删除
stu.display();
}
}
myfile.close();
}
void student::change_infor(){ //定义派生类学生的信息修改函数
student stu;
int num,p;
cout<<"请输入你要修改或者删除的学生的编号:";
cin>>num;
fstream myfile("student.txt",ios::in|ios::out);
while(myfile.good()){
myfile.read((char*)&stu,sizeof(stu));
if(num==stu.number){
myfile.seekg(-sizeof(stu),ios::cur);
cout<<"你是要修改还是要删除该学生的记录(1:删除 2:修改):";
cin>>p;
if(p==1){stu.number=-1;break;}
else {
cout<<"请输入新的信息"<<endl;
stu.enter();break;
}
}
}
myfile.write((char *)&stu,sizeof(stu));
myfile.close();
}
void teacher::display(){
cout<<setw(8)<<"姓名"<<setw(8)<<"编号"<<setw(5)<<"性别"<<setw(12)<<"出生日期"<<setw(12)<<"身份证号"<<setw(10)<<"职务"<<setw(10)<<"部门"<<endl;
cout<<setw(8)<<name<<setw(8)<<number<<setw(5)<<sex<<setw(4)<<bir.year<<setw(4)<<bir.month<<setw(4)<<bir.day<<setw(12)<<id<<setw(10)<<principalship<<setw(10)<<department<<endl;
}
void teacher::readfile(){
ifstream myfile("teacher.txt",ios::nocreate);
while(myfile){
people *p;
teacher tec;p=&tec;
if(myfile.read((char*)&tec,sizeof(tec))){
if(tec.number!=-1)
p->display();
}
}
myfile.close();
}
void teacher::write(){
teacher tec;
char ch;
ofstream myfile("teacher.txt",ios::app);
do{
tec.enter();
myfile.write((char *)&tec,sizeof(tec));
cout<<"还需要输入下个学生的信息吗(y/n):";
cin>>ch;}while(ch=='y'||ch=='Y');
myfile.close();
}
void teacher::change_infor(){
teacher tec;
int num,p;
cout<<"请输入你要修改或者删除的老师的编号:";
cin>>num;
fstream myfile("teacher.txt",ios::in|ios::out);
while(myfile.good()){
myfile.read((char*)&tec,sizeof(tec));
if(num==tec.number){
myfile.seekg(-sizeof(tec),ios::cur);
cout<<"你是要修改还是要删除该老师的记录(1:删除 2:修改):";
cin>>p;
if(p==1){tec.number=-1;break;}
else {
cout<<"请输入新的信息"<<endl;
tec.enter();break;
}
}
}
myfile.write((char *)&tec,sizeof(tec));
myfile.close();
}
void graduate::display(){
cout<<setw(8)<<"姓名"<<setw(8)<<"编号"<<setw(5)<<"性别"<<setw(12)<<"出生日期"<<setw(8)<<"身份证号"<<setw(8)<<"班级名称"<<setw(10)<<"专业"<<endl;
cout<<setw(8)<<name<<setw(8)<<number<<setw(5)<<sex<<setw(4)<<bir.year<<setw(4)<<bir.month<<setw(4)<<bir.day<<setw(8)<<id<<setw(8)<<classnumber<<setw(10)<<subject<<endl;
cout<<"他的导师的情况是:"<<endl;
adviser.display();
}
void graduate::readfile(){
ifstream myfile("graduate.txt",ios::nocreate);
while(myfile){
people *p;
graduate gra;p=&gra;
if(myfile.read((char*)&gra,sizeof(gra))){
if(gra.number!=-1)
p->display();
}
}
myfile.close();
}
void graduate::write(){
graduate gra;
char ch;
ofstream myfile("graduate.txt",ios::app);
do{
gra.enter();
myfile.write((char *)&gra,sizeof(gra));
cout<<"还需要输入下个研究生的信息吗(y/n):";
cin>>ch;}while(ch=='y'||ch=='Y');
myfile.close();
}
void graduate::change_infor(){
graduate gra;
int num,p;
cout<<"请输入你要修改或者删除的研究生的编号:";
cin>>num;
fstream myfile("graduate.txt",ios::in|ios::out);
while(myfile.good()){
myfile.read((char*)&gra,sizeof(gra));
if(num==gra.number){
myfile.seekg(-sizeof(gra),ios::cur);
cout<<"你是要修改还是要删除该研究生的记录(1:删除 2:修改):";
cin>>p;
if(p==1){gra.number=-1;break;}
else {
cout<<"请输入新的信息"<<endl;
gra.enter();break;
}
}
}
myfile.write((char *)&gra,sizeof(gra));
myfile.close();
}
void teacher_asistant::display(){
cout<<setw(8)<<"姓名"<<setw(8)<<"编号"<<setw(5)<<"性别"<<setw(12)<<"出生日期"<<setw(12)<<"身份证号"<<setw(8)<<"班级名称"<<setw(10)<<"专业"<<setw(10)<<"职务"<<setw(10)<<"部门"<<endl;
cout<<setw(8)<<name<<setw(8)<<number<<setw(5)<<sex<<setw(4)<<bir.year<<setw(4)<<bir.month<<setw(4)<<bir.day<<setw(8)<<id<<setw(8)<<classnumber<<setw(10)<<subject<<setw(10)<<principalship<<setw(10)<<department<<endl;
cout<<"他的导师的情况是:"<<endl;
adviser.display();
}
void teacher_asistant::readfile(){
ifstream myfile("tec_asistant.txt",ios::nocreate);
while(myfile){
people *p;
teacher_asistant tec_asis;p=&tec_asis;
if(myfile.read((char*)&tec_asis,sizeof(tec_asis))){
if(tec_asis.number!=-1)
p->display();
}
}
myfile.close();
}
void teacher_asistant::write(){
teacher_asistant tec_asis;
char ch;
ofstream myfile("tec_asistant.txt",ios::app);
do{
tec_asis.enter();
myfile.write((char *)&tec_asis,sizeof(tec_asis));
cout<<"还需要输入下个助教生的信息吗(y/n):";
cin>>ch;}while(ch=='y'||ch=='Y');
myfile.close();
}
void teacher_asistant::change_infor(){
teacher_asistant tec_asis;
int num,p;
cout<<"请输入你要修改或者删除的助教生的编号:";
cin>>num;
fstream myfile("tec_asistant.txt",ios::in|ios::out);
while(myfile.good()){
myfile.read((char*)&tec_asis,sizeof(tec_asis));
if(num==tec_asis.number){
myfile.seekg(-sizeof(tec_asis),ios::cur);
cout<<"你是要修改还是要删除该助教生的记录(1:删除 2:修改):";
cin>>p;
if(p==1){tec_asis.number=-1;break;}
else {
cout<<"请输入新的信息"<<endl;
tec_asis.enter();break;
}
}
}
myfile.write((char *)&tec_asis,sizeof(tec_asis));
myfile.close();
}
void menu()
{
cout<<"\t *******************************************************"<<endl;
cout<<"\n\n\t\t**************************************************"<<endl;
cout<<"\t\t*\t !!!欢迎进入人事管理系统!!!\t *"<<endl;
cout<<"\t\t*------------------------------------------------*"<<endl;
cout<<" \t\t* 1.人事信息录入 2.显示人事信息 *"<<endl;
cout<<" \t\t* 3.信息的修改或删除 4.返回主菜单 0.退出*"<<endl;
cout<<"\t\t**************************************************"<<endl;
cout<<" \t\t\t\t请选择操作(0=======4) "<<endl;
cout<<"\t\t\t\t 请选择:";
}
void select(){
people *pt;student st; teacher te; graduate gr; teacher_asistant t_a;
if(i==1) pt=&st;
else if(i==2) pt=&gr;
else if(i==3) pt=&te;
else if(i==4) pt=&t_a;
do{
int ch;
cin>>ch;
switch(ch){
case 0:exit(0);
case 1:pt->write();cout<<"你还想进行何种操作:";break;
case 2:pt->readfile();cout<<"你还想进行何种操作:";break;
case 3:pt->change_infor();cout<<"你还想进行何种操作:";break;
case 4:k=0;break;
default:cout<<"你的选择错误,请重新选择:";break;
}}while(k);
}
void main(){
b:
cout<<"\t *******************************************************"<<endl;
cout<<"\n\n\t\t**************************************************"<<endl;
cout<<"\t\t*\t !!!欢迎进入人事管理系统!!!\t *"<<endl;
cout<<"\t\t*------------------------------------------------*"<<endl;
cout<<"\t\t* 1:学生 *"<<endl;
cout<<"\t\t* 2:研究生 *"<<endl;
cout<<"\t\t* 3:教师 *"<<endl;
cout<<"\t\t* 4:助教 *"<<endl;
cout<<"\t\t* 0:退出 *"<<endl;
cout<<" **************************************************"<<endl;
cout<<"请选择(0---4):";
cin>>i;
switch(i){
case 0:cout<<"你已经退出系统,欢迎你再次使用。";getch();exit(0);
case 1:{system("cls");menu();select();break;}
case 2:{system("cls");menu();select();break;}
case 3:{system("cls");menu();select();break;}
case 4:{system("cls");menu();select();break;}
default :cout<<"不好意思,你的选择错误,请重新选择:";break;
}
if(k==0)
k=1;
system("cls");
goto b;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -