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