1.worker.h
#pragma once
#include<iostream>
using namespace std;
#include<string>
//职工抽象类
class Worker
{
public:
//显示个人信息
virtual void showInfo() = 0;
//获取岗位名称
virtual string getDeptName() = 0;
//职工编号
int m_Id;
//职工姓名.
string m_Name;
//部门编号
int m_DeptId;
};
2.manager.h
#pragma once
#include<iostream>
using namespace std;
#include<string>
#include"worker.h"
class Manager :public Worker
{
public:
//构造函数
Manager(int id, string name, int dId);
//显示个人信息
virtual void showInfo();
//获取岗位名称
virtual string getDeptName();
};
3.employee.h
#pragma once
#include<iostream>
using namespace std;
#include<string>
#include"worker.h"
class Employee :public Worker
{
public:
//构造函数
Employee(int id,string name,int dId);
//显示个人信息
virtual void showInfo();
//获取岗位名称
virtual string getDeptName();
};
4.boss.h
#pragma once
#include<iostream>
using namespace std;
#include<string>
#include"worker.h"
class Boss :public Worker
{
public:
//构造函数
Boss(int id, string name, int dId);
//显示个人信息
virtual void showInfo();
//获取岗位名称
virtual string getDeptName();
};
5.workermanager.h
#pragma once//防止头文件重复包含
#include<iostream>
#include"worker.h"
using namespace std;
#include"employee.h"
#include"manager.h"
#include"boss.h"
#include<fstream>
#define FILENAME "empFile.txt"
class WorkerManager
{
public:
//构造函数
WorkerManager();
//展示函数
void Show_Menu();
//退出系统
void ExitSystem();
//记录职工人数
int m_EmpNum;
//职工数组指针
Worker **m_EmpArray;
// 保存文件
void save();
//添加职工
void Add_Emp();
//判断文件是否为空标志
bool m_FileIsEmpty;
//统计文件中人数
int get_EmpNum();
//初始化员工
void init_Emp();
//显示职工
void show_Emp();
//删除职工
void Del_Emp();
//判断职工是否存在,如果存在返回职工所在数组中的位置,不存在返回-1
int IsExist(int id);
//修改职工
void Mod_Emp();
//查找职工
void Find_Emp();
//排序
void Sort_Emp();
//清空文件
void Clean_File();
//析构函数
~WorkerManager();
};
6.manager.cpp
#include "manager.h"
//构造函数
Manager::Manager(int id, string name, int dId)
{
this->m_Id = id;
this->m_Name = name;
this->m_DeptId = dId;
}
//显示个人信息
void Manager::showInfo()
{
cout << "职工编号:" << this->m_Id
<< "\t职工姓名:" << this->m_Name
<< "\t岗位:" << this->getDeptName()
<< "\t岗位职责:完成老板交给的任务,并下发任务给员工" << endl;
}
//获取岗位名称
string Manager::getDeptName()
{
return string("经理");
}
7.employee.cpp
#include "employee.h"
//构造函数
Employee::Employee(int id, string name, int dId)
{
this->m_Id = id;
this->m_Name = name;
this->m_DeptId = dId;
}
//显示个人信息
void Employee::showInfo()
{
cout << "职工编号:" << this->m_Id
<< "\t职工姓名:" << this->m_Name
<< "\t岗位:" << this->getDeptName()
<< "\t岗位职责:完成经理交给的任务" << endl;
}
//获取岗位名称
string Employee::getDeptName()
{
return string("员工");
}
- boss.cpp
#include