创建一个worker抽象类
//职工抽象类 class worker { public: //职工的编号、姓名、部门编号 int m_id; string m_name; int m_DeptId; //显示个人信息 virtual void showInfo()=0; //获取岗位名称 virtual string getDeptName() = 0; };
//创建普通员工文件
//普通员工文件 #pragma once; #include<iostream> #include "worker.h" using namespace std; class Employee :public worker { public: //构造函数 Employee(int id,string name,int dId); //显示个人信息 virtual void showInfo(); //获取岗位名称 virtual string getDeptName(); };
实现普通员工
#include<iostream> #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 << " 职工姓名:"<<this->m_name << " 职工岗位:" <<this->getDeptName() << " 岗位职责:完成经理交给的任务" << endl; } //获取岗位名称 string Employee:: getDeptName() { return string("员工"); }
测试,在职工管理系统.cpp
worker *worker=NULL; worker = new Employee(1,"张三",1); worker->showInfo(); worker = new Manager(2,"李四",2); worker->showInfo(); worker = new Boos(3, "王五", 3); worker->showInfo();
经理类&老板类是一样的~