Class inheritance and derivation definition and use

3. A company's finance department needs to develop a program that calculates employee salaries. The company has 3 types of employees. The wages of the workers are the hourly
salary (set by the member function) multiplied by the working hours of the month (set by the member function) plus the salary of the seniority; the salary of the salesman
is the hourly salary (set by the member function) Set by member function) multiplied by the working hours of the month (set by member function)
plus plus seniority wages, where the sales commission is equal to the amount of goods sold by the salesperson in the current month (set by member function) 1% of the salary;
the salary of management personnel is the basic salary of 1,000 yuan plus seniority salary.
Seniority wages means that the monthly wages of employees will increase by 35 yuan for each additional year of service in the company . Please use the object-oriented method to analyze and design this program, and write a complete
program in C++ language.
[Reference answer]/ biancheng4_3.cpp: Class inheritance and derivation definition and use /
#include
#include
using namespace std;
class Employee
{ protected: char name[30]; int working_years; public: Employee(char nm,int wy) { strcpy(name,nm); working_years=wy; }









char * GetName( ) {return name;}
float ComputePay( ) {return 35.0f
working_years;}
};
class Worker:public Employee
{
float hours,wage;
public:
Worker(char *nm,int wy):Employee(nm,wy)
{
hours=0;
wage=0;
}

void SetHours(float hrs) {hours=hrs;}
void SetWage(float wg) {wage=wg;}
float ComputePay( ) { return Employee::ComputePay( )+wage*hours;}
};
class SalesPerson:public Worker
{ float sales_made;
public:
SalesPerson(char nm,int wg):Worker(nm,wg)
{ sales_made=0;}
void SetSales(float sl) {sales_made=sl;}
float ComputePay( )
{ return Worker::ComputePay( )+0.01f
sales_made;}
};
class Manager:public Employee
{
float salary;
public:
Manager(char *nm,int wy):Employee(nm,wy)
{ salary=0; }
void SetSalary(float sl) {salary=sl;}
float ComputePay( )
{ return Employee::ComputePay( )+salary;}
};
void main( )
{ Worker Zhang(“Zhang wei”,8);
Zhang.SetHours(181.5f);
Zhang.SetWage(9.5f);
cout<<“Salary for “<<Zhang.GetName( )<<” is :”;
cout<<Zhang.ComputePay( )<<"\n";
SalesPerson Wang(“Wang min”,11);
Wang.SetSales(38750.85f);
Wang.SetHours(198.7f);
Wang.SetWage(10.1f);
cout<<“Salary for “<<Wang.GetName( )<<” is :”;
cout<<Wang.ComputePay( )<<"\n";
Manager He(“He jun”,25);
He.SetSalary(567.5f);
cout<<“Salary for “<<He.GetName( )<<” is :”;
cout<<He.ComputePay( )<<"\n";
}

Guess you like

Origin blog.csdn.net/AR_Pai/article/details/110950800
Recommended