fork(2) download
  1. <?php
  2.  
  3.  
  4. class Company
  5. {
  6. private $departments = array();
  7.  
  8. public function setDepartments($departments)
  9. {
  10. $this->departments = $departments;
  11. }
  12.  
  13. }
  14.  
  15. class Department
  16. {
  17. private $employees = array();
  18.  
  19. public function setEmployees($employees)
  20. {
  21. $this->employees = $employees;
  22. }
  23.  
  24. public function getEmployees()
  25. {
  26. return $this->employees;
  27. }
  28.  
  29. public function getTotalSalary()
  30. {
  31. $totalSalary = 0;
  32.  
  33. foreach($this->employees as $employee) {
  34. $totalSalary += $employee->getSalary();
  35. }
  36. return $totalSalary;
  37. }
  38.  
  39. public function getTotalCoffeeConsumption()
  40. {
  41. $totalCoffeeConsumption = 0;
  42.  
  43. foreach($this->employees as $employee) {
  44. $totalCoffeeConsumption += $employee->getCoffeeConsumption();
  45. }
  46. return $totalCoffeeConsumption;
  47. }
  48.  
  49. public function getTotalProduction()
  50. {
  51. $totalProduction = 0;
  52.  
  53. foreach($this->employees as $employee) {
  54. $totalProduction += $employee->getProduction();
  55. }
  56. return $totalProduction;
  57. }
  58. }
  59.  
  60. abstract class Employee
  61. {
  62. protected $baseRate;
  63. protected $rank;
  64. protected $isBoss;
  65.  
  66. abstract protected function getBaseCoffeeConsumption();
  67. abstract protected function getBaseRate();
  68. abstract protected function getBaseProduction();
  69.  
  70. public function __construct($rank, $isBoss = false)
  71. {
  72. $this->rank = $rank;
  73. $this->isBoss = $isBoss;
  74. }
  75.  
  76. public function getSalary()
  77. {
  78. $salary = 0;
  79.  
  80. if($this->rank == 1) {
  81. $salary = $this->getBaseRate();
  82. } elseif($this->rank == 2) {
  83. $salary = $this->getBaseRate() * 1.25;
  84. } elseif($this->rank == 3) {
  85. $salary = $this->getBaseRate() * 1.5;
  86. }
  87.  
  88. if($this->isBoss) {
  89. $salary *= 1.5;
  90. }
  91.  
  92. return $salary;
  93. }
  94.  
  95. public function getCoffeeConsumption()
  96. {
  97. $coffee = $this->getBaseCoffeeConsumption();
  98.  
  99. if($this->isBoss) {
  100. $coffee *= 2;
  101. }
  102.  
  103. return $coffee;
  104. }
  105.  
  106. public function getProduction()
  107. {
  108. $production = $this->getBaseProduction();
  109.  
  110. if($this->isBoss) {
  111. $production = 0;
  112. }
  113. return $production;
  114. }
  115. }
  116.  
  117. class Manager extends Employee
  118. {
  119. protected function getBaseCoffeeConsumption()
  120. {
  121. return 20;
  122. }
  123.  
  124. protected function getBaseRate()
  125. {
  126. return 500;
  127. }
  128.  
  129. protected function getBaseProduction()
  130. {
  131. return 200;
  132. }
  133. }
  134.  
  135. class Engineer extends Employee
  136. {
  137. protected function getBaseCoffeeConsumption()
  138. {
  139. return 5;
  140. }
  141.  
  142. protected function getBaseRate()
  143. {
  144. return 200;
  145. }
  146.  
  147. protected function getBaseProduction()
  148. {
  149. return 50;
  150. }
  151.  
  152. }
  153.  
  154. class Analyst extends Employee
  155. {
  156. protected function getBaseCoffeeConsumption()
  157. {
  158. return 50;
  159. }
  160.  
  161. protected function getBaseRate()
  162. {
  163. return 800;
  164. }
  165.  
  166. protected function getBaseProduction()
  167. {
  168. return 5;
  169. }
  170. }
  171.  
  172. class Marketer extends Employee
  173. {
  174. protected function getBaseCoffeeConsumption()
  175. {
  176. return 15;
  177. }
  178.  
  179. protected function getBaseRate()
  180. {
  181. return 400;
  182. }
  183.  
  184. protected function getBaseProduction()
  185. {
  186. return 150;
  187. }
  188. }
  189.  
  190. $col1 = 20;
  191. $col2 = 8;
  192. $col3 = 8;
  193. $col4 = 8;
  194. $col5 = 8;
  195. $col6 = 8;
  196.  
  197. function padRight($string, $length)
  198. {
  199. $padding = $length - mb_strlen($string);
  200. $string .= str_repeat(" ", $padding);
  201. return $string;
  202. }
  203.  
  204. function padLeft($string, $length)
  205. {
  206. $padding = $length - mb_strlen($string)+2;
  207. $string = str_repeat(" ", $padding) . $string;
  208. return $string;
  209. }
  210.  
  211. $procurement = new Department;
  212. $emps = array();
  213. for($i = 0; $i < 9; $i++) {
  214. $emps[] = new Manager(1);
  215. }
  216. for($i = 0; $i < 3; $i++) {
  217. $emps[] = new Manager(2);
  218. }
  219. for($i = 0; $i < 2; $i++) {
  220. $emps[] = new Manager(3);
  221. }
  222. for($i = 0; $i < 2; $i++) {
  223. $emps[] = new Marketer(1);
  224. }
  225. $emps[] = new Manager(2, true);
  226. $procurement->setEmployees($emps);
  227. echo "Всего сотрудников: " . count($procurement->getEmployees()) . "\n";
  228. echo "Всего выдано зп: " . $procurement->getTotalSalary() . "\n";
  229. echo "Всего выпито кофе: " . $procurement->getTotalCoffeeConsumption() . "\n";
  230. echo "Всего произведено страниц отчетов: " . $procurement->getTotalProduction() . "\n";
  231.  
  232.  
  233.  
  234. echo padRight('Департамент', $col1) .
  235. padLeft('сотр.', $col2) .
  236. padLeft('тугр.', $col3) .
  237. padLeft('кофе', $col4) .
  238. padLeft('стр.', $col5) .
  239. padLeft('тугр/стр', $col6) . '\n\n';
Runtime error #stdin #stdout #stderr 0.01s 82880KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Fatal error:  Uncaught Error: Call to undefined function mb_internal_encoding() in /home/HQNIro/prog.php:4
Stack trace:
#0 {main}
  thrown in /home/HQNIro/prog.php on line 4