-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSalariedEmployee.cpp
More file actions
40 lines (34 loc) · 1.15 KB
/
SalariedEmployee.cpp
File metadata and controls
40 lines (34 loc) · 1.15 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
// Fig. 12.12: SalariedEmployee.cpp
// SalariedEmployee class member-function definitions.
#include <iomanip>
#include <stdexcept>
#include <sstream>
#include "SalariedEmployee.h" // Salaried Employee class definition
using namespace std;
// constructor
SalariedEmployee::SalariedEmployee(const string& first,
const string& last, const string& ssn, double salary)
: Employee(first, last, ssn) {
setWeeklySalary(salary);
}
// set salary
void SalariedEmployee::setWeeklySalary(double salary) {
if (salary < 0.0) {
throw invalid_argument("Weekly salaray must be >= 0.0");
}
weeklySalary = salary;
}
// return salary
double SalariedEmployee::getWeeklySalary() const { return weeklySalary; }
// calculate earnings;
// override pure virtual earnings in Employee
double SalariedEmployee::earnings() const { return getWeeklySalary();}
// return a string representation of SalariedEmployee's information
string SalariedEmployee::toString() const {
ostringstream output;
output << fixed << setprecision(2);
output << "salaried employee: "
<< Employee::toString() // reuse abstract base-class function
<< "\nweekly salary: " << getWeeklySalary();
return output.str();
}