高等院校人事信息管理系统

#include<iostream>
#include<string>
#include<fstream>     //包含文件流对象文件
#include<iomanip>
using namespace std;
class person            //员工类的定义
{
protected:
	int   no;           //编号
	char  name[20];     //姓名
	char  sex[10];       //性别
	int   age;          //年龄
	char  party[20];     //政治面貌
	char  study[30];     //学历
	float  pay;         //工资
	int   type;         //员工类型,1:授课教师 2:行政人员  3:表示行政人员兼职教师
	person* mynext;     //指向下一个员工的指针
public:
	person();            //员工类无参构造函数的定义
	person(int pnum, char pname[], char psex[], int page, char pparty[], char pstudy[], float ppay, int ntype);
	//员工类有参构造函数的定义
	person(int pnum, char pname[], char psex[], int page, char pparty[], char pstudy[], float ppay, int ntype, person* next);     //员工类有参构造函数的定义
	int getnum();           //提取员工编号函数的定义
	char* getname();       //提取员工姓名函数的定义
	char* getsex();         //提取员工性别函数的定义
	int getage();           //提取员工年龄函数的定义
	void getagee(int as);     //设置员工年龄函数的定义
	char* getparty();       //提取员工政治面貌函数的定义
	char* getstudy();        //提取员工学历函数的定义
	virtual float getpay();    //计算员工工资函数的定义
	void getpayy(float temp); //设置员工工资函数的定义
	int gettype();           //提取员工类型函数的定义
	person* getnext();       //提取指向下一个员工指针函数的定义
	void setnext(person* next); //设置指向下一个员工指针函数的定义
	void output();           //输出员工信息函数的定义
};
person::person()         //员工类无参构造函数
{
	no = 0;
	strcpy(name, "");
	strcpy(sex, "");
	age = 0;
	strcpy(party, "");
	strcpy(study, "");
	pay = 0.0;
	type = 0;
	mynext = NULL;
}
person::person(int pnum, char pname[], char psex[], int page, char pparty[], char pstudy[], float ppay, int ptype)          //员工类有参构造函数
{
	no = pnum;
	strcpy(name, pname);
	strcpy(sex, psex);
	age = page;
	strcpy(party, pparty);
	strcpy(study, pstudy);
	pay = ppay;
	type = ptype;
	mynext = NULL;
}
person::person(int pnum, char pname[], char psex[], int page, char pparty[], char pstudy[], float ppay, int ptype, person* next) //员工类有参构造函数
{
	no = pnum;
	strcpy(name, pname);
	strcpy(sex, psex);
	age = page;
	strcpy(party, pparty);
	strcpy(study, pstudy);
	pay = ppay;
	type = ptype;
	mynext = next;
}
int   person::getnum() { return no; }
char* person::getname() { return name; }
char* person::getsex() { return sex; }
char* person::getparty() { return party; }
char* person::getstudy() { return study; }
int   person::getage() { return age; }
void  person::getagee(int as) { age = as; }
float  person::getpay() { return pay; }
void  person::getpayy(float temp) { pay = temp; }
int   person::gettype() { return type; }
void  person::setnext(person* next) { mynext = next; }
person* person::getnext() { return mynext; }
void  person::output()
{
	cout << "编号:" << no <<" "<< "姓名:" << name << endl;
	cout << "性别:" << sex << "年龄:" << age << endl;
	cout << "政治面貌:" << party << "学历:" << study << endl;
	cout << "工资:" << pay << "人员类型:" << type << endl;
}
class teacher :virtual public person   //授课教师类的定义
{
protected:
	char teachpos[20];    //职称
	float coursefee;      //每节课的课时费
	float coursenum;     //学时数
public:
	teacher();          //教师类无参构造函数的定义
	float getpay();      //计算教师工资函数的定义
};
teacher::teacher()     //教师类无参构造函数的实现
{
	cout << "请输入授课教师的职称:";
	cin >> teachpos;
	coursefee = 30.0;
	cout << "请输入授课教师完成的学时数:";
	cin >> coursenum;
}
float teacher::getpay()  //计算工资函数的实现
{
	if (strcmp(teachpos, "教授") == 0)
		pay = 1600;
	if (strcmp(teachpos, "副教授") == 0)
		pay = 1200;
	if (strcpy(teachpos, "讲师") == 0)
		pay = 800;
	pay = pay + coursefee * coursenum;
	return pay;
}
class staff :virtual public person     //行政人员类的定义
{
protected:
	char pos[20];         //行政职务
	float stafffee;         //行政补贴
public:
	staff();             //行政人员类无参构造函数的定义
	float getpay();       //计算行政人员工资函数的定义
};
staff::staff()             //行政人员类无参构造函数的实现
{
	cout << "请输入行政人员的职务级别:";
	cin >> pos;
	cout << "请输入行政人员的补贴:";
	cin >> stafffee;
}
float staff::getpay()        //计算工资函数的实现
{
	if (strcmp(pos, "处级") == 0)
		pay = 2500;
	if (strcmp(pos, "科级") == 0)
		pay = 2000;
	if (strcmp(pos, "科员") == 0)
		pay = 1500;
	pay = pay + stafffee;
	return pay;
}
class staffteacher :public staff, public teacher   //行政人员类的定义
{
public:
	staffteacher();     //类无参构造函数的定义
	float getpay();     //计算工资函数的定义
};
staffteacher::staffteacher()  //类无参构造函数的实现
{
	coursefee = 20.0;
}
float staffteacher::getpay()   //计算工资函数的实现
{
	if (strcmp(pos, "处级") == 0)
	{
		if (strcmp(teachpos, "教授") == 0)
			pay = 2000;
		else if (strcmp(teachpos, "副教授") == 0)
			pay = 1800;
		else
			pay = 1600;
	}
	if (strcmp(pos, "科级") == 0)
	{
		if (strcmp(teachpos, "教授") == 0)
			pay = 1800;
		else if (strcmp(teachpos, "副教授") == 0)
			pay = 1600;
		else
			pay = 1400;
	}
	if (strcmp(pos, "科员") == 0)
	{
		if (strcmp(teachpos, "教授") == 0)
			pay = 1600;
		else if (strcmp(teachpos, "副教授") == 0)
			pay = 1400;
		else
			pay = 1200;
	}
	pay = pay + coursenum * coursefee + stafffee;
	return pay;
}
class  school
{
private:
	person* myfirst;       //指向学校人员链表中结点的指针
public:
	school();             //school类无参构造函数的定义
	school(int nnum, char nname[], char nsex[], int nage, char nparty[], char nstudy[], float npay, int ntype);
	//school类带参数构造函数的定义
	~school();               //school类析构函数的定义
	void load();             //从文件中加载员工信息
	void add();             //增加员工信息
	void input(int number);   //键盘输入新员工基本信息
	void insert(int nnum, char nname[], char nsex[], int nage, char nparty[], char nstudy[], float npay, int ntype);
	//学校员工链表中插入新员工结点
	bool findnum();         //按编号查询员工信息
	bool findname();        //按姓名查询员工信息
	bool modify();          //修改员工信息
	bool deleteperson();     //删除员工信息
	void count();           //统计员工信息
	void save();            //员工信息存盘
	void  showall();        //显示学校所有员工信息
};
school::school()         //school类无参构造函数的实现
{
	myfirst = NULL;
}

school::school(int nnum, char nname[], char nsex[], int nage, char nparty[], char nstudy[], float npay, int ntype)                 //school类带参数构造函数的实现
{
	myfirst = new person(nnum, nname, nsex, nage, nparty, nstudy, npay, ntype);
}

school::~school()      //school类析构函数的实现
{
	person* next = myfirst, * temp;
	while (next != NULL)
	{
		temp = next;
		next = next->getnext();
		delete temp;
	}
	myfirst = NULL;
}

void school::load()        //从文件中加载员工信息
{
	int nnum, nage, ntype;
	char nname[20], nsex[20], nparty[20], nstudy[20];
	float npay;
	ifstream fin("person.txt", ios::in);
	while (fin.good())
	{
		fin >> nnum >> nname >> nsex >> nage >> nparty >> nstudy >> npay >> ntype;
		if (!(fin.eof()))
			insert(nnum, nname, nsex, nage, nparty, nstudy, npay, ntype);
	}
	fin.close();
	cout << endl << "存储在文件中的学校人员信息已加载到系统中" << endl;
}

void school::add()        //增加新员工
{
	int tmpnum, number1, number2;
	person* p = myfirst;
	if (p == NULL)
	{
		cout << "目前学校无员工,请输入新员工的编号:";
		cin >> tmpnum;
		input(tmpnum);
	}
	else
	{
		if (p->getnext() == NULL)
		{
			number1 = p->getnum() + 1;
			input(number1);
		}
		else
		{
			while (p->getnext() != NULL)
				p = p->getnext();
			number2 = p->getnum() + 1;
			input(number2);
		}
	}
}

void school::input(int number) //键盘输入新员工基本信息
{
	int nage, ntype;
	float npay;
	char nname[20], nsex[20], nparty[20], nstudy[20];
	cout << "请选择是任课教师(输入1),行政人员(输入2)还是行政人员兼职教师(输入3):" << endl;
	cin >> ntype;
	cout << "请输入编号为" << number << "的员工信息" << endl;
	cout << "输入姓名:" << endl;
	cin >> nname;
	cout << "输入性别:" << endl;
	cin >> nsex;
	cout << "输入年龄:" << endl;
	cin >> nage;
	cout << "输入政治面貌:群众还是党员?" << endl;
	cin >> nparty;
	cout << "输入学历:小学,初中,高中,专科,本科,硕士,博士:" << endl;
	cin >> nstudy;
	cout << "下面计算工资:" << endl;
	if (ntype == 1)
	{
		teacher t1;  npay = t1.getpay();
	}
	else if (ntype == 2)
	{
		staff s1;    npay = s1.getpay();
	}
	else if (ntype == 3)
	{
		cout << "请输入行政人员兼职教师的工资信息:"; staffteacher st1;  npay = st1.getpay();
	}
	insert(number, nname, nsex, nage, nparty, nstudy, npay, ntype);
}

void school::insert(int nnum, char nname[], char nsex[], int nage, char nparty[], char nstudy[], float npay, int ntype)           //学校员工链表中插入新员工结点
{
	person* p = myfirst;
	if (p == NULL)
		myfirst = new person(nnum, nname, nsex, nage, nparty, nstudy, npay, ntype);
	else
	{
		while (p->getnext() != NULL)
			p = p->getnext();
		p->setnext(new person(nnum, nname, nsex, nage, nparty, nstudy, npay, ntype, p->getnext()));
	}
}

bool school::findnum()     //按编号查询员工信息
{
	int id;
	person* ahead = myfirst;
	person* follow = ahead;
	cout << "请输入员工的编号:" << endl;
	cin >> id;
	if (ahead == NULL)
	{
		cout << "本校暂无员工信息!" << endl;   return false;
	}
	else
	{
		while (ahead != NULL)
		{
			if (ahead->getnum() == id)
			{
				ahead->output();   return true;
			}
			else
			{
				follow = ahead;	 ahead = ahead->getnext();
			}
		}
		cout << "本校无此员工信息!" << endl;
		return false;
	}
}

bool school::findname()   //按姓名查询员工信息
{
	char tmpname[20];
	person* ahead = myfirst;
	person* follow = ahead;
	cout << "请输入员工的姓名:";
	cin >> tmpname;
	if (ahead == NULL)
	{
		cout << "本校暂无员工信息!" << endl;  return false;
	}
	else
	{
		while (ahead != NULL)
		{
			if (strcmp(ahead->getname(), tmpname) == 0)
			{
				ahead->output();	  return true;
			}
			else
			{
				follow = ahead;    ahead = ahead->getnext();
			}
		}
		cout << "本校无此员工信息!" << endl;
		return false;
	}
}

bool school::modify()     //修改员工信息
{
	int number;
	person* ahead = myfirst;
	person* follow = ahead;
	cout << "请输入要修改的学校员工编号:";
	cin >> number;
	if (ahead == NULL)
	{
		cout << "本校无员工!" << endl;  return false;
	}
	else
	{
		while (ahead != NULL)
		{
			if (ahead->getnum() == number)
			{
				ahead->output();
				while (1)
				{
					int i;
					float tmpnumber;
					char temp[30];
					cout << "请选择要修改的员工信息:" << endl;
					cout << "   1:姓名  2:性别  3:年龄   4:政治面貌  5:学历  6:工资 " << endl;
					cout << "   请选择(1~6)中的选项:";
					cin >> i;
					switch (i)
					{
					case 1: { cout << "输入修改姓名:"; cin >> temp; strcpy(ahead->getname(), temp); }; break;
					case 2: { cout << "输入修改性别:"; cin >> temp; strcpy(ahead->getsex(), temp);   }; break;
					case 3: { cout << "输入修改年龄:"; cin >> tmpnumber; ahead->getagee(tmpnumber);  }; break;
					case 4: { cout << "输入修改政治面貌:"; cin >> temp; strcpy(ahead->getparty(), temp); }; break;
					case 5: { cout << "输入修改学历:"; cin >> temp; strcpy(ahead->getstudy(), temp); }; break;
					case 6: { cout << "输入修改工资:"; cin >> tmpnumber; ahead->getpayy(tmpnumber); }; break;
					}
					return true;
				}
			}
			else
			{
				ahead = ahead->getnext();  follow = ahead;
			}
		}
		cout << "本校没有此工作编号的员工!" << endl;
		return false;
	}
}

bool school::deleteperson() //删除员工信息
{
	int i;
	person* ahead = myfirst;
	person* follow = ahead;
	cout << "请输入要删除学校人员的工作编号:";
	cin >> i;
	if (ahead == NULL)
	{
		cout << "无员工可以删除";  return false;
	}
	else  if (ahead->getnum() == i)
	{
		myfirst = myfirst->getnext();
		cout << "工作编号为" << i << "的学校员工已被删除了!" << endl;
		delete ahead;
		return true;
	}
	else
	{
		ahead = ahead->getnext();
		while (ahead != NULL)
		{
			if (ahead->getnum() == i)
			{
				follow->setnext(ahead->getnext());
				cout << "编号为" << i << "的成员以被删除\n";
				delete ahead;
				return true;
			}
			follow = ahead;
			ahead = ahead->getnext();
		}
		cout << "要删除的学校员工不存在,无法删除!" << endl;
		return false;
	}
}

void school::count()    //统计员工信息
{
	int i, amount = 0;
	cout << "  ***********************************************" << '\n'
		<< "  *                                              *" << '\n'
		<< "  *           1.统计学校职工中的党员人数          *" << '\n'
		<< "  *                                              *" << '\n'
		<< "  *           2.统计学校中女职工人数              *" << '\n'
		<< "  *                                               *" << '\n'
		<< "  *************************************************" << '\n'
		<< "请您选择上面的选项:" << endl;
	cin >> i;
	person* ahead = myfirst;
	person* follow = ahead;
	if (ahead == NULL)    cout << "学校无人员信息" << endl;
	else
	{
		switch (i)
		{
		case 1: {  while (ahead != NULL)
		{
			if (strcmp(ahead->getparty(), "党员") == 0)
			{
				ahead = ahead->getnext();  amount++;
			}
			else
				ahead = ahead->getnext();
		}
				cout << "学校中的党员人数:" << amount << endl; };
				break;
		case 2: {   while (ahead != NULL)
		{
			if (strcmp(ahead->getsex(), "女") == 0)
			{
				ahead = ahead->getnext();	  amount++;
			}
			else
				ahead = ahead->getnext();
		}
				cout << "学校中的女员工人数:" << amount << endl;    };
				break;
		}
	}
}

void school::save()        //员工信息存盘
{
	ofstream fout("person.txt", ios::out);
	person* p = myfirst;
	while (p)
	{
		fout << p->getnum() << "\t" << p->getname() << "\t" << p->getsex() << "\t" << p->getage() << "\t"
			<< p->getparty() << "\t" << p->getstudy() << "\t" << p->getpay() << "\t" << p->gettype() << endl;
		p = p->getnext();
	}
	fout.close();
	cout << "保存数据已经完成" << endl;
}

void  school::showall()    //显示学校所有员工信息
{
	person* ahead = myfirst;
	cout << setw(8) << "编号" << setw(8) << "姓名" << setw(8) << "性别" << setw(8) << "年龄" << setw(8)
		<< "政治面貌" << setw(8) << "学历" << setw(8) << "工资" << setw(8) << "人员类型" << endl;
	while (ahead != NULL)
	{
		cout << setw(4) << ahead->getnum() << setw(6) << ahead->getname() << setw(5) << ahead->getsex()
			<< setw(4) << ahead->getage() << setw(10) << ahead->getparty() << setw(6) << ahead->getstudy()
			<< setw(12) << ahead->getpay() << setw(12) << ahead->gettype() << endl;
		ahead = ahead->getnext();
	}
}
void main()
{
	school sc1;
	int i;
	while (1)
	{
		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;
		cout << "================================" << endl;
		cout << "请选择上面的选项(1~10):" << endl;
		cin >> i;
		switch (i)
		{
		case 1:sc1.load(); break;
		case 2:sc1.add(); break;
		case 3:sc1.findnum(); break;
		case 4:sc1.findname(); break;
		case 5:sc1.modify(); break;
		case 6:sc1.deleteperson(); break;
		case 7:sc1.count(); break;
		case 8:sc1.save();  break;
		case 9:sc1.showall(); break;
		case 10:exit(1); break;
		}
	}
}
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值