fork download
  1. //********************************************************
  2. //
  3. // Assignment 11 - Object Oriented Design
  4. //
  5. // Name: Carlos Dominguez
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: 04/25/2026
  10. //
  11. // Description: An object oriented program design using
  12. // C++ that will process our existing set of employees.
  13. // It utilizes a class called Employee and generates an
  14. // array of objects that are used to store, calculate,
  15. // and print out a simple report of inputted and calculated
  16. // values.
  17. //
  18. //
  19. // Object Oriented Design (using C++)
  20. //
  21. //********************************************************
  22.  
  23. #include <iomanip> // std::setprecision, std::setw
  24. #include <iostream> // std::cout, std::fixed
  25. #include <string> // string functions
  26. #include <cctype> // std::islower, std::toupper
  27.  
  28. // define constants
  29. #define EMP_SIZE 5
  30. #define STD_HOURS 40.0
  31. #define OT_RATE 1.5
  32. #define MA_TAX_RATE 0.05
  33. #define NH_TAX_RATE 0.0
  34. #define VT_TAX_RATE 0.06
  35. #define CA_TAX_RATE 0.07
  36. #define DEFAULT_TAX_RATE 0.08
  37. #define NAME_SIZE 20
  38. #define TAX_STATE_SIZE 3
  39. #define FED_TAX_RATE 0.25
  40. #define FIRST_NAME_SIZE 10
  41. #define LAST_NAME_SIZE 10
  42.  
  43. using namespace std;
  44.  
  45. // class Employee
  46. class Employee
  47. {
  48. private:
  49.  
  50. // private data available only to member functions
  51.  
  52. string firstName; // Employee First Name
  53. string lastName; // Employee Last Name
  54. string taxState; // Employee Tax State
  55. int clockNumber; // Employee Clock Number
  56. float wageRate; // Hourly Wage Rate
  57. float hours; // Hours worked in a week
  58. float overTimeHrs; // Overtime Hours worked
  59. float grossPay; // Weekly Gross Pay
  60. float stateTax; // State Tax
  61. float fedTax; // Fed Tax
  62. float netPay; // Net Pay
  63.  
  64. // private member function to calculate Overtime Hours
  65. float calcOverTimeHrs ( )
  66. {
  67. // Calculate the overtime hours for the week
  68. if (hours > STD_HOURS)
  69. overTimeHrs = hours - STD_HOURS; // ot hours
  70. else
  71. overTimeHrs = 0; // no ot hours
  72.  
  73. // the calculated overtime hours
  74. return (overTimeHrs);
  75.  
  76. } // calcOverTimeHrs
  77.  
  78. // private member function to calculate Gross Pay
  79. float calcGrossPay ( )
  80. {
  81. // Process gross pay based on if there is overtime
  82. if (overTimeHrs > 0)
  83. {
  84. // overtime
  85. grossPay = (STD_HOURS * wageRate) // normal pay
  86. + (overTimeHrs * (wageRate * OT_RATE)); // ot pay
  87. }
  88. else // no overtime pay
  89. {
  90. grossPay = wageRate * hours; // normal pay
  91. }
  92.  
  93. // the calculated gross pay
  94. return (grossPay);
  95.  
  96. } // calcGrossPay
  97.  
  98. // private member function to calculate State Tax
  99. float calcStateTax ()
  100. {
  101.  
  102. float theStateTax; // calculated state tax
  103.  
  104. theStateTax = grossPay; // initialize to gross pay
  105.  
  106. // calculate state tax based on where employee resides
  107.  
  108. if (taxState.compare("MA") == 0)
  109. theStateTax *= MA_TAX_RATE;
  110. else if (taxState.compare("VT") == 0)
  111. theStateTax *= VT_TAX_RATE;
  112. else if (taxState.compare("NH") == 0)
  113. theStateTax *= NH_TAX_RATE;
  114. else if (taxState.compare("CA") == 0)
  115. theStateTax *= CA_TAX_RATE;
  116. else
  117. theStateTax *= DEFAULT_TAX_RATE; // any other state
  118.  
  119. // return the calculated state tax
  120. return (theStateTax);
  121.  
  122. } // calcStateTax
  123.  
  124. // private member function to calculate Federal Tax
  125. float calcFedTax ()
  126. {
  127.  
  128. float theFedTax; // The calculated Federal Tax
  129.  
  130. // Federal Tax is the same for all regardless of state
  131. theFedTax = grossPay * FED_TAX_RATE;
  132.  
  133. // return the calculated federal tax
  134. return (theFedTax);
  135.  
  136. } // calcFedTax
  137.  
  138. // private member function to calculate Net Pay
  139. float calcNetPay ()
  140. {
  141.  
  142. float theNetPay; // total take home pay (minus taxes)
  143. float theTotalTaxes; // total taxes owed
  144.  
  145. // calculate the total taxes owed
  146. theTotalTaxes = stateTax + fedTax;
  147.  
  148. // calculate the net pay
  149. theNetPay = grossPay - theTotalTaxes;
  150.  
  151. // return the calculated net pay
  152. return (theNetPay);
  153.  
  154. } // calcNetPay
  155.  
  156. public:
  157.  
  158. // public member functions that can be called
  159. // to access private data member items
  160.  
  161. // public no argument constructor with defaults
  162. Employee() {firstName=""; lastName=""; taxState="";
  163. clockNumber=0; wageRate=0; hours=0;}
  164.  
  165. // public constructor with arguments passed to it
  166. Employee (string myFirstName, string myLastName, string myTaxState,
  167. int myClockNumber, float myWageRate, float myHours);
  168.  
  169. ~Employee(); // destructor
  170.  
  171. // public getter function prototypes to retrieve private data
  172. string getFirstName();
  173. string getLastName();
  174. string getTaxState();
  175. int getClockNumber();
  176. float getWageRate();
  177. float getHours();
  178. float getOverTimeHrs();
  179. float getGrossPay();
  180.  
  181. // TODO - Add public getter function prototype to retrieve stateTax
  182. float getStateTax();
  183.  
  184. // TODO - Add public getter function prototype to retrieve fedTax
  185. float getFedTax();
  186.  
  187. // TODO - Add public getter function prototype to retrieve netPay
  188. float getNetPay();
  189.  
  190. // member function prototype to print an Employee object
  191. void printEmployee(Employee e); // passes an object
  192.  
  193. }; // class Employee
  194.  
  195. // constructor with arguments
  196. Employee::Employee (string myFirstName, string myLastName, string myTaxState,
  197. int myClockNumber, float myWageRate, float myHours)
  198. {
  199. // initialize all member data items
  200. firstName = myFirstName; // input
  201. lastName = myLastName; // input
  202.  
  203. // Convert myTaxState to uppercase if entered in lowercase
  204. if (std::islower(myTaxState[0]))
  205. myTaxState[0] = std::toupper(myTaxState[0]);
  206. if (std::islower(myTaxState[1]))
  207. myTaxState[1] = std::toupper(myTaxState[1]);
  208.  
  209. taxState = myTaxState; // input
  210. clockNumber = myClockNumber; // input
  211. wageRate = myWageRate; // input
  212. hours = myHours; // input
  213. overTimeHrs = calcOverTimeHrs(); // calculated overtime hours
  214. grossPay = calcGrossPay(); // calculated gross pay
  215.  
  216. // TODO - set stateTax as the return from calcStateTax member function
  217. stateTax = calcStateTax();
  218.  
  219. // TODO - set fedTax as the return from calcFedTax member function
  220. fedTax = calcFedTax();
  221.  
  222. // TODO - set netPay as the return from calcNetPay member function
  223. netPay = calcNetPay();
  224.  
  225. } // Employee constructor
  226.  
  227. // Employee's destructor
  228. Employee::~Employee()
  229. {
  230. // nothing to print here, but could ...
  231. }
  232.  
  233. // A "getter" function that will retrieve the First Name
  234. string Employee::getFirstName() {
  235. return firstName;
  236. }
  237.  
  238. // A "getter" function that will retrieve the employee Last Name
  239. string Employee::getLastName() {
  240. return lastName;
  241. }
  242.  
  243. // A "getter" function that will retrieve the employee Tax State
  244. string Employee::getTaxState() {
  245. return taxState;
  246. }
  247.  
  248. // A "getter" function that will retrieve the employee Clock Number
  249. int Employee::getClockNumber() {
  250. return clockNumber;
  251. }
  252.  
  253. // A "getter" function that will retrieve the employee Wage Rate
  254. float Employee::getWageRate() {
  255. return wageRate;
  256. }
  257.  
  258. // A "getter" function that will retrieve the employee Hours Worked
  259. float Employee::getHours() {
  260. return hours;
  261. }
  262.  
  263. // A "getter" function that will retrieve the employee Overtime Hours
  264. float Employee::getOverTimeHrs() {
  265. return overTimeHrs;
  266. }
  267.  
  268. // A "getter" function that will retrieve the employee Gross Pay
  269. float Employee::getGrossPay() {
  270. return grossPay;
  271. }
  272.  
  273. // TODO - Add a "getter" function that will retrieve the employee stateTax
  274. float Employee::getStateTax() {
  275. return stateTax;
  276. }
  277.  
  278. // TODO - Add a "getter" function that will retrieve the employee fedTax
  279. float Employee::getFedTax() {
  280. return fedTax;
  281. }
  282.  
  283. // TODO - Add a "getter" function that will retrieve the employee netPay
  284. float Employee::getNetPay() {
  285. return netPay;
  286. }
  287.  
  288. // a member function to print out the info in a given Employee object
  289. void Employee::printEmployee(Employee e) {
  290.  
  291. // Build full name for alignment
  292. string fullName = e.getFirstName() + " " + e.getLastName();
  293.  
  294. cout << left << setw(20) << fullName
  295. << left << setw(4) << e.getTaxState()
  296. << right << setfill('0') << setw(6) << e.getClockNumber() << setfill(' ')
  297. << right << setw(7) << fixed << setprecision(2) << e.getWageRate()
  298. << right << setw(6) << fixed << setprecision(1) << e.getHours()
  299. << right << setw(5) << fixed << setprecision(1) << e.getOverTimeHrs()
  300. << right << setw(8) << fixed << setprecision(2) << e.getGrossPay()
  301. << right << setw(8) << e.getStateTax()
  302. << right << setw(8) << e.getFedTax()
  303. << right << setw(9) << e.getNetPay()
  304. << "\n";
  305.  
  306. } // printEmployee
  307.  
  308. // main function to start the processing
  309. int main ()
  310. {
  311. // local variables to collect user input
  312.  
  313. string myFirstName; // First Name to input
  314. string myLastName; // Last Name to input
  315. string myTaxState; // Tax State to input
  316. int myClockNumber; // Clock Number to input
  317. float myWageRate; // Wage Rate to input
  318. float myHours; // Hours to input
  319.  
  320. cout << fixed // fix the number of decimal digits
  321. << setprecision(2); // to 2
  322.  
  323. // Array of Objects to store each of our employees
  324. Employee e[EMP_SIZE];
  325.  
  326. // prompt for information to read in employee information
  327. for (int i = 0; i < EMP_SIZE; ++i)
  328. {
  329. // Enter Employee Information
  330. cout <<"\n\n Enter Employee First Name: ";
  331. cin>>myFirstName ;
  332. cout <<"\n Enter Employee Last Name: ";
  333. cin>>myLastName ;
  334. cout <<"\n Enter Employee Tax State: ";
  335. cin>>myTaxState ;
  336. cout<<"\n Enter Employee Clock Number: ";
  337. cin>>myClockNumber;
  338. cout <<"\n Enter Employee Hourly Wage Rate: ";
  339. cin>>myWageRate;
  340. cout <<"\n Enter Employee Hours Worked for the Week: ";
  341. cin>>myHours;
  342.  
  343. // Call our constructor to create an employee object
  344. e[i] = {myFirstName, myLastName, myTaxState,
  345. myClockNumber, myWageRate, myHours};
  346. }
  347.  
  348. // Now print the full table all at once
  349. cout << "\n\n*** Pay Calculator ***\n\n";
  350. cout << "---------------------------------------------------------------------------------\n";
  351. cout << "Name Tax Clock# Wage Hours OT Gross State Fed Net\n";
  352. cout << " State Pay Tax Tax Pay\n";
  353. cout << "---------------------------------------------------------------------------------\n";
  354.  
  355. for (int i = 0; i < EMP_SIZE; ++i)
  356. e[i].printEmployee(e[i]);
  357.  
  358. cout << "---------------------------------------------------------------------------------\n";
  359.  
  360. return 0;
  361.  
  362. } // main
  363.  
Success #stdin #stdout 0s 5312KB
stdin
Connie
Cobol
MA
98401
10.60
51.0
Mary
Apl
NH
526488
9.75
42.5
Frank
Fortran
VT
765349
10.50
37.0
Jeff
Ada
NY
34645
12.25
45
Anton
Pascal
CA
127615
8.35
40.0
stdout

 Enter Employee First Name: 
 Enter Employee Last Name: 
 Enter Employee Tax State: 
 Enter Employee Clock Number: 
 Enter Employee Hourly Wage Rate: 
 Enter Employee Hours Worked for the Week: 

 Enter Employee First Name: 
 Enter Employee Last Name: 
 Enter Employee Tax State: 
 Enter Employee Clock Number: 
 Enter Employee Hourly Wage Rate: 
 Enter Employee Hours Worked for the Week: 

 Enter Employee First Name: 
 Enter Employee Last Name: 
 Enter Employee Tax State: 
 Enter Employee Clock Number: 
 Enter Employee Hourly Wage Rate: 
 Enter Employee Hours Worked for the Week: 

 Enter Employee First Name: 
 Enter Employee Last Name: 
 Enter Employee Tax State: 
 Enter Employee Clock Number: 
 Enter Employee Hourly Wage Rate: 
 Enter Employee Hours Worked for the Week: 

 Enter Employee First Name: 
 Enter Employee Last Name: 
 Enter Employee Tax State: 
 Enter Employee Clock Number: 
 Enter Employee Hourly Wage Rate: 
 Enter Employee Hours Worked for the Week: 

*** Pay Calculator ***

---------------------------------------------------------------------------------
Name                Tax  Clock#  Wage   Hours  OT   Gross   State  Fed      Net
                    State                           Pay     Tax    Tax      Pay
---------------------------------------------------------------------------------
Connie Cobol        MA  098401  10.60  51.0 11.0  598.90   29.95  149.73   419.23
Mary Apl            NH  526488   9.75  42.5  2.5  426.56    0.00  106.64   319.92
Frank Fortran       VT  765349  10.50  37.0  0.0  388.50   23.31   97.12   268.07
Jeff Ada            NY  034645  12.25  45.0  5.0  581.88   46.55  145.47   389.86
Anton Pascal        CA  127615   8.35  40.0  0.0  334.00   23.38   83.50   227.12
---------------------------------------------------------------------------------