LegoDrifter

Untitled

May 17th, 2020
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. class Employee{
  7. protected:
  8. char ime[50];
  9. int exp;
  10. int god;
  11. public:
  12. Employee(char * ime="", int exp=0,int god=0)
  13. {
  14. strcpy(this->ime,ime);
  15. this->exp=exp;
  16. this->god=god;
  17. }
  18. virtual double plata()=0;
  19. virtual double bonus()=0;
  20.  
  21.  
  22. int get_god()
  23. {
  24. return god;
  25. }
  26. virtual ~Employee(){}
  27. virtual int getType()=0;
  28. };
  29. class SalaryEmployee:public Employee{
  30. private:
  31. int salary;
  32. public:
  33. SalaryEmployee(char * ime="", int exp=0,int god=0,int salary=0)
  34. :Employee(ime,exp,god)
  35. {
  36. this->salary=salary;
  37. }
  38. double bonus()
  39. {
  40. return (salary*exp)/100;
  41. }
  42. double plata()
  43. {
  44. return salary+bonus();
  45. }
  46. int getType()
  47. {
  48. return 1;
  49. }
  50.  
  51. };
  52. class HourlyEmployee:public Employee{
  53. private:
  54. int totalhours;
  55. int pay_per_hour;
  56. public:
  57. HourlyEmployee(char * ime="", int exp=0,int god=0,int totalhours=0,int pay_per_hour=0)
  58. :Employee(ime,exp,god)
  59. {
  60. this->totalhours=totalhours;
  61. this->pay_per_hour=pay_per_hour;
  62. }
  63. double bonus()
  64. {
  65. if(totalhours>320)
  66. {
  67. return (pay_per_hour*0.5)*(totalhours-320);
  68. }
  69. else
  70. return 0;
  71. }
  72. double plata()
  73. {
  74. return (totalhours*pay_per_hour)+bonus();
  75.  
  76. }
  77. int getType()
  78. {
  79. return 2;
  80. }
  81.  
  82. };
  83. class Freelancer:public Employee{
  84. private:
  85. int broj_proekti;
  86. double sumi[100];
  87. public:
  88. Freelancer(char * ime="", int exp=0,int god=0,int broj_proekti=0,double *sumi=0)
  89. :Employee(ime,exp,god)
  90. {
  91. this->broj_proekti=broj_proekti;
  92. for(int i=0;i<broj_proekti;i++)
  93. {
  94. this->sumi[i]=sumi[i];
  95. }
  96. }
  97. double bonus()
  98. {
  99. if(broj_proekti>5) return (broj_proekti-5)*1000;
  100. else return 0;
  101.  
  102. }
  103. double plata()
  104. {
  105. double total=0;
  106. for(int i=0;i<broj_proekti;i++)
  107. {
  108. total+=sumi[i];
  109. }
  110. return total+bonus();
  111. }
  112. int getType()
  113. {
  114. return 3;
  115. }
  116.  
  117. };
  118.  
  119. class Company{
  120. private:
  121. char ime[50];
  122. int brVrab;
  123. Employee ** employees;
  124. public:
  125. Company(char *ime)
  126. {
  127. this->employees = new Employee *[0];
  128. this->brVrab=0;
  129. strcpy(this->ime,ime);
  130. }
  131. Company &operator +=(Employee *c)
  132. {
  133. Employee **tmp = new Employee*[brVrab+1];
  134. for(int i=0;i<brVrab;i++)
  135. {
  136. tmp[i]=employees[i];
  137. }
  138. tmp[brVrab++]=c;
  139. delete [] employees;
  140. employees=tmp;
  141. return *this;
  142. }
  143. double vkupnaPlata()
  144. {
  145. double total=0;
  146. for(int i=0;i<brVrab;i++)
  147. {
  148. total+=employees[i]->plata();
  149. }
  150. return total;
  151. }
  152. double filtriranaPlata(Employee *emp)
  153. {
  154. double vkupno=0;
  155. for(int i=0;i<brVrab;i++)
  156. {
  157. if(employees[i]==emp)
  158. {
  159. vkupno+=employees[i]->plata();
  160. }
  161. }
  162. }
  163. void pecatiRabotnici()
  164. {
  165. int sal_e=0;
  166. int hour_e=0;
  167. int free=0;
  168. for(int i=0;i<brVrab;i++)
  169. {
  170. if(employees[i]->getType()==1)
  171. {
  172. sal_e++;
  173. }
  174. if(employees[i]->getType()==2)
  175. {
  176. hour_e++;
  177. }
  178. if(employees[i]->getType()==3)
  179. {
  180. free++;
  181. }
  182. }
  183. cout<<"Vo kompanijata Smetkovodstveno_biro_Ekonomik rabotat:"<<endl;
  184. cout<<"Salary employees: "<<sal_e<<endl;
  185. cout<<"Hourly employees: "<<hour_e<<endl;
  186. cout<<"Freelancers: "<<free<<endl;
  187.  
  188. }
  189.  
  190. };
  191.  
  192. bool operator==(Employee &e,Employee &emp) {
  193. if((e.get_god()==emp.get_god())&&(e.bonus()==emp.bonus())) return true;
  194. else return false;
  195. }
  196.  
  197.  
  198. int main() {
  199.  
  200. char name[50];
  201. cin >> name;
  202. Company c(name);
  203.  
  204. int n;
  205. cin >> n;
  206.  
  207. char employeeName[50];
  208. int age;
  209. int experience;
  210. int type;
  211.  
  212. for (int i=0; i <n; ++i) {
  213. cin >> type;
  214. cin >> employeeName >> age >> experience;
  215.  
  216. if (type == 1) {
  217. int basicSalary;
  218. cin >> basicSalary;
  219. c += new SalaryEmployee(employeeName, age, experience, basicSalary);
  220. }
  221.  
  222. else if (type == 2) {
  223. int hoursWorked;
  224. int hourlyPay;
  225. cin >> hoursWorked >> hourlyPay;
  226. c += new HourlyEmployee(employeeName, age, experience, hoursWorked, hourlyPay);
  227. }
  228.  
  229. else {
  230. int numProjects;
  231. cin >> numProjects;
  232. double projects[10];
  233. for (int i=0; i < numProjects; ++i) {
  234. cin >> projects[i];
  235. }
  236. c += new Freelancer(employeeName, age, experience, numProjects, projects);
  237. }
  238. }
  239.  
  240. c.pecatiRabotnici();
  241. cout << "Vkupnata plata e: " << c.vkupnaPlata() << endl;
  242. Employee * emp = new HourlyEmployee("Petre_Petrov",31,6,340,80);
  243. cout << "Filtriranata plata e: " << c.filtriranaPlata(emp);
  244.  
  245. delete emp;
  246. }
Add Comment
Please, Sign In to add comment