美文网首页
多态薪酬计算

多态薪酬计算

作者: 墨狂之逸才 | 来源:发表于2018-06-19 15:58 被阅读13次

    Employee.h

    #pragma once
    #include <iostream>
    #include <string>
    using namespace std;
    //姓名 工号 等级
    class Employee
    {
    public:
        Employee();
        virtual void getSalary()=0;
        virtual void show();
        virtual ~Employee();//虚析构函数
    protected:
        float m_salary;
        float m_baseSalary;//基本工资
        float m_attendanceRate;//出勤率
        string m_name;
        int m_no;
        int m_level;
    };
    
    
    
    

    Employee.cpp

    #include "stdafx.h"
    #include "Employee.h"
    #include <iostream>
    using namespace std;
    
    Employee::Employee()
    {
        m_name = "";
        m_no = 0;
        m_level = 0;
        m_attendanceRate = 0;
        m_baseSalary = 2500;
        m_salary = 0.0;//计算得到
    }
    
    
    Employee::~Employee()
    {
    }
    
    void Employee::show(){
        cout << "姓名:" << m_name << "工号:" << m_no << "等级:" << m_level << "薪资:" << m_salary << endl;
    }
    
    

    OrdinaryEmployee.h

    #pragma once
    #include "Employee.h"
    class OrdinaryEmployee : public Employee
    {
    public:
        OrdinaryEmployee();
        //不指明基类构造就会调用默认构造
        OrdinaryEmployee(string name,int no,int level,float attendanceRate);
        virtual void getSalary();
    
        ~OrdinaryEmployee();
    };
    
    

    OrdinaryEmployee.cpp

    #include "stdafx.h"
    #include "OrdinaryEmployee.h"
    
    
    OrdinaryEmployee::OrdinaryEmployee()
    {
    }
    
    void OrdinaryEmployee::getSalary(){
        m_salary = m_attendanceRate * m_baseSalary;
    }
    
    OrdinaryEmployee::OrdinaryEmployee(string name, int no, int level, float attendanceRate){
        m_name = name;
        m_no = no;
        m_level = level;
        m_attendanceRate = attendanceRate;
    }
    
    
    OrdinaryEmployee::~OrdinaryEmployee()
    {
    }
    
    

    SalesMan.h

    #pragma once
    #include "Employee.h"
    #include "OrdinaryEmployee.h"
    class SalesMan : public OrdinaryEmployee
    {
    public:
        SalesMan();
        SalesMan(string name, int no, int level, float commissionRate, float sales, float attendanceRate);
        ~SalesMan();
        void getSalary();
    private:
        float m_commissionRate;//提成比例
        float m_sales;//销售份额
    
    };
    
    
    

    SalesMan.cpp

    #include "stdafx.h"
    #include "SalesMan.h"
    #include <iostream>
    using namespace std;
    
    SalesMan::SalesMan()
    {
    }
    
    SalesMan::SalesMan(string name, int no, int level, float commissionRate, float sales, float attendanceRate) :OrdinaryEmployee(name, no, level, attendanceRate){
        m_sales = sales;
        m_commissionRate = commissionRate;
    }
    
    void SalesMan::getSalary(){
        m_salary = m_baseSalary * m_attendanceRate / 2 + m_sales * m_commissionRate;
    }
    
    SalesMan::~SalesMan()
    {
    }
    
    
    

    OrdinaryEmployee.h

    #pragma once
    #include "Employee.h"
    class OrdinaryEmployee : public Employee
    {
    public:
        OrdinaryEmployee();
        //不指明基类构造就会调用默认构造
        OrdinaryEmployee(string name,int no,int level,float attendanceRate);
        virtual void getSalary();
    
        ~OrdinaryEmployee();
    };
    
    
    

    OrdinaryEmployee.cpp

    #include "stdafx.h"
    #include "OrdinaryEmployee.h"
    
    
    OrdinaryEmployee::OrdinaryEmployee()
    {
    }
    
    void OrdinaryEmployee::getSalary(){
        m_salary = m_attendanceRate * m_baseSalary;
    }
    
    OrdinaryEmployee::OrdinaryEmployee(string name, int no, int level, float attendanceRate){
        m_name = name;
        m_no = no;
        m_level = level;
        m_attendanceRate = attendanceRate;
    }
    
    
    OrdinaryEmployee::~OrdinaryEmployee()
    {
    }
    
    

    main.cpp

    // 多态工资计算-23期-92-子羽.cpp : 定义控制台应用程序的入口点。
    
    //基本工资 = 2500 * 出勤率    
    //
    //提成 = 提成比例 * 销售份额
    //员工   姓名 工号 等级
    //普通员工 基本工资
    //经理 奖金 + 基本工资(奖金)
    //销售   基本工资 / 2 + 提成(提成比例, 销售份额)
    //结合继承,多态设计普通员工,经理,销售的薪酬计算
    
    #include "stdafx.h"
    #include "Manager.h"
    #include "SalesMan.h"
    #include "OrdinaryEmployee.h"
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        OrdinaryEmployee oe1 = OrdinaryEmployee("jason", 1, 1, 0.98);
        oe1.getSalary();
        oe1.show();
    
        Manager m1 = Manager("rose", 3, 1, 1 , 3000);
        m1.getSalary();
        m1.show();
    
        SalesMan am1 = SalesMan("jack", 2, 1, 0.95, 300000, 0.04);
        am1.getSalary();
        am1.show(); 
    
        return 0;
    }
    
    
    

    结果:

    薪资计算.png

    相关文章

      网友评论

          本文标题:多态薪酬计算

          本文链接:https://www.haomeiwen.com/subject/sknaeftx.html