📄 vc0706.cpp
字号:
//Example 7.6:定义职工档案类
#include <afx.h>
#include <iostream.h>
// 定义工资类
class Salary
{
public:
float m_fWage; // 基本工资
float m_fSubsidy; // 岗位津贴
float m_fRent; // 房租
float m_fCostOfElec; // 电费
float m_fCostOfWater; // 水费
public:
float RealSum() // 计算实发工资
{
return m_fWage + m_fSubsidy
- m_fRent - m_fCostOfElec - m_fCostOfWater;
};
};
// 定义职务类型
enum Position
{
MANAGER, // 经理
ENGINEER, // 工程师
EMPLOYEE, // 职员
WORKER // 工人
};
// 定义职工类
class Employee
{
CString m_sDepartment; // 工作部门
CString m_sName; // 姓名
CTime m_tBirthdate; // 出生日期
Position m_nPosition; // 职务
CTime m_tDateOfWork; // 参加工作时间
Salary m_fSalary; // 工资
public:
void Register(CString Depart, CString Name, CTime tBirthdate,
Position nPosition, CTime tDateOfWork);
void SetSalary(float wage, float subsidy, float rent, float elec,
float water);
float GetSalary();
void ShowMessage(); // 打印职工信息
};
// 职工类的成员函数定义
void Employee::Register(CString Depart, CString Name, CTime tBirthdate,
Position nPosition, CTime tDateOfWork)
{
m_sDepartment = Depart;
m_sName = Name;
m_tBirthdate = tBirthdate;
m_nPosition = nPosition;
m_tDateOfWork = tDateOfWork;
}
void Employee::SetSalary(float wage, float subsidy, float rent,
float elec, float water)
{
m_fSalary.m_fWage=wage;
m_fSalary.m_fSubsidy=subsidy;
m_fSalary.m_fRent=rent;
m_fSalary.m_fCostOfElec=elec;
m_fSalary.m_fCostOfWater=water;
}
float Employee::GetSalary()
{
return m_fSalary.RealSum();
}
void Employee::ShowMessage()
{
cout << "Depart: " << m_sDepartment << endl;
cout << "Name: " << m_sName << endl;
cout << "Birthdate: " << m_tBirthdate.Format("%B %d, %Y") << endl;
switch(m_nPosition)
{
case MANAGER:
cout << "Position: " << "MANAGER" <<endl;
break;
case ENGINEER:
cout << "Position: " << "ENGINEER" <<endl;
break;
case EMPLOYEE:
cout << "Position: " << "EMPLOYEE" <<endl;
break;
case WORKER:
cout << "Position: " << "WORKER" <<endl;
break;
}
cout << "Date of Work: " << m_tDateOfWork.Format("%B %d, %Y") << endl;
cout << "Salary: " << GetSalary() <<endl;
cout<<"----------------------------------"<<endl;
}
#define MAX_EMPLOYEE 1000
void main()
{
Employee EmployeeList[MAX_EMPLOYEE]; // 定义职工档案数组
int EmpCount=0;
CTime birthdate,workdate;
//输入第一个职工数据
birthdate = CTime(1980,5,3,0,0,0);
workdate = CTime(1999,7,1,0,0,0);
EmployeeList[EmpCount].Register("人事处",
"张三",birthdate,MANAGER,workdate);
EmployeeList[EmpCount].SetSalary(1000,200,100,50,20);
EmpCount++;
//输入第二个职工数据
birthdate = CTime(1979,6,4,0,0,0);
workdate = CTime(2000,6,1,0,0,0);
EmployeeList[EmpCount].Register("图书馆",
"李斯",birthdate,MANAGER,workdate);
EmployeeList[EmpCount].SetSalary(1500,200,150,50,20);
EmpCount++;
//输出所有职工的记录
for(int i=0;i<EmpCount;i++)
EmployeeList[i].ShowMessage();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -