先看一下整体框架
//boss.h
#pragma once
#include <iostream>
#include "worker.h"
using namespace std;
class Boss :public Worker
{
public:
//声明构造函数
Boss(int id, string name, int dep);
virtual void showInfo();
virtual string getDeptName();
};
//manager.h
#pragma once
//普通员工
#include <iostream>
using namespace std;
#include "worker.h"
class Manager :public Worker
{
public:
//声明构造函数
Manager(int id, string name, int dep);
//显示个人信息
virtual void showInfo();
//获取岗位名称
virtual string getDeptName();
};
//employee.h
#pragma once
//普通员工
#include <iostream>
using namespace std;
#include "worker.h"
class Employee :public Worker
{
public:
//声明构造函数
Employee(int id, string name, int dep);
//显示个人信息
virtual void showInfo();
//获取岗位名称
virtual string getDeptName();
};
//worker.h
#pragma once
#include <iostream>
#include <string>
using namespace std;
//员工抽象基类(运用多态弄出三个小类)
class Worker
{
public:
//显示个人信息(用到多态)
virtual void showInfo() = 0;
//获取岗位名称
virtual string getDeptName() = NULL;
int p_ID; //员工编号
string p_Name;//员工姓名
int p_DeptId;//员工所在部门名称编号
};
//workManager.h
#pragma once //防止头文件重复包含
#include<iostream> //包含输入输出流头文件
using namespace std;//使用标准命名空间
#include "worker.h"
#include "employee.h"
#include "manager.h"
#include"boss.h"
#include <fstream>
#define FILENAME "empFile.txt"
class WorkManager
{
public:
//构造函数
WorkManager();
//展示菜单
void showMenu();
//退出系统功能
void exitSystem();
//记录员工人数
int p_EmpNum;
//员工数组指针
Worker ** p_EmpArray;
//添加员工
void add_Emp();
//保存文件
void save();
//判断文件是否为空的标志
bool p_FileIsEmpty;
//统计人数
int getEmpNum();
//初始化员工
void init_Emp();
//显示员工
void show_Emp();
//删除员工
void del_Emp();
//判断员工是否存在
int isExist(int id);
//修改员工
void modify_Emp();
//查找员工
void find_Emp();
//员工排序
void sort_Emp();
//清空文件
void clean_Emp();
//析构函数
~WorkManager();
};
//boss.cpp
#include "boss.h"
Boss::Boss(int id, string name, int dep)
{
this->p_ID = id;
this->p_Name = name;
this->p_DeptId = dep;
}
void Boss::showInfo()
{
cout << "员工编号:" << this->p_ID
<< "\t员工姓名:" << this->p_Name
<< "\t员工岗位:" << this->getDeptName()
<< "\t岗位职责:管理公司所有事情" << endl;
}
string Boss::getDeptName()
{
return string("老板");
}
//employee.cpp
#include "employee.h"
Employee::Employee(int id, string name, int dep)
{
this->p_ID = id;
this->p_Name = name;
this->p_DeptId = dep;
}
void Employee::showInfo()
{
cout << "员工编号:" << this->p_ID
<< "\t员工姓名:" << this->p