fork download
  1. //********************************************************
  2. //
  3. // Assignment 11 - Object Oriented Design
  4. //
  5. // Name: Jasmine Patel
  6. //
  7. // Class: C Programming, Fall 2026
  8. //
  9. // Date: 11/28/26
  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.  
  27. using namespace std;
  28.  
  29. // define constants
  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. #define EMP_SIZE 5
  44.  
  45. using std::string;
  46.  
  47. // class Employee
  48. class Employee
  49. {
  50. private:
  51.  
  52. // private data available only to member functions
  53. // all data is initialized to support creating instances that
  54. // are not done via a full constructor with data to be used
  55.  
  56. string firstName = ""; // Employee First Name
  57. string lastName = ""; // Employee Last Name
  58. string taxState = ""; // Employee Tax State
  59. int clockNumber = 0; // Employee Clock Number
  60. float wageRate = 0.0; // Hourly Wage Rate
  61. float hours = 0.0; // Hours worked in a week
  62. float overTimeHrs = 0.0; // Overtime Hours worked
  63. float grossPay = 0.0; // Weekly Gross Pay
  64. float stateTax = 0.0; // State Tax
  65. float fedTax = 0.0; // Fed Tax
  66. float netPay = 0.0; // Net Pay
  67.  
  68. // private functions for call only by an Employee object
  69. // ... these are gernally more complex computations
  70. float calcOverTimeHrs();
  71. float calcGrossPay();
  72. float calcStateTax();
  73. float calcFedTax();
  74. float calcNetPay();
  75.  
  76. // Delcare "getter" function prototypes to retrieve private data
  77. // Note: The inline keyword is not required for the prototypes
  78. string getFirstName();
  79. string getLastName();
  80. string getTaxState();
  81. int getClockNumber();
  82. float getWageRate();
  83. float getHours();
  84. float getOverTimeHrs();
  85. float getGrossPay();
  86.  
  87. // TODO - Declare a "getter" function declaration that will retrieve the employee stateTax
  88. float getStateTax();
  89.  
  90. // TODO - Declare a "getter" function declaration that will retrieve the employee fedTax
  91. float getFedTax();
  92.  
  93. // TODO - Declare a "getter" function declaration that will retrieve the employee netPay
  94. float getNetPay();
  95.  
  96. public:
  97.  
  98. // public member functions that can be called
  99. // to access private data member items
  100.  
  101. // public no argument constructor with defaults
  102. // All Employee class data will be initialized to defaults
  103. Employee() {}
  104.  
  105. // public constructor with arguments passed to it
  106. Employee (string myFirstName, string myLastName, string myTaxState,
  107. int myClockNumber, float myWageRate, float myHours);
  108.  
  109. ~Employee(); // destructor
  110.  
  111. // print out Employee data to the console
  112. void printEmployee();
  113.  
  114.  
  115. }; // End class declarations.
  116.  
  117. // The inlined Employee members follow...
  118.  
  119. // A "getter" function that will retrieve the First Name
  120. inline string Employee::getFirstName() {
  121. return firstName;
  122. }
  123.  
  124. // A "getter" function that will retrieve the employee Last Name
  125. inline string Employee::getLastName() {
  126. return lastName;
  127. }
  128.  
  129. // A "getter" function that will retrieve the employee Tax State
  130. inline string Employee::getTaxState() {
  131. return taxState;
  132. }
  133.  
  134. // A "getter" function that will retrieve the employee Clock Number
  135. inline int Employee::getClockNumber() {
  136. return clockNumber;
  137. }
  138.  
  139. // A "getter" function that will retrieve the employee Wage Rate
  140. inline float Employee::getWageRate() {
  141. return wageRate;
  142. }
  143.  
  144. // A "getter" function that will retrieve the employee Hours Worked
  145. inline float Employee::getHours() {
  146. return hours;
  147. }
  148.  
  149. // A "getter" function that will retrieve the employee Overtime Hours
  150. inline float Employee::getOverTimeHrs() {
  151. return overTimeHrs;
  152. }
  153.  
  154. // A "getter" function that will retrieve the employee Gross Pay
  155. inline float Employee::getGrossPay() {
  156. return grossPay;
  157. }
  158.  
  159. // TODO - Add an inline "getter" function that will retrieve the employee stateTax
  160. inline float Employee::getStateTax() {
  161. return stateTax;
  162. }
  163.  
  164. // TODO - Add an inline "getter" function that will retrieve the employee fedTax
  165. inline float Employee::getFedTax() {
  166. return fedTax;
  167. }
  168.  
  169. // TODO - Add an inline "getter" function that will retrieve the employee netPay
  170. inline float Employee::getNetPay() {
  171. return netPay;
  172. }
  173.  
  174.  
  175. // private member function to calculate Overtime Hours
  176. float Employee::calcOverTimeHrs ( )
  177. {
  178. // Calculate the overtime hours for the week
  179. if (hours > STD_HOURS)
  180. overTimeHrs = hours - STD_HOURS; // ot hours
  181. else
  182. overTimeHrs = 0; // no ot hours
  183.  
  184. // the calculated overtime hours
  185. return (overTimeHrs);
  186.  
  187. } // calcOverTimeHrs
  188.  
  189. // private member function to calculate Gross Pay
  190. float Employee::calcGrossPay ( )
  191. {
  192. // Process gross pay based on if there is overtime
  193. if (overTimeHrs > 0)
  194. {
  195. // overtime
  196. grossPay = (STD_HOURS * wageRate) // normal pay
  197. + (overTimeHrs * (wageRate * OT_RATE)); // ot pay
  198. }
  199. else // no overtime pay
  200. {
  201. grossPay = wageRate * hours; // normal pay
  202. }
  203.  
  204. // the calculated gross pay
  205. return (grossPay);
  206.  
  207. } // calcGrossPay
  208.  
  209. // private member function to calculate State Tax
  210. float Employee::calcStateTax ()
  211. {
  212.  
  213. float theStateTax; // calculated state tax
  214.  
  215. theStateTax = grossPay; // initialize to gross pay
  216.  
  217. // calculate state tax based on where employee resides
  218.  
  219. if (taxState.compare("MA") == 0)
  220. theStateTax *= MA_TAX_RATE;
  221. else if (taxState.compare("VT") == 0)
  222. theStateTax *= VT_TAX_RATE;
  223. else if (taxState.compare("NH") == 0)
  224. theStateTax *= NH_TAX_RATE;
  225. else if (taxState.compare("CA") == 0)
  226. theStateTax *= CA_TAX_RATE;
  227. else
  228. theStateTax *= DEFAULT_TAX_RATE; // any other state
  229.  
  230. // return the calculated state tax
  231. return (theStateTax);
  232.  
  233. } // calcStateTax
  234.  
  235. // private member function to calculate Federal Tax
  236. float Employee::calcFedTax ()
  237. {
  238.  
  239. float theFedTax; // The calculated Federal Tax
  240.  
  241. // Federal Tax is the same for all regardless of state
  242. theFedTax = grossPay * FED_TAX_RATE;
  243.  
  244. // return the calculated federal tax
  245. return (theFedTax);
  246.  
  247. } // calcFedTax
  248.  
  249. // private member function to calculate Net Pay
  250. float Employee::calcNetPay ()
  251. {
  252.  
  253. float theNetPay; // total take home pay (minus taxes)
  254. float theTotalTaxes; // total taxes owed
  255.  
  256. // calculate the total taxes owed
  257. theTotalTaxes = stateTax + fedTax;
  258.  
  259. // calculate the net pay
  260. theNetPay = grossPay - theTotalTaxes;
  261.  
  262. // return the calculated net pay
  263. return (theNetPay);
  264.  
  265. } // calcNetPay
  266.  
  267.  
  268. // constructor with arguments
  269. Employee::Employee (string myFirstName, string myLastName, string myTaxState,
  270. int myClockNumber, float myWageRate, float myHours)
  271. {
  272. // initialize all member data items
  273. firstName = myFirstName; // input
  274. lastName = myLastName; // input
  275.  
  276. // Convert myTaxState to uppercase if entered in lowercase
  277. if (std::islower(myTaxState[0]))
  278. myTaxState[0] = std::toupper(myTaxState[0]);
  279. if (std::islower(myTaxState[1]))
  280. myTaxState[1] = std::toupper(myTaxState[1]);
  281.  
  282. taxState = myTaxState; // input
  283. clockNumber = myClockNumber; // input
  284. wageRate = myWageRate; // input
  285. hours = myHours; // input
  286. overTimeHrs = calcOverTimeHrs(); // calculated overtime hours
  287. grossPay = calcGrossPay(); // calculated gross pay
  288.  
  289. // TODO - set stateTax as the return from calcStateTax member function
  290. stateTax = calcStateTax();
  291.  
  292. // TODO - set fedTax as the return from calcFedTax member function
  293. fedTax = calcFedTax();
  294.  
  295. // TODO - set netPay as the return from calcNetPay member function
  296. netPay = calcNetPay();
  297.  
  298. } // Employee constructor
  299.  
  300. // a member function to print out the info in a given Employee object
  301. void Employee::printEmployee() {
  302.  
  303. // Display the entered input on the Employee
  304. cout << endl << endl <<"*** Entered Details are *** " << endl;
  305. cout << endl <<" First Name: "<< getFirstName();
  306. cout << endl <<" Last Name: "<< getLastName();
  307. cout << endl <<" Tax State: "<< getTaxState();
  308. cout << endl <<" Clock Number: "<< getClockNumber();
  309. cout << endl <<" Wage Rate: "<< getWageRate ();
  310. cout << endl <<" Hours: "<< getHours ();
  311.  
  312. // Display the calculated values of the Employee
  313. cout<< endl << endl <<" *** Calculated Values are *** " << endl;
  314.  
  315. // print out overtime hours based on the employee information entered
  316. cout << endl << " Overtime Hours : " << getOverTimeHrs();
  317.  
  318. // print out gross pay based on the employee information entered
  319. cout << endl << " Gross Pay : $" << getGrossPay();
  320.  
  321. // TODO - Add cout statement with call to stateTax getter function
  322. cout << endl << " State Tax : $" << getStateTax();
  323.  
  324. // TODO - Add cout statement with call to fedTax getter function
  325. cout << endl << " Federal Tax : $" << getFedTax();
  326.  
  327. // TODO - Add cout statement with call to netPay getter function
  328. cout << endl << " Net Pay : $" << getNetPay();
  329.  
  330. // add a new line to separate the next employee
  331. cout <<"\n";
  332.  
  333. } // printEmployee
  334.  
  335. // Employee's destructor
  336. Employee::~Employee()
  337. {
  338. // nothing to print here, but could ...
  339. }
  340.  
  341.  
  342. // main function to start the processing
  343. int main ()
  344. {
  345. // local variables to collect user input
  346.  
  347. string myFirstName; // First Name to input
  348. string myLastName; // Last Name to input
  349. string myTaxState; // Tax State to input
  350. int myClockNumber; // Clock Number to input
  351. float myWageRate; // Wage Rate to input
  352. float myHours; // Hours to input
  353.  
  354. cout << fixed // fix the number of decimal digits
  355. << setprecision(2); // to 2
  356.  
  357. // Array of Objects to store each of our employees
  358. // This calls the default constructor for each array element
  359. Employee e[EMP_SIZE];
  360.  
  361. // prompt for information to read in employee information
  362. for (int i = 0; i < EMP_SIZE; ++i)
  363. {
  364. // Enter Employee Information
  365. cout <<"\n\n Enter Employee First Name: ";
  366. cin>>myFirstName ;
  367. cout <<"\n Enter Employee Last Name: ";
  368. cin>>myLastName ;
  369. cout <<"\n Enter Employee Tax State: ";
  370. cin>>myTaxState ;
  371. cout<<"\n Enter Employee Clock Number: ";
  372. cin>>myClockNumber;
  373. cout <<"\n Enter Employee Hourly Wage Rate: ";
  374. cin>>myWageRate;
  375. cout <<"\n Enter Employee Hours Worked for the Week: ";
  376. cin>>myHours;
  377.  
  378. // Call our constructor to create an employee object
  379. // using the input entered above. The constructor
  380. // will also put into motion the execution of the
  381. // various private member functions which will
  382. // calculate the overtime, gross pay, state tax, federal
  383. // tax, and net pay for the current employee.
  384.  
  385. // The updated object will be returned and placed in the
  386. // the element of our array of objects named "e", using the index
  387. // of the current value of our loop index "i" ... thus: e[i]
  388. e[i] = {myFirstName, myLastName, myTaxState,
  389. myClockNumber, myWageRate, myHours
  390. };
  391.  
  392. // Call the printEmployee public member function to display all
  393. // the inputted and calculated values for the current employee
  394. e[i].printEmployee();
  395.  
  396. } // for
  397.  
  398. return 0;
  399.  
  400. } // main
Success #stdin #stdout 0s 544KB
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: 

*** Entered Details are *** 

 First Name: Connie
 Last Name: Cobol
 Tax State: MA
 Clock Number: 98401
 Wage Rate: 10.60
 Hours: 51.00

 *** Calculated Values are *** 

 Overtime Hours : 11.00
 Gross Pay : $598.90
 State Tax : $29.95
 Federal Tax : $149.73
 Net Pay : $419.23


 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: 

*** Entered Details are *** 

 First Name: Mary
 Last Name: Apl
 Tax State: NH
 Clock Number: 526488
 Wage Rate: 9.75
 Hours: 42.50

 *** Calculated Values are *** 

 Overtime Hours : 2.50
 Gross Pay : $426.56
 State Tax : $0.00
 Federal Tax : $106.64
 Net Pay : $319.92


 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: 

*** Entered Details are *** 

 First Name: Frank
 Last Name: Fortran
 Tax State: VT
 Clock Number: 765349
 Wage Rate: 10.50
 Hours: 37.00

 *** Calculated Values are *** 

 Overtime Hours : 0.00
 Gross Pay : $388.50
 State Tax : $23.31
 Federal Tax : $97.12
 Net Pay : $268.07


 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: 

*** Entered Details are *** 

 First Name: Jeff
 Last Name: Ada
 Tax State: NY
 Clock Number: 34645
 Wage Rate: 12.25
 Hours: 45.00

 *** Calculated Values are *** 

 Overtime Hours : 5.00
 Gross Pay : $581.88
 State Tax : $46.55
 Federal Tax : $145.47
 Net Pay : $389.86


 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: 

*** Entered Details are *** 

 First Name: Anton
 Last Name: Pascal
 Tax State: CA
 Clock Number: 127615
 Wage Rate: 8.35
 Hours: 40.00

 *** Calculated Values are *** 

 Overtime Hours : 0.00
 Gross Pay : $334.00
 State Tax : $23.38
 Federal Tax : $83.50
 Net Pay : $227.12