设计一个程序,对高校人员的信息进行管理。通过该系统实现对人员
基本信息的录入、保存、删除、修改、查询等操作。
设计要求及提示如下:
1、高校人员信息包括:工号、姓名、性别、类别(分为教师、教辅、行政)、系别、专业、职称等。
2、使用类和对象的概念实现程序设计。
3、以菜单形式显示各功能项。
4、各功能项如下:
1)人员基本信息的录入 。
2)人员基本信息的删除。
3)人员基本信息的修改。
4)人员基本信息的查询。
a)按工号查询个人信息;
(b)按姓名查询个人信息;
(c)按性别查询人员信息;
(d)按类别查询人员信息;
5)人员基本信息的统计。
(a)按性别统计人员人数;
(b)按系别统计人员人数;
(c)按类别统计人员人数;
(d)按职称统计人员人数;
6)退出系统。
5、执行某个功能之后,程序将重新显示菜单供用户选择。
6、将高校人员信息保存到文件中
为了使得代码多样化,我们先单独定义头文件:
//头文件集合
#pragma once
#ifndef TWJJH
#define TWJJH
#include<iostream>
#include<string>
#include<conio.h>
#include<windows.h>
#include<fstream>
#include<vector>
#include<iomanip>
using namespace std;
#endif
头文件集合
#pragma once
#ifndef JS
#define JS
#include"头文件集合.h"
#include"员工父类.h"
class js :virtual public yuangong {
public:
void set(int num1, string name1, string sex1, int age1, string suozaixibu1, string zhuanye1, string zhicheng1);
void get();
void wj();
string suozaixibu;
string zhuanye;
string zhicheng;
};
#endif
教师头文件
#pragma once
#ifndef SYS
#define SYS
#include"头文件集合.h"
#include"员工父类.h"
class sys :public yuangong {
public:
void set(int num1, string name1, string sex1, int age1, string shiyanshi1, string zhiwu1);
void get();
void wj();
string shiyanshi;
string zhiwu;
};
#endif
实验员
#pragma once
#ifndef XZRY
#define XZRY
#include"头文件集合.h"
#include"员工父类.h"
class xzry :virtual public yuangong {
public:
void set(int num1, string name1, string sex1, int age1, string zhengzhimianmao1, string zhicheng1);
void get();
void wj();
string zhengzhimianmao;
string zhicheng;
};
#endif
行政人员
#pragma once
#ifndef JSJ
#define JSJ
#include"头文件集合.h"
#include"员工父类.h"
#include"1.教师.h"
#include"3.行政人员.h"
class jsjxzry :virtual public xzry ,virtual public js{
public:
void set(int num1, string name1, string sex1, int age1, string suozaixibu1, string zhuanye1, string zhicheng1, string zhengzhimianmao1);
void get();
void wj();
string zhicheng;
};
#endif
教师兼行政人员
#include"头文件集合.h"
#include"4.教师兼行政人员.h"
void jsjxzry::set(int num1, string name1, string sex1, int age1, string suozaixibu1, string zhuanye1, string zhicheng1, string zhengzhimianmao1) {
num = num1;
name = name1;
sex = sex1;
age = age1;
suozaixibu = suozaixibu1;
zhuanye = zhuanye1;
zhicheng = zhicheng1;
zhengzhimianmao = zhengzhimianmao1;
}
void jsjxzry::get() {
cout << "职业:教师兼行政人员 " << "编号:";
cout << setfill(' ') << setw(3) << num << " " << "姓名:";
cout << setfill(' ') << setw(8) <<name << " " << "性别:" << sex << " " << "年龄:" << age << " " << "所在系部:" << suozaixibu << " " << "专业:" << zhuanye << " " << "职称:" << zhicheng << " " << "政治面貌:" << zhengzhimianmao << endl;
}
void jsjxzry::wj() {
ofstream ofs;
ofs.close();
ofs.open("目的文件.txt", ios::app);
ofs << "职业:教师兼行政人员" << " " << "编号:"<<num << " " <<"姓名:"<< name << " " << "性别:"<<sex << " " << "年龄:"<<age << " " <<"所在系部:"<< suozaixibu << " " <<"专业:"<< zhuanye << " " << "职称:"<<zhicheng << " " <<"政治面貌:" <<zhengzhimianmao << endl;
ofs.close();
}
教师兼行政人员
#pragma once
#ifndef YGFL
#define YGFL
#include"头文件集合.h"
class yuangong {
public:
int num;
string name;
string sex;
int age;
virtual void get() {};
virtual void wj() {};
};
#endif
员工父类
#include"头文件集合.h"
#include"1.教师.h"
void js::set(int num1, string name1, string sex1, int age1, string suozaixibu1, string zhuanye1, string zhicheng1) {
num = num1;
name = name1;
sex = sex1;
age = age1;
suozaixibu = suozaixibu1;
zhuanye = zhuanye1;
zhicheng = zhicheng1;
}
void js::get() {
cout << "职业:教师 " << "编号:";
cout << setfill(' ') << setiosflags(ios::left) << setw(3) << num << " " << "姓名:";
cout << setfill(' ') << setiosflags(ios::left) << setw(8) << name << " " << "性别:" << sex << " " << "年龄:" << age << " " << "所在系部:" << suozaixibu << " " << "专业:" << zhuanye << " " << "职称:" << zhicheng << endl;
}
void js::wj() {
ofstream ofs;
ofs.close();
ofs.open("目的文件.txt", ios::app);
ofs << "职业:教师"<<" "<< "编号:" << num << " " << "姓名:" << name << " " << "性别:" << sex << " " << "年龄:" << age << " " << "所在系部:" << suozaixibu << " " << "专业:" << zhuanye << " " << "职称:" << zhicheng << endl;
ofs.close();
}
教师
#pragma once
#ifndef GLXT
#define GLXT
#include<iostream>
#include"员工父类.h"
using namespace std;
class guanli {
public:
void biaotou();//表头输出
int srkz_gws(int a, int b);//个位数输入控制
void color(int a);//输出字体颜色控制
void jinggao();//警告输出
void jinggao2();//警告输出
void jieshu();//程序退出
bool numpd(string str);//判断一个字符串是不是都是数字
void zjry();//增加人员
void cxry();//查询人员
void xsry();//显示人员
void bjry();//修改人员
void scry();//删除人员
void tjry();//统计人员
void qcry();//清除人员
void save();//数据存入文件
void save2();//数据存入文件备份
void get();//从文件读入数据
void get2();//从备份文件读入数据
string checkbh(int x);//查询是否编号重复
string checkxm(string x);//查询是否姓名重复
void yicunzai(string jiancha);//已存在后输出已存在的职员
int shurubh();//输入编号
string shuruxm();//输入姓名
string shuruxb();//输入性别
int shurunl();//输入年龄
string shuruszxb();//输入所在系部
string shuruzy();//输入专业
string shuruzc();//输入职称
string shuruzzmm();//输入政治面貌
string shurusys();//输入实验室
string shuruzw();//输入职务
int blcxxb(string x);//查询四个数组中某性别的数量
int blcxzc(string x);//查询四个数组中某职称的数量
bool blcxbh(int x);//判断是否存储某编号的数量
int blcxnl(int x,int y);//判断有人员的年龄情况
bool wjpd(string& name);//查询文件是否存在
yuangong** zzz=NULL;//排序用指针
void lrzz();//排序用函数
int jssize();//教师数组人数
int sysize();//实验员数组人数
int xzsize();//行政人员数组人数
int jjsize();//教师兼行政人员数组人数
void mdwj();//目的文件编写
void vpx();//四个数组按分别编号从小到大排序
int xmcc(string x);//姓名查重
void xmsc();//显示所有人的姓名
};
#endif
管理系统
#pragma once
#ifndef JS
#define JS
#include"头文件集合.h"
#include"员工父类.h"
class js :virtual public yuangong {
public:
void set(int num1, string name1, string sex1, int age1, string suozaixibu1, string zhuanye1, string zhicheng1);
void get();
void wj();
string suozaixibu;
string zhuanye;
string zhicheng;
};
#endif
教师
#include"头文件集合.h"
#include"2.实验员.h"
void sys::set(int num1, string name1, string sex1, int age1, string shiyanshi1, string zhiwu1) {
num = num1;
name = name1;
sex = sex1;
age = age1;
shiyanshi = shiyanshi1;
zhiwu = zhiwu1;
}
void sys::get() {
cout << "职业:实验员 " << "编号:"<< setfill(' ') << setiosflags(ios::left) << setw(3) << num << " " << "姓名:"<<setfill(' ') << setiosflags(ios::left) << setw(8) << name<< " " << "性别:" << sex << " " << "年龄:" << age << " " << "所在实验室:" << shiyanshi << " " << "职务:" << zhiwu << endl;
}
void sys::wj() {
ofstream ofs;
ofs.close();
ofs.open("目的文件.txt", ios::app);
ofs << "职业:实验员" << " " << "编号:" << num << " " << "姓名:" << name << " " << "性别:" << sex << " " << "年龄:" << age << " " << "实验室:" << shiyanshi << " " << "职务:" << zhiwu << endl;
ofs.close();
}
实验员
#include"头文件集合.h"
#include"管理系统.h"
#include"1.教师.h"
int main() {
guanli gl;
//gl.full_screen();
gl.get();
while (1) {
gl.biaotou();
cout << "请输入所需功能前对应的数字" << endl;
string shuru;
int cdxz;
while (1) {
cin >> shuru;
if (shuru.size() >= 1 && shuru.size() <= 2 && gl.numpd(shuru)) {
if (stoi(shuru) <= 11 ){
cdxz = stoi(shuru);
break;
}
else {
gl.jinggao();
}
}
else {
gl.jinggao();
}
}
switch (cdxz) {
case 1:
gl.zjry();
system("cls");
break;
case 2:
gl.cxry();
cout << "请按任意键继续" << endl;
while (!_kbhit()) {};
system("cls");
break;
case 3:
gl.xsry();
cout << "请按任意键继续" << endl;
while (!_kbhit()) {};
system("cls");
break;
case 4:
gl.bjry();
cout << "请按任意键继续" << endl;
while (!_kbhit()) {};
system("cls");
break;
case 5:
gl.scry();
cout << "请按任意键继续" << endl;
while (!_kbhit()) {};
system("cls");
break;
case 6:
gl.tjry();
cout << "请按任意键继续" << endl;
while (!_kbhit()) {};
system("cls");
break;
case 7:
gl.save2();
cout << "备份成功" << endl;
cout << "请按任意键继续" << endl;
while (!_kbhit()) {};
system("cls");
break;
case 8:
gl.get2();
gl.color(4);
cout << "提示:若文件中数据编号与程序中已有数据编号相同,文件中数据将被舍弃;" << endl;
cout << " 若提示文件不存在,可以选择执行功能7,程序会自动生成空文件。" << endl;
gl.color(7);
cout << "请按任意键继续" << endl;
while (!_kbhit()) {};
system("cls");
break;
case 9:
gl.qcry();
system("cls");
break;
case 10:
gl.mdwj();
cout << "请按任意键继续" << endl;
while (!_kbhit()) {};
system("cls");
break;
case 11:
gl.jieshu();
break;
}
}
return 0;
}
主函数
#include"头文件集合.h"
#include"3.行政人员.h"
void xzry::set(int num1, string name1, string sex1, int age1, string zhengzhimianmao1, string zhicheng1) {
num = num1;
name = name1;
sex = sex1;
age = age1;
zhengzhimianmao = zhengzhimianmao1;
zhicheng = zhicheng1;
}
void xzry::get() {
cout << "职业:行政人员 " << "编号:";
cout << setfill(' ') << setiosflags(ios::left) << setw(3) << num << " " << "姓名:";
cout << setfill(' ') << setiosflags(ios::left) << setw(8) << name << " " << "性别:" << sex << " " << "年龄:" << age << " " << "政治面貌:" << zhengzhimianmao << " " << "职称:" << zhicheng << endl;
}
void xzry::wj() {
ofstream ofs;
ofs.close();
ofs.open("目的文件.txt", ios::app);
ofs << "职业:行政人员" << " " << "编号:" << num << " " << "姓名:" << name << " " << "性别:" << sex << " " << "年龄:" << age << " " << "政治面貌:" << zhengzhimianmao << " " << "职称:" << zhicheng << endl;
ofs.close();
}
行政人员
#include"员工父类.h"
#include"管理系统.h"
#include"1.教师.h"
#include"2.实验员.h"
#include"3.行政人员.h"
#include"4.教师兼行政人员.h"
vector<js>jiaoshijihe;
vector<sys>shiiyanyuanjihe;
vector<xzry>xzryjihe;
vector<jsjxzry>jsjxzryjihe;
void guanli::xmsc() {
for (int e = 0; e < jiaoshijihe.size(); e++) {
cout << jiaoshijihe[e].name<<endl;
}
for (int e = 0; e < shiiyanyuanjihe.size(); e++) {
cout << shiiyanyuanjihe[e].name << endl;
}
for (int e = 0; e < xzryjihe.size(); e++) {
cout << xzryjihe[e].name << endl;
}
for (int e = 0; e < jsjxzryjihe.size(); e++) {
cout << jsjxzryjihe[e].name << endl;
}
}
void guanli::vpx() {
for (int e = 0; e < jiaoshijihe.size(); e++) {
int tishen = e;
for (int ee = e; ee < jiaoshijihe.size(); ee++) {
if (jiaoshijihe[tishen].num > jiaoshijihe[ee].num) {
tishen = ee;
}
}
js a = jiaoshijihe[e];
jiaoshijihe[e] = jiaoshijihe[tishen];
jiaoshijihe[tishen] = a;
}
for (int e = 0; e < shiiyanyuanjihe.size(); e++) {
int tishen = e;
for (int ee = e; ee < shiiyanyuanjihe.size(); ee++) {
if (shiiyanyuanjihe[tishen].num > shiiyanyuanjihe[ee].num) {
tishen = ee;
}
}
sys a = shiiyanyuanjihe[e];
shiiyanyuanjihe[e] = shiiyanyuanjihe[tishen];
shiiyanyuanjihe[tishen] = a;
}
for (int e = 0; e < xzryjihe.size(); e++) {
int tishen = e;
for (int ee = e; ee < xzryjihe.size(); ee++) {
if (xzryjihe[tishen].num > xzryjihe[ee].num) {
tishen = ee;
}
}
xzry a = xzryjihe[e];
xzryjihe[e] = xzryjihe[tishen];
xzryjihe[tishen] = a;
}
for (int e = 0; e < jsjxzryjihe.size(); e++) {
int tishen = e;
for (int ee = e; ee < jsjxzryjihe.size(); ee++) {
if (jsjxzryjihe[tishen].num > jsjxzryjihe[ee].num) {
tishen = ee;
}
}
jsjxzry a = jsjxzryjihe[e];
jsjxzryjihe[e] = jsjxzryjihe[tishen];
jsjxzryjihe[tishen] = a;
}
}
void guanli::mdwj() {
cout << "请选择目的文件录入数据的方式:" << endl;
cout << "1.按照男女类" << endl;
cout << "2.按照职业分类" << endl;
cout << "3.按照姓名拼写排序" << endl;
cout << "4.按照编号从小到大的顺序" << endl;
cout << "5.按照编号从大到小的顺序" << endl;
cout << "6.按照年龄从小到大的顺序" << endl;
cout << "7.按照年龄从大到小的顺序" << endl;
cout << "8.取消录入" << endl;
int xsxz = srkz_gws(1, 8);
if (xsxz != 8) {
ofstream ofs;
ofs.close();
ofs.open("目的文件.txt", ios::trunc);
ofs.close();
}
int geshu = jssize() + sysize() + xzsize() + jjsize();
switch (xsxz) {
case 1:
lrzz();
for (int e = 0; e < geshu; e++) {
int tishen = e;
for (int ee = e + 1; ee < geshu; ee++) {
if (zzz[ee]->num < zzz[tishen]->num) {
tishen = ee;
}
}
yuangong* a = zzz[e];
zzz[e] = zzz[tishen];
zzz[tishen] = a;
}
for (int e = 0; e < geshu; e++) {
if (zzz[e]->sex == "男") {
zzz[e]->wj();
}
}
for (int e = 0; e < geshu; e++) {
if (zzz[e]->sex == "女") {
zzz[e]->wj();
}
}
break;
case 2:
vpx();
for (int e = 0; e < jiaoshijihe.size(); e++) {
jiaoshijihe[e].wj();
}
for (int e = 0; e < shiiyanyuanjihe.size(); e++) {
shiiyanyuanjihe[e].wj();
}
for (int e = 0; e < xzryjihe.size(); e++) {
xzryjihe[e].wj();
}
for (int e = 0; e < jsjxzryjihe.size(); e++) {
jsjxzryjihe[e].wj();
}
break;
case 3:
lrzz();
for (int e = 0; e < geshu; e++) {
int tishen = e;
for (int ee = e + 1; ee < geshu; ee++) {
if (zzz[ee]->name < zzz[tishen]->name) {
tishen = ee;
}
}
yuangong* a = zzz[e];
zzz[e] = zzz[tishen];
zzz[tishen] = a;
}
for (int e = 0; e < geshu; e++) {
zzz[e]->wj();
}
break;
case 4:
lrzz();
for (int e = 0; e < geshu; e++) {
int tishen = e;
for (int ee = e + 1; ee < geshu; ee++) {
if (zzz[ee]->num < zzz[tishen]->num) {
tishen = ee;
}
}
yuangong* a = zzz[e];
zzz[e] = zzz[tishen];
zzz[tishen] = a;
}
for (int e = 0; e < geshu; e++) {
zzz[e]->wj();
}
break;
case 5:
lrzz();
for (int e = 0; e < geshu; e++) {
int tishen = e;
for (int ee = e + 1; ee < geshu; ee++) {
if (zzz[ee]->num > zzz[tishen]->num) {
tishen = ee;
}
}
yuangong* a = zzz[e];
zzz[e] = zzz[tishen];
zzz[tishen] = a;
}
for (int e = 0; e < geshu; e++) {
zzz[e]->wj();
}
break;
case 6:
lrzz();
for (int e = 0; e < geshu; e++) {
int tishen = e;
for (int ee = e + 1; ee < geshu; ee++) {
if (zzz[ee]->age < zzz[tishen]->age) {
tishen = ee;
}
}
yuangong* a = zzz[e];
zzz[e] = zzz[tishen];
zzz[tishen] = a;
}
for (int e = 0; e < geshu; e++) {
zzz[e]->wj();
}
break;
case 7:
lrzz();
for (int e = 0; e < geshu; e++) {
int tishen = e;
for (int ee = e + 1; ee < geshu; ee++) {
if (zzz[ee]->age > zzz[tishen]->age) {
tishen = ee;
}
}
yuangong* a = zzz[e];
zzz[e] = zzz[tishen];
zzz[tishen] = a;
}
for (int e = 0; e < geshu; e++) {
zzz[e]->wj();
}
break;
case 8:
break;
}
if ( xsxz != 8) {
cout << "录入成功!" << endl;
}
}
void guanli::lrzz() {
if (zzz != NULL) {
delete zzz;
zzz = NULL;
}
int geshu = jssize() + sysize() + xzsize() + jjsize();
zzz = new yuangong * [jssize() + sysize() + xzsize() + jjsize()];//创建指针数组
int jsjh = jssize();
int sysjh = sysize();
int xzryjh = xzsize();
int jsjjh = jjsize();
for (int e = 0; e < jiaoshijihe.size(); e++) {
zzz[e] = &jiaoshijihe[e];
}
for (int e = 0; e < shiiyanyuanjihe.size(); e++) {
zzz[e + jsjh] = &shiiyanyuanjihe[e];
}
for (int e = 0; e < xzryjihe.size(); e++) {
zzz[e + jsjh + sysjh] = &xzryjihe[e];
}
for (int e = 0; e <jsjxzryjihe.size(); e++) {
zzz[e + jsjh + sysjh + xzryjh] = &jsjxzryjihe[e];
}
}
int guanli::jssize() {
return jiaoshijihe.size();
}
int guanli::sysize() {
return shiiyanyuanjihe.size();
}
int guanli::xzsize() {
return xzryjihe.size();
}
int guanli::jjsize() {
return jsjxzryjihe.size();
}
void guanli::biaotou() {
cout << "\t\t\t\t\t======================================" << endl;
cout << "\t\t\t\t\t|+|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|+|" << endl;
cout << "\t\t\t\t\t|+| |+|" << endl;
cout << "\t\t\t\t\t|+| 欢迎使用高校人员信息管理系统 |+|" << endl;
cout << "\t\t\t\t\t|+| |+|" << endl;
cout << "\t\t\t\t\t|+|功能列表: |+|" << endl;
cout << "\t\t\t\t\t|+| |+|" << endl;
cout << "\t\t\t\t\t|+| 1.增加员工信息 |+|" << endl;
cout << "\t\t\t\t\t|+| 2.查询员工信息 |+|" << endl;
cout << "\t\t\t\t\t|+| 3.显示员工信息 |+|" << endl;
cout << "\t\t\t\t\t|+| 4.修改员工信息 |+|" << endl;
cout << "\t\t\t\t\t|+| 5.删除员工信息 |+|" << endl;
cout << "\t\t\t\t\t|+| 6.统计员工信息 |+|" << endl;
cout << "\t\t\t\t\t|+| 7.备份员工信息 |+|" << endl;
cout << "\t\t\t\t\t|+| 8.读取备份信息 |+|" << endl;
cout << "\t\t\t\t\t|+| 9.清空员工信息 |+|" << endl;
cout << "\t\t\t\t\t|+| 10.目的文件编写 |+|" << endl;
cout << "\t\t\t\t\t|+| 11.退出程序 |+|" << endl;
cout << "\t\t\t\t\t|+| |+|" << endl;
cout << "\t\t\t\t\t|+|++++++++++++++++++++++++++++++++|+|" << endl;
cout << "\t\t\t\t\t======================================" << endl;
cout << "提示:请按照提示规范输入信息" << endl;
}
int guanli::srkz_gws(int a, int b) {
string xz;
cin>>xz;
while (xz.size() != 1 || (xz.size() == a && (xz[0] - '0' < 1 || xz[0] - '0' > b))) {
jinggao();
cin >> xz;
}
return xz[0] - '0';
}
void guanli::color(int a){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), a);
}
void guanli::jinggao() {
color(4);
cout << "警告:请输入正确的数字" << endl;
color(7);
}
void guanli::jinggao2() {
color(4);
cout << "警告:请按规定输入" << endl;
color(7);
}
void guanli::jieshu() {
cout << "感谢您的使用" << endl;
save();
Sleep(500);
exit(0);
}
bool guanli::numpd(string str)
{
for (int i = 0; i < str.size(); i++)
{
int tmp = (int)str[i];
if (tmp >= 48 && tmp <= 57)
{
continue;
}
else
{
return false;
}
}
return true;
}
void guanli::zjry() {
cout << "请选择您想添加的职工种类对应的数字" << endl;
cout << "1.教师"<<endl;
cout << "2.实验员"<<endl;
cout << "3.行政人员"<<endl;
cout << "4.教师兼行政人员"<<endl;
cout << "5.取消添加职工信息"<<endl;
int zengjia = srkz_gws(1, 5);
switch (zengjia) {
case 1:
{
int a1 = shurubh();
if (a1 == -1) {
return;
}
string a2 = shuruxm();
string a3 = shuruxb();
int a4 = shurunl();
string a5 = shuruszxb();
string a6 = shuruzy();
string a7 = shuruzc();
jiaoshijihe.resize(jiaoshijihe.size() + 1);
jiaoshijihe[jiaoshijihe.size() - 1].set(a1,a2,a3 ,a4,a5, a6,a7);
save();
break;
}
case 2: {
int a1 = shurubh();
if (a1 == -1) {
return;
}
string a2 = shuruxm();
string a3 = shuruxb();
int a4 = shurunl();
string a5 = shurusys();
string a6 = shuruzw();
shiiyanyuanjihe.resize(shiiyanyuanjihe.size() + 1);
shiiyanyuanjihe[shiiyanyuanjihe.size() - 1].set(a1, a2, a3, a4, a5, a6);
save();
break;
}
case 3: {
int a1 = shurubh();
if (a1 == -1) {
return;
}
string a2 = shuruxm();
string a3 = shuruxb();
int a4 = shurunl();
string a5 = shuruzzmm();
string a6 = shuruzc();
xzryjihe.resize(xzryjihe.size() + 1);
xzryjihe[xzryjihe.size() - 1].set(a1, a2, a3, a4, a5, a6);
save();
break;
}
case 4: {
int a1 = shurubh();
if (a1 == -1) {
return;
}
string a2 = shuruxm();
string a3 = shuruxb();
int a4 = shurunl();
string a5 = shuruszxb();
string a6 = shuruzy();
string a7 = shuruzc();
string a8 = shuruzzmm();
jsjxzryjihe.resize(jsjxzryjihe.size() + 1);
jsjxzryjihe[jsjxzryjihe.size() - 1].set(a1, a2, a3, a4, a5, a6, a7,a8);
save();
break;
}
case 5:
break;
}
if (zengjia != 5) {
cout << "添加成功!" << endl;
}
cout << "请按任意键继续" << endl;
while (!_kbhit()) {};
}
void guanli::cxry() {
cout << "请选择查询方式" << endl;
cout << "1.姓名查询" << endl;
cout << "2.编号查询" << endl;
cout << "3.姓氏查询" << endl;
cout << "4.取消查询" << endl;
int chaxunxz = srkz_gws(1, 4);
switch (chaxunxz) {
case 1:
{
cout << "请输入需要查询职员的姓名:" << endl;
string czname;
cin >> czname;
if (xmcc(czname) >= 2) {
for (int e = 0; e < jiaoshijihe.size(); e++) {
if (jiaoshijihe[e].name == czname) {
jiaoshijihe[e].get();
}
}
for (int e = 0; e < shiiyanyuanjihe.size(); e++) {
if (shiiyanyuanjihe[e].name == czname) {
shiiyanyuanjihe[e].get();
}
}
for (int e = 0; e < xzryjihe.size(); e++) {
if (xzryjihe[e].name == czname) {
xzryjihe[e].get();
}
}
for (int e = 0; e < jsjxzryjihe.size(); e++) {
if (jsjxzryjihe[e].name == czname) {
jsjxzryjihe[e].get();
}
}
break;
}
else {
string jieguo = checkxm(czname);
if (jieguo == "w") {
cout << "未查找到拥有该编号的职员" << endl;
}
else {
yicunzai(jieguo);
}
}
break;
}
case 2:
{
string bianhao;
int bhzs;
cout << "请输入需要查询职员的编号:" << endl;
cin >> bianhao;
while (1) {
if (numpd(bianhao)) {
bhzs = stoi(bianhao);
break;
}
else {
jinggao2();
cin >> bianhao;
}
}
string jieguo = checkbh(bhzs);
if (jieguo == "w") {
cout << "未查找到拥有该编号的职员" << endl;
}
else {
yicunzai(jieguo);
}
break; }
case 3:
{
cout << "请输入需要查询的姓氏:" << endl;
string czname;
cin >> czname;
for (int e = 0; e < jiaoshijihe.size(); e++) {
string zs(jiaoshijihe[e].name, 0, 2);
if (zs == czname) {
jiaoshijihe[e].get();
}
}
for (int e = 0; e < shiiyanyuanjihe.size(); e++) {
string zs(shiiyanyuanjihe[e].name, 0, 2);
if (zs == czname) {
shiiyanyuanjihe[e].get();
}
}
for (int e = 0; e < xzryjihe.size(); e++) {
string zs(xzryjihe[e].name, 0, 2);
if (zs == czname) {
xzryjihe[e].get();
}
}
for (int e = 0; e < jsjxzryjihe.size(); e++) {
string zs(jsjxzryjihe[e].name, 0, 2);
if (zs== czname) {
jsjxzryjihe[e].get();
}
}
break;
}
case 4:
break;
}
}
void guanli::xsry() {
cout << "请选择显示方式:" << endl;
cout << "1.按照男女类显示" << endl;
cout << "2.按照职业分类显示" << endl;
cout << "3.按照姓名拼写排序显示" << endl;
cout << "4.按照编号从小到大的顺序显示" << endl;
cout << "5.按照编号从大到小的顺序显示" << endl;
cout << "6.按照年龄从小到大的顺序显示" << endl;
cout << "7.按照年龄从大到小的顺序显示" << endl;
cout << "8.取消显示" << endl;
int xsxz = srkz_gws(1, 8);
int geshu= jssize() + sysize() + xzsize() + jjsize();
switch (xsxz) {
case 1:
lrzz();
for (int e = 0; e < geshu; e++) {
int tishen = e;
for (int ee = e + 1; ee < geshu; ee++) {
if (zzz[ee]->num < zzz[tishen]->num) {
tishen = ee;
}
}
yuangong* a = zzz[e];
zzz[e] = zzz[tishen];
zzz[tishen] = a;
}
for (int e = 0; e < geshu; e++) {
if (zzz[e]->sex == "男") {
zzz[e]->get();
}
}
for (int e = 0; e < geshu; e++) {
if (zzz[e]->sex == "女") {
zzz[e]->get();
}
}
break;
case 2:
vpx();
for (int e = 0; e < jiaoshijihe.size(); e++) {
jiaoshijihe[e].get();
}
for (int e = 0; e < shiiyanyuanjihe.size(); e++) {
shiiyanyuanjihe[e].get();
}
for (int e = 0; e < xzryjihe.size(); e++) {
xzryjihe[e].get();
}
for (int e = 0; e < jsjxzryjihe.size(); e++) {
jsjxzryjihe[e].get();
}
break;
case 3:
lrzz();
for (int e = 0; e < geshu; e++) {
int tishen = e;
for (int ee = e + 1; ee < geshu; ee++) {
if (zzz[ee]->name < zzz[tishen]->name) {
tishen = ee;
}
}
yuangong* a = zzz[e];
zzz[e] = zzz[tishen];
zzz[tishen] = a;
}
for (int e = 0; e < geshu; e++) {
zzz[e]->get();
}
break;
case 4:
lrzz();
for (int e = 0; e < geshu; e++) {
int tishen = e;
for (int ee = e+1; ee < geshu; ee++) {
if (zzz[ee]->num < zzz[tishen]->num) {
tishen = ee;
}
}
yuangong* a = zzz[e];
zzz[e] = zzz[tishen];
zzz[tishen] = a;
}
for (int e = 0; e < geshu; e++) {
zzz[e]->get();
}
break;
case 5:
lrzz();
for (int e = 0; e < geshu; e++) {
int tishen = e;
for (int ee = e + 1; ee < geshu; ee++) {
if (zzz[ee]->num > zzz[tishen]->num) {
tishen = ee;
}
}
yuangong* a = zzz[e];
zzz[e] = zzz[tishen];
zzz[tishen] = a;
}
for (int e = 0; e < geshu; e++) {
zzz[e]->get();
}
break;
case 6:
lrzz();
for (int e = 0; e < geshu; e++) {
int tishen = e;
for (int ee = e + 1; ee < geshu; ee++) {
if (zzz[ee]->age < zzz[tishen]->age) {
tishen = ee;
}
}
yuangong* a = zzz[e];
zzz[e] = zzz[tishen];
zzz[tishen] = a;
}
for (int e = 0; e < geshu; e++) {
zzz[e]->get();
}
break;
case 7:
lrzz();
for (int e = 0; e < geshu; e++) {
int tishen = e;
for (int ee = e + 1; ee < geshu; ee++) {
if (zzz[ee]->age > zzz[tishen]->age) {
tishen = ee;
}
}
yuangong* a = zzz[e];
zzz[e] = zzz[tishen];
zzz[tishen] = a;
}
for (int e = 0; e < geshu; e++) {
zzz[e]->get();
}
break;
case 8:
break;
}
if (jiaoshijihe.size() == 0 && shiiyanyuanjihe.size()== 0 && xzryjihe.size() == 0 && jsjxzryjihe.size() == 0&&xsxz!=8) {
cout << "暂无录入信息" << endl;
}
}
void guanli::save() {
ofstream ofs;
ofs.open("教师信息.txt", ios::out );
for (int e = 0; e < jiaoshijihe.size(); e++) {
ofs << jiaoshijihe[e].num << " " << jiaoshijihe[e].name << " " << jiaoshijihe[e].sex << " " << jiaoshijihe[e].age << " " << jiaoshijihe[e].suozaixibu << " " << jiaoshijihe[e].zhuanye << " " << jiaoshijihe[e].zhicheng << endl;
}
ofs.close();
ofs.open("实验员信息.txt", ios::out);
for (int e = 0; e < shiiyanyuanjihe.size(); e++) {
ofs << shiiyanyuanjihe[e].num << " " << shiiyanyuanjihe[e].name << " " << shiiyanyuanjihe[e].sex << " " << shiiyanyuanjihe[e].age << " " << shiiyanyuanjihe[e].shiyanshi<< " " << shiiyanyuanjihe[e].zhiwu << endl;
}
ofs.close();
ofs.open("行政人员信息.txt", ios::out);
for (int e = 0; e < xzryjihe.size(); e++) {
ofs << xzryjihe[e].num << " " << xzryjihe[e].name << " " << xzryjihe[e].sex << " " << xzryjihe[e].age << " " << xzryjihe[e].zhengzhimianmao << " " << xzryjihe[e].zhicheng << endl;
}
ofs.close();
ofs.open("教师兼行政人员信息.txt", ios::out);
for (int e = 0; e < jsjxzryjihe.size(); e++) {
ofs << jsjxzryjihe[e].num << " " << jsjxzryjihe[e].name << " " << jsjxzryjihe[e].sex << " " << jsjxzryjihe[e].age << " " << jsjxzryjihe[e].suozaixibu << " " << jsjxzryjihe[e].zhuanye << " " << jsjxzryjihe[e].zhicheng <<" "<< jsjxzryjihe[e].zhengzhimianmao<< endl;
}
ofs.close();
}
void guanli::save2() {
ofstream ofs;
ofs.open("教师信息备份.txt", ios::out);
for (int e = 0; e < jiaoshijihe.size(); e++) {
ofs << jiaoshijihe[e].num << " " << jiaoshijihe[e].name << " " << jiaoshijihe[e].sex << " " << jiaoshijihe[e].age << " " << jiaoshijihe[e].suozaixibu << " " << jiaoshijihe[e].zhuanye << " " << jiaoshijihe[e].zhicheng << endl;
}
ofs.close();
ofs.open("实验员信息备份.txt", ios::out);
for (int e = 0; e < shiiyanyuanjihe.size(); e++) {
ofs << shiiyanyuanjihe[e].num << " " << shiiyanyuanjihe[e].name << " " << shiiyanyuanjihe[e].sex << " " << shiiyanyuanjihe[e].age << " " << shiiyanyuanjihe[e].shiyanshi << " " << shiiyanyuanjihe[e].zhiwu << endl;
}
ofs.close();
ofs.open("行政人员信息备份.txt", ios::out);
for (int e = 0; e < xzryjihe.size(); e++) {
ofs << xzryjihe[e].num << " " << xzryjihe[e].name << " " << xzryjihe[e].sex << " " << xzryjihe[e].age << " " << xzryjihe[e].zhengzhimianmao << " " << xzryjihe[e].zhicheng << endl;
}
ofs.close();
ofs.open("教师兼行政人员信息备份.txt", ios::out);
for (int e = 0; e < jsjxzryjihe.size(); e++) {
ofs << jsjxzryjihe[e].num << " " << jsjxzryjihe[e].name << " " << jsjxzryjihe[e].sex << " " << jsjxzryjihe[e].age << " " << jsjxzryjihe[e].suozaixibu << " " << jsjxzryjihe[e].zhuanye << " " << jsjxzryjihe[e].zhicheng << " " << jsjxzryjihe[e].zhengzhimianmao << endl;
}
ofs.close();
}
void guanli::get() {
string a1;
string a2;
int a3;
string a4;
string a5;
string a6;
string a7;
ifstream ifs;
ifs.open("教师信息.txt", ios::in );
if (ifs) {
for (int e = jiaoshijihe.size();!ifs.eof();e++) {
int num;
ifs >> num;
if (blcxbh(num)==1&&num>=0) {
jiaoshijihe.resize(jiaoshijihe.size() + 1);
jiaoshijihe[e].num = num;
ifs>> jiaoshijihe[e].name >> jiaoshijihe[e].sex >> jiaoshijihe[e].age >> jiaoshijihe[e].suozaixibu >> jiaoshijihe[e].zhuanye >> jiaoshijihe[e].zhicheng;
}
else {
e--;
ifs >> a1 >> a2 >> a3 >> a4 >> a5 >> a6;
}
}
/*if (jiaoshijihe.size() >= 1) {
cout << " 教师信息.txt文件读取成功" << endl;
}
else {
cout << " 教师信息.txt文件为空" << endl;
}*/
}
/*else {
cout << " 教师信息.txt文件不存在" << endl;
}*/
ifs.close();
ifs.open("实验员信息.txt", ios::in);
if (ifs) {
for (int e = shiiyanyuanjihe.size(); !ifs.eof(); e++) {
int num;
ifs >> num;
if (blcxbh(num)==1 && num >= 0) {
shiiyanyuanjihe.resize(shiiyanyuanjihe.size() + 1);
shiiyanyuanjihe[e].num = num;
ifs >> shiiyanyuanjihe[e].name >> shiiyanyuanjihe[e].sex >> shiiyanyuanjihe[e].age >> shiiyanyuanjihe[e].shiyanshi >> shiiyanyuanjihe[e].zhiwu;
}
else {
e--;
ifs >> a1 >> a2 >> a3 >> a4 >> a5;
}
}
/*if (shiiyanyuanjihe.size() >= 1) {
cout << " 实验员信息.txt文件读取成功" << endl;
}
else {
cout << " 实验员信息.txt文件为空" << endl;
}*/
}
/*else {
cout << " 实验员信息.txt文件不存在" << endl;
}*/
ifs.close();
ifs.open("行政人员信息.txt", ios::in);
if (ifs) {
for (int e = xzryjihe.size(); !ifs.eof(); e++) {
int num;
ifs >> num;
if (blcxbh(num)==1 && num >= 0) {
xzryjihe.resize(xzryjihe.size() + 1);
xzryjihe[e].num = num;
ifs >> xzryjihe[e].name >>xzryjihe[e].sex >>xzryjihe[e].age>>xzryjihe[e].zhengzhimianmao >> xzryjihe[e].zhicheng;
}
else {
e--;
ifs >> a1 >> a2 >> a3 >> a4 >> a5;
}
}
/*if (xzryjihe.size() >= 1) {
cout << " 行政人员信息.txt文件读取成功" << endl;
}
else {
cout << " 行政人员信息.txt文件为空" << endl;
}*/
}
/*else {
cout << " 行政人员信息.txt文件不存在" << endl;
}*/
ifs.close();
ifs.open("教师兼行政人员信息.txt", ios::in);
if (ifs) {
for (int e = jsjxzryjihe.size(); !ifs.eof(); e++) {
int num;
ifs >> num;
if (blcxbh(num)==1 && num >= 0) {
jsjxzryjihe.resize(jsjxzryjihe.size() + 1);
jsjxzryjihe[e].num = num;
ifs >> jsjxzryjihe[e].name >>jsjxzryjihe[e].sex >> jsjxzryjihe[e].age>> jsjxzryjihe[e].suozaixibu >> jsjxzryjihe[e].zhuanye>>jsjxzryjihe[e].zhicheng >> jsjxzryjihe[e].zhengzhimianmao;
}
else {
e--;
ifs >> a1 >> a2 >> a3 >> a4 >> a5>>a6>>a7;
}
}
/*if (jsjxzryjihe.size() >= 1) {
cout << "教师兼行政人员信息.txt文件读取成功" << endl;
}
else {
cout << "教师兼行政人员信息.txt文件为空" << endl;
}*/
}
/*else {
cout << "教师兼行政人员信息.txt文件不存在" << endl;
}*/
ifs.close();
}
void guanli::get2() {
string a1;
string a2;
int a3;
string a4;
string a5;
string a6;
string a7;
ifstream ifs;
ifs.open("教师信息备份.txt", ios::in);
if (ifs) {
for (int e = jiaoshijihe.size(); !ifs.eof(); e++) {
int num;
ifs >> num;
if (blcxbh(num) == 1 && num >= 0) {
jiaoshijihe.resize(jiaoshijihe.size() + 1);
jiaoshijihe[e].num = num;
ifs >> jiaoshijihe[e].name >> jiaoshijihe[e].sex >> jiaoshijihe[e].age >> jiaoshijihe[e].suozaixibu >> jiaoshijihe[e].zhuanye >> jiaoshijihe[e].zhicheng;
}
else {
e--;
ifs >> a1 >> a2 >> a3 >> a4 >> a5 >> a6;
}
}
if (jiaoshijihe.size() >= 1) {
cout << " 教师信息备份.txt文件读取成功" << endl;
}
else {
cout << " 教师信息备份.txt文件读入为空" << endl;
}
}
else {
cout << " 教师信息备份.txt文件不存在" << endl;
}
ifs.close();
ifs.open("实验员信息备份.txt", ios::in);
if (ifs) {
for (int e = shiiyanyuanjihe.size(); !ifs.eof(); e++) {
int num;
ifs >> num;
if (blcxbh(num) == 1 && num >= 0) {
shiiyanyuanjihe.resize(shiiyanyuanjihe.size() + 1);
shiiyanyuanjihe[e].num = num;
ifs >> shiiyanyuanjihe[e].name >> shiiyanyuanjihe[e].sex >> shiiyanyuanjihe[e].age >> shiiyanyuanjihe[e].shiyanshi >> shiiyanyuanjihe[e].zhiwu;
}
else {
e--;
ifs >> a1 >> a2 >> a3 >> a4 >> a5;
}
}
if (shiiyanyuanjihe.size() >= 1) {
cout << " 实验员信息备份.txt文件读取成功" << endl;
}
else {
cout << " 实验员信息备份.txt文件读入为空" << endl;
}
}
else {
cout << " 实验员信息备份.txt文件不存在" << endl;
}
ifs.close();
ifs.open("行政人员信息备份.txt", ios::in);
if (ifs) {
for (int e = xzryjihe.size(); !ifs.eof(); e++) {
int num;
ifs >> num;
if (blcxbh(num) == 1 && num >= 0) {
xzryjihe.resize(xzryjihe.size() + 1);
xzryjihe[e].num = num;
ifs >> xzryjihe[e].name >> xzryjihe[e].sex >> xzryjihe[e].age >> xzryjihe[e].zhengzhimianmao >> xzryjihe[e].zhicheng;
}
else {
e--;
ifs >> a1 >> a2 >> a3 >> a4 >> a5;
}
}
if (xzryjihe.size() >= 1) {
cout << " 行政人员信息备份.txt文件读取成功" << endl;
}
else {
cout << " 行政人员信息备份.txt文件读入为空" << endl;
}
}
else {
cout << " 行政人员信息备份.txt文件不存在" << endl;
}
ifs.close();
ifs.open("教师兼行政人员信息备份.txt", ios::in);
if (ifs) {
for (int e = jsjxzryjihe.size(); !ifs.eof(); e++) {
int num;
ifs >> num;
if (blcxbh(num) == 1 && num >= 0) {
jsjxzryjihe.resize(jsjxzryjihe.size() + 1);
jsjxzryjihe[e].num = num;
ifs >> jsjxzryjihe[e].name >> jsjxzryjihe[e].sex >> jsjxzryjihe[e].age >> jsjxzryjihe[e].suozaixibu >> jsjxzryjihe[e].zhuanye >> jsjxzryjihe[e].zhicheng >> jsjxzryjihe[e].zhengzhimianmao;
}
else {
e--;
ifs >> a1 >> a2 >> a3 >> a4 >> a5 >> a6 >> a7;
}
}
if (jsjxzryjihe.size() >= 1) {
cout << "教师兼行政人员信息备份.txt文件读取成功" << endl;
}
else {
cout << "教师兼行政人员信息备份.txt文件读入为空" << endl;
}
}
else {
cout << "教师兼行政人员信息备份.txt文件不存在" << endl;
}
ifs.close();
save();
}
string guanli:: checkbh(int x) {
for (int e = 0; e < jiaoshijihe.size(); e++) {
if (jiaoshijihe[e].num == x) {
string zancun = "j";
zancun += to_string(e);
return zancun;
}
}
for (int e = 0; e < shiiyanyuanjihe.size(); e++) {
if (shiiyanyuanjihe[e].num == x) {
string zancun = "s";
zancun += to_string(e);
return zancun;
}
}
for (int e = 0; e < xzryjihe.size(); e++) {
if (xzryjihe[e].num == x) {
string zancun = "x";
zancun += to_string(e);
return zancun;
}
}
for (int e = 0; e < jsjxzryjihe.size(); e++) {
if (jsjxzryjihe[e].num == x) {
string zancun = "m";
zancun += to_string(e);
return zancun;
}
}
return "w";
}
string guanli::checkxm(string x) {
for (int e = 0; e < jiaoshijihe.size(); e++) {
if (jiaoshijihe[e].name == x) {
string zancun = "j";
zancun += to_string(e);
return zancun;
}
}
for (int e = 0; e < shiiyanyuanjihe.size(); e++) {
if (shiiyanyuanjihe[e].name == x) {
string zancun = "s";
zancun += to_string(e);
return zancun;
}
}
for (int e = 0; e < xzryjihe.size(); e++) {
if (xzryjihe[e].name == x) {
string zancun = "x";
zancun += to_string(e);
return zancun;
}
}
for (int e = 0; e < jsjxzryjihe.size(); e++) {
if (jsjxzryjihe[e].name == x) {
string zancun = "m";
zancun += to_string(e);
return zancun;
}
}
return "w";
}
int guanli::xmcc(string x) {
int geshu = 0;
for (int e = 0; e < jiaoshijihe.size(); e++) {
if (jiaoshijihe[e].name == x) {
geshu++;
}
}
for (int e = 0; e < shiiyanyuanjihe.size(); e++) {
if (shiiyanyuanjihe[e].name == x) {
geshu++;
}
}
for (int e = 0; e < xzryjihe.size(); e++) {
if (xzryjihe[e].name == x) {
geshu++;
}
}
for (int e = 0; e < jsjxzryjihe.size(); e++) {
if (jsjxzryjihe[e].name == x) {
geshu++;
}
}
return geshu;
}
void guanli::yicunzai(string jiancha) {
if (jiancha[0] == 'j') {
jiancha.erase(jiancha.begin(), jiancha.begin() + 1);
int zhanshi = stoi(jiancha);
jiaoshijihe[zhanshi].get();
}
else if (jiancha[0] == 's') {
jiancha.erase(jiancha.begin(), jiancha.begin() + 1);
int zhanshi = stoi(jiancha);
shiiyanyuanjihe[zhanshi].get();
}
else if (jiancha[0] == 'x') {
jiancha.erase(jiancha.begin(), jiancha.begin() + 1);
int zhanshi = stoi(jiancha);
xzryjihe[zhanshi].get();
}
else {
jiancha.erase(jiancha.begin(), jiancha.begin() + 1);
int zhanshi = stoi(jiancha);
jsjxzryjihe[zhanshi].get();
}
}
void guanli::bjry() {
cout << "请选择职员检索方式" << endl;
cout << "1.姓名检索" << endl;
cout << "2.编号检索" << endl;
cout << "3.取消修改" << endl;
cout << "提示:考虑到重名情况,建议使用编号检索" << endl;
int jsxz = srkz_gws(1, 3);
string jiancha;
switch (jsxz) {
case 1: {
cout << "请输入您想修改的职员信息的姓名" << endl;
string czname;
cin >> czname;
if (xmcc(czname) >= 2) {
cout << "该姓名有重复,请使用编号检索" << endl;
return;
}
jiancha = checkxm(czname);
break;
}
case 2: {
cout << "请输入您想修改的职员信息的编号" << endl;
string bianhao;
int bhzs;
cin >> bianhao;
while (1) {
if (numpd(bianhao)) {
bhzs = stoi(bianhao);
break;
}
else {
jinggao2();
cin >> bianhao;
}
}
jiancha = checkbh(bhzs);
break;
}
case 3:
return;
}
if (jiancha == "w") {
cout << "查无此人" << endl;
}
else {
if (jiancha[0] == 'j') {
jiancha.erase(jiancha.begin(), jiancha.begin() + 1);
int zanshi = stoi(jiancha);
int tuichu = 1;
while (tuichu==1) {
cout << "您的修改对象的原信息为:" << endl;
jiaoshijihe[zanshi].get();
cout << "请选择修改方式" << endl;
cout << "1.修改编号" << endl;
cout << "2.修改姓名" << endl;
cout << "3.修改性别" << endl;
cout << "4.修改年龄" << endl;
cout << "5.修改所在系部" << endl;
cout << "6.修改专业" << endl;
cout << "7.修改职称" << endl;
cout << "8.多方面修改" << endl;
cout << "9.结束修改" << endl;
int xuanze = srkz_gws(1, 9);
switch (xuanze) {
case 1:
{
int x = shurubh();
if (x == -1) {
break;
}
jiaoshijihe[zanshi].num =x; save();
break;
}
case 2: {
jiaoshijihe[zanshi].name = shuruxm(); save();
break;
}
case 3:
{
jiaoshijihe[zanshi].sex = shuruxb(); save();
break;
}
case 4:
{
jiaoshijihe[zanshi].age = shurunl(); save();
break;
}
case 5:
{
jiaoshijihe[zanshi].suozaixibu = shuruszxb(); save();
break;
}
case 6:
{
jiaoshijihe[zanshi].zhuanye = shuruzy(); save();
break;
}
case 7:
{
jiaoshijihe[zanshi].zhicheng = shuruzc(); save();
break;
}
case 8:
{
int x = shurubh();
if (x == -1) {
}
else {
jiaoshijihe[zanshi].num = x;
}
jiaoshijihe[zanshi].name = shuruxm();
jiaoshijihe[zanshi].sex = shuruxb();
jiaoshijihe[zanshi].age = shurunl();
jiaoshijihe[zanshi].suozaixibu = shuruszxb();
jiaoshijihe[zanshi].zhuanye = shuruzy();
jiaoshijihe[zanshi].zhicheng = shuruzc(); save();
break;
}
case 9:tuichu = 2;
break;
}
if (xuanze != 9) {
system("cls");
cout << "修改成功!" << endl;
}
}
}
else if (jiancha[0] == 's') {
jiancha.erase(jiancha.begin(), jiancha.begin() + 1);
int zanshi = stoi(jiancha);
int jieshu = 1;
while (jieshu == 1) {
cout << "您的修改对象的原信息为:" << endl;
shiiyanyuanjihe[zanshi].get();
cout << "请选择修改方式" << endl;
cout << "1.修改编号" << endl;
cout << "2.修改姓名" << endl;
cout << "3.修改性别" << endl;
cout << "4.修改年龄" << endl;
cout << "5.修改所在实验室" << endl;
cout << "6.修改职务" << endl;
cout << "7.多方面修改" << endl;
cout << "8.结束修改" << endl;
int xuanze = srkz_gws(1, 8);
switch (xuanze) {
case 1:
{
int x = shurubh();
if (x == -1) {
break;
}
shiiyanyuanjihe[zanshi].num = x; save();
break;
}
case 2: {
shiiyanyuanjihe[zanshi].name = shuruxm(); save();
break;
}
case 3:
{
shiiyanyuanjihe[zanshi].sex = shuruxb(); save();
break;
}
case 4:
{
shiiyanyuanjihe[zanshi].age = shurunl(); save();
break;
}
case 5:
{
shiiyanyuanjihe[zanshi].shiyanshi = shurusys(); save();
break;
}
case 6:
{
shiiyanyuanjihe[zanshi].zhiwu = shuruzw(); save();
break;
}
case 7:
{
int x = shurubh();
if (x == -1) {
}
else {
shiiyanyuanjihe[zanshi].num = x;
}
shiiyanyuanjihe[zanshi].name = shuruxm();
shiiyanyuanjihe[zanshi].sex = shuruxb();
shiiyanyuanjihe[zanshi].age = shurunl();
shiiyanyuanjihe[zanshi].shiyanshi = shurusys();
shiiyanyuanjihe[zanshi].zhiwu = shuruzw(); save();
break;
}
case 8:
{
jieshu = 2;
break;
}
}
if (xuanze != 8) {
system("cls");
cout << "修改成功!" << endl;
}
}
}
else if (jiancha[0] == 'x') {
jiancha.erase(jiancha.begin(), jiancha.begin() + 1);
int zanshi = stoi(jiancha);
int jieshu = 1;
while (jieshu == 1) {
cout << "您的修改对象的原信息为:" << endl;
xzryjihe[zanshi].get();
cout << "请选择修改方式" << endl;
cout << "1.修改编号" << endl;
cout << "2.修改姓名" << endl;
cout << "3.修改性别" << endl;
cout << "4.修改年龄" << endl;
cout << "5.修改政治面貌" << endl;
cout << "6.修改职称" << endl;
cout << "7.多方面修改" << endl;
cout << "8.结束修改" << endl;
int xuanze = srkz_gws(1, 8);
switch (xuanze) {
case 1:
{
int x = shurubh();
if (x == -1) {
break;
}
xzryjihe[zanshi].num = x; save();
break;
}
case 2: {
xzryjihe[zanshi].name = shuruxm(); save();
break;
}
case 3:
{
xzryjihe[zanshi].sex = shuruxb(); save();
break;
}
case 4:
{
xzryjihe[zanshi].age = shurunl(); save();
break;
}
case 5:
{
xzryjihe[zanshi].zhengzhimianmao = shuruzzmm(); save();
break;
}
case 6:
{
xzryjihe[zanshi].zhicheng = shuruzc(); save();
break;
}
case 7:
{
int x = shurubh();
if (x == -1) {
}
else {
xzryjihe[zanshi].num = x;
}
xzryjihe[zanshi].name = shuruxm();
xzryjihe[zanshi].sex = shuruxb();
xzryjihe[zanshi].age = shurunl();
xzryjihe[zanshi].zhengzhimianmao = shuruzzmm();
xzryjihe[zanshi].zhicheng = shuruzc(); save();
break;
}
case 8:
{jieshu = 2;
break;
}
}
if (xuanze != 8) {
system("cls");
cout << "修改成功!" << endl;
}
}
}
else {
jiancha.erase(jiancha.begin(), jiancha.begin() + 1);
int zanshi = stoi(jiancha);
int jieshu = 1;
while (jieshu == 1) {
cout << "您的修改对象的原信息为:" << endl;
jsjxzryjihe[zanshi].get();
cout << "请选择修改方式" << endl;
cout << "1.修改编号" << endl;
cout << "2.修改姓名" << endl;
cout << "3.修改性别" << endl;
cout << "4.修改年龄" << endl;
cout << "5.修改所在系部" << endl;
cout << "6.修改专业" << endl;
cout << "7.修改职称" << endl;
cout << "8.修改政治面貌" << endl;
cout << "9.多方面修改" << endl;
cout << "10.结束修改" << endl;
string zssr;
int xuanze;
while (1) {
cin >> zssr;
if (zssr.size() >= 1 && zssr.size() <= 2 && numpd(zssr)) {
if (stoi(zssr) <= 10) {
xuanze = stoi(zssr);
break;
}
else {
jinggao();
}
}
else {
jinggao();
}
}
switch (xuanze) {
case 1:
{
int x = shurubh();
if (x == -1) {
break;
}
jsjxzryjihe[zanshi].num = x; save();
break;
}
case 2: {
jsjxzryjihe[zanshi].name = shuruxm(); save();
break;
}
case 3:
{
jsjxzryjihe[zanshi].sex = shuruxb(); save();
break;
}
case 4:
{
jsjxzryjihe[zanshi].age = shurunl(); save();
break;
}
case 5:
{
jsjxzryjihe[zanshi].suozaixibu = shuruszxb(); save();
break;
}
case 6:
{
jsjxzryjihe[zanshi].zhuanye = shuruzy(); save();
break;
}
case 7:
{
jsjxzryjihe[zanshi].zhicheng = shuruzc(); save();
break;
}
case 8:
{
jsjxzryjihe[zanshi].zhengzhimianmao = shuruzzmm(); save();
break;
}
case 9:
{int x = shurubh();
if (x == -1) {
}
else {
jsjxzryjihe[zanshi].num = x;
}
jsjxzryjihe[zanshi].name = shuruxm();
jsjxzryjihe[zanshi].sex = shuruxb();
jsjxzryjihe[zanshi].age = shurunl();
jsjxzryjihe[zanshi].suozaixibu = shuruszxb();
jsjxzryjihe[zanshi].zhuanye = shuruzy();
jsjxzryjihe[zanshi].zhicheng = shuruzc();
jsjxzryjihe[zanshi].zhengzhimianmao = shuruzzmm(); save();
break;
}
case 10:
jieshu = 2;
break;
}
if (xuanze != 10) {
system("cls");
cout << "修改成功!" << endl;
}
}
}
}
}
string guanli::shuruzw() {
cout << "请输入职务" << endl;
string zhiwu;
cin >> zhiwu;
return zhiwu;
}
string guanli::shurusys() {
cout << "请输入所在实验室" << endl;
string sys;
cin >> sys;
return sys;
}
string guanli::shuruzzmm() {
cout << "请输入政治面貌" << endl;
string zzmm;
cin >> zzmm;
return zzmm;
}
string guanli::shuruzc() {
cout << "请输入职称" << endl;
string zhicheng;
cin >> zhicheng;
return zhicheng;
}
string guanli::shuruzy() {
cout << "请输入专业" << endl;
string zhuanye;
cin >> zhuanye;
return zhuanye;
}
string guanli::shuruszxb() {
cout << "请输入所在系部" << endl;
string suozaixibu;
cin >> suozaixibu;
return suozaixibu;
}
int guanli::shurunl() {
cout << "请输入年龄(18-60)" << endl;
string nianling;
int zsnl;
cin >> nianling;
while (1) {
if ((nianling.size() <= 2) && numpd(nianling) && (stoi(nianling) >= 18) &&( stoi(nianling) <= 60) &&(nianling.size()>1)) {
zsnl = stoi(nianling);
break;
}
else {
jinggao2();
cin >> nianling;
}
}
return zsnl;
}
string guanli::shuruxb() {
cout << "请输入性别(男/女)" << endl;
string xingbie;
while (1) {
cin >> xingbie;
if (xingbie == "男" || xingbie == "女") {
break;
}
else {
jinggao2();
}
}
return xingbie;
}
string guanli::shuruxm() {
cout << "请输入姓名" << endl;
string xingming;
cin >> xingming;
return xingming;
}
int guanli::shurubh() {
cout << "请输入纯数字编号" << endl;
string bianhao;
cin >> bianhao;
int zsbh;
while (1) {
if (numpd(bianhao)) {
if (bianhao.size()<=9) {
zsbh = stoi(bianhao);
string jiancha = checkbh(zsbh);
if (jiancha == "w") {
break;
}
else {
cout << "当前编号已存在,已存在职员信息为:" << endl;
yicunzai(jiancha);
cout << "请按任意键继续" << endl;
while (!_kbhit()) {}
return -1;
}
}
else {
color(4);
cout << "警告:输入数字过大" << endl;
color(7);
cin >> bianhao;
}
}
else {
jinggao2();
cin >> bianhao;
}
}
return zsbh;
}
void guanli::scry() {
cout << "请选择职员检索方式" << endl;
cout << "1.姓名检索" << endl;
cout << "2.编号检索" << endl;
cout << "3.取消删除" << endl;
cout << "提示:考虑到重名情况,建议使用编号检索" << endl;
int jsxz = srkz_gws(1, 3);
string jiancha;
switch (jsxz) {
case 1: {
cout << "请输入您想删除的职员信息的姓名" << endl;
string czname;
cin >> czname;
if (xmcc(czname) >= 2) {
cout << "该姓名有重复,请使用编号检索" << endl;
return;
}
jiancha = checkxm(czname);
break;
}
case 2: {
cout << "请输入您想删除的职员信息的编号" << endl;
string bianhao;
int bhzs;
cin >> bianhao;
while (1) {
if (numpd(bianhao)) {
bhzs = stoi(bianhao);
break;
}
else {
jinggao2();
cin >> bianhao;
}
}
jiancha = checkbh(bhzs);
break;
}
case 3:
return;
}
if (jiancha == "w") {
cout << "查无此人" << endl;
}
else {
if (jiancha[0] == 'j') {
jiancha.erase(jiancha.begin(), jiancha.begin() + 1);
int zhanshi = stoi(jiancha);
jiaoshijihe.erase(jiaoshijihe.begin()+zhanshi);
save();
}
else if (jiancha[0] == 's') {
jiancha.erase(jiancha.begin(), jiancha.begin() + 1);
int zhanshi = stoi(jiancha);
shiiyanyuanjihe.erase(shiiyanyuanjihe.begin() + zhanshi);
save();
}
else if (jiancha[0] == 'x') {
jiancha.erase(jiancha.begin(), jiancha.begin() + 1);
int zhanshi = stoi(jiancha);
xzryjihe.erase(xzryjihe.begin() + zhanshi);
save();
}
else {
jiancha.erase(jiancha.begin(), jiancha.begin() + 1);
int zhanshi = stoi(jiancha);
jsjxzryjihe.erase(jsjxzryjihe.begin() + zhanshi);
save();
}
cout << "删除成功!" << endl;
}
}
int guanli::blcxxb(string x) {
int geshu = 0;
for (int e = 0; e < jiaoshijihe.size(); e++) {
if (jiaoshijihe[e].sex == x) {
geshu++;
}
}
for (int e = 0; e < shiiyanyuanjihe.size(); e++) {
if (shiiyanyuanjihe[e].sex == x) {
geshu++;
}
}
for (int e = 0; e < xzryjihe.size(); e++) {
if (xzryjihe[e].sex == x) {
geshu++;
}
}
for (int e = 0; e < jsjxzryjihe.size(); e++) {
if (jsjxzryjihe[e].sex == x) {
geshu++;
}
}
return geshu;
}
bool guanli::blcxbh(int x) {
int geshu = 0;
for (int e = 0; e < jiaoshijihe.size(); e++) {
if (jiaoshijihe[e].num == x) {
geshu++;
}
}
for (int e = 0; e < shiiyanyuanjihe.size(); e++) {
if (shiiyanyuanjihe[e].num == x) {
geshu++;
}
}
for (int e = 0; e < xzryjihe.size(); e++) {
if (xzryjihe[e].num == x) {
geshu++;
}
}
for (int e = 0; e < jsjxzryjihe.size(); e++) {
if (jsjxzryjihe[e].num == x) {
geshu++;
}
}
if (geshu == 0) {
return 1;
}
else {
return 0;
}
}
int guanli::blcxzc(string x) {
int geshue = 0;
for (int e = 0; e < jiaoshijihe.size(); e++) {
if (jiaoshijihe[e].zhicheng == x) {
geshue++;
}
}
for (int e = 0; e < xzryjihe.size(); e++) {
if (xzryjihe[e].zhicheng == x) {
geshue++;
}
}
for (int e = 0; e < jsjxzryjihe.size(); e++) {
if (jsjxzryjihe[e].zhicheng == x) {
geshue++;
}
}
return geshue;
}
int guanli::blcxnl(int x,int y) {
int geshu = 0;
for (int e = 0; e < jiaoshijihe.size(); e++) {
if (jiaoshijihe[e].age >= x&&jiaoshijihe[e].age<=y) {
geshu++;
}
}
for (int e = 0; e < shiiyanyuanjihe.size(); e++) {
if (shiiyanyuanjihe[e].age >= x&&shiiyanyuanjihe[e].age<=y) {
geshu++;
}
}
for (int e = 0; e < xzryjihe.size(); e++) {
if (xzryjihe[e].age >= x&& xzryjihe[e].age <=y) {
geshu++;
}
}
for (int e = 0; e < jsjxzryjihe.size(); e++) {
if (jsjxzryjihe[e].age>=x&& jsjxzryjihe[e].age<=y) {
geshu++;
}
}
return geshu;
}
void guanli::tjry() {
int zongshu = jiaoshijihe.size() + shiiyanyuanjihe.size() + xzryjihe.size() + jsjxzryjihe.size();
cout << "高校人员管理系统收录人员总数为:" << zongshu << endl;
cout << "————————————————————————" << endl;
cout << "其中通过职业划分————" << endl;
cout << " 教师的人数为:" << jiaoshijihe.size() << endl;
cout << " 实验员的人数为:" << shiiyanyuanjihe.size() << endl;
cout << " 行政人员的人数为:" << xzryjihe.size() << endl;
cout << " 教师兼行政人员的人数为:" << jsjxzryjihe.size() << endl;
cout << "————————————————————————" << endl;
cout << "性别————" << endl;
cout << " 男性人数为:" <<blcxxb("男") << endl;
cout << " 女性人数为:" << blcxxb("女") << endl;
cout << "————————————————————————" << endl;
cout << "职称————" << endl;
cout << " 有职称的人数为:" <<blcxzc("教授")+ blcxzc("副教授") + blcxzc("讲师") + blcxzc("助教") << endl;
cout << " 职称为教授的人数为:" <<blcxzc("教授") << endl;
cout << " 职称为副教授的人数为:" << blcxzc("副教授") << endl;
cout << " 职称为讲师的人数为:" << blcxzc("讲师") << endl;
cout << " 职称为助教的人数为:" << blcxzc("助教") << endl;
cout << "————————————————————————" << endl;
cout << "年龄————" << endl;
cout << " 40岁以上的人数为" << blcxnl(41,100) << endl;
cout << " 30-40岁的人数为:" << blcxnl(30,40) << endl;
cout << " 30岁以下的人数为:" << blcxnl(18,29) << endl;
}
bool guanli:: wjpd(string& name) {
ifstream f(name.c_str());
bool x= f.good();
f.close();
return x;
}
void guanli::qcry() {
jiaoshijihe.clear();
shiiyanyuanjihe.clear();
xzryjihe.clear();
jsjxzryjihe.clear();
save();
cout << "列表已清空,请按任意键继续" << endl;
while (!_kbhit()) {};
}
系统本体
添加员工信息 (zjry)
用户可以选择添加教师、实验员、行政人员或教师兼行政人员的信息。其中教师包含了各类职称需要用户进行输入,比如输入教授,讲师等,该职称信息同时也将录入员工的信息中。而涉及行政类的人员同时也要包含政治面貌的行政信息。系统收集用户输入的员工信息并存储到相应的全局向量中。在添加信息模块当中,同时包含了检测非法输入的功能,如果用户录入编号时没有按照规定的方法或者格式录入编号,则将会发出警告并无法录入
查询员工信息 (cxry)
用户可以选择按姓名、编号或姓氏等等信息查询员工信息,在该模块中,系统将读取用户输入的信息,可以是数字或者字符串等,同时系统遍历所有员工信息,找到符合条件的员工并显示其详细信息。在姓名查询中,如果出现同名的情况同样也会显示出同名人的信息,而如果使用姓氏查询则会显示出所有该姓氏的人员名单信息
显示员工信息 (xsry)
用户可以选择按多种排序方式(如男女、职业分类、姓名拼写等)显示员工信息。如果使用男女排序,则会按照从男到女的顺序进行排列。职业分类同理,姓名拼写按照a-z的顺序进行排列。系统根据用户选择对全局向量进行排序,并遍历显示员工信息。
修改员工信息 (bjry)
用户可以选择按姓名或编号精确定位检索员工信息并进行修改。系统找到符合条件的员工,让用户选择修改哪些字段,并更新员工信息。
删除员工信息 (scry)
用户可以选择按姓名或编号精确检索员工信息并进行删除。系统按照用户的输入找到符合条件的员工并从全局向量中删除该员工信息。
统计员工信息 (tjry)
系统统计员工总数、按职业分类的人数、按性别分类的人数、按职称分类的人数以及按年龄区间分类的人数。统计结果以表格形式显示给用户。
备份与恢复 (save, get, save2, get2)
save 和 save2 函数用于将员工信息保存到文本文件中,实现数据备份。get 和 get2 函数用于从文本文件中读取员工信息,实现数据恢复。备份和恢复操作针对不同类型的员工信息分别处理。
清空员工信息 (qcry)
系统清空所有全局向量中的员工信息,并将清空后的状态保存到文件中。
排序算法
在显示员工信息和目的文件编写时,使用了简单的冒泡排序算法对全局向量进行排序。虽然效率不高,但考虑到员工数量不大,可以满足需求。
文件读写算法
在备份和恢复数据时,系统使用C++的文件流(ifstream 和 ofstream)进行文件的读写操作。
读取文件时,系统按行读取数据,并根据数据格式解析出员工信息。写入文件时,系统按固定格式将员工信息写入文件,便于后续读取。
搜索算法
在查询和修改员工信息时,系统使用线性搜索算法遍历全局向量,找到符合条件的员工信息。
线性搜索算法简单高效,但效率随员工数量增加而降低。考虑到员工数量不大,可以满足需求。
统计算法
统计员工信息时,系统使用简单的计数算法对不同类型的员工信息进行统计。算法遍历所有员工信息,根据条件增加相应计数器的值。统计完成后输出结果。
运行效果展示: