C++类的基础实现(Company)

#include <iostream>
#include <cstring>

using namespace std;

class Sale     //销售额
{
    protected:
        int m_sale;
        static int all_sale;

      public:
        Sale(int s)
        {
            m_sale = s;
            all_sale += s;
        }
};

int Sale::all_sale = 0;

class People
{
    protected:
      char m_name[20];
      int m_salary;
      int m_num;
    public:
    People(const char *name)
    {
        strcpy(m_name, name);
    }

    virtual void show() = 0;
};

class SaleMan : public Sale
{
    protected:
      char m_name[20];
      int m_salary;
    public:
      static int m_num;
      int m_id;

    public:
      SaleMan(const char *name, int s) : Sale(s)
      {
          strcpy(m_name, name);
          m_salary = m_sale * 4/10;
          m_num++;
          m_id = m_num;
      }
      void show()
      {
          cout << "姓名:" << m_name << "  "
               << "职位:"
               << "销售员"
               << "  "
               << "编号"
               << m_id
               << "  "
               << "薪水:" << m_salary << endl;
      }
};

int SaleMan::m_num = 1000;

class SaleManager : public Sale, public People
{
    public:
      SaleManager(const char *name, int s) : Sale(s), People(name)
      {
          m_salary = 4000 +all_sale * 2/10;
      }
      void show()
      {
          cout << "姓名:" << m_name << "  "
               << "职位:"
               << "销售经理"
               << "  "
               << "薪水:" << m_salary << endl;

      }
};

class Manager : public People
{
    public:
      Manager(const char *name) : People(name)
      {
          m_salary = 8000;
      }
      void show()
      {
          cout << "姓名:" << m_name << "  "
               << "职位:"
               << "经理"
               << "  "
               << "薪水:" << m_salary << endl;
      }
};

class Technician : public People
{
    protected:
      int m_time;
    public:
      Technician(const char *name, int t) : People(name)
      {
          m_time = t;
          m_salary = t * 100;
      }
      void show()
      {
          cout << "姓名:" << m_name << "  "
               << "职位:"
               << "技术员"
               << "  "
               << "薪水:" << m_salary << endl;
      }
};

int main(int argc, char const *argv[])
{
    SaleMan a("Loli",9000);
    SaleMan a1("Lila", 5000);
    SaleMan a2("Lancy", 5000);
    SaleMan a3("Lange", 5000);
    SaleManager b("Ricardo",5000);
    Manager c("Liming");
    Technician d("Robot", 135);
    Technician d1("Rilly", 152);

    a.show();
    a1.show();
    a2.show();
    a3.show();
    b.show();
    c.show();
    d.show();
    d1.show();
    //system("cls");
    return 0;
}
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭