-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasePlusCommissionEmployee.cpp
More file actions
44 lines (38 loc) · 1.28 KB
/
BasePlusCommissionEmployee.cpp
File metadata and controls
44 lines (38 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Fig. 12.16: BasePlusCommissionEmployee.cpp
// BasePlusCommissionEmployee member-function definitions.
#include <iomanip>
#include <stdexcept>
#include <sstream>
#include "BasePlusCommissionEmployee.h"
using namespace std;
// constructor
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); // validate and store base salary
}
// set base salary
void BasePlusCommissionEmployee::setBaseSalary(double salary) {
if (salary < 0.0) {
throw invalid_argument("Salary must be >= 0.0");
}
baseSalary = salary;
}
// return base salary
double BasePlusCommissionEmployee::getBaseSalary() const {
return baseSalary;
}
// calculate earnings;
// override virtual function earnings in CommissionEmployee
double BasePlusCommissionEmployee::earnings() const {
return getBaseSalary() + CommissionEmployee::earnings();
}
// return a string representation of a BasePlusCommissionEmployee
string BasePlusCommissionEmployee::toString() const {
ostringstream output;
output << fixed << setprecision(2);
output << "base-salaried " << CommissionEmployee::toString()
<< "; base salary: " << getBaseSalary();
return output.str();
}