Advertisement
userxbw

Employee types records C++

Aug 31st, 2022 (edited)
848
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <array>
  4. using namespace std;
  5.  
  6. void dataEntryMess();
  7. void messLine();
  8. string employType(int c);
  9. string hoursworked();
  10.  
  11. enum class paycode
  12. { TEAM=1, SALES=2, PEICE=3, HOURLY=4, QUIT=-1};
  13.  
  14. class employee {
  15.  
  16. private:
  17. protected:
  18. int type;
  19. double hrsworked;
  20. double payrate;
  21. double overtime;
  22. double sales;
  23. int items;
  24.  
  25. public:
  26. employee(double t,double hw,
  27. double pr,double ot,double s,int i){
  28. hrsworked=hw;
  29. payrate=pr;
  30. overtime=ot;
  31. sales=s;
  32. items=i;
  33.  
  34. } // end constructor
  35. employee(){
  36. type=0;
  37. hrsworked=0.0;
  38. payrate=0.0;
  39. overtime=0.0;
  40. sales=0.0;
  41. items=0;
  42.  
  43. } // end constructor
  44.  
  45. void setType(int t){type=t;}
  46. void setHoursWorked(double hw){hrsworked=hw;}
  47. void setPayRate(double pr){payrate=pr;}
  48. void setOvertime(double ot){overtime=ot;}
  49. void setSales(double s){sales=s;}
  50.  
  51. int getType(){return type;}
  52. double getHoursWorked(){return hrsworked;}
  53. double getPayRate(){return payrate;}
  54. double getOverTime(){return overtime;}
  55. double getSales(){return sales;}
  56. }; // end class
  57.  
  58.  
  59. class TeamLeader : public employee
  60. {
  61.  
  62. public:
  63. TeamLeader(double pr){
  64. payrate=pr;
  65. }
  66. double getPayRate(){return payrate;}
  67.  
  68. };
  69.  
  70. class Sales : public employee
  71. {
  72. private:
  73. const double sales_worker = 500.00;
  74. const double gross_sales = 6.5;
  75.  
  76. public:
  77. Sales(double s){
  78. sales=s;
  79. }
  80.  
  81. double getPayRate(){
  82. return (sales_worker+(sales*gross_sales));
  83. }
  84.  
  85. };
  86. class Peice : public employee
  87. {
  88. protected:
  89. const double peice_work = 0.96;
  90.  
  91.  
  92. public:
  93. Peice(int p){
  94. items=p;
  95. }
  96. double getPayRate(){
  97. return (peice_work*items);
  98. }
  99. };
  100.  
  101. class Hourly : public employee
  102. {
  103. const double over_time = 1.5;
  104. const int full_time = 40;
  105. public:
  106. Hourly(double w,double h){
  107. payrate=w;
  108. hrsworked=h;
  109. }
  110.  
  111. double getHoursWorked(){return hrsworked;}
  112.  
  113. double getPayRate(){
  114. double ot=(hrsworked-full_time);
  115. return (ot>0)?
  116.        ((ot*(over_time*payrate))+
  117.        (full_time*payrate)):
  118.        (hrsworked*payrate);
  119. }
  120.  
  121. };
  122.  
  123. int main(){
  124. char run='y';
  125. int t=0,s=0,p=0,h=0;
  126. int c;
  127. double pr,hrs;
  128.  
  129. vector <TeamLeader> tl;
  130. vector <Sales> sl;
  131. vector <Peice> pe;
  132. vector <Hourly> hry;
  133.  
  134. do
  135. {
  136. dataEntryMess();
  137. cin>>c;
  138.  
  139. switch(static_cast<paycode>(c)){
  140.     case paycode::TEAM:
  141.     cout<< employType(c);
  142.     cin>>pr;
  143.     tl.push_back(TeamLeader(pr));
  144.     cout<<"Fortnight pay is: $"
  145.     <<tl.at(t++).getPayRate()<<endl<<endl;
  146.     break;
  147.     case paycode::SALES:
  148.     cout<< employType(c);
  149.     cin>>pr;
  150.     sl.push_back(Sales(pr));
  151.     cout<<"Fortnight pay is: $"
  152.     <<sl.at(s++).getPayRate()<<endl<<endl;
  153.     break;
  154.     case paycode::PEICE:
  155.     cout<< employType(c);
  156.     int i;
  157.     cin>>i;
  158.     pe.push_back(Peice(i));
  159.     cout<<"Fortnight pay is : $"
  160.     <<pe.at(p++).getPayRate()<<endl<<endl;
  161.     break;
  162.     case paycode::HOURLY:
  163.     cout<< employType(c);
  164.     cin>>pr;
  165.     cout<< hoursworked()<<endl;
  166.     double hrw;
  167.     cin>>hrw;
  168.     hry.push_back(Hourly(pr,hrw));
  169.     cout<<"Fortnight pay is : $"
  170.     <<hry.at(h++).getPayRate()<<endl<<endl;
  171.     break;
  172.     case paycode::QUIT:
  173.     run='n';
  174.     break;
  175.     default:
  176.     cerr<<"bad input"<<endl;
  177.     c=0;
  178.     cin.clear();
  179.  cin.ignore(numeric_limits<streamsize>::max(), '\n');
  180.     break;
  181.     }// end switch
  182. }while(run == 'y');
  183.  
  184. double total;
  185. for(auto it:tl)
  186. total+=it.getPayRate();
  187. for(auto it:sl)
  188. total+=it.getPayRate();
  189. for(auto it:pe)
  190. total+=it.getPayRate();
  191. for(auto it:hry)
  192. total+=it.getPayRate();
  193.  
  194. cout<<endl<<"Total amount paid out : $"<<total<<endl;
  195.  
  196.  
  197. return 0;
  198. }
  199. // Functions
  200.  
  201. void dataEntryMess(){
  202. messLine();
  203.  
  204. cout<<"Enter code for employee's number code [-1 to end]: \n";
  205.  
  206. }
  207.  
  208. void messLine(){
  209. for(int i=0;i<30;i++)
  210.     cout<<"*";
  211. cout<<"\n";
  212. }
  213.  
  214. string employType(int c){
  215. array<string, 5> type ={" ",
  216. "Team leader's",
  217. "Sales employee's",
  218. "Peice worker's",
  219. "Hourly worker's"};
  220.  
  221. switch(static_cast<paycode>(c)){
  222.     case paycode::TEAM:
  223.         return "Enter "+ type.at(c) +" pay  rate : ";
  224.     case paycode::SALES:
  225.     return "Enter "+type.at(c)+" gross weekly sales: ";
  226.     case paycode::PEICE:
  227.     return "Enter "+type.at(c)+" amount of peices sold: ";
  228.     case paycode::HOURLY:
  229.     return "Enter "+type.at(c)+" pay rate: ";
  230.     case paycode::QUIT:
  231.     // its here to complete the enum elements
  232.     break;
  233.     } //end switch
  234. return "oops something went wrong!";// for control path
  235. }
  236. string hoursworked(){
  237. return "Enter the numbers of hours worked: ";
  238. }
  239.  
  240.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement