fork download
  1. <?php
  2. // your code goes here
  3.  
  4. /*
  5. Департамент закупок: 9×ме1, 3×ме2, 2×ме3, 2×ма1 + руководитель департамента ме2
  6. Департамент продаж: 12×ме1, 6×ма1, 3×ан1, 2×ан2 + руководитель ма2
  7. Департамент рекламы: 15×ма1, 10×ма2, 8×ме1, 2×ин1 + руководитель ма3
  8. Департамент логистики: 13×ме1, 5×ме2, 5×ин1 + руководитель ме1
  9. */
  10.  
  11.  
  12. class Employee {
  13. protected $salary;
  14. protected $coffee;
  15. protected $reports;
  16. protected $rank;
  17. protected $isHead;
  18.  
  19. public function __construct($rank, $isHead) {
  20. $this->rank = $rank;
  21. $this->isHead = $isHead;
  22. $this->setSalary($this->salary);
  23. $this->setCoffee($this->coffee);
  24. $this->setReports($this->reports);
  25. }
  26.  
  27. public function getSalary() {
  28. return $this->salary;
  29. }
  30. public function setSalary($salary) {
  31. switch ($this->rank) {
  32. case 1:
  33. $this->salary = $salary;
  34. break;
  35. case 2:
  36. $this->salary = $salary * 1.25;
  37. break;
  38. case 3:
  39. $this->salary = $salary * 1.5;
  40. break;
  41. default:
  42. $this->salary = "Ошибка";
  43. break;
  44. }
  45. if ($this->isHead) {
  46. $this->salary *= 2;
  47. }
  48. }
  49. public function getCoffee() {
  50. return $this->coffee;
  51. }
  52. public function setCoffee($coffee) {
  53. $this->coffee = $coffee;
  54. if ($this->isHead) {
  55. $this->coffee *= 2;
  56. }
  57. }
  58. public function getReports() {
  59. return $this->reports;
  60. }
  61. public function setReports($reports) {
  62. if ($this->isHead) {
  63. $this->reports = 0;
  64. } else {
  65. $this->reports = $reports;
  66. }
  67. }
  68. public function getRank()
  69. {
  70. return $this->rank;
  71. }
  72. public function setRank($rank)
  73. {
  74. $this->rank = $rank;
  75. }
  76. public function getIsHead()
  77. {
  78. return $this->isHead;
  79. }
  80. public function setIsHead($isHead)
  81. {
  82. $this->isHead = $isHead;
  83. }
  84.  
  85. }
  86.  
  87. class Manager extends Employee {
  88. public $name = "manager";
  89. protected $salary = 500;
  90. protected $coffee = 20;
  91. protected $reports = 200;
  92. }
  93.  
  94. class Marketer extends Employee {
  95. public $name = "marketer";
  96. protected $salary = 400;
  97. protected $coffee = 15;
  98. protected $reports = 150;
  99. }
  100.  
  101. class Engineer extends Employee {
  102. protected $salary = 200;
  103. protected $coffee = 5;
  104. protected $reports = 50;
  105. }
  106.  
  107. class Analyst extends Employee {
  108. protected $salary = 800;
  109. protected $coffee = 50;
  110. protected $reports = 5;
  111. }
  112.  
  113. class Department {
  114. private $name;
  115. private $employees;
  116.  
  117. public function __construct($name, $employees) {
  118. $this->name = $name;
  119. $this->employees = $employees;
  120. }
  121.  
  122. public function getName() {
  123. return $this->name;
  124. }
  125. public function setName($name) {
  126. $this->name = $name;
  127. }
  128.  
  129. public function getAllEmployees() {
  130. return count($this->employees);
  131. }
  132.  
  133. public function getAllSalary() {
  134. $allSalary = 0;
  135. foreach ($this->employees as $employee) {
  136. $allSalary += $employee->getSalary();
  137. }
  138. return $allSalary;
  139. }
  140.  
  141. public function getAllCoffee() {
  142. $allCoffee = 0;
  143. foreach ($this->employees as $employee) {
  144. $allCoffee += $employee->getCoffee();
  145. }
  146. return $allCoffee;
  147. }
  148.  
  149. public function getAllReports() {
  150. $allReports = 0;
  151. foreach ($this->employees as $employee) {
  152. $allReports += $employee->getReports();
  153. }
  154. return $allReports;
  155. }
  156. }
  157.  
  158. function createManagers($quantity, $rank, $isHead) {
  159. $employees = array();
  160. for ($i = 0; $i < $quantity; $i++) {
  161. array_push($employees, new Manager($rank, $isHead));
  162. }
  163. return $employees;
  164. }
  165.  
  166. function createMarketers($quantity, $rank, $isHead) {
  167. $employees = array();
  168. for ($i = 0; $i < $quantity; $i++) {
  169. array_push($employees, new Marketer($rank, $isHead));
  170. }
  171. return $employees;
  172. }
  173.  
  174. function createEngineers($quantity, $rank, $isHead) {
  175. $employees = array();
  176. for ($i = 0; $i < $quantity; $i++) {
  177. array_push($employees, new Engineer($rank, $isHead));
  178. }
  179. return $employees;
  180. }
  181.  
  182. function createAnalysts($quantity, $rank, $isHead) {
  183. $employees = array();
  184. for ($i = 0; $i < $quantity; $i++) {
  185. array_push($employees, new Analyst($rank, $isHead));
  186. }
  187. return $employees;
  188. }
  189.  
  190. function padRight($string, $length) {
  191. $spacesCount = $length - mb_strlen($string);
  192. //echo strlen($string) . $length;
  193. for ($i = 0; $i < $spacesCount; $i++) {
  194. $string .= " ";
  195. }
  196. return $string;
  197. }
  198.  
  199. function padLeft($string, $length) {
  200. $modString = "";
  201. $spacesCount = $length - mb_strlen($string);
  202. for ($i = 0; $i < $spacesCount; $i++) {
  203. $modString .= " ";
  204. }
  205. $modString .= $string;
  206. return $modString;
  207. }
  208.  
  209. function outputString($str1, $str2, $str3, $str4, $str5, $str6) {
  210. $col = 11;
  211. echo padRight($str1, $col);
  212. echo padLeft($str2, $col);
  213. echo padLeft($str3, $col);
  214. echo padLeft($str4, $col);
  215. echo padLeft($str5, $col);
  216. echo padLeft($str6, $col) . "\n";
  217. }
  218.  
  219. $totalEmployees = 0;
  220. $totalSalary = 0;
  221. $totalCoffee = 0;
  222. $totalReports = 0;
  223. $totalConsumption = 0;
  224. $countDepartments = 0;
  225.  
  226. outputString("Департамент", "сотр.", "тугр.", "кофе", "стр.", "тугр./стр.");
  227.  
  228. for ($i = 0; $i < 70; $i++) {
  229. echo "-";
  230. }
  231. echo "\n";
  232.  
  233. $employees = array();
  234. $departments = array();
  235.  
  236. $employees = array_merge($employees, createManagers(9, 1, false), createManagers(3, 2, false),
  237. createManagers(2, 3, false), createMarketers(2, 1, false), createManagers(1, 2, true));
  238.  
  239. $purchases = new Department("Закупок", $employees);
  240. array_push($departments, $purchases);
  241. $countDepartments++;
  242.  
  243. $employees = array();
  244. $employees = array_merge($employees, createManagers(12, 1, false), createMarketers(6, 1, false),
  245. createAnalysts(3, 1, false), createAnalysts(2, 2, false), createMarketers(1, 2, true));
  246.  
  247. $sales = new Department("Продаж", $employees);
  248. array_push($departments, $sales);
  249. $countDepartments++;
  250.  
  251. $employees = array();
  252. $employees = array_merge($employees, createMarketers(15, 1, false), createMarketers(10, 2, false),
  253. createManagers(8, 1, false), createEngineers(2, 1, false), createMarketers(1, 3, true));
  254.  
  255. $ad = new Department("Рекламы", $employees);
  256. array_push($departments, $ad);
  257. $countDepartments++;
  258.  
  259. $employees = array();
  260. $employees = array_merge($employees, createManagers(13, 1, false), createManagers(5, 2, false),
  261. createEngineers(5, 1, false), createManagers(1, 1, true));
  262.  
  263. $logistics = new Department("Логистики", $employees);
  264. array_push($departments, $logistics);
  265. $countDepartments++;
  266.  
  267. foreach ($departments as $department) {
  268.  
  269. $employeesCount = $department->getAllEmployees();
  270. $totalEmployees += $employeesCount;
  271.  
  272. $salary = $department->getAllSalary();
  273. $totalSalary += $salary;
  274.  
  275. $coffee = $department->getAllCoffee();
  276. $totalCoffee += $coffee;
  277.  
  278. $reports = $department->getAllReports();
  279. $totalReports += $reports;
  280.  
  281. $consumption = round($salary / $reports, 2);
  282. $totalConsumption += $consumption;
  283.  
  284. outputString($department->getName(), $employeesCount, $salary, $coffee, $reports, $consumption);
  285. }
  286.  
  287. echo "\n";
  288.  
  289. outputString("Среднее", $totalEmployees / $countDepartments, $totalSalary / $countDepartments, $totalCoffee / $countDepartments,
  290. $totalReports / $countDepartments, $totalConsumption / $countDepartments);
  291.  
  292. outputString("Всего", $totalEmployees, $totalSalary, $totalCoffee, $totalReports, $totalConsumption);
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
Департамент      сотр.      тугр.       кофе       стр. тугр./стр.
----------------------------------------------------------------------
Закупок             17       9925        350       3100        3.2
Продаж              24      13800        610       3325       4.15
Рекламы             36      16600        575       5450       3.05
Логистики           24      11625        425       3850       3.02

Среднее          25.25    12987.5        490    3931.25      3.355
Всего              101      51950       1960      15725      13.42