ps:我是基于黑马程序员视频中的程序进行一定的改写以及注释。
我用的是vs2017
我感觉这对C++进行一定的基础学习还是有一定的作用,
项目对文件以及程序的布置都是值得学习和思考的,
我认为这里用的需要注意的知识点就是虚函数,继承,以及多态。
#include<iostream>
#include<fstream>
using namespace std;
#include"woker.h"
#define FILENAME "empFile.txt"
class WorkerManager
{
public:
//构造函数
WorkerManager();
//析构函数
~WorkerManager();
void showMenu();
void exitSystem();
void addEmp(); //添加职工
void saveDate(); //保存数据
int get_EmpNum();//读取数据中的人数
void init_Emp();//初始化员工
void show_Emp();//显示员工信息
int IsExit(int id);//查看数据是否存在
void Del_Emp();//删除操作
void change_Emp();//改变对应数据的信息
void find_Emp();//查看对应数据的信息
void sort_Emp();//对信息进行排序
void clean_Emp();//清理文件中的所有数据
int m_EmpNum; //记录文件中的人数个数
bool e_FileIsEmpty; //作为判断文件是否为空的标志
worker ** m_EmpArray; //员工数组的指针 其中**的意思是 一个指向worker基类,第二个指向抽象实例化之后的类
};
#pragma once
#include<iostream>
using namespace std;
#include"woker.h"
class Boss : public worker
{
public:
Boss(int id, string name, int dId);
virtual void showIofo();
virtual string getDeptName();
};
#pragma once
#include<iostream>
#include"woker.h"
using namespace std;
class staff : public worker
{
public:
staff(int id, string name, int dId);
virtual void showIofo();
virtual string getDeptName();
};
#pragma once
#include<iostream>
#include<string>
using namespace std;
class worker
{
public:
virtual void showIofo() = 0;
virtual string getDeptName() = 0;
int m_Id;
string m_Name;
int m_DeptId;
};
#include"manager.h"
#include<string>
using namespace std;
manager::manager(int id, string name, int dId)
{
this->m_Id = id;
this->m_Name = name;
this->m_DeptId = dId;
}
void manager::showIofo()
{
cout << "职工编号: " << this->m_Id
<< " \t职工姓名: " << this->m_Name
<< " \t岗位:" << this->getDeptName()
<< " \t岗位职责:完成老板交给的任务,并下发任务给员工" << endl;
}
string manager::getDeptName()
{
return string("经理");
}
#include"Boss.h"
Boss::Boss(int id, string name, int dId)
{
this->m_Id = id;
this->m_Name = name;
this->m_Id = dId;
}
void Boss::showIofo()
{
cout << "职工编号: " << this->m_Id
<< " \t职工姓名: " << this->m_Name
<< " \t岗位:" << this->getDeptName()
<< " \t岗位职责:管理公司所有事务" << endl;
}
string Boss::getDeptName()
{
return string("老板");
}
#include<iostream>
#include"Employee.h"
using namespace std;
int main() {
WorkerManager WM;
int choice = 0;
while (true)
{
//展示菜单
WM.showMenu();
cout << "请输入您的选择:" << endl;
cin >> choice;