Because the NumDays.h and NumDays.cpp files contents have not changed, they are contained in the .7z file but not displayed separately here.
TimeOff.h
#ifndef TIME_OFF_H_
#define TIME_OFF_H_
#include "NumDays.h"
#include <string>
using std::string;
class TimeOff
{
private:
string employeeName; // Holding an employee's name
int employeeID; // Holding an employee's ID
NumDays maxSickDays, sickTaken,
maxVacation, vacTaken,
maxUnpaid, unpaidTaken;
public:
TimeOff(string, int, double, double, double, double, double, double);
// Mutators
void setEmployeeName(string name)
{ employeeName = name; }
void setEmployeeID(int ID)
{ employeeID = ID; }
void setMaxSick(double hrs)
{ maxSickDays.setHours(hrs); }
void setSickTaken(double hrs)
{ sickTaken.setHours(hrs); }
void setMaxVacation(double hrs)
{ maxVacation.setHours(hrs); }
void setVacTaken(double hrs)
{ vacTaken.setHours(hrs); }
void setMaxUnpaid(double hrs)
{ maxUnpaid.setHours(hrs); }
void setUnpaidTaken(double hrs)
{ unpaidTaken.setHours(hrs); }
void print();
// Accessors
string getEmployeeName() const
{ return employeeName; }
int getEmployeeID() const
{ return employeeID; }
double getMaxSick() const
{ return maxSickDays.getDays(); }
double getSickTaken() const
{ return sickTaken.getDays(); }
double getMaxVacation() const
{ return maxVacation.getDays(); }
double getVacationTaken() const
{ return vacTaken.getDays(); }
double getMaxUnpaid() const
{ return maxUnpaid.getDays(); }
double getUnpaidTaken() const
{ return unpaidTaken.getDays(); }
};
#endif
TimeOff.cpp
#include "TimeOff.h"
#include <iomanip>
using std::setprecision;
using std::setw;
#include <iostream>
using std::cout;
using std::fixed;
using std::left;
using std::right;
using std::showpoint;
// Maximum amount of paid vacation days
const int MAX_PAID = 240;
/* **********************************************************
TimeOff::TimeOff() - Constructor
********************************************************** */
TimeOff::TimeOff(string name, int ID, double maxSick, double sickT,
double maxVac, double vacT,
double maxUnp, double unpT)
{
employeeName = name;
employeeID = ID;
setMaxSick(maxSick);
setSickTaken(sickT);
maxVac <= MAX_PAID ? setMaxVacation(maxVac) :
setMaxVacation(MAX_PAID);
setVacTaken(vacT);
setMaxUnpaid(maxUnp);
setUnpaidTaken(unpT);
}
/* **********************************************************
TimeOff::print()
This function outputs a summary about an employee's days
off.
********************************************************** */
void TimeOff::print()
{
cout << fixed << showpoint << setprecision(2);
cout << setw(15) << left << "Employee ID: " << getEmployeeID() << "\n"
<< setw(15) << right << "Employee Name: " << setw(5) << right << getEmployeeName() << "\n\n";
cout << left << "Max. Sick Days: " << setw(6) << left << getMaxSick() << "\n"
<< setw(16) << right << "Sick Days: " << setw(5) << right << getSickTaken() << "\n\n";
cout << left << "Max. Vacation Days: " << setw(7) << left << getMaxVacation() << "\n"
<< setw(20) << "Vacation Days: " << setw(4) << right << getVacationTaken() << "\n\n";
cout << left << "Max. Unpaid Days: " << setw(6) << left << getMaxUnpaid() << "\n"
<< setw(18) << right << "Unpaid Days: " << setw(4) << right << getUnpaidTaken() << "\n\n\n";
}
TimeOffDm.cpp
#include "TimeOff.h"
#include <iostream>
using std::cin;
using std::cout;
int main()
{
// Array of 2 TimeOff objects, initialized with the following data:
// Employee name, ID, Max. sick days, sick days taken, Max. vacation,
// vacation taken, Max. unpaid vacation days, unpaid vacation days taken
TimeOff offDays[2] = { TimeOff("Precious Ramotswe", 1, 200, 30, 255, 86, 40, 10),
TimeOff("Grace Makutsi", 2, 164, 10, 20, 50, 40, 10) };
cout << "No. 1 Ladies' Detective Agency - Leave Tracker\n\n";
for (auto outputDays : offDays)
{
outputDays.print();
}
cin.get();
cin.ignore();
return 0;
}
No comments:
Post a Comment