C++面向对象实例员工工资

假设某销售公司有一般员工,销售员工和销售经理。月工资计算办法:

一般员工月薪=基本工资

销售员工月薪=基本工资+销售额*提成率

销售经理月薪=基本工资+职务工资+销售额提成率

编写程序,定义一个表示基本员工的基类Employee,他包含三个表示员工基本信息的成员:

编号number,姓名name,和基本工资basicSalary。

由Employee类派生销售员工Salasman类,Salasman类包含两个新数据成员:销售额sales和静态数据成员提成比例commrate。

再由Salasman类派生表示销售经理的Salamanager类。Salasmanager类包含新书局成员:岗位工资jobSalary。

为这些类定义初始化数据的构造函数,以及输入数据Input 计算工资Pay 和输出工资条Print的成员函数。

该公司员工基本工资2000元,销售经理的岗位工资3000元,提成率=5/1000。在main函数中,输入若干不同的员工信息测试你的类结构。

代码如下:

#include<iostream>
#include<String.h>
using namespace std;
class Employee{
protected:
    char number[5];
    char name[10];
    double basicSalary;
public:
    Employee(char number1[]="",char name1[]="",double basicSalary1=2000){
        strcpy(number,number1);
        strcpy(name,name1);
        basicSalary=basicSalary1;
    }
    void Input();
    void Print();
};
void Employee::Input(){
    cout<<"编号:" ;   cin>> number;
    cout<<"姓名:" ;   cin>> name;
}
void  Employee::Print()
{
	cout<<"编号:"<<this->number<<"\t普通员工:"<<this->name<<"\t本月工资:"<<this->basicSalary<<endl;
}

class Salesman:public Employee{
protected:
    int sales;
    static double commrate;

public:
    Salesman(int sales1=0){
        sales=sales1;
    }
    void input(){
        Employee::Input();
		cout<<"本月个人售额:";
		cin>>this->sales;
    }
    double Pay()
	{
		double salary;
		salary=basicSalary+sales*commrate;
		return salary;
	}
	void Print()
	{
		cout<<"编号:"<<this->number<<"\t销售员:"<<this->name<<"\t本月工资:"<<this->Salesman::Pay()<<endl;
	}
};
double Salesman:: commrate=0.005;
class Salesmanager:public Salesman{
public:
    Salesmanager(double jSalary=3000){
        jobSalary = jSalary;
    }
    void input(){
        Employee::Input();
		cout<<"部门总销售额:";
		cin>>this->sales;
    }
    double Pay(){
        double salary;
		salary =jobSalary +sales*commrate;
		return salary;
	}
	void Print()
	{
		cout<<"编号:"<<this->number<<"\t销售经理:"<<this->name<<"\t本月工资:"<<this->Salesmanager::Pay()<<endl;
	}
protected:
	double jobSalary;
};

int main(){
  cout<<"普通员工:"<<endl;
  Employee a;
  a.Input();
  a.Print();

  cout<<"销售员:"<<endl;
  Salesman b;
  b.input();
  b.Print();

  cout<<"销售经理:"<<endl;
  Salesmanager c;
  c.input();
  c.Print();
}


发布了109 篇原创文章 · 获赞 40 · 访问量 6141

猜你喜欢

转载自blog.csdn.net/qq_15719613/article/details/105691876