Posted By

DrPepper on 11/02/10


Tagged

class member


Versions (?)

[CISP400] Employee and ProductionWorker class


 / Published in: C++
 

  1. /*#############################################################################
  2.   # CISP 400 ch15.cpp #
  3.   # #
  4.   # Class : wed 14:00- #
  5.   # Assignemnt : Employee and ProductionWorker class #
  6.   ############################################################################
  7.   # Date Edit #
  8.   ##########################################################################*/
  9.  
  10. #include <iostream>
  11. #include <cstdlib>
  12. #include <iomanip>
  13. #include <string>
  14. #include <cstdio>
  15. #include <cstring>
  16. #include <vector>
  17. using namespace std;
  18.  
  19. class Employee /*: public ProductionWorker*/
  20. {
  21. protected:
  22. string temp;
  23. string temp1;
  24. protected:
  25. string empName;
  26. string empNumber;
  27. string hireDate;
  28. int nightPer;
  29. public:
  30. Employee()
  31. {
  32. nightPer =0;
  33. }
  34. Employee(string &name,string &number,string &date) /* : ProductionWorker() */
  35. {
  36. empName = name;
  37. empNumber = number;
  38. hireDate = date;
  39. }
  40.  
  41. string getDate() const
  42. {
  43. return hireDate;
  44. }
  45. string getEmpNum() const
  46. {
  47. return empNumber;
  48. }
  49. string getEmpName() const
  50. {
  51. return empName;
  52. }
  53. };
  54.  
  55. class ProductionWorker : public Employee
  56. {
  57. private:
  58. float pay;
  59. double workTime;
  60. double add;
  61. public:
  62. int shift; // day for 1 night for 2
  63. double hourlyPayRate;
  64. ProductionWorker() : Employee()
  65. {
  66. add = 0;
  67. workTime = 0;
  68. pay = 0;
  69. shift = 0;
  70. hourlyPayRate = 0;
  71. }
  72. ProductionWorker(int shift,float hourlyPayRate,double workTime,double add) : Employee()
  73. {
  74. float Pay;
  75. Pay = calPay(shift,hourlyPayRate,workTime,add);
  76. setValue(Pay,shift,hourlyPayRate,workTime,add);
  77. }
  78. double calPay(int, double, double,double);//mutator function
  79.  
  80. void setValue(double Pay, int Shift,double hourPay, double workT,double addRate)
  81. {
  82. pay = Pay;
  83. shift = Shift;
  84. hourlyPayRate = hourPay;
  85. workTime = workT;
  86. add = addRate;
  87. }
  88.  
  89. double getPay() const // Accessor function
  90. {
  91. return pay;
  92. }
  93.  
  94. int getShift() const
  95. {
  96. return shift;
  97. }
  98. };
  99.  
  100. double ProductionWorker::calPay(int shift,double hourlyPayRate,double workTime,double add)
  101. {
  102. float payRate =0;
  103. if (shift == 1)
  104. {
  105.  
  106. payRate = hourlyPayRate * workTime;
  107. cout << payRate << endl;
  108. return payRate;
  109. }
  110. else
  111. {
  112. payRate = (hourlyPayRate*(1+add/100)*workTime);
  113. cout << payRate << endl;
  114. return payRate;
  115. }
  116. }
  117.  
  118. void setDate(string &date,int month,int day,int year);
  119.  
  120. int main(){
  121. string name;
  122. string number;
  123. int month;
  124. int day;
  125. int year;
  126. int sh;
  127. double hourPay;
  128. double workTime;
  129. int add;
  130.  
  131. cout << "Enter a Employee Name : ";
  132. getline(cin,name);
  133. cout << "Enter a Employee Number : ";
  134. getline(cin,number);
  135. cout << "Enter a Hire Date (month) : ";
  136. cin >> month;
  137. while((month < 1) ||(month > 12))
  138. {
  139. cout << "Month is Invalid "<< endl;
  140. cout << "Could you please enter correct month within 1 to 12"<< endl;
  141. cin >> month;
  142. }
  143. cout << "Enter a Hire Date (day) : ";
  144. cin >> day;
  145. while((day < 1) ||(day > 31))
  146. {
  147. cout << "Month is Invalid "<< endl;
  148. cout << "Could you please enter correct day within 1 to 12"<< endl;
  149. cin >> day;
  150. }
  151. cout << "Enter a Hire Date (year) : ";
  152. cin >> year;
  153. while((year < 1800) ||(year > 2500))
  154. {
  155. cout << "Month is Invalid "<< endl;
  156. cout << "Could you please enter correct year within 1800 to 2500"<< endl;
  157. cin >> year;
  158. }
  159. // setDate(date,month,day,year);
  160.  
  161. Employee emp(name,number,date);
  162.  
  163. cout << "Enter a shift (day 1 night 2) : ";
  164. cin >> sh;
  165. while((sh<0) || (sh>2) )
  166. {
  167. cout << "Invalid number "<<endl;
  168. cout << "Please enter 1 or 2 (1 is Day time, 2 is night time )" <<endl;
  169. cin >> sh;
  170. }
  171. cout << "Enter a work time : ";
  172. cin >> workTime;
  173. while((workTime<0) || (workTime > 744))
  174. {
  175. cout << "work time is invalid"<<endl;
  176. cout << "work time is within 774 hours per month" << endl;
  177. cout << "work note: 774 hours working is the same amount that one worker works 24 hours/31days"<<endl;
  178. cin >> workTime;
  179. }
  180. cout << "Enter a Basic Hourly Pay Rate: ";
  181. cin >> hourPay;
  182. while(hourPay < 0)
  183. {
  184. cout << "Hour Pay is invalid "<< endl;
  185. cout << "Hour Pay is more than 0 "<< endl;
  186. cin >> hourPay;
  187. }
  188. cout << "Enter a Night time additional pay rate (%) : ";
  189. cin >> add;
  190. while(add < 0)
  191. {
  192. cout << "Additional rate is negative number "<<endl;
  193. cout << "please enter more than 0 for additional pay rate at night time workers"<<endl;
  194. cin >> add;
  195. }
  196. ProductionWorker pw(sh,hourPay, workTime,add);
  197. system("clear");
  198. /*##############################################################################
  199.   # need edit here take data from each class and each class need to convert #
  200.   # data for print out #
  201.   ############################################################################*/
  202.  
  203. cout << "******* Result **********" << endl;
  204. cout << "Name : "<< emp.getEmpName() << endl;
  205. cout << "ID Number : " << emp.getEmpNum() << endl;
  206. cout << "Hire Date : " << emp.getDate() << endl;
  207. cout << "Shift : " << pw.getShift() << endl;
  208. cout << "Payment : " << pw.getPay() << endl;
  209.  
  210. return 0;
  211. }

Report this snippet  

You need to login to post a comment.