fork download
  1. <?php
  2.  
  3.  
  4. class Department
  5. {
  6. public function createEmployee($amount, $profession, $rank, $chief = 0)
  7. {
  8. for($i=1; $i <= $amount; $i++) {
  9. $this->employees[] = new Employee($profession, $rank, $chief);
  10. }
  11. }
  12.  
  13. public function __construct($name)
  14. {
  15. $this->name = $name;
  16. }
  17.  
  18. public function DepartmentEmployeersNumber()
  19. {
  20. return count($this->employees);
  21. }
  22.  
  23. public function DepartmentPayment()
  24. {
  25. $departmentPayment = 0;
  26. foreach ($this->employees as $employee) {
  27. $departmentPayment += $employee->payment;
  28. }
  29. return $departmentPayment;
  30. }
  31.  
  32. public function DepartmentCoffeeSpending()
  33. {
  34. $departmentCoffee = 0;
  35. foreach ($this->employees as $employee) {
  36. $departmentCoffee += $employee->coffee;
  37. }
  38. return $departmentCoffee;
  39. }
  40.  
  41. public function DepartmentPages()
  42. {
  43. $departmentPages = 0;
  44. foreach ($this->employees as $employee) {
  45. $departmentPages += $employee->pages;
  46. }
  47. return $departmentPages;
  48. }
  49.  
  50. public function DepartmentEfficiency()
  51. {
  52. return round ($this->DepartmentPayment() / $this->DepartmentPages(), 1);
  53. }
  54. }
  55.  
  56. class Employee
  57. {
  58. public $payment;
  59. public $coffee;
  60. public $pages;
  61. public $rank;
  62.  
  63. public function __construct($profession, $rank, $chief = 0)
  64. {
  65. $this->rank = $rank;
  66.  
  67. if ($profession == 'manager') {
  68. $this->payment = 500;
  69. $this->coffee = 20;
  70. $this->pages = 200;
  71. } elseif ($profession == 'marketer') {
  72. $this->payment = 400;
  73. $this->coffee = 15;
  74. $this->pages = 150;
  75. } elseif ($profession == 'engineer') {
  76. $this->payment = 200;
  77. $this->coffee = 5;
  78. $this->pages = 50;
  79. } elseif ($profession == 'analyst') {
  80. $this->payment = 800;
  81. $this->coffee = 50;
  82. $this->pages = 5;
  83. }
  84.  
  85. if ($this->rank == 2) {
  86. $this->payment *= 1.25;
  87. } elseif ($this->rank == 3) {
  88. $this->payment *= 1.5;
  89. }
  90.  
  91. if ($chief == 1) {
  92. $this->payment *= 1.5;
  93. $this->coffee *= 2;
  94. $this->pages = 0;
  95. }
  96. }
  97. }
  98.  
  99. $employees = array();
  100.  
  101. $purchases = new Department('Закупок');
  102. $purchases->createEmployee(9, 'manager', 1);
  103. $purchases->createEmployee(3, 'manager', 2);
  104. $purchases->createEmployee(2, 'manager', 3);
  105. $purchases->createEmployee(2, 'marketer', 1);
  106. $purchases->createEmployee(1, 'manager', 2, 1);
  107. $employees[] = $purchases;
  108.  
  109. $sales = new Department('Продаж');
  110. $sales->createEmployee(12, 'manager', 1);
  111. $sales->createEmployee(6, 'marketer', 1);
  112. $sales->createEmployee(3, 'analyst', 1);
  113. $sales->createEmployee(2, 'analyst', 2);
  114. $sales->createEmployee(1, 'marketer', 2, 1);
  115. $employees[] = $sales;
  116.  
  117. $advertising = new Department('Рекламы');
  118. $advertising->createEmployee(15, 'marketer', 1);
  119. $advertising->createEmployee(10, 'marketer', 2);
  120. $advertising->createEmployee(8, 'manager', 1);
  121. $advertising->createEmployee(2, 'engineer', 1);
  122. $advertising->createEmployee(1, 'marketer', 3, 1);
  123. $employees[] = $advertising;
  124.  
  125. $logistics = new Department('Логистики');
  126. $logistics->createEmployee(13, 'manager', 1);
  127. $logistics->createEmployee(5, 'manager', 2);
  128. $logistics->createEmployee(5, 'engineer', 1);
  129. $logistics->createEmployee(1, 'manager', 1, 1);
  130. $employees[] = $logistics;
  131.  
  132. $col1 = 14;
  133. $col2 = 5;
  134. $col3 = 10;
  135. $col4 = 9;
  136. $col5 = 7;
  137. $col6 = 13;
  138.  
  139. function padLeft($string, $length)
  140. {
  141. $count = $length - mb_strlen($string);
  142. $space = str_repeat(' ', $count);
  143. echo $space . $string;
  144. }
  145.  
  146. function padRight($string, $length)
  147. {
  148. $count = $length - mb_strlen($string);
  149. $space = str_repeat(' ', $count);
  150. echo $string . $space;
  151. }
  152.  
  153. echo padRight("Департамент", $col1) .
  154. padLeft("сотр.", $col2) .
  155. padLeft("тугр.", $col3) .
  156. padLeft("кофе", $col4) .
  157. padLeft("стр.", $col5) .
  158. padLeft("тугр./стр.\n", $col6);
  159.  
  160. echo str_repeat("-", 58)."\n";
  161.  
  162. $totalEmployees = 0;
  163. $totalPayment = 0;
  164. $totalCoffeeSpending = 0;
  165. $totalPages = 0;
  166. $totalEfficiency = 0;
  167. foreach ($employees as $department) {
  168. echo padRight($department->name, $col1) .
  169. padLeft($department->DepartmentEmployeersNumber(), $col2) .
  170. padLeft($department->DepartmentPayment(), $col3) .
  171. padLeft($department->DepartmentCoffeeSpending(), $col4) .
  172. padLeft($department->DepartmentPages(), $col5) .
  173. padLeft($department->DepartmentEfficiency(), $col6) .
  174. "\n";
  175. $totalEmployees += $department->DepartmentEmployeersNumber();
  176. $totalPayment += $department->DepartmentPayment();
  177. $totalCoffeeSpending += $department->DepartmentCoffeeSpending();
  178. $totalPages += $department->DepartmentPages();
  179. $totalEfficiency += $department->DepartmentEfficiency();
  180. }
  181.  
  182. echo str_repeat("-", 58)."\n";
  183.  
  184. echo padRight("Среднее", $col1) .
  185. padLeft(floor($totalEmployees / count($employees)), $col2) .
  186. padLeft(floor($totalPayment / count($employees)), $col3) .
  187. padLeft(floor($totalCoffeeSpending / count($employees)), $col4) .
  188. padLeft(floor($totalPages / count($employees)), $col5) .
  189. padLeft(floor($totalEfficiency / count($employees)), $col6) .
  190. "\n";
  191.  
  192. echo padRight("Всего", $col1) .
  193. padLeft($totalEmployees, $col2) .
  194. padLeft($totalPayment, $col3) .
  195. padLeft($totalCoffeeSpending, $col4) .
  196. padLeft($totalPages, $col5) .
  197. padLeft($totalEfficiency, $col6) .
  198. "\n";
  199.  
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
Департамент   сотр.     тугр.     кофе   стр.  тугр./стр.
----------------------------------------------------------
Закупок          17    9612.5      350   3100          3.1
Продаж           24     13550      610   3325          4.1
Рекламы          36     16300      575   5450            3
Логистики        24     11375      425   3850            3
----------------------------------------------------------
Среднее          25     12709      490   3931            3
Всего           101   50837.5     1960  15725         13.2