ShiftSupervisor.h
#include "Employee.h"
// ShiftSupervisor class derived from Employee
class ShiftSupervisor : public Employee
{
private:
double annualSalary; // Annual salary
double annualBonus; // Annual bonus
public:
// Constructor
ShiftSupervisor() : Employee()
{
annualSalary = 0.0;
annualBonus = 0.0;
}
// Parameterized Constructor
ShiftSupervisor(string name, int number, string hireDate,
double salary) :
Employee(name, number, hireDate)
{
annualSalary = salary;
}
// Mutator functions
void setAnnualSalary(double salary)
{ annualSalary = salary; }
void setAnnualBonus(double bonus)
{ annualBonus = bonus; }
void calcAnnualBonus()
{ annualBonus *= annualSalary; }
// Accessor functions
double getAnnualSalary() const
{ return annualSalary; }
double getAnnualBonus() const
{ return annualBonus; }
double getTotalSalary() const
{ return annualSalary + annualBonus; }
};
#endif
ShiftSupervisorClass.cpp
#include "ShiftSupervisor.h"
#include <iomanip>
using std::setprecision;
using std::setw;
#include <iostream>
using std::cin;
using std::cout;
using std::left;
using std::right;
using std::fixed;
const double BONUS = 0.10;
const int PRODUCTION_GOAL = 128948;
void getProductionData(ShiftSupervisor &);
bool isGoalMet(const int &);
void outputData(const ShiftSupervisor &);
int main()
{
// Create a ShiftSupervisor object
ShiftSupervisor supervisor("Corum J. Irsei", 29835, "05/07/2016", 25760.0);
cout << "TAKEUCHI MANUFACTURING CO. - FINANCE DEPARTMENT\n\n";
cout << "Enter number of units produced at this supervisor's line\n"
<< "to determine whether annual salary bonus applies.\n\n";
getProductionData(supervisor);
cout << "TAKEUCHI MANUFACTURING CO. - PAYROLL SYSTEM\n\n";
outputData(supervisor);
cout << "You are now leaving the Database System ...\n\n";
cout << "TAKEUCHI MANUFACTURING CO.\n"
<< "Unrivaled quality, products with a difference,\n"
<< "and fast development responding to the users' needs.";
cin.get();
cin.ignore();
return 0;
}
/* **********************************************************
getProductionData() : const obj &
This function asks the user to input the number of units
produced at a supervisor's line. If the production goal
has been met, the bonus is set and the amount of bonus
calculated. Otherwise the bonus is set to 0.0.
********************************************************** */
void getProductionData(ShiftSupervisor &supervisor)
{
int unitsTotal = 0;
cout << "Supervisor Name: " << supervisor.getEmpName() << "\n"
<< "Supervisor ID-#: " << supervisor.getEmpID() << "\n";
cout << "Production Goal: " << PRODUCTION_GOAL << " Units\n\n";
cout << "Number of units produced: ";
cin >> unitsTotal;
while (unitsTotal < 85000 || unitsTotal >= 135000)
{
cout << "Number of units produced (Min: 85000, Max: 135000): ";
cin >> unitsTotal;
}
cout << "\n";
if (isGoalMet(unitsTotal) == true)
{
supervisor.setAnnualBonus(BONUS);
supervisor.calcAnnualBonus();
}
else
{
supervisor.setAnnualBonus(0.0);
}
}
/* **********************************************************
isGoalMet() : const int &
This function determines whether the production goal has
been met.
********************************************************** */
bool isGoalMet(const int &units)
{
bool goalMet = false;
if (units >= PRODUCTION_GOAL)
{
cout << "Production Goal Met!\n";
goalMet = true;
}
return goalMet;
}
/* **********************************************************
outputData() : const obj &
This function outputs a supervisor's personal data, his
or her annual salary, annual bonus and total salary.
********************************************************** */
void outputData(const ShiftSupervisor &supervisor)
{
cout << left << setw(12) << "Supervisor: "
<< right << supervisor.getEmpName() << "\n"
<< left << setw(12) << "ID-Number: "
<< right << supervisor.getEmpID() << "\n"
<< left << setw(11) << "Date Hired: "
<< right << supervisor.getEmpDateHired() << "\n\n";
cout << fixed << setprecision(2);
cout << left << setw(17) << "Annual Salary: $ "
<< right << supervisor.getAnnualSalary() << "\n";
cout << left << setw(17) << "Annual Bonus: $ "
<< right << setw(8) << supervisor.getAnnualBonus() << "\n";
cout << left << setw(17) << "Total Salary: $ "
<< right << supervisor.getTotalSalary() << "\n\n";
}
No comments:
Post a Comment