⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 employee.h

📁 数据结构C++代码,经典代码,受益多多,希望大家多多支持
💻 H
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -