需求描述

1、企业增加了一种全新的工种,称为销售顾问,其工资按照顾问咨询次数和销售产品的数量共同计算,每咨询一次报酬300元,每销售一件产品提成50元,请在已有类的基础上设计该员工类;
2、由于员工类型多样,系统需要采用多态性对各类员工对象数据进行统一保存和处理,请根据此要求将已有类中涉及到员工工资计算和信息输出的接口设置为虚函数,为多态性的使用奠定基础;
3、设计类型SalaryManager,其成员变量可保存系统中所有员工类型的对象,设计接口getTotalSalary和getAllInfo,分别计算所有员工的工资以及输出所有员工的信息;
4、编写一个测试main方法,为每种员工类型创建1-2个对象,并使用SalaryManager类型对象进行管理,调用方法输出所有员工的工资以及员工信息。

类图设计

总体类图:

Employee类:


ProductLineEmployee类:

SaleEmployee类:

AdviserEmployee类:

SaleAdviserEmployee类:

SalaryManager类:

源代码

//class.h
#include <string>
#include <vector>using namespace std;class Date{int year;int month;int day;public:Date();Date(int year,int month,int day);Date(const Date& x);~Date();Date& operator=(const Date& x);int getYear();void setYear(int year);int getMonth();void setMonth(int month);int getDay();void setDay(int day);void pritDate();float returnSub(Date s);
};class Salary{double money;public:Salary();Salary(double money);Salary(const Salary& x);~Salary();Salary& operator=(const Salary& x);Salary& operator+(const Salary& x);Salary& operator-(const Salary& x);double getMoney();void setMoney(double money);
};class Employee{static int counts;int no;string name;Salary sal;Date start;Date last;public:Employee();Employee(string name,Salary sal,Date start,Date last);Employee(const Employee& x);~Employee();Employee& operator=(const Employee& x);int getNo();string getName();void setName(string name);Salary getSalary();void setSalary(Salary sal);Date getStart();void setStart(Date start);Date getLast();void setLast(Date last);virtual void getMessage();virtual void printSalary();
};class ProductLineEmployee: public Employee{string type;public:ProductLineEmployee();ProductLineEmployee(string name,Salary sal,Date start,Date last);ProductLineEmployee(const ProductLineEmployee& x);~ProductLineEmployee();ProductLineEmployee& operator=(const ProductLineEmployee& x);void getMessage();void printSalary();
};class SaleEmployee: public Employee{string type;public:SaleEmployee();SaleEmployee(string name,Salary sal,Date start,Date last);SaleEmployee(const SaleEmployee& x);~SaleEmployee();SaleEmployee& operator=(const SaleEmployee& x);void getMessage();void printSalary();
};class AdviserEmployee: public Employee{string type;public:AdviserEmployee();AdviserEmployee(string name,Salary sal,Date start,Date last);AdviserEmployee(const AdviserEmployee& x);~AdviserEmployee();AdviserEmployee& operator=(const AdviserEmployee& x);void getMessage();void printSalary();
};class SaleAdviserEmployee: public Employee{string type;
public:SaleAdviserEmployee();SaleAdviserEmployee(string name,Salary sal,Date start,Date last);SaleAdviserEmployee(const SaleAdviserEmployee& x);~SaleAdviserEmployee();SaleAdviserEmployee& operator=(const SaleAdviserEmployee& x);void getMessage();void printSalary();
};class SalaryManager{vector<Employee*> ob;
public:SalaryManager();~SalaryManager();void insertEmployee(Employee* x);void delEmployee();void getTotalSalary();void getTotalInfo();
};//class.cpp
#include "class.h"
#include <iostream>using namespace std;Date::Date(){year = 2020;month = 5;day = 19;
}Date::Date(int year,int month,int day){this->year = year;this->month = month;this->day = day;
}Date::Date(const Date& x){year = x.year;month = x.month;day = x.day;
}Date::~Date(){};Date& Date::operator=(const Date& x){if(this == &x)return *this;year = x.year;month = x.month;day = x.day;return *this;
}int Date:: getYear(){return year;
}void Date::setYear(int year){if(year <= 0){cout << "data is illegal!" << endl;this->year = 2020;}elsethis->year = year;
}int Date::getMonth(){return month;
}void Date::setMonth(int month){if(month <= 0 || month >12){cout << "data is illegal!" << endl;this->month = 5;}elsethis->month = month;
}int Date::getDay(){return day;
}void Date::setDay(int day){if(day <= 0 || day > 31){cout << "data is illegal!" << endl;this->day = 19;}elsethis->day = day;
}void Date::pritDate(){cout << year << "-" << month << "-" << day << endl;
}float Date::returnSub(Date s){return ((year-s.year)*12 + ((month+day/30) - (s.month +s.day/30)));
}Salary::Salary(){money = 0.0;
}Salary::Salary(double money){this->money = money;
}Salary::Salary(const Salary& x){money = x.money;
}Salary::~Salary(){};Salary& Salary::operator=(const Salary& x){if(this == &x)return *this;money = x.money;return *this;
}Salary& Salary::operator+(const Salary& x){money += x.money;return *this;
}Salary& Salary::operator-(const Salary& x){money -= x.money;return *this;
}double Salary::getMoney(){return money;
}void Salary::setMoney(double money){if(money < 0){cout << "data is illegal!" << endl;this->money = 0.0;}elsethis->money = money;
}int Employee::counts = 0;Employee::Employee(){no = ++counts;name = "null";sal = 0.0;
}Employee::Employee(string name,Salary sal,Date start,Date last){no = ++counts;this->name = name;this->sal = sal;this->start = start;this->last = last;
}Employee::Employee(const Employee& x){no = ++counts;name = x.name;sal = x.sal;start = x.start;last = x.last;
}Employee::~Employee(){counts--;
}Employee& Employee::operator=(const Employee& x){if(this == &x)return *this;no = ++counts;name = x.name;sal = x.sal;start = x.start;last = x.last;return *this;
}int Employee::getNo(){return no;
}string Employee::getName(){return name;
}void Employee::setName(string name){this->name = name;
}Salary Employee:: getSalary(){return sal;
}void Employee::setSalary(Salary sal){double temp = sal.getMoney();if(temp < 0){cout << "date is illegal!" << endl;this->sal = 0.0;}elsethis->sal = sal;
}Date Employee:: getStart(){return start;
}void Employee::setStart(Date start){this->start = start;
}Date Employee::getLast(){return last;
}void Employee::setLast(Date last){this->last = last;
}void Employee::getMessage(){cout << "no: " << no << endl;cout << "name: " << name << endl;double t1 = sal.getMoney() ;cout << "salary: " << t1<< endl;cout << "startDate: " ;start.pritDate();cout << "lastDate: ";last.pritDate();cout << "please input any key to continue_ " << endl;char ch = getchar();
}void Employee::printSalary(){}ProductLineEmployee::ProductLineEmployee(){type = "ProductLineEmployee";
}ProductLineEmployee::ProductLineEmployee(string name,Salary sal,Date start,Date last):Employee(name,sal,start,last){this->type = "ProductLineEmployee";
}ProductLineEmployee::ProductLineEmployee(const ProductLineEmployee& x):Employee(x){type = x.type;
}ProductLineEmployee::~ProductLineEmployee(){}ProductLineEmployee& ProductLineEmployee::operator=(const ProductLineEmployee& x){if(this == &x)return *this;type = x.type;return *this;
}void ProductLineEmployee::getMessage(){cout << "no: " << this->getNo() << endl;cout << "name: " << this->getName() << endl;cout << "employeeType: " << type << endl;Salary t1 = this->getSalary();double t2 = t1.getMoney();cout << "salary: " << t2 << endl;Date t3 = this->getStart();cout << "startDate: ";t3.pritDate();t3 = this->getLast();cout << "lastDate: ";t3.pritDate();cout << "please input any key to continue_ ";char ch = getchar();
}void ProductLineEmployee::printSalary(){Salary t1 = this->getSalary();double t2 = t1.getMoney();Date t3 = this->getLast();Date t4 = this->getStart();float f = t3.returnSub(t4);cout << "count salary: " << t2*f << endl;
}SaleEmployee::SaleEmployee(){type = "SaleEmployee";
}SaleEmployee::SaleEmployee(string name,Salary sal,Date start,Date last):Employee(name,sal,start,last){this->type = "SaleEmployee";
}SaleEmployee::SaleEmployee(const SaleEmployee& x):Employee(x){type = x.type;
}SaleEmployee::~SaleEmployee(){}SaleEmployee& SaleEmployee::operator=(const SaleEmployee& x){if(this == &x)return *this;type = x.type;return *this;
}void SaleEmployee::getMessage(){cout << "no: " << this->getNo() << endl;cout << "name: " << this->getName() << endl;cout << "employeeType: " << type << endl;Salary t1 = this->getSalary();double t2 = t1.getMoney();cout << "basic salary: " <<t2 << endl;Date t3 = this->getStart();cout << "startDate: ";t3.pritDate();t3 = this->getLast();cout << "lastDate: " ;t3.pritDate();cout << "please input any key to continue_ ";char ch = getchar();
}void SaleEmployee::printSalary(){Salary t1 = this->getSalary();double t2 = t1.getMoney();Date t3 = this->getLast();Date t4 = this->getStart();float f = t3.returnSub(t4);cout << "count salary: " << t2*f +50*50<< endl;
}AdviserEmployee::AdviserEmployee(){type = "AdviserEmployee";
}AdviserEmployee::AdviserEmployee(string name,Salary sal,Date start,Date last):Employee(name,sal,start,last){this->type = "AdviserEmployee";
}AdviserEmployee::AdviserEmployee(const AdviserEmployee& x):Employee(x){type = x.type;
}AdviserEmployee::~AdviserEmployee(){}AdviserEmployee& AdviserEmployee::operator=(const AdviserEmployee& x){if(this == &x)return *this;type = x.type;return *this;
}void AdviserEmployee::getMessage(){cout << "no: " << this->getNo() << endl;cout << "name: " << this->getName() << endl;cout << "employeeType: " << type << endl;cout << "salary:  according to the counts of asking" << endl;Date t3 = this->getStart();cout << "startDate: ";t3.pritDate();t3 = this->getLast();cout << "lastDate: " ;t3.pritDate();cout << "please input any key to continue_ ";char ch = getchar();
}void AdviserEmployee::printSalary(){cout << "count salary: " << 25*50 << endl;
}SaleAdviserEmployee::SaleAdviserEmployee(){type = "SaleAdviserEmployee";}SaleAdviserEmployee::SaleAdviserEmployee(string name,Salary sal,Date start,Date last):Employee(name,sal,start,last){type = "SaleAdviserEmployee";
}SaleAdviserEmployee::SaleAdviserEmployee(const SaleAdviserEmployee& x):Employee(x){type = x.type;
}SaleAdviserEmployee::~SaleAdviserEmployee(){}SaleAdviserEmployee& SaleAdviserEmployee::operator=(const SaleAdviserEmployee& x){if(this == &x)return *this;type = x.type;return *this;
}void SaleAdviserEmployee::getMessage(){cout << "no: " << this->getNo() << endl;cout << "name: " << this->getName() << endl;cout << "employeeType: " << type << endl;cout << "salary:  according to the counts of asking and sale" << endl;Date t3 = this->getStart();cout << "startDate: ";t3.pritDate();t3 = this->getLast();cout << "lastDate: " ;t3.pritDate();cout << "please input any key to continue_ ";char ch = getchar();
}void SaleAdviserEmployee::printSalary(){cout << "count salary: " << 25*300 + 12*50 << endl;
}SalaryManager::SalaryManager(){}SalaryManager::~SalaryManager(){}void SalaryManager::insertEmployee(Employee* x){ob.push_back(x);}void SalaryManager::delEmployee(){ob.pop_back();}void SalaryManager::getTotalSalary(){cout << "Total Employee's Salary:\n\n";vector<Employee*>::iterator it;for(it=ob.begin();it!=ob.end();it++){cout << "no: "<< (*it)->getNo() << endl;cout << "name: " << (*it)->getName() << endl;cout << "salary: " ;(*it)->printSalary();cout << endl << endl;}
}void SalaryManager::getTotalInfo(){cout << "Total Employee's Information:\n\n";vector<Employee*>::iterator it;for(it=ob.begin();it!=ob.end();it++){(*it)->getMessage();cout<< endl << endl;}
}//main.cpp
#include <iostream>
#include "class.h"using namespace std;int main()
{Date s(2000,2,20);Date e(2020,6,1);Date e1(2019,6,1);Salary m1(500);Salary m2(400);Salary m3;ProductLineEmployee p1("Tom1",m1,s,e);ProductLineEmployee p2("Tom2",m1,s,e1);SaleEmployee s1("Amy",m2,s,e);AdviserEmployee a1("Jack1",m3,s,e);AdviserEmployee a2("Jack2",m3,s,e);AdviserEmployee a3("Jack3",m3,s,e);SaleAdviserEmployee sa1("Lucy1",m3,s,e);SaleAdviserEmployee sa2("Lucy2",m3,s,e);SalaryManager m;m.insertEmployee(&p1);m.insertEmployee(&p2);m.insertEmployee(&s1);m.insertEmployee(&a1);m.insertEmployee(&a2);m.insertEmployee(&a3);m.insertEmployee(&sa1);m.insertEmployee(&sa2);m.getTotalInfo();cout << "" << endl;m.getTotalSalary();return 0;
}

部分功能测试






更多相关内容请参见

我的博客

C++ 建立工资计算系统(3)相关推荐

  1. 建立工资计算系统(2)

    问题描述 某企业为了提升自身管理效率,特别委托你为企业设计一个自动计算和发放员工工资的软件,具体设计内容包括: 1.随着该企业规模的扩展,企业的员工类型逐渐多样化,工资系统的管理方式要随之发生改变.企 ...

  2. 建立工资计算系统(1)——员工和工资

    问题描述 1.创建一个Date类,能够表示一个日期,除了对日期进行输出.设置的一般成员方法以外,还需要一个方法,能够计算对象所保存日期与参数所给日期之间的差距,计算单位为"月",同 ...

  3. 工资计算系统数据流图绘制

    以下内容知识点并非原创,觉得分析问题的思路非常好.内容摘自: https://www.bilibili.com/video/av25329421/?p=7 工资计算系统数据流图绘制 顶层数据流图 功能 ...

  4. 计算机会计学ufo报表,计算机会计实践部分工资管理系统.ppt

    <计算机会计实践部分工资管理系统.ppt>由会员分享,可在线阅读,更多相关<计算机会计实践部分工资管理系统.ppt(22页珍藏版)>请在人人文库网上搜索. 1.计算机会计学,主 ...

  5. 在Linux下制作工资表(转)

    在Linux下制作工资表(转) 在Linux桌面系统下,使用办公套件的电子表格模块可方便制作各种常用的表格,并进行数据计算或插入图表.下面以工资表为例,讲解在Linux下应用RedOffice电子表格 ...

  6. C语言|职工工资管理系统

    #include <stdio.h> #include <stdlib.h> #include <math.h> #include <windows.h> ...

  7. Access教程 第二章 建立数据库

    本章内容 ◆ 数据库的设计概念与创建数据库. ◆ 表的创建及表与表之间的关系. ◆ 数据库的修改.设计与编辑. 一.数据库的设计 1.概念及准则 下面介绍数据库设计的概念,及由此而产生的数据库设计准则 ...

  8. wps工资表怎么用计算机,用WPS表格轻松制作出美观实用的工资条

    用WPS表格轻松制作出美观实用的工资条 分类:计算机等级 | 更新时间:2016-07-08| 来源:转载 在任何企业之财务管理中,一定少不了工资计算和设计工资条.工资条头之美观及操作速度是设计的一个 ...

  9. linux生成表格文件大小,在Linux下制作工资表(转)

    在Linux下制作工资表(转)[@more@] 在Linux桌面系统下,使用办公套件的电子表格模块可方便制作各种常用的表格,并进行数据计算或插入图表.下面以工资表为例,讲解在Linux下应用RedOf ...

最新文章

  1. 恕我直言,牛逼哄哄的MongoDB你可能只会30%
  2. Spring的环绕通知
  3. 给求职的同学的几点建议
  4. 添加自定义菜单,报错40155
  5. adhoc包无法安装_iOS 5.1.1 设备不能安装AdHoc问题版本号
  6. webpack实用配置
  7. 身为一个产品经理应该了解自己的本职
  8. 程序员身体容易出什么毛病..
  9. leetcode 21 合并两个有序链表 (python)
  10. MyBatis的其它方法
  11. python3.5和python3.6关于json模块的区别
  12. android 自定义pickerview,Simple PickerView for Android - 这是一个高仿 IOS PickerView 控件的库...
  13. IMX6DL 串口篇
  14. 有关大学计算机基础考试的试题,大学计算机基础考试试题
  15. css canvas_混合canvas API和HTML / CSS模型
  16. QQ游戏-大家来找茬 外挂
  17. Yocto系列讲解[理论篇]26 - BitBake全过程(4)
  18. 私有云厂商云宏破解金融行业转型“数字底座”难题
  19. cad记忆口诀_42条简单易记的CAD口诀,一天精通入门,七天上手绘图!
  20. 运用hibernate接口实现增删改查

热门文章

  1. disable到底是指什么
  2. 【Proxyee-down】一款比IDM还强大的下载器!
  3. 亚马逊主图视频是什么?有哪些优势?
  4. 怎么调用通达信接口?
  5. 10年代码经验程序员UP主复刻“阴间”超级马里奥,获赞27万,马里奥:我头呢?
  6. 【Proteus仿真】【51单片机】PWM电机调速系统设计
  7. word中实现文献引用
  8. PHP MySQL 持久连接(mysql_pconnect)
  9. 《 公共关系学 》综合复习资料
  10. 什么是多态,JAVA 中多态的实现机制