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