fork download
  1. //********************************************************
  2. //
  3. // Assignment 11 - Object Oriented Design
  4. //
  5. // Name: <Matthew Tracy>
  6. //
  7. // Class: C Programming, <Spring 2026>
  8. //
  9. // Date: <04/25/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. // TODO - Add an inline "getter" function that will retrieve the employee fedTax
  164. inline float Employee::getfedTax() {
  165. return fedTax;
  166. }
  167. // TODO - Add an inline "getter" function that will retrieve the employee netPay
  168. inline float Employee::getNetPay() {
  169. return netPay;
  170. }
  171.  
  172. // private member function to calculate Overtime Hours
  173. float Employee::calcOverTimeHrs ()
  174. {
  175. // Calculate the overtime hours for the week
  176. if (hours > STD_HOURS)
  177. overTimeHrs = hours - STD_HOURS; // ot hours
  178. else
  179. overTimeHrs = 0; // no ot hours
  180.  
  181. // the calculated overtime hours
  182. return (overTimeHrs);
  183.  
  184. } // calcOverTimeHrs
  185.  
  186. // private member function to calculate Gross Pay
  187. float Employee::calcGrossPay ( )
  188. {
  189. // Process gross pay based on if there is overtime
  190. if (overTimeHrs > 0)
  191. {
  192. // overtime
  193. grossPay = (STD_HOURS * wageRate) // normal pay
  194. + (overTimeHrs * (wageRate * OT_RATE)); // ot pay
  195. }
  196. else // no overtime pay
  197. {
  198. grossPay = wageRate * hours; // normal pay
  199. }
  200.  
  201. // the calculated gross pay
  202. return (grossPay);
  203.  
  204. } // calcGrossPay
  205.  
  206. // private member function to calculate State Tax
  207. float Employee::calcStateTax ()
  208. {
  209.  
  210. float theStateTax; // calculated state tax
  211.  
  212. theStateTax = grossPay; // initialize to gross pay
  213.  
  214. // calculate state tax based on where employee resides
  215.  
  216. if (taxState.compare("MA") == 0)
  217. theStateTax *= MA_TAX_RATE;
  218. else if (taxState.compare("VT") == 0)
  219. theStateTax *= VT_TAX_RATE;
  220. else if (taxState.compare("NH") == 0)
  221. theStateTax *= NH_TAX_RATE;
  222. else if (taxState.compare("CA") == 0)
  223. theStateTax *= CA_TAX_RATE;
  224. else
  225. theStateTax *= DEFAULT_TAX_RATE; // any other state
  226.  
  227. // return the calculated state tax
  228. return (theStateTax);
  229.  
  230. } // calcStateTax
  231.  
  232. // private member function to calculate Federal Tax
  233. float Employee::calcFedTax ()
  234. {
  235.  
  236. float theFedTax; // The calculated Federal Tax
  237.  
  238. // Federal Tax is the same for all regardless of state
  239. theFedTax = grossPay * FED_TAX_RATE;
  240.  
  241. // return the calculated federal tax
  242. return (theFedTax);
  243.  
  244. } // calcFedTax
  245.  
  246. // private member function to calculate Net Pay
  247. float Employee::calcNetPay ()
  248. {
  249.  
  250. float theNetPay; // total take home pay (minus taxes)
  251. float theTotalTaxes; // total taxes owed
  252.  
  253. // calculate the total taxes owed
  254. theTotalTaxes = stateTax + fedTax;
  255.  
  256. // calculate the net pay
  257. theNetPay = grossPay - theTotalTaxes;
  258.  
  259. // return the calculated net pay
  260. return (theNetPay);
  261.  
  262. } // calcNetPay
  263.  
  264.  
  265. // constructor with arguments
  266. Employee::Employee (string myFirstName, string myLastName, string myTaxState,
  267. int myClockNumber, float myWageRate, float myHours)
  268. {
  269. // initialize all member data items
  270. firstName = myFirstName; // input
  271. lastName = myLastName; // input
  272.  
  273. // Convert myTaxState to uppercase if entered in lowercase
  274. if (std::islower(myTaxState[0]))
  275. myTaxState[0] = std::toupper(myTaxState[0]);
  276. if (std::islower(myTaxState[1]))
  277. myTaxState[1] = std::toupper(myTaxState[1]);
  278.  
  279. taxState = myTaxState; // input
  280. clockNumber = myClockNumber; // input
  281. wageRate = myWageRate; // input
  282. hours = myHours; // input
  283. overTimeHrs = calcOverTimeHrs(); // calculated overtime hours
  284. grossPay = calcGrossPay(); // calculated gross pay
  285.  
  286. // TODO - set stateTax as the return from calcStateTax member function
  287. stateTax = calcStateTax();
  288.  
  289. // TODO - set fedTax as the return from calcFedTax member function
  290. fedTax = calcFedTax();
  291.  
  292. // TODO - set netPay as the return from calcNetPay member function
  293. netPay = calcNetPay();
  294.  
  295. } // Employee constructor
  296.  
  297. // a member function to print out the info in a given Employee object
  298. void Employee::printEmployee() {
  299.  
  300. // Display the entered input on the Employee
  301. cout << endl << endl <<"*** Entered Details are *** " << endl;
  302. cout << endl <<" First Name: "<< getFirstName();
  303. cout << endl <<" Last Name: "<< getLastName();
  304. cout << endl <<" Tax State: "<< getTaxState();
  305. cout << endl <<" Clock Number: "<< getClockNumber();
  306. cout << endl <<" Wage Rate: "<< getWageRate ();
  307. cout << endl <<" Hours: "<< getHours ();
  308.  
  309. // Display the calculated values of the Employee
  310. cout<< endl << endl <<" *** Calculated Values are *** " << endl;
  311.  
  312. // print out overtime hours based on the employee information entered
  313. cout << endl << " Overtime Hours : " << getOverTimeHrs();
  314.  
  315. // print out gross pay based on the employee information entered
  316. cout << endl << " Gross Pay : $" << getGrossPay();
  317.  
  318. // TODO - Add cout statement with call to stateTax getter function
  319. cout << endl << " State Tax : $" << getstateTax();
  320.  
  321. // TODO - Add cout statement with call to fedTax getter function
  322. cout << endl << " Fed Tax : $" << getfedTax();
  323.  
  324. // TODO - Add cout statement with call to netPay getter function
  325. cout << endl << " Net Pay : $" << getNetPay();
  326.  
  327. // add a new line to separate the next employee
  328. cout <<"\n";
  329.  
  330. } // printEmployee
  331.  
  332. // Employee's destructor
  333. Employee::~Employee()
  334. {
  335. // nothing to print here, but could ...
  336. }
  337.  
  338.  
  339. // main function to start the processing
  340. int main ()
  341. {
  342. // local variables to collect user input
  343.  
  344. string myFirstName; // First Name to input
  345. string myLastName; // Last Name to input
  346. string myTaxState; // Tax State to input
  347. int myClockNumber; // Clock Number to input
  348. float myWageRate; // Wage Rate to input
  349. float myHours; // Hours to input
  350.  
  351. cout << fixed // fix the number of decimal digits
  352. << setprecision(2); // to 2
  353.  
  354. // Array of Objects to store each of our employees
  355. // This calls the default constructor for each array element
  356. Employee e[EMP_SIZE];
  357.  
  358. // prompt for information to read in employee information
  359. for (int i = 0; i < EMP_SIZE; ++i)
  360. {
  361. // Enter Employee Information
  362. cout <<"\n\n Enter Employee First Name: ";
  363. cin>>myFirstName ;
  364. cout <<"\n Enter Employee Last Name: ";
  365. cin>>myLastName ;
  366. cout <<"\n Enter Employee Tax State: ";
  367. cin>>myTaxState ;
  368. cout<<"\n Enter Employee Clock Number: ";
  369. cin>>myClockNumber;
  370. cout <<"\n Enter Employee Hourly Wage Rate: ";
  371. cin>>myWageRate;
  372. cout <<"\n Enter Employee Hours Worked for the Week: ";
  373. cin>>myHours;
  374.  
  375. // Call our constructor to create an employee object
  376. // using the input entered above. The constructor
  377. // will also put into motion the execution of the
  378. // various private member functions which will
  379. // calculate the overtime, gross pay, state tax, federal
  380. // tax, and net pay for the current employee.
  381.  
  382. // The updated object will be returned and placed in the
  383. // the element of our array of objects named "e", using the index
  384. // of the current value of our loop index "i" ... thus: e[i]
  385. e[i] = {myFirstName, myLastName, myTaxState,
  386. myClockNumber, myWageRate, myHours
  387. };
  388.  
  389. // Call the printEmployee public member function to display all
  390. // the inputted and calculated values for the current employee
  391. e[i].printEmployee();
  392.  
  393. } // for
  394.  
  395. return 0;
  396.  
  397. } // main
Success #stdin #stdout 0.01s 5320KB
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
 Fed 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
 Fed 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
 Fed 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
 Fed 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
 Fed Tax : $83.50
 Net Pay : $227.12