#pragma once
class Employee
{
public:
Employee();
Employee(char *pcName, char *pcNo, int nDept);//构造函数
~Employee();
public:
void SetName(char *pcName); //设置姓名
void SetNo(char *pcNo); //设置编号
void SetDept(int nDept); //设置部门号
void Display(); //输出雇员信息
protected:
char m_cName[20]; //姓名
char m_cNo[20]; //编号
int m_nDepartment; //部门号
};
#include "stdafx.h"
#include "Employee.h"
#include
using namespace std;
Employee::Employee()
{
}
Employee::Employee(char *pcName, char *pcNo, int nDept)//构造函数
{
SetName(pcName);
SetNo(pcNo);
SetDept(nDept);
}
Employee::~Employee()
{
}
void Employee::SetName(char *pcName) //设置姓名
{
strcpy_s(m_cName, pcName);
}
void Employee::SetNo(char *pcNo) //设置编号
{
strcpy_s(m_cNo, pcNo);
}
void Employee::SetDept(int nDept) //设置部门号
{
m_nDepartment = nDept;
}
void Employee::Display() //输出雇员信息
{
cout << "姓名:" << m_cName << endl
<< "编号:" << m_cNo << endl
<< "部门号:" << m_nDepartment << endl;
}
#pragma once
#include "Employee.h"
class Manager : public Employee //继承于Employee类
{
public:
Manager();
Manager(char *pcName, char *pcNo, int nDept, int nLvl);//构造函数
~Manager();
public:
void Setlvl(int nLvl); //设置级别
void Display(); //重定义,输出经理的信息
private:
int m_nLevel; //级别
};
#include "stdafx.h"
#include "Manager.h"
#include
using namespace std;
Manager::Manager()
{
}
Manager::~Manager()
{
}
Manager::Manager(char *pcName, char *pcNo, int nDept, int nLvl)
:Employee(pcName, pcNo, nDept) //构造函数,调用基类的构造函数
{
Setlvl(nLvl);
}
void Manager::Setlvl(int nLvl) //设置级别
{
m_nLevel = nLvl;
}
void Manager::Display() //重定义,输出经理的信息
{
cout << "姓名:" << m_cName << endl
<< "编号:" << m_cNo << endl
<< "部门号:" << m_nDepartment << endl
<< "级别:" << m_nLevel << endl;
}
// ClassExample20220505.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include"Manager.h"
#include
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
Employee e("孙悟空", "500001", 12);
e.Display();
Manager m("唐僧", "9800152", 12, 8);
m.Display();
m.SetName("菩提老祖");
m.SetNo("9800151");
m.SetDept(3);
m.Setlvl(10);
m.Display();
getchar();
return 0;
}
运行结果:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)