fork download
  1. //********************************************************
  2. //
  3. // Assignment 11 - Object Oriented Design
  4. //
  5. // Name: Heather Grothe
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: 04/23/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. float getStateTax();
  181. float getFedTax();
  182. float getNetPay();
  183.  
  184. // member function prototype to print an Employee object
  185. void printEmployee(Employee e); // passes an object
  186.  
  187. }; // class Employee
  188.  
  189. // constructor with arguments
  190. Employee::Employee (string myFirstName, string myLastName, string myTaxState,
  191. int myClockNumber, float myWageRate, float myHours)
  192. {
  193. // initialize all member data items
  194. firstName = myFirstName; // input
  195. lastName = myLastName; // input
  196.  
  197. // Convert myTaxState to uppercase if entered in lowercase
  198. if (std::islower(myTaxState[0]))
  199. myTaxState[0] = std::toupper(myTaxState[0]);
  200. if (std::islower(myTaxState[1]))
  201. myTaxState[1] = std::toupper(myTaxState[1]);
  202.  
  203. taxState = myTaxState; // input
  204. clockNumber = myClockNumber; // input
  205. wageRate = myWageRate; // input
  206. hours = myHours; // input
  207. overTimeHrs = calcOverTimeHrs(); // calculated overtime hours
  208. grossPay = calcGrossPay(); // calculated gross pay
  209. stateTax = calcStateTax(); // calculated state tax
  210. fedTax = calcFedTax(); // calculated federal tax
  211. netPay = calcNetPay(); // calculated net pay
  212.  
  213. } // Employee constructor
  214.  
  215. // Employee's destructor
  216. Employee::~Employee()
  217. {
  218. // nothing to print here, but could ...
  219. }
  220.  
  221. // A "getter" function that will retrieve the First Name
  222. string Employee::getFirstName() {
  223. return firstName;
  224. }
  225.  
  226. // A "getter" function that will retrieve the employee Last Name
  227. string Employee::getLastName() {
  228. return lastName;
  229. }
  230.  
  231. // A "getter" function that will retrieve the employee Tax State
  232. string Employee::getTaxState() {
  233. return taxState;
  234. }
  235.  
  236. // A "getter" function that will retrieve the employee Clock Number
  237. int Employee::getClockNumber() {
  238. return clockNumber;
  239. }
  240.  
  241. // A "getter" function that will retrieve the employee Wage Rate
  242. float Employee::getWageRate() {
  243. return wageRate;
  244. }
  245.  
  246. // A "getter" function that will retrieve the employee Hours Worked
  247. float Employee::getHours() {
  248. return hours;
  249. }
  250.  
  251. // A "getter" function that will retrieve the employee Overtime Hours
  252. float Employee::getOverTimeHrs() {
  253. return overTimeHrs;
  254. }
  255.  
  256. // A "getter" function that will retrieve the employee Gross Pay
  257. float Employee::getGrossPay() {
  258. return grossPay;
  259. }
  260.  
  261. // A "getter" function that will retrieve the employee State Tax
  262. float Employee::getStateTax() {
  263. return stateTax;
  264. }
  265.  
  266. // A "getter" function that will retrieve the employee Fed Tax
  267. float Employee::getFedTax() {
  268. return fedTax;
  269. }
  270.  
  271. // A "getter" function that will retrieve the employee Net Pay
  272. float Employee::getNetPay() {
  273. return netPay;
  274. }
  275.  
  276. // a member function to print out the info in a given Employee object
  277. void Employee::printEmployee(Employee e) {
  278.  
  279. // Display the entered input on the Employee
  280. cout<<"\n\n *** Entered Details are *** \n";
  281. cout<<"\n First Name: "<< e.getFirstName();
  282. cout<<"\n Last Name: "<< e.getLastName();
  283. cout<<"\n Tax State: "<< e.getTaxState();
  284. cout <<"\n Clock Number: "<< e.getClockNumber();
  285. cout <<"\n Wage Rate: "<< e.getWageRate ();
  286. cout <<"\n Hours: "<< e.getHours ();
  287.  
  288. // Display the calculated values of the Employee
  289. cout<<"\n\n *** Calculated Values are *** \n";
  290.  
  291. // print out overtime hours based on the employee information entered
  292. cout <<"\n Overtime Hours : " << e.getOverTimeHrs();
  293.  
  294. // print out gross pay based on the employee information entered
  295. cout <<"\n Gross Pay : $" << e.getGrossPay();
  296.  
  297. // print out state tax based on the employee information entered
  298. cout << "\n State Tax : $" << e.getStateTax();
  299.  
  300. // print out fed tax based on the employee information entered
  301. cout << "\n Federal Tax : $" << e.getFedTax();
  302.  
  303. // print out net pay based on the employee information entered
  304. cout << "\n Net Pay : $" << e.getNetPay();
  305.  
  306. // add a new line to separate the next employee
  307. cout <<"\n";
  308.  
  309. } // printEmployee
  310.  
  311. // main function to start the processing
  312. int main ()
  313. {
  314. // local variables to collect user input
  315.  
  316. string myFirstName; // First Name to input
  317. string myLastName; // Last Name to input
  318. string myTaxState; // Tax State to input
  319. int myClockNumber; // Clock Number to input
  320. float myWageRate; // Wage Rate to input
  321. float myHours; // Hours to input
  322.  
  323. cout << fixed // fix the number of decimal digits
  324. << setprecision(2); // to 2
  325.  
  326. // Array of Objects to store each of our employees
  327. Employee e[EMP_SIZE];
  328.  
  329. // prompt for information to read in employee information
  330. for (int i = 0; i < EMP_SIZE; ++i)
  331. {
  332. // Enter Employee Information
  333. cout <<"\n\n Enter Employee First Name: ";
  334. cin>>myFirstName ;
  335. cout <<"\n Enter Employee Last Name: ";
  336. cin>>myLastName ;
  337. cout <<"\n Enter Employee Tax State: ";
  338. cin>>myTaxState ;
  339. cout<<"\n Enter Employee Clock Number: ";
  340. cin>>myClockNumber;
  341. cout <<"\n Enter Employee Hourly Wage Rate: ";
  342. cin>>myWageRate;
  343. cout <<"\n Enter Employee Hours Worked for the Week: ";
  344. cin>>myHours;
  345.  
  346. // Call our constructor to create an employee object
  347. // using the input entered above. The constructor
  348. // will also put into motion the execution of the
  349. // various private member functions which will
  350. // calculate the overtime, gross pay, state tax, federal
  351. // tax, and net pay for the current employee.
  352.  
  353. // The updated object will be returned and placed in the
  354. // the element of our array of objects named "e", using the index
  355. // of the current value of our loop index "i" ... thus: e[i]
  356. e[i] = {myFirstName, myLastName, myTaxState,
  357. myClockNumber, myWageRate, myHours};
  358.  
  359. // Call the printEmployee public member function to display all
  360. // the inputted and calculated values for the current employee
  361. e[i].printEmployee(e[i]);
  362.  
  363. } // for
  364.  
  365. return 0;
  366.  
  367. } // main
Success #stdin #stdout 0s 5328KB
stdin
Standard input is empty
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: 
 Last Name: 
 Tax State: 
 Clock Number: 5439
 Wage Rate: 0.00
 Hours: 0.00

 *** Calculated Values are *** 

 Overtime Hours : 0.00
 Gross Pay : $0.00
 State Tax : $0.00
 Federal Tax : $0.00
 Net Pay : $0.00


 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: 
 Last Name: 
 Tax State: 
 Clock Number: 5439
 Wage Rate: 0.00
 Hours: 0.00

 *** Calculated Values are *** 

 Overtime Hours : 0.00
 Gross Pay : $0.00
 State Tax : $0.00
 Federal Tax : $0.00
 Net Pay : $0.00


 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: 
 Last Name: 
 Tax State: 
 Clock Number: 5439
 Wage Rate: 0.00
 Hours: 0.00

 *** Calculated Values are *** 

 Overtime Hours : 0.00
 Gross Pay : $0.00
 State Tax : $0.00
 Federal Tax : $0.00
 Net Pay : $0.00


 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: 
 Last Name: 
 Tax State: 
 Clock Number: 5439
 Wage Rate: 0.00
 Hours: 0.00

 *** Calculated Values are *** 

 Overtime Hours : 0.00
 Gross Pay : $0.00
 State Tax : $0.00
 Federal Tax : $0.00
 Net Pay : $0.00


 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: 
 Last Name: 
 Tax State: 
 Clock Number: 5439
 Wage Rate: 0.00
 Hours: 0.00

 *** Calculated Values are *** 

 Overtime Hours : 0.00
 Gross Pay : $0.00
 State Tax : $0.00
 Federal Tax : $0.00
 Net Pay : $0.00