WDNMde_ 2020-06-13 11:03 采纳率: 50%
浏览 211
已采纳

无法解析的外部命令,大佬们看看函数没有实现吗??继承的问题

#include
#include
#include
#include
using namespace std;
class CommissionEmployee
{
public:
CommissionEmployee(const std::string &, const std::
string &,
const std::string &, double = 0.0, double = 0.0);
void setFirstName(const std::string &);
std::string getFirstName() const;
void setLastName(const std::string &);
std::string getLastName() const;
void setSocialSecurityNumber(const std::string &);
std::string getSocialSecurityNumber() const;
void setGrossSales(double);
double getGrossSales() const;
void setCommissionRate(double);
double getCommissionRate() const;
double earnings() const;
void print() const;
private:
std::string firstName;
std::string lastName;
std::string socialSecurityNumber;
double grossSales;
double commissionRate;
};
class BasePlusCommissionEmployee : public CommissionEmployee
{
public:
BasePlusCommissionEmployee(const std::string&,
const std::string&, const std::string&,
double = 0.0, double = 0.0, double = 0.0);
void setBaseSalary(double);
double getBaseSalary() const;
double earnings() const;
void print() const;
//类BasePlusCommissionEmployee 的对象可以直接访问继承于类CommissionEmployce 中声明为 protected 的数据成员
//派生类获得了访问 protected 基类数据成员的特权
private:
double baseSalary;
};
CommissionEmployee::CommissionEmployee(
const string &first, const string &last,
const string &ssn, double sales, double rate)
:firstName(first), lastName(last),//成员初始化器
socialSecurityNumber(ssn)
{

setGrossSales(sales);
setCommissionRate(rate);

}
void CommissionEmployee::setFirstName(const string &first)
{
firstName = first;
}
string CommissionEmployee::getFirstName() const
{
return firstName;
}
void CommissionEmployee::setLastName(const string &last)
{
lastName = last;
}

string CommissionEmployee::getLastName() const
{
return lastName;
}
void CommissionEmployee::setSocialSecurityNumber(const
string &ssn)
{
socialSecurityNumber = ssn;
}
string CommissionEmployee::getSocialSecurityNumber() const
{
return socialSecurityNumber;
}

void CommissionEmployee::setGrossSales(double sales)
{
if (sales >= 0.0)
grossSales = sales;
else
throw invalid_argument("Gross sales must be >= 0.0");
}
double CommissionEmployee::getGrossSales() const
{
return grossSales;
}
void CommissionEmployee::setCommissionRate(double rate)
{

    if (rate > 0.0 && rate < 1.0)
        commissionRate = rate;
    else
        throw invalid_argument("Commission rate must be > 0.0and < 1.0");

}
double CommissionEmployee::getCommissionRate() const
{
return commissionRate;
}
double CommissionEmployee::earnings() const
{
return getCommissionRate() * getGrossSales();
}
void CommissionEmployee::print() const
{
cout << "雇员: " << firstName << ' ' << lastName
<< "\n社会保障号码: " << socialSecurityNumber
<< "\n总销售额 : " << grossSales
<< "\n提成 : " << commissionRate;
}
BasePlusCommissionEmployee::BasePlusCommissionEmployee(
//成员初始化器语法调用构造函数
const string&first, const string&last, const string&ssn, double sales, double rate, double salary)
: CommissionEmployee(first, last, ssn, sales, rate)
{
setBaseSalary(salary);
}
void BasePlusCommissionEmployee::setBaseSalary(
double salary)
{
if (salary >= 0.0)
baseSalary = salary;
else
throw invalid_argument("Salary must be >= 0.0");
}
double BasePlusCommissionEmployee::getBaseSalary() const
{
return baseSalary;
}
double BasePlusCommissionEmployee::earnings() const
{
return getBaseSalary() + CommissionEmployee::earnings();
}
void BasePlusCommissionEmployee::print() const
{
cout << "base-salaried ";
CommissionEmployee::print();
cout << "\nbase salary : " << getBaseSalary();
}
int main()
{
BasePlusCommissionEmployee
employee("Bob", "Lewis", "333-33-3333", 5000, 0.4, 3000);
cout << fixed << setprecision(2);
cout << "Employee information obtained by get functions : \n"
<< "\nFirst name is " << employee.getFirstName()
<< "\nLast name is " << employee.getLastName()
<< "\nSocial security number is "
<< employee.getSocialSecurityNumber()
<< "\nGross sales is " << employee.getGrossSales()
<< "\nCommission rate is " << employee.getCommissionRate()
<< "\nBase salary is " << employee.getBaseSalary() << endl;
employee.setBaseSalary(1000);
cout << "\nUpdated employee information output by print function : \n"
<< endl;
employee.print();
cout << "\n\nEmployee's earnings : " << employee.earnings()
<< endl;
}

  • 写回答

1条回答 默认 最新

  • threenewbee 2020-06-13 11:34
    关注

    测试了你的代码,没有报错
    图片说明

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 加一个K2暂停音乐的功能
  • ¥15 完成虚拟机环境配置,还有安装kettle
  • ¥15 2024年全国大学生数据分析大赛A题:直播带货与电商产品的大数据分析 问题5. 请设计一份优惠券的投放策略,需要考虑优惠券的数量、优惠券的金额、投放时间段和投放商品种类等因素。求具体的python代码
  • ¥15 有人会搭建生鲜配送自营+平台的管理系统吗
  • ¥15 用matlab写代码
  • ¥30 motoradmin系统的多对多配置
  • ¥15 求组态王串口自定义通信配置方法或代码?
  • ¥15 实验 :UML2.0 结构建模
  • ¥20 用vivado写数字逻辑实验报告撰写,FPGA实验
  • ¥15 为什么shp文件会有这种小方块?