fork(1) download
  1. <?php
  2. class Department
  3. {
  4. public $name;
  5. public $employees = array();
  6.  
  7. public function addEmployees($quantity, $employee)
  8. {
  9. for($i = 0; $i < $quantity; $i++){
  10. array_push($this->employees, clone $employee);
  11. }
  12. return $this->employees;
  13. }
  14.  
  15. public function addLeader($employee){
  16. $employee->setRank();
  17. $employee->makeLeader();
  18. array_push($this->employees,$employee);
  19. return $this;
  20. }
  21.  
  22. public function getTotalEmployees()
  23. { $total = 0;
  24. foreach ($this->employees as $employee){
  25. $total++;
  26. }
  27. return $total;
  28. }
  29.  
  30. public function getTotalCoffee(){
  31. $total = 0;
  32. foreach ($this->employees as $employee) {
  33. $total+=$employee->coffee;
  34. }
  35. return $total;
  36. }
  37.  
  38. public function getTotalPapers(){
  39. $total = 0;
  40. foreach ($this->employees as $employee) {
  41. $total+=$employee->papers;
  42. }
  43. return $total;
  44. }
  45.  
  46. public function getTotalIncome(){
  47. $total = 0;
  48. foreach ($this->employees as $employee) {
  49. $total += $employee->income;
  50. }
  51. return floor($total);
  52. }
  53.  
  54.  
  55. }
  56.  
  57. abstract class Employee
  58. {
  59. public $rank;
  60. public $income;
  61. public $coffee;
  62. public $papers;
  63. public function __construct($rank)
  64. {
  65. $this->rank = $rank;
  66. }
  67.  
  68. public function setRank()
  69. {
  70. $rank = $this->rank;
  71. if($rank == 2){
  72. $this->income *= 1.25;
  73. }
  74. elseif($rank == 3){
  75. $this->income *= 1.5;
  76. }
  77. return $this;
  78. }
  79. public function makeLeader(){
  80. $this->income *= 1.5;
  81. $this->coffee *= 2;
  82. $this->papers = 0;
  83. return $this;
  84. }
  85. }
  86.  
  87. class Manager extends Employee
  88. {
  89. public $income = 500;
  90. public $coffee = 20;
  91. public $papers = 200;
  92. }
  93. class Marketer extends Employee
  94. {
  95. public $income = 400;
  96. public $coffee = 15;
  97. public $papers = 150;
  98. }
  99. class Engineer extends Employee
  100. {
  101. public $income = 200;
  102. public $coffee = 5;
  103. public $papers = 50;
  104. }
  105. class Analytics extends Employee
  106. {
  107. public $income = 800;
  108. public $coffee = 50;
  109. public $papers = 5;
  110. }
  111.  
  112. function padLeft($text, $length){
  113. $cl = mb_strlen($text);
  114. if($cl<$length){
  115. $text =str_repeat(" ", $length - $cl).$text;
  116. }
  117. return $text;
  118. }
  119. function padRight($text, $length){
  120. $cl = mb_strlen($text);
  121. if($cl<$length){
  122. $text = $text.str_repeat(" ", $length - $cl);
  123. }
  124. return $text;
  125. }
  126.  
  127.  
  128.  
  129. $col1 = 11;
  130. $col2 = 11;
  131. $col3 = 11;
  132. $col4 = 11;
  133. $col5 = 11;
  134. $col6 = 13;
  135. $col7 = 11;
  136.  
  137. $buyers = new Department;
  138. $buyers->name = "Закупок";
  139. $buyers->addEmployees(9, new Manager(1));
  140. $buyers->addEmployees(3, new Manager(2));
  141. $buyers->addEmployees(2, new Marketer(1));
  142. $buyers->addLeader(new Manager(2));
  143.  
  144. $sellers = new Department;
  145. $sellers->name = "Продаж";
  146. $sellers->addEmployees(12, new Manager(1));
  147. $sellers->addEmployees(6, new Marketer(1));
  148. $sellers->addEmployees(3, new Analytics(1));
  149. $sellers->addEmployees(2, new Analytics(2));
  150. $sellers->addLeader(new Marketer(2));
  151.  
  152. $advertisers = new Department;
  153. $advertisers->name = "Рекламы";
  154. $advertisers->addEmployees(15, new Marketer(1));
  155. $advertisers->addEmployees(10, new Marketer(2));
  156. $advertisers->addEmployees(8, new Manager(1));
  157. $advertisers->addEmployees(2, new Engineer(1));
  158. $advertisers->addLeader(new Manager(1));
  159.  
  160. $logistics = new Department;
  161. $logistics->name = "Логистики";
  162. $logistics->addEmployees(13, new Manager(1));
  163. $logistics->addEmployees(5, new Manager(2));
  164. $logistics->addEmployees(5, new Engineer(1));
  165. $logistics->addLeader(new Manager(1));
  166.  
  167. $departments = array($buyers, $sellers, $advertisers, $logistics);
  168.  
  169. foreach ($departments as $department) {
  170. $totalEmp+=$department->getTotalEmployees();
  171. $totalInc+=$department->getTotalIncome();
  172. $totalCof+=$department->getTotalCoffee();
  173. $totalPap+=$department->getTotalPapers();
  174. $totalPrice+=floor($department->getTotalIncome()/$department->getTotalPapers());
  175. }
  176.  
  177. $avIncome = floor($totalInc/count($departments));
  178. $avEmp = floor($totalEmp / count($departments));
  179. $avCof = floor($totalCof / count($departments));
  180. $avPap = floor($totalPap / count($departments));
  181. $avPrice = floor($totalPrice / count($departments));
  182.  
  183. echo (padRight("Департамент",$col1).
  184. padLeft("сотр.",$col2).
  185. padLeft("тугр.",$col3).
  186. padLeft("кофе",$col4).
  187. padLeft("стр.",$col5).
  188. padLeft("тугр./стр.",$col6)."\n---------------------------------------------------------------------------\n");
  189.  
  190.  
  191.  
  192. foreach ($departments as $department){
  193. echo padRight($department->name,$col1).
  194. padLeft($department->getTotalEmployees(),$col2).
  195. padLeft($department->getTotalIncome(),$col3).
  196. padLeft($department->getTotalCoffee(),$col4).
  197. padLeft($department->getTotalPapers(),$col5).
  198. padLeft(floor($department->getTotalIncome()/$department->getTotalPapers()),$col6)."\n";
  199. }
  200.  
  201.  
  202. echo (
  203. padRight("Среднее", $col1).
  204. padLeft($avEmp, $col2).
  205. padLeft($avIncome, $col3).
  206. padLeft($avCof, $col4).
  207. padLeft($avPap, $col5).
  208. padLeft($avPrice, $col6)."\n"
  209. );
  210.  
  211. echo(
  212. padRight("Всего",$col1).
  213. padLeft($totalEmp, $col2).
  214. padLeft($totalInc, $col3).
  215. padLeft($totalCof, $col4).
  216. padLeft($totalPap, $col5).
  217. padLeft($totalPrice, $col6)
  218.  
  219.  
  220. );
Success #stdin #stdout #stderr 0.02s 24400KB
stdin
Standard input is empty
stdout
Департамент      сотр.      тугр.       кофе       стр.   тугр./стр.
---------------------------------------------------------------------------
Закупок             15       7737        310       2700            2
Продаж              24      13150        610       3325            3
Рекламы             36      15150        585       5450            2
Логистики           24      10750        425       3850            2
Среднее             24      11696        482       3831            2
Всего               99      46787       1930      15325            9
stderr
PHP Notice:  Undefined variable: totalEmp in /home/eUKC16/prog.php on line 171
PHP Notice:  Undefined variable: totalInc in /home/eUKC16/prog.php on line 172
PHP Notice:  Undefined variable: totalCof in /home/eUKC16/prog.php on line 173
PHP Notice:  Undefined variable: totalPap in /home/eUKC16/prog.php on line 174
PHP Notice:  Undefined variable: totalPrice in /home/eUKC16/prog.php on line 175