fork download
  1. <?php
  2.  
  3. class Employee
  4. {
  5. public $salary;
  6. public $coffee;
  7. public $pages;
  8. public $rank;
  9.  
  10. public function __construct($profession, $rank = 1)
  11. {
  12. switch ($profession) {
  13. case 'manager':
  14. $this->salary = 500 * $rank;
  15. $this->pages = 200;
  16. $this->coffee = 20;
  17. $this->rank = $rank;
  18. break;
  19. case 'engineer':
  20. $this->salary = 200 * $rank;
  21. $this->pages = 50;
  22. $this->coffee = 5;
  23. $this->rank = $rank;
  24. break;
  25. case 'analyst':
  26. $this->salary = 800 * $rank;
  27. $this->pages = 5;
  28. $this->coffee = 50;
  29. $this->rank = $rank;
  30. break;
  31. case 'marketer':
  32. $this->salary = 400 * $rank;
  33. $this->pages = 150;
  34. $this->coffee = 15;
  35. $this->rank = $rank;
  36. break;
  37. default: exit("Profession \"$profession\" not found.");
  38. }
  39. }
  40. }
  41.  
  42. class Report
  43. {
  44. public $departmentName;
  45. public $salary;
  46. public $coffee;
  47. public $pages;
  48. public $employeeCount;
  49. }
  50.  
  51. class Department
  52. {
  53. public $employees;
  54. public $name;
  55.  
  56. public function __construct(array $employees, $name)
  57. {
  58. $this->employees = $employees;
  59. $this->name = $name;
  60. }
  61.  
  62. public function getReport()
  63. {
  64. $report = new Report;
  65. foreach ($this->employees as $employee) {
  66. $report->salary += $employee[0]->salary * $employee[1];
  67. $report->coffee += $employee[0]->coffee * $employee[1];
  68. $report->pages += $employee[0]->pages * $employee[1];
  69. $report->employeeCount += $employee[1];
  70. }
  71. $report->departmentName = $this->name;
  72. return $report;
  73. }
  74. }
  75.  
  76. $manager1 = new Employee('manager', 1);
  77. $manager2 = new Employee('manager', 1.25);
  78. $manager3 = new Employee('manager', 1.5);
  79. $marketer1 = new Employee('marketer', 1);
  80. $marketer2 = new Employee('marketer', 1.25);
  81. $analyst1 = new Employee('analyst', 1);
  82. $analyst2 = new Employee('analyst', 1.25);
  83. $engineer1 = new Employee('engineer', 1);
  84.  
  85. $procurement = new Department(array(
  86. array($manager1, 9),
  87. array($manager2, 3),
  88. array($manager3, 2),
  89. array($marketer1, 2),
  90. ), 'Закупок');
  91.  
  92. $selling = new Department(array(
  93. array($manager1, 12),
  94. array($marketer1, 6),
  95. array($analyst1, 3),
  96. array($analyst2, 2),
  97. ), 'Продаж');
  98.  
  99. $advertisement = new Department(array(
  100. array($marketer1, 15),
  101. array($marketer2, 10),
  102. array($manager1, 8),
  103. array($engineer1, 2),
  104. ), 'Рекламы');
  105.  
  106. $logistics = new Department(array(
  107. array($manager1, 13),
  108. array($manager2, 5),
  109. array($engineer1, 5),
  110. ), 'Логистики');
  111.  
  112. foreach (array($procurement, $selling, $advertisement, $logistics) as $department) {
  113. $summary[] = $department->getReport();
  114. }
  115.  
  116. echo "Департамент:\t\tсотр.\t\tтугр.\t\tкофе\t\tстр.\t\tтугр./стр.\n";
  117. echo "--------------------------------------------------------------------------------------\n";
  118. foreach ($summary as $report) {
  119. echo "$report->departmentName\t\t\t\t$report->employeeCount\t\t$report->salary\t\t$report->coffee\t\t$report->pages\t\t";
  120. echo round($report->salary / $report->pages, 1);
  121. echo "\n";
  122. }
  123.  
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
Департамент:		сотр.		тугр.		кофе		стр.		тугр./стр.
--------------------------------------------------------------------------------------
Закупок				16		8675		310		3100		2.8
Продаж				23		12800		580		3325		3.8
Рекламы				35		15400		545		5450		2.8
Логистики				23		10625		385		3850		2.8