fork download
  1. <?php
  2. header("Content-Type: text/plain; charset=utf-8");
  3. ?>
  4. <?php
  5.  
  6. //объявление классов >>
  7. abstract class Employee
  8. {
  9. public $salary;
  10. public $coffee;
  11. public $reports;
  12. public $rank;
  13. public function __construct($rank, $isDirector)
  14. {
  15. $this->rank = $rank;
  16. if ($isDirector == 1) {
  17. $this->salary *= 1.5;
  18. $this->coffee *= 2;
  19. $this->reports *= 0;
  20. }
  21. if ($rank == 2) {
  22. $this->salary *= 1.25;
  23. } elseif ($rank == 3) {
  24. $this->salary *= 1.5;
  25. }
  26. }
  27. }
  28. class Engineer extends Employee
  29. {
  30. public $salary = 200;
  31. public $coffee = 5;
  32. public $reports = 50;
  33. }
  34.  
  35. class Marketolog extends Employee
  36. {
  37. public $salary = 400;
  38. public $coffee = 15;
  39. public $reports = 150;
  40. }
  41. class Manager extends Employee
  42. {
  43. public $salary = 500;
  44. public $coffee = 20;
  45. public $reports = 200;
  46. }
  47.  
  48. class Analyst extends Employee
  49. {
  50. public $salary = 800;
  51. public $coffee = 50;
  52. public $reports = 5;
  53. }
  54. class Department
  55. {
  56. public $name;
  57. public $count;
  58. public $salary;
  59. public $coffee;
  60. public $reports;
  61. public $repSal;
  62. public $workers = array();
  63. public function __construct($name, $array)
  64. {
  65. $this->workers = $array;
  66. $this->name = $name;
  67. $this->count = count($this->workers);
  68. $this->salary = $this->getSalary();
  69. $this->coffee = $this->getCoffee();
  70. $this->reports = $this->getReports();
  71. $this->repSal = number_format($this->getSalaryReports(), 2);
  72. }
  73. public function getCount()
  74. {
  75. return count($this->workers);
  76. }
  77. public function getSalary()
  78. {
  79. $sumSalary = 0;
  80. foreach ($this->workers as $worker) {
  81. $sumSalary += $worker->salary;
  82. }
  83. return $sumSalary;
  84. }
  85. public function getCoffee()
  86. {
  87. $sumCoffee = 0;
  88. foreach ($this->workers as $worker) {
  89. $sumCoffee += $worker->coffee;
  90. }
  91. return $sumCoffee;
  92. }
  93. public function getReports()
  94. {
  95. $sumReports = 0;
  96. foreach ($this->workers as $worker) {
  97. $sumReports += $worker->reports;
  98. }
  99. return $sumReports;
  100. }
  101. public function getSalaryReports()
  102. {
  103. return $this->getSalary() / $this->getReports();
  104. }
  105.  
  106. }
  107.  
  108. //Создание работников(объектов) внутри департамента >>
  109. function getEmployee($rank, $class, $count, $isDirector = 0)
  110. {
  111. $employees = array();
  112. for ($i = 1; $i <= $count; $i++) {
  113. $employee = new $class($rank, $isDirector);
  114. $employees[] = $employee;
  115. }
  116. return $employees;
  117. }
  118.  
  119. $ma = 'Marketolog';
  120. $me = 'Manager';
  121. $an = 'Analyst';
  122. $in = 'Engineer';
  123.  
  124. $procurement = new Department('Procurement', array_merge(getEmployee(1, $me, 9), getEmployee(2, $me, 3), getEmployee(3, $me, 2), getEmployee(1, $ma, 2), getEmployee(2, $me, 1, 1)));
  125. $sales = new Department('Sales dp', array_merge(getEmployee(1, $me, 12), getEmployee(1, $ma, 6), getEmployee(1, $an, 3), getEmployee(2, $an, 2), getEmployee(2, $ma, 1, 1)));
  126. $advertising = new Department('Advertising', array_merge(getEmployee(1, $ma, 15), getEmployee(2, $ma, 10), getEmployee(1, $me, 8), getEmployee(1, $in, 2), getEmployee(3, $ma, 1, 1)));
  127. $logistic = new Department('Logistic', array_merge(getEmployee(1, $me, 13), getEmployee(2, $me, 5), getEmployee(1, $in, 5), getEmployee(1, $me, 1, 1)));
  128. $departments = array(
  129. $procurement,
  130. $sales,
  131. $advertising,
  132. $logistic
  133. );
  134.  
  135. //Создание функций для вывода таблицы на экран и подсчет суммы по департаментам
  136.  
  137.  
  138. function padRight($string, $arg)
  139. {
  140. $count = $arg - mb_strlen($string);
  141. if ($count <= 0) {
  142. return $string;
  143. }
  144. $space = str_repeat(' ', $count);
  145. return $string . $space;
  146. }
  147. function padLeft($string, $arg)
  148. {
  149. $count = $arg - mb_strlen($string);
  150. if ($count <= 0) {
  151. return $string;
  152. }
  153. $space = str_repeat(' ', $count);
  154. return $space . $string;
  155. }
  156.  
  157. $text = 'Департамент сотр. тугр кофе стр. туг/стр.';
  158. $textAr = explode(' ', $text);
  159.  
  160. $col1 = 22;
  161. $col2 = 11;
  162. function getShow($array)
  163. {
  164. global $col1;
  165. global $col2;
  166. foreach ($array as $k => $str) {
  167. if ($k == 0) {
  168. echo padRight($str, $col1);
  169. } else {
  170. echo padLeft($str, $col2);
  171. }
  172.  
  173.  
  174. }
  175. echo "\n";
  176.  
  177. }
  178. //Вывод на экран>>
  179. getShow($textAr);
  180. echo str_repeat('-', 80) . "\n";
  181. $count = 0;
  182. $coffee = 0;
  183. $salary = 0;
  184. $reports = 0;
  185. $repSal = 0;
  186. foreach ($departments as $department) {
  187. echo padRight($department->name, $col1);
  188. echo padLeft($department->count, $col2);
  189. $count += $department->count;
  190. echo padLeft($department->salary, $col2);
  191. $salary += $department->salary;
  192. echo padLeft($department->coffee, $col2);
  193. $coffee += $department->coffee;
  194. echo padLeft($department->reports, $col2);
  195. $reports += $department->reports;
  196. echo padLeft($department->repSal, $col2) . "\n";
  197. $repSal += $department->repSal;
  198. }
  199. echo str_repeat('-', 80) . "\n";
  200. $repSal /= 4;
  201. $total = array(
  202. 'Всего',
  203. $count,
  204. $salary,
  205. $coffee,
  206. $reports,
  207. $repSal
  208. );
  209. getShow($total);
  210.  
  211.  
  212.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
 
Департамент                 сотр.       тугр       кофе       стр.   туг/стр.
--------------------------------------------------------------------------------
Procurement                    17     9612.5        350       3100       3.10
Sales dp                       24      13550        610       3325       4.08
Advertising                    36      16300        575       5450       2.99
Logistic                       24      11375        425       3850       2.95
--------------------------------------------------------------------------------
Всего                         101    50837.5       1960      15725       3.28