c++面向对象程序设计大作业(人事管理系统)

1.登录

Administrator_login.h

#pragma once
#include"controller.h"
#include
#include
#define FILENAME3 "password.txt"
using namespace std;
class Login
{
public:
	Login();
	void login();
public:
	Controller con;
private:
	string str;
};

Administrator_login1.cpp

#include"Administrator_login.h"
Login::Login()
{
	ifstream ifs;
	ifs.open(FILENAME3, ios::in);
	if (!ifs.is_open())
	{
		cout << "未设置密码" << endl;
		ifs.close();
		return;
	}
	else
		ifs >> str;
	ifs.close();
}
void Login:: login()
{
	string s;
	cout << "请输入登录密码" << endl;
	cin >> s;
	if (s == this->str)
	{
		this->con.Choice();
	}
	else
	{
		cout << "密码错误,非管理员禁止登录!" << endl;
		exit(-1);
	}
}

2.董事长类

boss.h

#pragma once
#include
#include"Work.h"
using namespace std;
class Boss :public Work
{
public:
	Boss(int id, string name, int depid);
	virtual void  Show_Information();
	virtual string Get_position_name();
};

boss,cpp

#include"boss.h"
using namespace std;
Boss::Boss(int id, string name, int depid)
{
	this->n_ID = id;
	this->n_Name = name;
	this->n_Dep_number = depid;
}
void Boss::Show_Information()
{
	cout << "职工编号:" << this->n_ID << endl;
	cout << "职工姓名:" << this->n_Name << endl;
	cout << "职工部门:" << this->n_Dep_number << endl;
	cout << "职工职责:管理经理" << endl;
}
string Boss::Get_position_name()
{
	return string("懂事长");
}

3.应聘者类

Candidate.h

#pragma once
#include
#include"user.h"
class Candidate :public User
{
public:
	Candidate(int id, string name, int depid);
	void Show_Information();
	string Get_Motivation();
};

Candidate.cpp

#include"Candidate.h"
Candidate::Candidate(int id, string name, int depid)
{
	this->id = id;
	this->n_Name = name;
	this->depid = depid;
}
void Candidate::Show_Information()
{
	cout << "访客id为:" << this->id << endl;
	cout << "访客姓名为:" << this->n_Name << endl;
	cout << "访客类型为:" << this->depid << endl;
}
string Candidate::Get_Motivation()
{
	string s("前来公司应聘");
	return s;
}

4.控制

controller.h

#pragma once
#include
#include"Menu.h"
#include"Manager_User.h"
#include"Manager_Work.h"
#include"head_view.h"
class Controller
{
public:
	//系统选择
	void Choice();
	//展示用户菜单
	void Show_Menu_user();
	//展示职员菜单
	void Show_Menu_work();
	//查看信息
	void view();
	//进入职员系统
	void Choice_work();
	//进入用户系统
	void Choice_User();
public:
	Menu menu;
	Manager_User user;
	Manager_Work work;
};

constroller.cpp

#include"controller.h"
void Controller::Choice()
{
	cout << "请输入对应数字选择管理系统" << endl;
	cout << "1 职员管理" << endl;
	cout << "2 用户管理" << endl;
	int select = 0;
	cin >> select;
	try
	{
		if (select == 2)
		{
			Show_Menu_user();
			Choice_User();
		}
		else if (select == 1)
		{
			Show_Menu_work();
			Choice_work();
		}
		if (select != 1 && select != 2)
		{
			throw(-1);
		}
	}
	catch (int a)
	{
		cout << "输入错误" << endl;
		cout << "请重新输入" << endl;
		while (1)
		{
			cin >> select;
			if (select == 2)
			{
				Show_Menu_user();
				Choice_User();
				break;
			}
			else if (select == 1)
			{
				Show_Menu_work();
				Choice_work();
				break;
			}
			cout << "输入错误" << endl;
			cout << "请重新输入" << endl;
		}
		//return;
	}
}
void Controller::Choice_User()
{
	//选择编号
	int n;
	cout << "请输入你的选择" << endl;
	cin >> n;
	//提供分支选择,提供每个功能接口
	while (1)
	{
		if (n == 0)
		{
			user.Exit_the_system();//退出管理系统
			break;
		}
		switch (n)
		{
			//增加用户信息
		case 1:
			user.Add_Person();
			break;
			//显示
		case 2:
			user.Show_inf();
			break;
			//查找
		case 3:
			user.Find_user();
			break;
		default:
			system("cls");
			break;
		}
		Show_Menu_user();
		cout << "请输入你的选择" << endl;
		cin >> n;
	}
	
}
void Controller::Choice_work()
{
	//选择编号
	int n;
	cout << "请输入你的选择" << endl;
	cin >> n;
	//提供分支选择,提供每个功能接口
	while (1)
	{
		if (n == 0)
		{
			work.Exit_the_system();//退出管理系统
			break;
		}
		switch (n)
		{
			//增加职工信息
		case 1:
			work.Add_Person();
			break;
			//显示
		case 2:
			work.Show_inf();
			break;
			//删除
		case 3:

			work.Delete_P();
			break;
			//修改
		case 4:
			work.Revise_Per();
			break;
			//查找
		case 5:
			work.Find_per();
			break;
			//排序
		case 6:
			work.Sort_per();
			break;
			//清空
		case 7:
			work.Clear_File();
			break;
		default:
			system("cls");
			break;
		}
		Show_Menu_work();
		cout << "请输入你的选择" << endl;
		cin >> n;
	}
	
	
}
void Controller::view()
{
	Manager_User user;
	Manager_Work work;
	Head_view vi(user, work);
	vi.View_user();
	vi.View_work();
}
void Controller::Show_Menu_user()
{
	this->menu.menu_user();
}
void Controller::Show_Menu_work()
{
	this->menu.menu_work();
}

5.视图

head_view.h

#pragma once
#include
#include"Manager_User.h"
#include"Manager_Work.h"
using namespace std;
class Head_view
{
public:
	Head_view(Manager_User user,Manager_Work work)
	{
		this->n_User = user;
		this->n_Work = work;
	}
	void View_user()
	{
		this->n_User.Show_inf();
	}
	void View_work()
	{
		this->n_Work.Show_inf();
	}
public:
	Manager_User n_User;
	Manager_Work n_Work;
};

6.总经理

Manager.h

#pragma once
#include
#include"Work.h"
using namespace std;
class Manager:public Work
{
public:
	Manager(int id, string name, int depid);
	virtual void  Show_Information();
	virtual string Get_position_name();
};

Manager.cpp

#include"Manager.h"
using namespace std;

Manager::Manager(int id, string name, int depid)
{
	this->n_ID = id;
	this->n_Name = name;
	this->n_Dep_number = depid;
}
void Manager::Show_Information()
{
	cout << "职工编号:" << this->n_ID << endl;
	cout << "职工姓名:" << this->n_Name << endl;
	cout << "职工部门:" << this->n_Dep_number << endl;
	cout << "职工职责:完成董事长的任务" << endl;
}
string Manager::Get_position_name()
{
	return string("总经理");
}

7.管理用户

Manager_User.h

#pragma once
#include
#include
#include"visitor.h"
#include"Candidate.h"
#include"VIP.h"
#include"user.h"
//#include"controller.h"
#define FILENAME2 "user.txt"
using namespace std;
class Manager_User 
{
public:
	Manager_User();
	//保存文件
	void Save();
	void Show_inf();
	//获取用户数量
	int get_usernumber();
	//初始化用户
	void init_user();
	//增加用户
	void Add_Person();
	//退出系统
	void Exit_the_system();
	//查找用户
	void Find_user();
	//判断用户是否存在
	int IsExist(int id);

public:
	//用户人数
	int user_num;
	//标志文件是否为空
	bool n_FileIsEmpty;
	//用户数组指针
	User** array;
};

Manager_User.cpp


#include"Manager_User.h"
#include
Manager_User::Manager_User()
{
	ifstream ifs;
	ifs.open(FILENAME2, ios::in);
	//1.文件不存在情况
	if (!ifs.is_open())
	{
		cout << "文件不存在" << endl;
		//初始化属性
		this->user_num = 0;
		this->array = NULL;
		this->n_FileIsEmpty = true;
		ifs.close();
		return;
	}
	//2.文件存在,但是数据为空
	char ch;
	//读一个字符
	ifs >> ch;
	//如果读完了,文件为空
	if (ifs.eof())
	{
		cout << "文件为空!" << endl;
		//初始化属性
		this->user_num = 0;
		this->array = NULL;
		this->n_FileIsEmpty = true;
		//关闭文件
		ifs.close();
		return;
	}
	//3.文件存在,数据也存在
	int num = this->get_usernumber();
	//更新用户数量
	this->user_num = num;
	//根据用户数量创建数组
	this->array = new User * [this->user_num];//开辟空间
	//初始化用户
	//将文件中的数据存到数组中
	init_user();
}
void Manager_User::Show_inf()
{
	//先判断文件是否为空
	if (this->n_FileIsEmpty)
	{
		cout << "文件不存在或者文件为空" << endl;
	}
	//不为空时
	//用多态调用程序接口
	else
	{
		for (int i = 0; i < user_num; i++)
		{
			cout << "用户类型为:" << this->array[i]->Get_Motivation() << endl;
			this->array[i]->Show_Information();
			cout << endl;
		}
		//按任意键后清屏
		system("pause");
		system("cls");
	}
}
int Manager_User::get_usernumber()
{
	ifstream ifs;
	//以读文件方式打开文件
	ifs.open(FILENAME2, ios::in);
	int id;
	int depid;
	string name;
	int num = 0;//记录人数
	while (ifs >> id && ifs >> name && ifs >> depid)
	{
		//每读取一行人数+1
		num++;
	}
	ifs.close();
	return num;
}
void Manager_User::Save()
{
	ofstream ofs;
	//写入文件
	ofs.open(FILENAME2, ios::out);
	//将每个人的数据写到文件中
	for (int i = 0; i < this->user_num; i++)
	{
		ofs << this->array[i]->id << " "
			<< this->array[i]->n_Name << " "
			<< this->array[i]->depid << endl;
	}
	ofs.close();
}
void Manager_User::init_user()
{
	ifstream ifs;
	//以读文件方式打开
	ifs.open(FILENAME2, ios::in);
	string name;
	int id;
	int depid;
	int index = 0;
	while (ifs >> id && ifs >> name && ifs >> depid)
	{
		User* p = NULL;
		//根据不同的部门id创建不同的对象
		if (depid == 1)
			p = new Visitor(id, name, depid);
		else if (depid == 2)
		    p = new Candidate(id, name, depid);
		else
		{
			p = new Vip(id, name, depid);
		}
	//存放在数组中
		this->array[index] = p;
		index++;
	}
	ifs.close();
}
void Manager_User::Add_Person()
{
	cout << "请输入添加用户的数量" << endl;
	//记录添加用户数量
	int add_num = 0;
	cin >> add_num;
	if (add_num > 0)
	{
		//新空间的大小=原来人数+新增人数
		int newSize = this->user_num + add_num;
		//开辟新空间
		User** newSpace = new User * [newSize];
		if (this->array)
		{
			for (int i = 0; i < this->user_num; i++)
			{
				newSpace[i] = this->array[i];
			}
		}
		//批量添加数据
		for (int i = 0; i < add_num; i++)
		{
			//用户编号
			int id;
			//用户姓名
			string name;
			//用户类型
			int dSelect;
			cout << "请输入第" << i + 1 << "个用户id" << endl;
			cin >> id;
			cout << "请输入第" << i + 1 << "个用户姓名:" << endl;
			cin >> name;
			cout << "请输入第" << i + 1 << "个用户类型:" << endl;

			cout << "请选择用户类型:" << endl;

			cout << "3-VIP" << endl;
			cout << "2-应聘者" << endl;
			cout << "1-访客" << endl;
			cin >> dSelect;
			User* p = NULL;
			switch (dSelect)
			{
			case 1:
				p = new Visitor(id, name, 1);
				break;
			case 2:
				p = new Candidate(id, name, 2);
				break;
			case 3:
				p = new Vip(id, name, 3);
				break;

			}
			newSpace[this->user_num + i] = p;
		}
		//先释放原有空间
		delete[] this->array;
		//更改新空间的指向
		this->array = newSpace;
		//更新用户人数
		this->user_num = newSize;
		cout << "已成功添加" << add_num << "名用户" << endl;
		//保存数据到文件中
		this->Save();
	}
	else
	{
		cout << "输入有误" << endl;
	}
	//按任意键后清屏回到上级目录
	system("pause");
	system("cls");
}
void Manager_User::Exit_the_system()
{
	cout << "感谢使用" << endl;
	system("pause");
	exit(0);
}
void Manager_User::Find_user()
{
	if (this->n_FileIsEmpty)
	{
		cout << "文件不存在或文件为空!" << endl;
	}
	else
	{
		cout << "请输入查找的方式:" << endl;
		cout << "1 按用户编号查找" << endl;
		cout << "2 按用户姓名查找" << endl;

		int select = 0;
		cin >> select;

		if (select == 1)
		{
			//按照编号查
			int id;
			cout << "请输入查找的用户编号:" << endl;
			cin >> id;

			//先判断该职工是否存在
			int ret = IsExist(id);
			if (ret != -1)
			{
				//找到职工
				cout << "查找成功!该职工信息如下:" << endl;
				this->array[ret]->Show_Information();
			}
			else
			{
				cout << "查无此人!" << endl;
			}
		}
		else if (select == 2)
		{
			//按照姓名查
			string name;
			cout << "请输入查找的姓名:" << endl;
			cin >> name;

			//加入判断是否查到的标志
			bool flag = false;//默认未找到用户
			for (int i = 0; i < user_num; i++)
			{
				if (this->array[i]->n_Name == name)
				{
					cout << "查找成功!用户编号为" << this->array[i]->id << "号用户信息如下:" << endl;
					flag = true;
					this->array[i]->Show_Information();//调用显示信息的函数
				}
			}
			if (flag == false)
			{
				cout << "查无此人!" << endl;
			}
		}
		else
		{
			cout << "输入的选项有误!" << endl;
		}
	}
	//按任意键清屏
	system("pause");
	system("cls");
}
int Manager_User::IsExist(int id)
{
	//一开始认定不在
	int index = -1;
	for (int i = 0; i < this->user_num; i++)
	{
		if (this->array[i]->id == id)
		{
			index = i;
			break;
			//找到即可退出
		}
	}
	return index;
}

8.管理职员

Manager_Work.h

#pragma once
#include
#include"Manager.h"
#include"personnel.h"
#include"Work.h"
#include"boss.h"
#include"project_manager.h"
#include"sales_manager.h"
//#include"controller.h"
#include
#define FILENAME "empFile.txt"
using namespace std;
class Manager_Work
{
public:
	//初始化
	Manager_Work();
	//退出系统
	void Exit_the_system();
	//添加职工
	void Add_Person();
	//保存文件
	void Save();
	//统计人数
	int get_pernumber();
	//初始化员工
	void init_personnel();
	//显示职工
	void Show_inf();
	//删除职工
	void Delete_P();
	//按照职工编号判断职工是否存在
	int IsExist(int id);
	//修改职工
	void Revise_Per();
	//查找职工
	void Find_per();
	//排序
	void Sort_per();
	//清空文件
	void Clear_File();
	//清理
	~Manager_Work();
public:
	//职工人数
	int n_pernumber;
	//职工数组指针
	Work** array;
	//标志文件是否为空
	bool n_FileIsEmpty;
	//如果文件为空,就不进行显示,修改,删除等操作
};

Manager_Work.cpp

#include"Manager_Work.h"
#include
using namespace std;
Manager_Work::Manager_Work()
{
	//分类讨论:
	ifstream ifs;
	ifs.open(FILENAME, ios::in);
	//1.文件不存在
	if (!ifs.is_open())
	{
		cout << "文件不存在" << endl;
		//初始化属性
		this->n_pernumber = 0;
		this->array = NULL;
		this->n_FileIsEmpty = true;
		ifs.close();
		return;
	}
	//2.文件存在数据为空
	char ch;
	//走读一个字符
	ifs >> ch;
	//如果读完了,文件为空
	if (ifs.eof())
	{
		cout << "文件为空!" << endl;
		//初始化属性
		this->n_pernumber = 0;
		this->array = NULL;
		this->n_FileIsEmpty = true;
		//关闭文件
		ifs.close();
		return;
	}
	//3.文件存在,数据存在
	int num = this->get_pernumber();
	//更新成员属性
	this->n_pernumber = num;
	//根据职工数创建数组
	this->array = new Work * [this->n_pernumber];//堆区开辟空间
	//初始化职工
	//将文件中的数据存到数组中
	init_personnel();
}

void Manager_Work::Revise_Per()
{
	if (this->n_FileIsEmpty)
	{
		cout << "文件不存在或者文件为空" << endl;
	}
	else
	{
		cout << "请输入修改职工的编号" << endl;
		int id;
		cin >> id;
		//判断职工是否存在
		int n = this->IsExist(id);
		if (n != -1)
		{
			//查找到职工编号
			//删除掉该位置的数据
			delete this->array[n];
			//每个数据都重新修改一下
			//初始状态
			int new_id = 0;
			string new_name = " ";
			int dSelect = 0;
			cout << "查找到" << id << "职工,请输入新的职工编号" << endl;
			cin >> new_id;
			cout << "请输入姓名:" << endl;
			cin >> new_name;
			cout << "请输入岗位" << endl;
			cout << "5-项目经理" << endl;
			cout << "4-销售经理" << endl;
			cout << "3-老板" << endl;
			cout << "2-总经理" << endl;
			cout << "1-员工" << endl;
			cin >> dSelect;
			//重新申请空间
			Work* p = NULL;
			switch (dSelect)
			{
			case 1:
				p = new Personnel(new_id, new_name, dSelect);
				break;
			case 2:
				p = new Manager(new_id, new_name, dSelect);
				break;
			case 3:
				p = new Boss(new_id, new_name, dSelect);
			case 4:
				p = new Sales_manager(new_id, new_name, dSelect);
			case 5:
				p = new Porject_Manager(new_id, new_name, dSelect);

				break;
			}
			//更改数据到数组中
			this->array[n] = p;
			cout << "修改成功" << this->array[n]->n_Dep_number << endl;
			//保存到文件中
			this->Save();
		}
		else
		{
			cout << "职工不存在,修改失败" << endl;
		}
	}
	// 按任意键清屏
	system("pause");
	system("cls");
}
//查找职工信息
void Manager_Work::Find_per()
{
	if (this->n_FileIsEmpty)
	{
		cout << "文件不存在或文件为空!" << endl;
	}
	else
	{
		cout << "请输入查找的方式:" << endl;
		cout << "1 按职工编号查找" << endl;
		cout << "2 按职工姓名查找" << endl;

		int select = 0;
		cin >> select;

		if (select == 1)
		{
			//按照编号查
			int id;
			cout << "请输入查找的职工编号:" << endl;
			cin >> id;

			//先判断该职工是否存在
			int ret = IsExist(id);
			if (ret != -1)
			{
				//找到职工
				cout << "查找成功!该职工信息如下:" << endl;
				this->array[ret]->Show_Information();
			}
			else
			{
				cout << "查无此人!" << endl;
			}
		}
		else if (select == 2)
		{
			//按照姓名查
			string name;
			cout << "请输入查找的姓名:" << endl;
			cin >> name;

			//加入判断是否查到的标志
			bool flag = false;//默认未找到职工
			for (int i = 0; i < n_pernumber; i++)
			{
				if (this->array[i]->n_Name == name)
				{
					cout << "查找成功!职工编号为" << this->array[i]->n_ID << "号职工信息如下:" << endl;
					flag = true;
					this->array[i]->Show_Information();//调用显示信息的函数
				}
			}
			if (flag == false)
			{
				cout << "查无此人!" << endl;
			}
		}
		else
		{
			cout << "输入的选项有误!" << endl;
		}
	}
	//按任意键清屏
	system("pause");
	system("cls");
}
void Manager_Work::Clear_File()
{

	cout << "请确认是否清空" << endl;
	cout << "输入1 确认" << endl;
	cout << "输入0 返回" << endl;
	int select = 0;
	cin >> select;
	if (select == 1)
	{
		//删除文件后重新创建
		ofstream ofs(FILENAME, ios::trunc);
		ofs.close();
		if (this->array)
		{
			//逐个删除
			for (int i = 0; i < this->n_pernumber; i++)
			{
				delete this->array[i];
				//置空
				this->array[i] = NULL;
			}
			//删除堆区数组指针
			delete[]this->array;
			this->array = NULL;
			//职工人数置零
			this->n_pernumber = 0;
			//文件为空的标志置为true
			this->n_FileIsEmpty = true;
			cout << "清空成功!" << endl;
		}
	}
}
void Manager_Work::Show_inf()
{
	//先判断文件是否为空
	if (this->n_FileIsEmpty)
	{
		cout << "文件不存在或者文件为空" << endl;
	}
	//不为空时
	//用多态调用程序接口
	else
	{
		for (int i = 0; i < n_pernumber; i++)
		{
			cout << "职称为:" << this->array[i]->Get_position_name() << endl;
			this->array[i]->Show_Information();
			cout << endl;
		}
		//按任意键后清屏
		system("pause");
		system("cls");
	}
}
int Manager_Work::IsExist(int id)
{
	//一开始认定不在
	int index = -1;
	for (int i = 0; i < this->n_pernumber; i++)
	{
		if (this->array[i]->n_ID == id)
		{
			index = i;
			break;
			//找到即可退出
		}
	}
	return index;
}
void Manager_Work::Delete_P()
{
	if (this->n_FileIsEmpty)
	{
		cout << "文件不存在或者文件为空" << endl;
	}
	else
	{
		//按照职工编号删除
		cout << "请输入想删除的职工编号" << endl;
		int id = 0;
		cin >> id;
		//判断职工是否存在
		int index = this->IsExist(id);
		if (index  != -1)//如果职工存在
		{
			//该位置后的所有数据前移
			for (int i = index; i < this->n_pernumber; i++)
			{
				this->array[i] = this->array[i + 1];

			}
			this->n_pernumber--;
			//数据同步更新到文件中
			this->Save();
			cout << "删除成功" << endl;
		}
		else
		{
			cout << "该职工不存才,删除失败" << endl;
		}
	}
	//按任意键清屏
	system("pause");
	system("cls");
}
void Manager_Work::Sort_per()
{
	if (this->n_FileIsEmpty)
	{
		cout << "文件不存在或为空" << endl;
		//按任意键清屏
		system("pause");
		system("cls");

	}
	else
	{
		cout << "请选择职工排序方式" << endl;
		cout << "输入0 按职工编号升序排序" << endl;
		cout << "输入1 按职工编号降序排序" << endl;
		int select = 0;
		cin >> select;
		for (int i = 0; i < this->n_pernumber; i++)
		{
			int max_or_min = i;//声明最大值或最小值下标
			if (select == 1)//降序
			{
				for (int j = i + 1; j < this->n_pernumber; j++)
				{
					if (this->array[j]->n_ID > this->array[max_or_min]->n_ID)
					{
						max_or_min = j;
					}
				}
			}
			else//升序
			{
				for (int j = i + 1; j < this->n_pernumber; j++)
				{
					if (this->array[j]->n_ID < this->array[max_or_min]->n_ID)
					{
						max_or_min = j;
					}
				}
			}
			if (i != max_or_min)
			{
				Work* t = this->array[i];
				this->array[i] = this->array[max_or_min];
				this->array[max_or_min] = t;
			}

		}
		cout << "排序后的结果为:" << endl;
		this->Save();
		this->Show_inf();
	}
	
}
void Manager_Work::init_personnel()
{
	ifstream ifs;
	//以读文件方式打开
	ifs.open(FILENAME, ios::in);
	int id;
	string name;
	int depid;
	int index = 0;//数组下标
	while (ifs >> id && ifs >> name && ifs >> depid)
	{
		Work* p = NULL;
		//根据不同的部门id创建不同的对象
		if (depid == 1)
			p = new Personnel(id, name, depid);
		else if (depid == 2)
			p = new Manager(id, name, depid);
		else if (depid == 3)
			p = new Boss(id, name, depid);
		else if (depid == 4)
			p = new Sales_manager(id, name, depid);
		else
			p = new Porject_Manager(id, name, depid);
		//存放在数组中
		this->array[index] = p;
		index++;
	}
	ifs.close();
}
//清理操作
Manager_Work::~Manager_Work()
{
	//释放空间
	if (this->array)
	{
		delete[]this->array;
		this->array = NULL;
	}
}
int Manager_Work::get_pernumber()
{
	ifstream ifs;
	//以读文件方式打开文件
	ifs.open(FILENAME, ios::in);
	int id;
	string name;
	int depid;
	int num = 0;
	while (ifs >> id && ifs >> name && ifs >> depid)
	{
		num++;//人数++
	}
	ifs.close();
	return num;
}
void Manager_Work::Exit_the_system()
{
	cout << "感谢使用" << endl;
	system("pause");
	exit(0);
}
void Manager_Work::Save()
{
	ofstream ofs;
	//用输出的方式打开文件,写文件
	ofs.open(FILENAME, ios::out);
	//将每个人的数据写到文件中
	for (int i = 0; i < this->n_pernumber; i++)
	{
		ofs << this->array[i]->n_ID << " "
			<< this->array[i]->n_Name << " "
			<< this->array[i]->n_Dep_number << endl;
	}
	ofs.close();
}
void Manager_Work::Add_Person()
{
	cout << "请输入添加职工的数量" << endl;
	//记录添加职工数量
	int add_num = 0;
	cin >> add_num;
	if (add_num > 0)
	{
		//新空间的大小=原来人数+新增人数
		int newSize = this->n_pernumber + add_num;
		//开辟新空间
		Work** newSpace = new Work * [newSize];
		if (this->array)
		{
			for (int i = 0; i <this->n_pernumber; i++)
			{
				newSpace[i] = this->array[i];
			}
		}
		//批量添加数据
		for (int i = 0; i < add_num; i++)
		{
			//职工编号
			int id;
			//职工姓名
			string name;
			//部门选择
			int dSelect;
			cout << "请输入第" << i + 1 << "个职工编号:" << endl;
			cin >> id;
			cout << "请输入第" << i + 1 << "个职工姓名:" << endl;
			cin >> name;
			cout << "请选择职工岗位:" << endl;
			cout << "5-项目经理" << endl;
			cout << "4-销售经理" << endl;
			cout << "3-老板" << endl;
			cout << "2-经理" << endl;
			cout << "1-员工" << endl;
			cin >> dSelect;
			Work* p = NULL;
			switch (dSelect)
			{
			case 1:
				p = new Personnel(id, name, 1);
				break;
			case 2:
				p = new Manager(id, name, 2);
				break;
			case 3:
				p = new Boss(id, name, 3);
				break;
			case 4:
				p= new Sales_manager(id, name, 4);
				break;
			case 5:
				p = new Porject_Manager(id, name, 5);
			}
			newSpace[this->n_pernumber + i] = p;
		}
		//先释放原有空间
		delete[] this->array;
		//更改新空间的指向
		this->array = newSpace;
		//更新职工人数
		this->n_pernumber = newSize;
		cout << "已成功添加" << add_num << "名职工" << endl;
		//保存数据到文件中
		this->Save();
	}
	else
	{
		cout << "输入有误" << endl;
	}
	//按任意键后清屏回到上级目录
	system("pause");
	system("cls");
}

9.菜单

Menu.h

#pragma once
#include
#include"Menu_user.h"
#include"Menu_work.h"
using namespace std;
class Menu
{
public:
	void menu_user()
	{
		this->m_user.menu_user();
	}
	void menu_work()
	{
		this->m_work.menu_work();
	}
public:
	M_user m_user;
	M_work m_work;
};

10.用户菜单

Menu_user.h

#pragma once
#include
using namespace std;
class M_user
{
public:
	void menu_user()
	{
		cout << "欢迎使用用户管理系统" << endl;
		cout << "0 退出管理系统" << endl;
		cout << "1 增加用户信息" << endl;
		cout << "2 显示用户信息" << endl;
		cout << "3 查找用户信息" << endl;
	}
};

11.职员 菜单

Menu_work.h

#pragma once
#include
using namespace std;
class M_work
{
public:
	void menu_work()
	{
		cout << "欢迎使用职工管理系统" << endl;
		cout << "0 退出管理系统" << endl;
		cout << "1 增加职工信息" << endl;
		cout << "2 显示职工信息" << endl;
		cout << "3 删除离职职工" << endl;
		cout << "4 修改职工信息" << endl;
		cout << "5 查找职工信息" << endl;
		cout << "6 排序职工信息" << endl;
		cout << "7 清空所有数据" << endl;
	}
};

12.普通职工

personnel.h

#pragma once
#include
#include
#include"Work.h"
class Personnel :public Work
{
public:
	Personnel(int id, string name, int depid);
	virtual void Show_Information();
	virtual string Get_position_name();

};

personnel.cpp

#include"personnel.h"
using namespace std;
Personnel::Personnel(int id, string name, int depid)
{
	this->n_ID = id;
	this->n_Name = name;
	this->n_Dep_number = depid;
}
void Personnel::Show_Information()
{
	cout << "职工编号:" << this->n_ID << endl;
	cout << "职工姓名:" << this->n_Name << endl;
	cout << "职工部门:" << this->n_Dep_number << endl;
	cout << "职工职责:完成经理下达的任务"<< endl;
}
string Personnel::Get_position_name()
{
	return string("初级员工");
}

13.项目经理

project_manager.h

#pragma once
#include
#include"Work.h"
using namespace std;

class Porject_Manager :public Work
{
public:
	Porject_Manager(int id, string name, int depid);
	virtual void Show_Information();
	virtual string Get_position_name();
};
project_manager.cpp



```cpp
#include"project_manager.h"

Porject_Manager::Porject_Manager(int id, string name, int depid)
{
	this->n_ID = id;
	this->n_Name = name;
	this->n_Dep_number = depid;
}
void Porject_Manager::Show_Information()
{
	cout << "职工编号:" << this->n_ID << endl;
	cout << "职工姓名:" << this->n_Name << endl;
	cout << "职工部门:" << this->n_Dep_number << endl;
	cout << "职工职责:管理项目" << endl;
}
string Porject_Manager::Get_position_name()
{
	return string("项目经理");
}

14.销售经理

sales_manager.h

#pragma once
#include
#include"Work.h"
using namespace std;
class Sales_manager :public Work
{
public:
	Sales_manager(int id, string name, int depid);
	void Show_Information();
	string Get_position_name();

};

sales_manager.cpp

#include"sales_manager.h"

Sales_manager::Sales_manager(int id, string name, int depid)
{
	this->n_ID = id;
	this->n_Name = name;
	this->n_Dep_number = depid;
}
void Sales_manager::Show_Information()
{
	cout << "职工编号:" << this->n_ID << endl;
	cout << "职工姓名:" << this->n_Name << endl;
	cout << "职工部门:" << this->n_Dep_number << endl;
	cout << "职工职责:管理销售" << endl;
}
string Sales_manager::Get_position_name()
{
	return string("销售经理");
}

15.用户

user.h

#pragma once
#include
#include
using namespace std;
class User
{
public:
	
	virtual void Show_Information() = 0;//純虚
	virtual string Get_Motivation() = 0;
	int id;
	string n_Name;
	int depid;
};

16.VIP

VIP.h

#pragma once
#include
#include"user.h"
class Vip :public User
{
public:
	Vip(int id, string name, int depid);
	void Show_Information();
	string Get_Motivation();
};

VIP.cpp

#include"VIP.h"
Vip::Vip(int id, string name, int depid)
{
	this->id = id;
	this->n_Name = name;
	this->depid = depid;
}
void Vip::Show_Information()
{
	cout << "访客id为:" << this->id << endl;
	cout << "访客姓名为:" << this->n_Name << endl;
	cout << "访客类型为:" << this->depid << endl;
}
string Vip::Get_Motivation()
{
	string s("享受公司所有服务");
	return s;
}

17.访客

visitor.h

#pragma once
#include
#include"user.h"
class Visitor :public User
{
public:
	Visitor(int id,string name,int depid);
	void Show_Information();
	string Get_Motivation();
};

visitor.cpp

#include"visitor.h"
Visitor::Visitor(int id,string name,int depid)
{
	this->id = id;
	this->n_Name = name;
	this->depid = depid;
}
void Visitor::Show_Information()
{
	cout << "访客id为:" << this->id << endl;
	cout << "访客姓名为:" << this->n_Name << endl;
	cout << "访客类型为:" << this->depid << endl;
}
string Visitor::Get_Motivation()
{
	string s("刷视频看到本公司");
	return s;
}

18.职员

Work.h

#pragma once
#include
#include
using namespace std;
//职工类
class Work
{
public:
	virtual void Show_Information() = 0;//純虚
	virtual string Get_position_name() = 0;
	int n_ID;//职工编号
	string n_Name;//职工姓名
	int n_Dep_number;//部门编号
};

19.主函数

main.cpp

#pragma once
#include
#include"boss.h"
#include"Manager.h"
#include"Manager_Work.h"
#include"personnel.h"
#include"Work.h"
#include"Manager_User.h"
#include"project_manager.h"
#include"sales_manager.h"
#include"visitor.h"
#include"Candidate.h"
#include"VIP.h"
#include"user.h"
#include"head_view.h"
#include"controller.h"
#include"Menu.h"
#include"Administrator_login.h"
//#include
using namespace std;
int main()
{
	//登录
	Login l;
	l.login();
	return 0;
}

你可能感兴趣的:(C++面向对象,c++,C++学习笔记,c++,开发语言,后端)