fork(1) download
  1. <?php
  2.  
  3. abstract class Employee
  4. {
  5.  
  6. public $salary;
  7. public $pages;
  8. public $cofee;
  9. public $name;
  10.  
  11.  
  12. function __construct($rank)
  13. {
  14.  
  15.  
  16. $this->rank = $rank;
  17. }
  18.  
  19. function getSalary()
  20. {
  21. $multiply = 1;
  22. switch ($this->rank) {
  23. case 2:
  24. $multiply = 1.25;
  25. break;
  26. case 3:
  27. $multiply = 1.50;
  28. break;
  29. }
  30. return $this->salary * $multiply;
  31.  
  32. }
  33.  
  34. function setHead()
  35. {
  36. $this->salary = $this->salary * 1.50;
  37. $this->cofee = $this->cofee * 2;
  38. $this->pages = 0;
  39. }
  40.  
  41. }
  42.  
  43. class Manager extends Employee
  44. {
  45. public $name = "Менеджер";
  46. public $salary = 500;
  47. public $cofee = 20;
  48. public $pages = 200;
  49. }
  50.  
  51. class Market extends Employee
  52. {
  53. public $name = "Маркетолог";
  54. public $salary = 400;
  55. public $cofee = 15;
  56. public $pages = 150;
  57. }
  58.  
  59. class Engineer extends Employee
  60. {
  61. public $name = "Инженер";
  62. public $salary = 200;
  63. public $cofee = 5;
  64. public $pages = 50;
  65. }
  66.  
  67. class Analyst extends Employee
  68. {
  69. public $name = "Аналитик";
  70. public $salary = 800;
  71. public $cofee = 50;
  72. public $pages = 5;
  73. }
  74.  
  75.  
  76. class Department
  77. {
  78. function workers()
  79. {
  80. return count($this->data) - 1;
  81. }
  82. function cofee()
  83. {
  84. $cofee = 0;
  85. foreach ($this->data as $key => $worker) {
  86. if ($key === 'name') {
  87. continue;
  88. }
  89. $cofee += $worker->cofee;
  90. }
  91. return $cofee;
  92. }
  93. function costs()
  94. {
  95. $costs = 0;
  96. foreach ($this->data as $key => $worker) {
  97. if ($key === 'name') {
  98. continue;
  99. }
  100. $costs += $worker->getSalary();
  101. }
  102. return $costs;
  103. }
  104. function pages()
  105. {
  106. $pages = 0;
  107. foreach ($this->data as $key => $worker) {
  108. if ($key === 'name') {
  109. continue;
  110. }
  111. $pages += $worker->pages;
  112. }
  113. return $pages;
  114. }
  115.  
  116. function __construct($data)
  117. {
  118. $this->data = $data;
  119. $this->name = $data['name'];
  120.  
  121. }
  122. }
  123.  
  124.  
  125. function createEmployee($type, $rank, $quantity, $array)
  126. {
  127.  
  128. for ($i = 0; $i < $quantity; $i++) {
  129. $array[] = new $type($rank);
  130. }
  131. return $array;
  132.  
  133. }
  134.  
  135. function padRight($name, $col)
  136. {
  137. while (mb_strlen($name) < $col) {
  138. $name .= " ";
  139. }
  140. return $name;
  141. }
  142.  
  143. function padLeft($name, $col)
  144. {
  145. while (mb_strlen($name) < $col) {
  146. $name = " " . $name;
  147. }
  148. return $name;
  149. }
  150.  
  151.  
  152. function createDepartment($data)
  153. {
  154. $department = new Department($data);
  155. $costPerPage = round(($department->costs()) / ($department->pages()), 1);
  156.  
  157. echo padRight($department->name, 20);
  158. echo padLeft($department->workers(), 10);
  159. echo padLeft($department->costs(), 12);
  160. echo padLeft($department->cofee(), 10);
  161. echo padLeft($department->pages(), 12);
  162. echo padLeft($costPerPage, 15);
  163. echo "\n";
  164. }
  165.  
  166. $department1['name'] = "Закупок";
  167. $department1 = createEmployee('Manager', 1, 9, $department1);
  168. $department1 = createEmployee('Manager', 2, 3, $department1);
  169. $department1 = createEmployee('Manager', 3, 2, $department1);
  170. $department1 = createEmployee('Market', 1, 2, $department1);
  171. $department1['head'] = new Manager(2);
  172. $department1['head']->setHead();
  173.  
  174. $department2['name'] = "Продаж";
  175. $department2 = createEmployee('Manager', 1, 12, $department2);
  176. $department2 = createEmployee('Market', 1, 6, $department2);
  177. $department2 = createEmployee('Analyst', 1, 3, $department2);
  178. $department2 = createEmployee('Analyst', 2, 2, $department2);
  179. $department2['head'] = new Market(2);
  180. $department2['head']->setHead();
  181.  
  182. $department3['name'] = "Рекламы";
  183. $department3 = createEmployee('Market', 1, 15, $department3);
  184. $department3 = createEmployee('Market', 2, 10, $department3);
  185. $department3 = createEmployee('Manager', 1, 8, $department3);
  186. $department3 = createEmployee('Engineer', 1, 2, $department3);
  187. $department['head'] = new Market(3);
  188. $department['head']->setHead();
  189.  
  190. echo padRight("Департамент", 30) . padLeft("Сотр.", 10) . padLeft("тугр.", 15) . padLeft("кофе", 15) . padLeft("стр.", 15) . padLeft("тугр./стр.", 25) . "\n";
  191.  
  192. createDepartment($department1);
  193. createDepartment($department2);
  194. createDepartment($department3);
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Департамент         Сотр.      тугр.       кофе        стр.        тугр./стр.
Закупок              17      9612.5       350        3100            3.1
Продаж                24       13550       610        3325            4.1
Рекламы              35       15400       545        5450            2.8