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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
|
BENEFITS.H
#include <iostream>
#include <string>
using namespace std;
class Benefit {
public:
Benefit();
Benefit(string, double, int);
void displayBenefits();
string getHealthInsurance();
void setHealthInsurance(string);
double getLifeInsurance();
void setLifeInsurance(double);
int getVacation();
void setVacation(int);
private:
string healthInsurance;
double lifeInsurance;
int vacation;
};
EMPLOYEE.H
#include <iostream>
#include <string>
using namespace std;
class Employee {
public:
Employee();
Employee(string, string, char, int, double);
void displayEmployee();
string getFirstName();
void setFirstName(string);
string getLastName();
void setLastName(string);
char getGender();
void setGender(char);
int getDependents();
void setDependents(int);
double getAnnualSalary();
void setAnnualSalary(double);
void setAnnualSalary(string);
static int getNumEmployees();
void setDependents(string);
private:
string firstName;
string lastName;
char gender;
int dependents;
double annualSalary;
static int numEmployee;
virtual double calculatePay();
};
HOURLY.H
#pragma once
#include "Employee.h"
class Hourly :
public Employee
{
public:
Hourly(void);
class Hourly : Employee
{
//Constant values for minimum, maximum wage and hours
private const double MIN_WAGE = 10;
private const double MAX_WAGE = 75;
private const double MIN_HOURS = 0;
private const double MAX_HOURS = 50;
private double wage; // wage of employee
private double hours; // hours worked
private string category; // category
//Noargument constructor
public Hourly()
: base()
{
wage = MIN_WAGE;
hours = MIN_HOURS;
category = "Not Given";
}//End of Noargument constructor.
//3-argument constructor
public Hourly(double wage, double hours, string category)
: base()
{
setWage(wage);
setHours(hours);
setCategory(category);
}//End of 3-Argument constructor
//8-argument cinstructor
public Hourly(string first, string last, char gen, int dep, double wage, double hours, Benefit ben, string category)
: base(first, last, gen, dep, wage * 1300, ben)
{
setWage(wage);
setHours(hours);
setCategory(category);
}// End of 8-argument constructor
//Helper functions to set wage, hours and category
public void setWage(double wage)
{
if (wage >= MIN_WAGE && wage <= MAX_WAGE)
this.wage = wage;
else
this.wage = MIN_WAGE;
}//End of setWage
//Sets hours
public void setHours(double hours)
{
if (hours >= MIN_HOURS && hours <= MAX_HOURS)
this.hours = hours;
else
this.hours = MIN_HOURS;
}//End of setHours
//Sets category
public void setCategory(string category)
{
if (category == "temporary" || category == "part time" || category == "full time")
this.category = category;
else
this.category = "temporary";
}//End of setCategory
//Overrides the base class method calculatePay
public override double CalculatePay()
{
return wage * hours;
}//End of CalculatePay method
//Overrides the base class ToString to display data of the object
public override string ToString()
{
return string.Format("Employee Type : {0} First Name : {1} Last Name : {2} Gender : {3} Dependents : {4} Category : {5} Wage : {6:c} Hours : {7} Weekly Pay : {8:c} Annual Salary : {9:c} {10}",
GetType().Name.ToUpper(), FirstName, LastName, (Gender == 'M') ? "Male" : "Female", Dependents, category, wage, hours, CalculatePay(), AnnualSalary, benefit.ToString());
}//End of ToString method
}//End of Hourly class
}//End of namespace
~Hourly(void);
};
SALARIED.H
const int MIN_MANAGEMENT_LEVEL = 0;
const int MAX_MANAGEMENT_LEVEL = 3;
const double BONUS_PERCENT = .10;
class Salaried :public Employee
{
protected:
int managementLevel;
public:
Salaried() :Employee()//initial the common employee attributes
{
managementLevel = MIN_MANAGEMENT_LEVEL;
}
Salaried(string firstName, string lastName, char gender, int dependents, double salary, Benefit benefits, int manLevel)
:Employee(firstName, lastName, gender, dependents, salary, benefits)
{
setManagementLevel(manLevel); //use the property to ensure valid data in the managementLevel attribute
}
Salaried(double salary, int manLevel) :Employee()
{
Employee::setAnnualSalary(salary); //use the super class property to ensure valid data in the annual salary
setManagementLevel(manLevel);
}
void setManagementLevel(int manLevel)
{
if (manLevel >= MIN_MANAGEMENT_LEVEL && manLevel <= MAX_MANAGEMENT_LEVEL)
{
managementLevel = manLevel;
}
else
{
managementLevel = MIN_MANAGEMENT_LEVEL;
}
}
int getManagementLevel()
{
return managementLevel;
}
double calculatePay()
{
return Employee::calculatePay() * (1 + (managementLevel*BONUS_PERCENT));
}
void displayEmployee()
{
Employee::displayEmployee();
cout << "Salaried Employee\n";
cout << "Management level:\t" << managementLevel;
}
};
EMPLOYEE.CPP
#include <string>
#include <iomanip>
#include "Employee.h"
#include "Benefits.h"
using namespace std;
int Employee::numEmployee=0;
Employee::Employee() {
firstName = "not given";
lastName = "not given";
gender = 'U';
dependents = 0;
annualSalary = 20000;
numEmployee++;
}
Employee::Employee(string first, string last, char gen, int dep,
double salary) {
firstName = first;
lastName = last;
gender = gen;
dependents = dep;
annualSalary = salary;
numEmployee++;
}
Benefit::Benefit() {
healthInsurance=" not given";
lifeInsurance=0;
vacation=0;
}
Benefit::Benefit(string hInsurance, double lInsurance, int vacationDays){
healthInsurance=hInsurance;
lifeInsurance=lInsurance;
vacation=vacationDays;
}
string Benefit::getHealthInsurance() {
return healthInsurance;
}
double Benefit::getLifeInsurance() {
return lifeInsurance;
}
int Benefit::getVacation() {
return vacation;
}
void Benefit::setHealthInsurance(string hInsurance){
healthInsurance=hInsurance;
}
void Benefit::setLifeInsurance(double lInsurance) {
lifeInsurance=lInsurance;
}
void Benefit::setVacation(int vacationDays) {
vacation=vacationDays;
}
string Employee::getFirstName() {
return firstName;
}
string Employee::getLastName() {
return lastName;
}
void Employee::setFirstName(string fname) {
firstName = fname;
}
void Employee::setLastName(string lname) {
lastName = lname;
}
char Employee::getGender() {
return gender;
}
void Employee::setGender(char gen) {
switch (gen) {
case 'f':
case 'F':
case 'M':
case 'm':
gender = gen;
break;
default:
gender = 'U';
}
}
void Employee::setDependents(int dep) {
dependents = dep;
}
double Employee::getAnnualSalary() {
return annualSalary;
}
void Employee::setAnnualSalary(double salary) {
annualSalary = salary;
}
double Employee::calculatePay() {
return (annualSalary / 52);
}
int Employee::getNumEmployees()
{
return numEmployee;
}
void Employee::displayEmployee() {
cout << "Employee Information" << endl;
cout
<< "----------------------------------------------------------------------------"
<< endl;
cout << setw(16) << left << "Name:" << firstName << " " << lastName << endl;
cout << setw(16) << "Gender:" << gender << endl;
cout << setw(16) << "Dependents:" << dependents << endl;
cout << setw(16) << fixed << setprecision(2) << "Annual Salary:"
<< annualSalary << endl;
cout << setw(16) << "Weekly Salary:" << calculatePay() << endl;
}
void Benefit::displayBenefits() {
cout<< "Employee Benefits Information"<<endl;
cout
<< "----------------------------------------------------------------------------"
<< endl;
cout << setw(16) << left << "Health Insurance:" << healthInsurance<< endl;
cout << setw(16) << "Life Insurance:" << lifeInsurance << endl;
cout << setw(16) << fixed << setprecision(2) << "Vacation:"
<< vacation << endl;
}
|