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 function __construct($isDirector)
  13. {
  14. switch ($isDirector) {
  15. case 1:
  16. $this->salary *= 1.5;
  17. $this->coffee *= 2;
  18. $this->reports = 0;
  19. break;
  20. case 0:
  21. break;
  22. }
  23. }
  24. }
  25. class Engineer extends Employee
  26. {
  27. public $salary = 200;
  28. public $coffee = 5;
  29. public $reports = 50;
  30. }
  31.  
  32. class Marketolog extends Employee
  33. {
  34. public $salary = 400;
  35. public $coffee = 15;
  36. public $reports = 150;
  37. }
  38. class Manager extends Employee
  39. {
  40. public $salary = 500;
  41. public $coffee = 20;
  42. public $reports = 200;
  43. }
  44.  
  45. class Analyst extends Employee
  46. {
  47. public $salary = 800;
  48. public $coffee = 50;
  49. public $reports = 5;
  50. }
  51. class Department
  52. {
  53.  
  54. public $workers = array();
  55. public function __construct($array)
  56. {
  57. $this->workers = $array;
  58. }
  59. public function doCount()
  60. {
  61. $c = count($this->workers, 2);
  62. return $c;
  63. }
  64. public function doSalary()
  65. {
  66. $sumSalary = 0;
  67. foreach ($this->workers as $object) {
  68. foreach ($object as $k => $v) {
  69. if ($k === 'salary') {
  70. $salary = $v;
  71. }
  72. }
  73. $sumSalary += $salary;
  74. }
  75. return $sumSalary;
  76. }
  77. public function doCoffee()
  78. {
  79. $sumCoffee = 0;
  80. foreach ($this->workers as $object) {
  81. foreach ($object as $k => $v) {
  82. if ($k === 'coffee') {
  83. $coffee = $v;
  84. }
  85. }
  86. $sumCoffee += $coffee;
  87. }
  88. return $sumCoffee;
  89. }
  90. public function doReports()
  91. {
  92. $sumReports = 0;
  93. foreach ($this->workers as $object) {
  94. foreach ($object as $k => $v) {
  95. if ($k === 'reports') {
  96. $reports = $v;
  97. }
  98. }
  99. $sumReports += $reports;
  100. }
  101. return $sumReports;
  102. }
  103. public function doSalaryReports()
  104. {
  105. return $this->doSalary() / $this->doReports();
  106. }
  107. public function doShow()
  108. {
  109. $show = array();
  110. $show[] = get_class($this);
  111. $show[] = $this->doCount();
  112. $show[] = $this->doSalary();
  113. $show[] = $this->doCoffee();
  114. $show[] = $this->doReports();
  115. $show[] = $this->doSalaryReports();
  116. return $show;
  117. }
  118.  
  119. }
  120.  
  121. class Procurement extends Department
  122. {
  123. }
  124. class Sales extends Department
  125. {
  126. }
  127. class Advertising extends Department
  128. {
  129. }
  130. class Logistic extends Department
  131. {
  132. }
  133. //Создание работников(объектов) внутри департаментов(объектов) >>
  134. function doEmployeeFirstRank($class, $count, $isDirector = 0)
  135. {
  136. $employees = array();
  137. for ($i = 1; $i <= $count; $i++) {
  138. $employee = new $class($isDirector);
  139. $employees[] = $employee;
  140. }
  141. return $employees;
  142. }
  143. function doEmployeeSecondRank($class, $count, $isDirector = 0)
  144. {
  145. $employees = array();
  146. for ($i = 1; $i <= $count; $i++) {
  147. $employee = new $class($isDirector);
  148. $employee->salary *= 1.25;
  149. $employees[] = $employee;
  150. }
  151. return $employees;
  152. }
  153. function doEmployeeThirdRank($class, $number, $isDirector = 0)
  154. {
  155. $employees = array();
  156. for ($i = 1; $i <= $number; $i++) {
  157. $employee = new $class($isDirector);
  158. $employee->salary *= 1.5;
  159. $employees[] = $employee;
  160. }
  161. return $employees;
  162. }
  163. $ma = 'Marketolog';
  164. $me = 'Manager';
  165. $an = 'Analyst';
  166. $in = 'Engineer';
  167. $procurement = new Procurement(array_merge(doEmployeeFirstRank($me, 9), doEmployeeSecondRank($me, 3), doEmployeeThirdRank($me, 2), doEmployeeFirstRank($ma, 2), doEmployeeSecondRank($me, 1, 1)));
  168. $sales = new Sales(array_merge(doEmployeeFirstRank($me, 12), doEmployeeFirstRank($ma, 6), doEmployeeFirstRank($an, 3), doEmployeeSecondRank($an, 2), doEmployeeSecondRank($ma, 1, 1)));
  169. $advertising = new Advertising(array_merge(doEmployeeFirstRank($ma, 15), doEmployeeSecondRank($ma, 10), doEmployeeFirstRank($me, 8), doEmployeeFirstRank($in, 2), doEmployeeThirdRank($ma, 1, 1)));
  170. $logistic = new Logistic(array_merge(doEmployeeFirstRank($me, 13), doEmployeeSecondRank($me, 5), doEmployeeFirstRank($in, 5), doEmployeeFirstRank($me, 1, 1)));
  171. $vektor = array(
  172. $procurement,
  173. $sales,
  174. $advertising,
  175. $logistic
  176. );
  177.  
  178. //Создание функций для вывода таблицы на экран и подсчет суммы по департаментам
  179. function padRight($string, $arg)
  180. {
  181. $count = $arg - mb_strlen($string);
  182. if ($count <= 0) {
  183. return $string;
  184. }
  185. $space = str_repeat(' ', $count);
  186. return $string . $space;
  187. }
  188. function padLeft($string, $arg)
  189. {
  190. $count = $arg - mb_strlen($string);
  191. if ($count <= 0) {
  192. return $string;
  193. }
  194. $space = str_repeat(' ', $count);
  195. return $space . $string;
  196. }
  197.  
  198. $text = 'Департамент сотр. тугр кофе стр. туг/стр.';
  199. $textAr = explode(' ', $text);
  200.  
  201.  
  202. function letShow($array)
  203. {
  204. $col1 = 22;
  205. $col2 = 11;
  206. foreach ($array as $k => $str) {
  207. if ($k == 0) {
  208. echo padRight($str, $col1);
  209. } elseif (is_numeric($str) && $k == 5) {
  210.  
  211. echo padLeft((number_format($str, 2)), $col2);
  212. } else {
  213. echo padLeft($str, $col2);
  214. }
  215.  
  216. }
  217. echo "\n";
  218. }
  219. function doAll()
  220. {
  221.  
  222. }
  223.  
  224. $proc = $procurement->doShow();
  225. $log = $logistic->doShow();
  226. $adv = $advertising->doShow();
  227. $sal = $sales->doShow();
  228. $vek = array(
  229. $proc,
  230. $log,
  231. $adv,
  232. $sal
  233. );
  234.  
  235. $sumWorkers = 0;
  236. $sumSal = 0;
  237. $sumCoffee = 0;
  238. $sumReports = 0;
  239. $sumRepSal = 0;
  240. $end = array();
  241. foreach ($vek as $dep) {
  242. foreach ($dep as $k => $v) {
  243. switch ($k) {
  244. case 1:
  245. $sumWorkers += $v;
  246. break;
  247. case 2:
  248. $sumSal += $v;
  249. break;
  250. case 3:
  251. $sumCoffee += $v;
  252. break;
  253. case 4:
  254. $sumReports += $v;
  255. break;
  256. case 5:
  257. $sumRepSal += $v;
  258. break;
  259. }
  260. }
  261.  
  262. }
  263. $end[] = 'Всего';
  264. $end[] = $sumWorkers;
  265. $end[] = $sumSal;
  266. $end[] = $sumCoffee;
  267. $end[] = $sumReports;
  268. $end[] = $sumRepSal / 4;
  269.  
  270. //Вывод на экран
  271. letShow($textAr);
  272. echo str_repeat('-', 80) . "\n";
  273. letShow($procurement->doShow());
  274. letShow($logistic->doShow());
  275. letShow($advertising->doShow());
  276. letShow($sales->doShow());
  277. echo str_repeat('-', 80) . "\n";
  278. letShow($end);
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
 
Департамент                 сотр.       тугр       кофе       стр.   туг/стр.
--------------------------------------------------------------------------------
Procurement                    17     9612.5        350       3100       3.10
Logistic                       24      11375        425       3850       2.95
Advertising                    36      16300        575       5450       2.99
Sales                          24      13550        610       3325       4.08
--------------------------------------------------------------------------------
Всего                         101    50837.5       1960      15725       3.28