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