Steakknife

Salary Problems

Feb 17th, 2013
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.44 KB | None | 0 0
  1. //Benefit.cpp
  2. #include "Employee.h"
  3. #include "Benefit.h"
  4. #include <iostream>
  5. #include <iomanip>
  6.  
  7. Benefit::Benefit() : healthInsurance("not provided"), lifeInsurance(0.0), vacation(14)
  8. {
  9. }
  10.  
  11. Benefit::Benefit(string health, double life, int vac) :
  12. healthInsurance(health),
  13. lifeInsurance(life),
  14. vacation(vac)
  15. {
  16. }
  17.  
  18. Benefit::~Benefit()
  19. {
  20. }
  21.  
  22. void Benefit::displayBenefits()
  23. {
  24. cout << "\nBenefit Information\n";
  25. cout << "----------------------------------------------------------------\n";
  26. cout << "Health Insurance: \t" << healthInsurance << "\n";
  27. cout << "Life Insurance: \t" << setprecision(2) << showpoint << lifeInsurance << "\n";
  28. cout << "Vacation Days: \t\t" << vacation << " days\n";
  29. }
  30.  
  31. string Benefit::getHealthInsurance()
  32. {
  33. return healthInsurance;
  34. }
  35.  
  36. void Benefit::setHealthInsurance(string newHealthInsurance)
  37. {
  38. healthInsurance = newHealthInsurance;
  39. }
  40.  
  41. double Benefit::getLifeInsurance()
  42. {
  43. return lifeInsurance;
  44. }
  45.  
  46. void Benefit::setLifeInsurance(double newLifeInsurance)
  47. {
  48. lifeInsurance = newLifeInsurance;
  49. }
  50.  
  51. int Benefit::getVacation()
  52. {
  53. return vacation;
  54. }
  55.  
  56. void Benefit::setVacation(int newVacation)
  57. {
  58. vacation = newVacation;
  59. }
  60.  
  61. //Benefit.h
  62. #pragma once
  63. #include <string>
  64. using namespace std;
  65.  
  66. class Benefit
  67. {
  68.  
  69. private:
  70.  
  71. string healthInsurance;
  72. double lifeInsurance;
  73. int vacation;
  74. public:
  75.  
  76. Benefit();
  77. Benefit(string health, double life, int vac);
  78. ~Benefit();
  79. void displayBenefits();
  80.  
  81. string getHealthInsurance();
  82. void setHealthInsurance(string);
  83. double getLifeInsurance();
  84. void setLifeInsurance(double);
  85. int getVacation();
  86. void setVacation(int);
  87.  
  88.  
  89. };
  90.  
  91. //Employee.cpp
  92.  
  93. #include <iostream>
  94. #include <iomanip>
  95. #include "Employee.h"
  96. #include "Benefit.h"
  97.  
  98.  
  99. const double MIN_SALARY = 50000;
  100. const double MAX_SALARY = 250000;
  101. const int MAX_DEPENDENTS = 10;
  102. const int MIN_DEPENDENTS = 0;
  103. const char DEFAULT_GENDER = 'N'; //N stands for not identified
  104. const int NUMBER_WEEKS = 52;
  105. int Employee::numEmployees = 0;
  106.  
  107.  
  108. Employee::Employee() : benefit(), firstName("not given"), lastName("not given"), gender('U'), dependents(0), annualSalary(20000.0)
  109. {
  110. numEmployees++;
  111. }
  112.  
  113.  
  114. Employee::Employee(string first, string last, char gen, int dep, Benefit ben) :
  115.  
  116. firstName(first),
  117. lastName(last),
  118. gender(gen),
  119. dependents(dep),
  120. benefit(ben)
  121. {
  122. numEmployees++;
  123. }
  124.  
  125.  
  126. Employee::~Employee()
  127. {
  128. numEmployees--;
  129. }
  130.  
  131.  
  132. double Employee::calculatePay()
  133. {
  134. return (annualSalary/NUMBER_WEEKS);
  135. }
  136.  
  137.  
  138. void Employee::displayEmployee()
  139. {
  140. cout << "Name:\t\t" << firstName << " " << lastName << "\n";
  141. cout << "Gender:\t" << gender << "\n";
  142. cout << "Dependents:\t" << dependents << "\n";
  143. cout << "Annual Salary:\t$" << setprecision(2) << showpoint << fixed << annualSalary << "\n";
  144. cout << "Weekly Pay:\t$" << setprecision(2) << showpoint << fixed << calculatePay() << "\n";
  145. benefit.displayBenefits();
  146. }
  147.  
  148.  
  149. string Employee::getFirstName()
  150. {
  151. return firstName;
  152. }
  153. void Employee::setFirstName(string name)
  154. {
  155. firstName = name;
  156. }
  157.  
  158. string Employee::getLastName()
  159. {
  160. return lastName;
  161. }
  162. void Employee::setLastName(string name)
  163. {
  164. lastName = name;
  165. }
  166.  
  167.  
  168. char Employee::getGender()
  169. {
  170. return gender;
  171. }
  172.  
  173. void Employee::setGender(char gen)
  174. {
  175. switch (gen)
  176. {
  177. case 'f':case 'F': case 'M':case 'm':
  178. gender = gen;
  179. break;
  180. default:
  181. gender = DEFAULT_GENDER;
  182. }
  183. }
  184.  
  185.  
  186. int Employee::getDependents()
  187. {
  188. return dependents;
  189. }
  190.  
  191. void Employee::setDependents(int dep)
  192. {
  193. if (dep >= MIN_DEPENDENTS && dep <= MAX_DEPENDENTS)
  194. {
  195. dependents = dep;
  196. }
  197. else if (dep < MIN_DEPENDENTS)
  198. {
  199. dep = MIN_DEPENDENTS;
  200. }
  201. else
  202. {
  203. dependents = MAX_DEPENDENTS;
  204. }
  205. }
  206.  
  207. void Employee::setDependents(string dep)
  208. {
  209. Employee::setDependents(atoi(dep.c_str()));
  210. }
  211.  
  212.  
  213. double Employee::getAnnualSalary()
  214. {
  215. return annualSalary;
  216. }
  217.  
  218. void Employee::setAnnualSalary(double salary)
  219. {
  220. annualSalary = salary;
  221. }
  222.  
  223. void Employee::setAnnualSalary(string sal)
  224. {
  225. Employee::setAnnualSalary( atof(sal.c_str()));
  226. }
  227.  
  228.  
  229. Benefit Employee::getBenefit()
  230. {
  231. return benefit;
  232. }
  233.  
  234. void Employee::setBenefit(Benefit ben)
  235. {
  236. string tempString;
  237. double lifeInsurance;
  238. int vacation;
  239.  
  240.  
  241. benefit = ben;
  242. }
  243. int Employee::getNumEmployees()
  244. {
  245. return Employee::numEmployees;
  246. }
  247.  
  248. //Employee.h
  249. #pragma once
  250. #include "Benefit.h"
  251. #include <string>
  252. using namespace std;
  253.  
  254. void DislayApplicationInformation();
  255. void DisplayDivider(string);
  256. void DisplayDivider2(string);
  257. string GetInput (string);
  258. void TerminateApplication();
  259.  
  260. class Employee
  261. {
  262. protected:
  263. string firstName;
  264. string lastName;
  265. char gender;
  266. int dependents;
  267. double annualSalary;
  268.  
  269. Benefit benefit;
  270.  
  271. public:
  272. Employee();
  273. Employee(string, string, char, int, Benefit);
  274. ~Employee();
  275. virtual double calculatePay() = 0;
  276. virtual void displayEmployee() = 0;
  277. string getFirstName();
  278. void setFirstName(string first);
  279. string getLastName();
  280. void setLastName(string last);
  281. char getGender();
  282. void setGender(char gen);
  283. int getDependents();
  284. void setDependents(int dep);
  285. void setDependents(string dep);
  286. double getAnnualSalary();
  287. virtual void setAnnualSalary(double salary);
  288. void setAnnualSalary(string sal);
  289. Benefit getBenefit();
  290. void setBenefit(Benefit ben);
  291. static int getNumEmployees();
  292.  
  293. private:
  294. static int numEmployees;
  295. };
  296.  
  297.  
  298. #include "Hourly.h"
  299. #include <iostream>
  300. //Hourly.cpp
  301. #include <iomanip>
  302.  
  303. const double MIN_WAGE = 10;
  304. const double MAX_WAGE = 75;
  305. const double MIN_HOURS = 0;
  306. const double MAX_HOURS = 50;
  307.  
  308. Hourly::Hourly() : Employee(), MIN_WAGE(10), MAX_WAGE(75), MIN_HOURS(0), MAX_HOURS(50)
  309. {
  310. wage = 0;
  311. hours = 0;
  312. category = "X";
  313. }
  314.  
  315. Hourly::Hourly(double wage, double hours, string category) : Employee(), MIN_WAGE(10), MAX_WAGE(75), MIN_HOURS(0), MAX_HOURS(50)
  316. {
  317. setWage(wage);
  318. setHours(hours);
  319. setCategory(category);
  320. setAnnualSalary(calculatePay());
  321. }
  322.  
  323. Hourly::Hourly(string firstName, string lastName, char gender, int dependents, double wage, double hours, Benefit benefit, string category) :
  324. Employee(firstName, lastName, gender, dependents, benefit), MIN_WAGE(10), MAX_WAGE(75), MIN_HOURS(0), MAX_HOURS(50)
  325. {
  326. setWage(wage);
  327. setHours(hours);
  328. setCategory(category);
  329. setAnnualSalary(calculatePay());
  330. }
  331.  
  332. Hourly::~Hourly()
  333. {
  334. }
  335.  
  336. double Hourly::calculatePay()
  337. {
  338. return getWage() * getHours();
  339. }
  340.  
  341. void Hourly::setAnnualSalary(double salary)
  342. {
  343. Employee::setAnnualSalary(calculatePay()*50);
  344. }
  345.  
  346. void Hourly::displayEmployee(void)
  347. {
  348. Employee::displayEmployee();
  349. cout<<"Hourly Employee\n";
  350. cout<<"Category:\t\t" << category << "\n";
  351. cout<<"Wage:\t\t\t" << wage << "\n";
  352. cout<<"Hours:\t\t\t" << hours << "\n";
  353. }
  354.  
  355. double Hourly::getWage()
  356. {
  357. return wage;
  358. }
  359. void Hourly::setWage(double Wage)
  360. {
  361. if(Wage >= MIN_WAGE && Wage >= MAX_WAGE)
  362. wage = Wage;
  363. else if (Wage < MIN_WAGE)
  364. wage = MIN_WAGE;
  365. else if (Wage > MAX_WAGE)
  366. wage = MAX_WAGE;
  367.  
  368.  
  369. setAnnualSalary(calculatePay());
  370. }
  371.  
  372. double Hourly::getHours()
  373. {
  374. return hours;
  375. }
  376. void Hourly::setHours(double Hours)
  377. {
  378. if (Hours >= MIN_HOURS && Hours <= MAX_HOURS)
  379. hours = Hours;
  380. else if(Hours < MIN_HOURS)
  381. hours = MIN_HOURS;
  382. else if(Hours > MAX_HOURS)
  383. hours = MAX_HOURS;
  384.  
  385. setAnnualSalary(calculatePay());
  386. }
  387.  
  388. string Hourly::getCategory()
  389. {
  390. return category;
  391. }
  392. void Hourly::setCategory(string cat)
  393. {
  394. if(category == "temporary" || category == "part time" || category == "full time")
  395. category = cat;
  396. else
  397. category = "Unknown";
  398. }
  399.  
  400. //Hourly.h
  401. #pragma once
  402. #include "employee.h"
  403.  
  404.  
  405. class Hourly :
  406. public Employee
  407. {
  408. public:
  409.  
  410. Hourly();
  411. Hourly(string, string, char, int, double, double, Benefit, string);
  412. Hourly(double, double, string);
  413. ~Hourly();
  414.  
  415. double calculatePay();
  416. void displayEmployee();
  417.  
  418. void setAnnualSalary(double salary);
  419. double getWage();
  420. void setWage(double wage);
  421. double getHours();
  422. void setHours(double hours);
  423. string getCategory();
  424. void setCategory(string category);
  425.  
  426. private:
  427. const double MIN_WAGE;
  428. const double MAX_WAGE;
  429. const double MIN_HOURS;
  430. const double MAX_HOURS;
  431. double wage;
  432. double hours;
  433. string category;
  434. };
  435.  
  436. //Main.cpp
  437. #include "Employee.h"
  438. #include "Hourly.h"
  439. #include "Salaried.h"
  440. #include <iostream>
  441. #include <string>
  442. #include <iomanip>
  443. using namespace std;
  444.  
  445. int main()
  446. {
  447.  
  448.  
  449. DislayApplicationInformation();
  450. DisplayDivider("Employee 1");
  451.  
  452. Employee *employeeList1 = new Salaried(10000, 3);
  453. Benefit salariedBenefit;
  454.  
  455. employeeList1->setFirstName(GetInput("First Name "));
  456. employeeList1->setLastName(GetInput("Last Name "));
  457. string tempString = GetInput("Gender ");
  458. char gender = tempString.at(0);
  459. employeeList1->setGender(gender);
  460. employeeList1->setDependents(GetInput("Dependents "));
  461.  
  462. salariedBenefit.setHealthInsurance(GetInput("Health Insurance"));
  463. salariedBenefit.setLifeInsurance(atof(GetInput("Life Insurance").c_str()));
  464. salariedBenefit.setVacation(atoi(GetInput("Vacation").c_str()));
  465. employeeList1->setBenefit(salariedBenefit);
  466.  
  467. DisplayDivider2("Employee Information");
  468. employeeList1->displayEmployee();
  469. cout << "\n--- Number of Employee Objects Created ----\t";
  470. cout << "Number of employees: " << Employee::getNumEmployees() << "\n";
  471. DisplayDivider("Employee 2");
  472.  
  473. Employee *employeeList2 = new Hourly(50, 40, "full time");
  474. Benefit hourlyBenefit;
  475.  
  476. employeeList2->setFirstName(GetInput("First Name "));
  477. employeeList2->setLastName(GetInput("Last Name "));
  478. tempString = GetInput("Gender ");
  479. gender = tempString.at(0);
  480. employeeList2->setGender(gender);
  481. employeeList2->setDependents(GetInput("Dependents "));
  482.  
  483. hourlyBenefit.setHealthInsurance(GetInput("Health Insurance"));
  484. hourlyBenefit.setLifeInsurance(atof(GetInput("Life Insurance").c_str()));
  485. hourlyBenefit.setVacation(atoi(GetInput("Vacation").c_str()));
  486. employeeList2->setBenefit(hourlyBenefit);
  487.  
  488. DisplayDivider2("Employee Information");
  489. employeeList2->displayEmployee();
  490. cout << "\n--- Number of Employee Objects Created ----\t";
  491. cout << "Number of employees: " << Employee::getNumEmployees() << "\n";
  492.  
  493. TerminateApplication();
  494.  
  495. return 0;
  496. }
  497.  
  498. void DisplayDivider(string outputTitle)
  499. {
  500. cout << "************************" << outputTitle <<"************************\n";
  501. }
  502.  
  503. void DislayApplicationInformation()
  504. {
  505. cout << "Welcome to your first Object Oriented Program\n";
  506. cout << "Employee Class CIS247C, Week 6 Lab\n";
  507. cout << "Name: Name\n";
  508. }
  509. void DisplayDivider2(string outputTitle)
  510. {
  511. cout << "\n" << outputTitle << endl;
  512. cout << "----------------------------------------------------------------\n";
  513. }
  514.  
  515. string GetInput (string inputType)
  516. {
  517. string input;
  518. cout<<"Please enter your "<< inputType <<": ";
  519. getline(cin, input);
  520. return input;
  521. }
  522.  
  523. void TerminateApplication()
  524. {
  525. cout << "\nThank you for using the Employee Class program\n";
  526. }
  527.  
  528. //Salaried.cpp
  529. #include "Salaried.h"
  530. #include "Employee.h"
  531. #include <iostream>
  532. #include <iomanip>
  533.  
  534. using namespace std;
  535.  
  536.  
  537. Salaried::Salaried() : Employee(), minManagementLevel(0), maxManagementLevel(3), bonusPercent(.10)
  538. {
  539. managementLevel = 0;
  540. }
  541.  
  542.  
  543. Salaried::Salaried(string firstName, string lastName, char gender, int dependents, double salary, Benefit ben, int managementLevel) :
  544. Employee (firstName, lastName, gender, dependents, ben), minManagementLevel(0), maxManagementLevel(3), bonusPercent(.10)
  545. {
  546. managementLevel = 0;
  547. }
  548.  
  549.  
  550. Salaried::Salaried(double salary, int managementLevel) : Employee(), minManagementLevel(0), maxManagementLevel(3), bonusPercent(.10)
  551. {
  552. managementLevel = managementLevel;
  553. annualSalary = salary;
  554. }
  555.  
  556.  
  557. Salaried::~Salaried()
  558. {
  559. }
  560.  
  561.  
  562. double Salaried::calculatePay()
  563. {
  564. return annualSalary;
  565.  
  566. }
  567.  
  568.  
  569. void Salaried::displayEmployee()
  570. {
  571. Employee::displayEmployee();
  572. cout<<"Salaried Employee\n";
  573. cout<<"Management Level:\t" << managementLevel << "\n";
  574. }
  575.  
  576.  
  577. int Salaried::getManagementLevel()
  578. {
  579. return managementLevel;
  580. }
  581.  
  582. void Salaried::setManagementLevel(int manLevel)
  583. {
  584. if (manLevel >= minManagementLevel && manLevel <= maxManagementLevel)
  585. managementLevel = manLevel;
  586. else if (manLevel < minManagementLevel)
  587. managementLevel = minManagementLevel;
  588. else if (manLevel > maxManagementLevel)
  589. managementLevel = maxManagementLevel;
  590. }
  591.  
  592. //Salaried.h
  593. #pragma once
  594. #include "employee.h"
  595.  
  596.  
  597. class Salaried :
  598. public Employee
  599. {
  600. public:
  601.  
  602. Salaried();
  603. Salaried(string, string, char, int, double, Benefit, int);
  604. Salaried(double, int);
  605. ~Salaried();
  606.  
  607. double calculatePay();
  608. void displayEmployee();
  609. int getManagementLevel();
  610. void setManagementLevel(int manLevel);
  611.  
  612. private:
  613. const int minManagementLevel;
  614. const int maxManagementLevel;
  615. const double bonusPercent;
  616. int managementLevel;
  617. };
Advertisement
Add Comment
Please, Sign In to add comment