fork(1) download
  1. <?php
  2.  
  3. abstract class Employee {
  4. public $amount;
  5. public $rang;
  6. public $leader;
  7. public $salary;
  8. public $coffee;
  9. public $reports;
  10.  
  11.  
  12. public function __construct ($amount, $rang, $leader) {
  13. $this->amount = $amount;
  14. $this->rang = $rang;
  15. $this->leader = $leader;
  16.  
  17. if ($this->leader == true) {
  18. $this->salary *= 1.5;
  19. $this->coffee *= 2;
  20. $this->reports = 0;
  21. }
  22. }
  23.  
  24. // Возвращает кол-во людей (ме) или (ма) или (ин) или (ан).
  25. public function getAmount () {
  26. return $this->amount;
  27. }
  28.  
  29. public function getSalary () {
  30. $realSalary = $this->amount * $this->salary;
  31. if ($this->rang == 1) {
  32. $realSalary = $realSalary;
  33. } elseif ($this->rang = 2) {
  34. $realSalary *= 1.25;
  35. } else {
  36. $realSalary *= 1.5;
  37. }
  38. return $realSalary;
  39. }
  40.  
  41. public function getCoffee () {
  42. return $this->coffee;
  43. }
  44.  
  45. public function getReports () {
  46. return $this->reports;
  47. }
  48. }
  49.  
  50. class EmployeeList {
  51. public $depName;
  52. public $employeeList;
  53.  
  54. public function __construct ($depName, $employeeList) {
  55. $this->depName = $depName;
  56. $this->employeeList = $employeeList;
  57. }
  58.  
  59. public function getDepName () {
  60. return $this->depName;
  61. }
  62.  
  63. public function getEmployeeList() {
  64. return $this->employeeList;
  65. }
  66.  
  67. public function returnAmount() {
  68. $number = 0;
  69. foreach ($this->employeeList as $employee){
  70. $number += $employee->getAmount();
  71. }
  72. return $number;
  73. }
  74.  
  75. public function returnTotalSalary () {
  76. $number = 0;
  77. foreach ($this->employeeList as $employee){
  78. $number += $employee->getSalary();
  79. }
  80. return $number;
  81. }
  82.  
  83. public function returnCoffee () {
  84. $number = 0;
  85. foreach ($this->employeeList as $employee){
  86. $number += $employee->getCoffee();
  87. }
  88. return $number;
  89. }
  90.  
  91. public function returnReports () {
  92. $number = 0;
  93. foreach ($this->employeeList as $employee){
  94. $number += $employee->getReports();
  95. }
  96. return $number;
  97. }
  98.  
  99. public function returnAvgSandR() {
  100. $avg = $this->returnTotalSalary() / $this->returnAmount();
  101. return round($avg);
  102. }
  103. }
  104.  
  105. class Manager extends Employee {
  106. public $salary = 500;
  107. public $coffee = 20;
  108. public $reports = 200;
  109. }
  110.  
  111. class Marketer extends Employee {
  112. public $salary = 400;
  113. public $coffee = 15;
  114. public $reports = 150;
  115. }
  116.  
  117. class Engineer extends Employee {
  118. public $salary = 200;
  119. public $coffee = 5;
  120. public $reports = 50;
  121. }
  122.  
  123. class Analyst extends Employee {
  124. public $salary = 800;
  125. public $coffee = 50;
  126. public $reports = 5;
  127. }
  128.  
  129. //Департамент закупок: 9×ме1, 3×ме2, 2×ме3, 2×ма1 + руководитель департамента ме2
  130. $obj1 = new Manager(9,1,false);
  131. $obj2 = new Manager(3,2,false);
  132. $obj3 = new Manager(2,3,false);
  133. $obj4 = new Marketer(2,1,false);
  134. $obj5 = new Manager(1,2,true);
  135. $DepOfPurchases = new EmployeeList("Закупок", array($obj1, $obj2, $obj3, $obj4, $obj5));
  136.  
  137. //Департамент продаж: 12×ме1, 6×ма1, 3×ан1, 2×ан2 + руководитель ма2
  138. $obj6 = new Manager(12,1,false);
  139. $obj7 = new Marketer(6,1,false);
  140. $obj8 = new Analyst(3,1,false);
  141. $obj9 = new Analyst(2,2,false);
  142. $obj10 = new Marketer(1,2,true);
  143. $DepOfSales = new EmployeeList("Продаж", array($obj6, $obj7, $obj8, $obj9, $obj10));
  144.  
  145. //Департамент рекламы: 15×ма1, 10×ма2, 8×ме1, 2×ин1 + руководитель ма3
  146. $obj11 = new Marketer(15,1,false);
  147. $obj12 = new Marketer(10,2,false);
  148. $obj13 = new Manager(8,1,false);
  149. $obj14 = new Engineer(2,1,false);
  150. $obj15 = new Marketer(1,3,true);
  151. $DepOfAdvertising = new EmployeeList("Рекламы", array($obj11, $obj12, $obj13, $obj14, $obj15));
  152.  
  153. //Департамент логистики: 13×ме1, 5×ме2, 5×ин1 + руководитель ме1
  154. $obj16 = new Manager(13,1, false);
  155. $obj17 = new Manager(5,2,false);
  156. $obj18 = new Engineer(5,1,false);
  157. $obj19 = new Manager(1,1,true);
  158. $DepOfLogistics = new EmployeeList("Логистики", array($obj16, $obj17, $obj18, $obj19));
  159.  
  160. $departaments = array($DepOfPurchases, $DepOfSales, $DepOfAdvertising, $DepOfLogistics);
  161.  
  162. function padRight($string, $length) {
  163. $string = strval($string);
  164. $lengthStr = (mb_strlen($string));
  165. $spaces = $length - $lengthStr;
  166. if ($spaces >= 0) {
  167. return $string . str_repeat(' ', $spaces);
  168. } else {
  169. return ' ' . mb_substr($string, 0, $length - 2) . '.';
  170. }
  171. }
  172. function padLeft ($string, $length) {
  173. $string = strval($string);
  174. $lengthStr = (mb_strlen($string));
  175. $spaces = $length - $lengthStr;
  176. if ($spaces >= 0) {
  177. return $string . str_repeat(' ', $spaces);
  178. } else {
  179. return '.' . mb_substr($string, 0, $length - 2) . ' ';
  180. }
  181. }
  182.  
  183. $sumAmount = 0;
  184. $sumTotalSalary = 0;
  185. $sumCoffee = 0;
  186. $sumReports = 0;
  187. $sumSandR = 0;
  188.  
  189. // Ширина колонок
  190. $col1 = 30;
  191. $col2 = 12;
  192.  
  193. // Заголовок таблицы
  194. echo padRight("Департамент", $col1) .
  195. padLeft("сотр.", $col2) .
  196. padLeft("тугр.", $col2) .
  197. padLeft("кофе", $col2) .
  198. padLeft("стр.", $col2) .
  199. padLeft("тугр./стр.", $col2) ."\n";
  200.  
  201. // Сама таблица
  202. foreach ($departaments as $departament) {
  203. echo padRight($departament->getDepName(), $col1) .
  204. padLeft($departament->returnAmount(), $col2) .
  205. padLeft($departament->returnTotalSalary(), $col2) .
  206. padLeft($departament->returnCoffee(), $col2) .
  207. padLeft($departament->returnReports(), $col2) .
  208. padLeft($departament->returnAvgSandR(), $col2) .
  209. "\n";
  210. $sumAmount += $departament->returnAmount();
  211. $sumTotalSalary += $departament->returnTotalSalary();
  212. $sumCoffee += $departament->returnCoffee();
  213. $sumReports += $departament->returnReports();
  214. $sumSandR += $departament->returnAvgSandR();
  215. }
  216.  
  217. echo padRight("Среднее", $col1) .
  218. padLeft($sumAmount / count($departaments), $col2) .
  219. padLeft($sumTotalSalary / count($departaments), $col2) .
  220. padLeft($sumCoffee / count($departaments), $col2) .
  221. padLeft($sumReports / count($departaments), $col2) .
  222. padLeft($sumSandR / count($departaments), $col2) . "\n";
  223.  
  224. echo padRight("Всего", $col1) .
  225. padLeft($sumAmount, $col2) .
  226. padLeft($sumTotalSalary, $col2) .
  227. padLeft($sumCoffee, $col2) .
  228. padLeft($sumReports, $col2) .
  229. padLeft($sumSandR, $col2) . "\n";
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
Департамент                   сотр.       тугр.       кофе        стр.        тугр./стр.  
Закупок                       17          9362.5      115         750         551         
Продаж                        24          13550       165         360         565         
Рекламы                       36          16150       85          550         449         
Логистики                     24          11375       85          450         474         
Среднее                       25.25       12609.375   112.5       527.5       509.75      
Всего                         101         50437.5     450         2110        2039