employee.h
来自「数据结构C++代码,经典代码,受益多多,希望大家多多支持」· C头文件 代码 · 共 93 行
H
93 行
#include <iostream.h>
#include <string.h>
// base class for all employees
class Employee
{
protected:
// maintain an employee's name and social
// security number
char name[64];
char ssn[10];
public:
// constructor
Employee(char n[], char s[]);
// print basic employee information
void PrintEmployeeInfo(void);
};
// constructor. assign the name and social
// security number
Employee::Employee(char n[], char s[])
{
strcpy(name,n);
strcpy(ssn,s);
}
// print the name and social security number
void Employee::PrintEmployeeInfo(void)
{
cout << "Name: " << name << endl;
cout << "SSN: " << ssn << endl;
}
// salaried employee "is an" employee with a monthly
// salary
class SalaryEmployee : public Employee
{
private:
// monthly salary
float salary;
public:
// constructor
SalaryEmployee(char n[], char s[], float sal);
// print salary and base class information
void PrintEmployeeInfo(void);
};
// constructor. initialize base class and salary
SalaryEmployee::SalaryEmployee(char n[], char s[], float sal):
Employee(n,s),salary(sal)
{}
// execute PrintEmployee for base class and add
// information about the salary
void SalaryEmployee::PrintEmployeeInfo(void)
{
Employee::PrintEmployeeInfo();
cout << "Status: salaried employee" << endl;
cout << "Salary: " << salary << endl;
}
// salaried employee "is an" employee paid by the hour
class TempEmployee : public Employee
{
private:
// pay per hour and hours worked
float hourlypay;
float hoursworked;
public:
// constructor
TempEmployee(char n[], char s[], float hp, int hw);
// print salary and base class information
void PrintEmployeeInfo(void);
};
// constructor. initialize base class, hourly pay rate and number
// of hours worked
TempEmployee::TempEmployee(char n[], char s[], float hp, int hw):
Employee(n,s), hourlypay(hp), hoursworked(hw)
{}
// execute PrintEmployee for base class and print earnings
void TempEmployee::PrintEmployeeInfo(void)
{
Employee::PrintEmployeeInfo();
cout << "Status: temporary employee" << endl;
cout << "Earnings: " << hourlypay * hoursworked << endl;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?