fork download
  1. <?php
  2.  
  3. class Department {
  4. public $employees = array();
  5.  
  6. public function __construct($boss, $name,
  7. $managers1, $managers2, $managers3,
  8. $marketers1, $marketers2, $marketers3,
  9. $engineers1,
  10. $analysts1, $analysts2) {
  11. $this->name = $name;
  12. for ($i = 0; $i < $managers1; $i++){
  13. $this->employees[] = new Manager(1, false);
  14. }
  15. for ($i = 0; $i < $managers2; $i++){
  16. $this->employees[] = new Manager(2, false);
  17. }
  18. for ($i = 0; $i < $managers3; $i++){
  19. $this->employees[] = new Manager(3, false);
  20. }
  21. for ($i = 0; $i < $marketers1; $i++){
  22. $this->employees[] = new Marketer(1, false);
  23. }
  24. for ($i = 0; $i < $marketers2; $i++){
  25. $this->employees[] = new Marketer(2, false);
  26. }
  27. for ($i = 0; $i < $marketers3; $i++){
  28. $this->employees[] = new Marketer(3, false);
  29. }
  30. for ($i = 0; $i < $engineers1; $i++){
  31. $this->employees[] = new Engineer(1, false);
  32. }
  33. for ($i = 0; $i < $analysts1; $i++){
  34. $this->employees[] = new Analyst(1, false);
  35. }
  36. for ($i = 0; $i < $analysts2; $i++){
  37. $this->employees[] = new Analyst(2, false);
  38. }
  39. $this->employees[] = $boss;
  40. }
  41.  
  42. public function countCoffeeConsumption() {
  43. foreach ($this->employees as $employee) {
  44. $consumption = $consumption + $employee->coffee;
  45. }
  46. return $consumption;
  47. }
  48. public function countMoneyConsumption() {
  49. foreach ($this->employees as $employee) {
  50. $consumption = $consumption + $employee->salary;
  51. }
  52. return $consumption;
  53. }
  54. public function countReportsGeneration() {
  55. foreach ($this->employees as $employee) {
  56. $generation = $generation + $employee->reports;
  57. }
  58. return $generation;
  59. }
  60. public function countToogreeksPerPage() {
  61. $toogreeks = $this->countMoneyConsumption() / $this->countReportsGeneration();
  62. return round($toogreeks, 1);
  63. }
  64. }
  65.  
  66. abstract class Employee {
  67. public function countSalary($salary) {
  68. if ($this->rank == 2) {
  69. $salary = $salary * 1.25;
  70. }elseif ($this->rank == 3) {
  71. $salary = $salary * 1.5;
  72. }
  73. if ($this->isBoss == true) {
  74. $salary = $salary * 1.5;
  75. }
  76. return $salary;
  77. }
  78. public function countCoffee($coffee) {
  79. if ($this->isBoss == true) {
  80. $coffee = $coffee * 2;
  81. }
  82. return $coffee;
  83. }
  84. public function countReports($reports) {
  85. if ($this->isBoss == true) {
  86. $reports = 0;
  87. }
  88. return $reports;
  89. }
  90. }
  91.  
  92. class Manager extends Employee {
  93. public function __construct($rank, $isBoss) {
  94. $salary = 500;
  95. $coffee = 20;
  96. $reports = 200;
  97. $this->rank = $rank;
  98. $this->isBoss = $isBoss;
  99. $this->salary = $this->countSalary($salary);
  100. $this->coffee = $this->countCoffee($coffee);
  101. $this->reports = $this->countReports($reports);
  102. }
  103. }
  104. class Marketer extends Employee {
  105. public function __construct($rank, $isBoss) {
  106. $salary = 400;
  107. $coffee = 15;
  108. $reports = 150;
  109. $this->rank = $rank;
  110. $this->isBoss = $isBoss;
  111. $this->salary = $this->countSalary($salary);
  112. $this->coffee = $this->countCoffee($coffee);
  113. $this->reports = $this->countReports($reports);
  114. }
  115. }
  116. class Engineer extends Employee {
  117. public function __construct($rank, $isBoss) {
  118. $salary = 200;
  119. $coffee = 5;
  120. $reports = 50;
  121. $this->rank = $rank;
  122. $this->isBoss = $isBoss;
  123. $this->salary = $this->countSalary($salary);
  124. $this->coffee = $this->countCoffee($coffee);
  125. $this->reports = $this->countReports($reports);
  126. }
  127. }
  128. class Analyst extends Employee {
  129. public function __construct($rank, $isBoss) {
  130. $salary = 800;
  131. $coffee = 50;
  132. $reports = 5;
  133. $this->rank = $rank;
  134. $this->isBoss = $isBoss;
  135. $this->salary = $this->countSalary($salary);
  136. $this->coffee = $this->countCoffee($coffee);
  137. $this->reports = $this->countReports($reports);
  138. }
  139. }
  140.  
  141. //Функции для паддинга таблицы
  142. function padLeft($string, $length) {
  143. $stlen = mb_strlen($string);
  144. if ($stlen < $length) {
  145. for ($i = 0; $i < $length - $stlen; $i++) {
  146. $string = " " . $string;
  147. }
  148. }
  149. return $string;
  150. }
  151. function padRight($string, $length) {
  152. $stlen = mb_strlen($string);
  153. if ($stlen < $length) {
  154. for ($i = 0; $i < $length - $stlen; $i++) {
  155. $string = $string . " ";
  156. }
  157. }
  158. return $string;
  159. }
  160.  
  161. //Функции для подсчёта "в среднем по компании"
  162. function countAverageMoneyConsumption($company) {
  163. foreach ($company as $department) {
  164. $summary = $summary + $department->countMoneyConsumption();
  165. }
  166. return round($summary / count($company), 2);
  167. }
  168. function countAverageCoffeeConsumption($company) {
  169. foreach ($company as $department) {
  170. $summary = $summary + $department->countCoffeeConsumption();
  171. }
  172. return round($summary / count($company), 2);
  173. }
  174. function countAverageReportsGeneration($company) {
  175. foreach ($company as $department) {
  176. $summary = $summary + $department->countReportsGeneration();
  177. }
  178. return round($summary / count($company), 2);
  179. }
  180. function countAverageToogreeksPerPage($company) {
  181. foreach ($company as $department) {
  182. $summary = $summary + $department->countToogreeksPerPage();
  183. }
  184. return round($summary / count($company), 2);
  185. }
  186. function countAverageAmountOfEmployees($company) {
  187. foreach ($company as $department) {
  188. $summary = $summary + count($department->employees);
  189. }
  190. return round($summary / count($company), 2);
  191. }
  192.  
  193. //Функции для подсчёта "всего"
  194. function countTotalMoneyConsumption($company) {
  195. foreach ($company as $department) {
  196. $summary = $summary + $department->countMoneyConsumption();
  197. }
  198. return $summary;
  199. }
  200. function countTotalCoffeeConsumption($company) {
  201. foreach ($company as $department) {
  202. $summary = $summary + $department->countCoffeeConsumption();
  203. }
  204. return $summary;
  205. }
  206. function countTotalReportsGeneration($company) {
  207. foreach ($company as $department) {
  208. $summary = $summary + $department->countReportsGeneration();
  209. }
  210. return $summary;
  211. }
  212. function countTotalToogreeksPerPage($company) {
  213. foreach ($company as $department) {
  214. $summary = $summary + $department->countToogreeksPerPage();
  215. }
  216. return $summary;
  217. }
  218. function countTotalAmountOfEmployees($company) {
  219. foreach ($company as $department) {
  220. $summary = $summary + count($department->employees);
  221. }
  222. return $summary;
  223. }
  224.  
  225. //Создаём отделы
  226. $purchasing = new Department(new Manager(2, true), "Закупок",
  227. 9, 3, 2,
  228. 2, 0, 0,
  229. 0,
  230. 0, 0);
  231.  
  232. $sales = new Department(new Marketer(2, true), "Продаж",
  233. 12, 0, 0,
  234. 6, 0, 0,
  235. 0,
  236. 3, 2);
  237.  
  238. $marketing = new Department(new Marketer(3, true), "Рекламы",
  239. 8, 0, 0,
  240. 15, 10, 0,
  241. 2,
  242. 0, 0);
  243.  
  244. $logistics = new Department(new Manager(1, true), "Логистики",
  245. 13, 5, 0,
  246. 0, 0, 0,
  247. 5,
  248. 0, 0);
  249.  
  250. //Объединяем их в компанию
  251. $company = array($purchasing, $sales, $marketing, $logistics);
  252.  
  253. //Задаём ширину колонок
  254. $col1 = 20;
  255. $col2 = 8;
  256. $col3 = 10;
  257. $col4 = 10;
  258. $col5 = 10;
  259. $col6 = 12;
  260.  
  261. //Выводим на экран
  262. echo padRight("Департамент", $col1) .
  263. padLeft("сотр.", $col2) .
  264. padLeft("тугр.", $col3) .
  265. padLeft("кофе", $col4) .
  266. padLeft("стр.", $col5) .
  267. padLeft("тугр./стр.", $col6) . "\n----------------------------------------------------------------------\n-\n";
  268. foreach ($company as $department) {
  269. echo padRight($department->name, $col1) .
  270. padLeft(count($department->employees), $col2) .
  271. padLeft($department->countMoneyConsumption(), $col3) .
  272. padLeft($department->countCoffeeConsumption(), $col4) .
  273. padLeft($department->countReportsGeneration(), $col5) .
  274. padLeft($department->countToogreeksPerPage(), $col6) . "\n";
  275. }
  276. echo "-\n" . padRight("Среднее", $col1) .
  277. padLeft(countAverageAmountOfEmployees($company), $col2) .
  278. padLeft(countAverageMoneyConsumption($company), $col3) .
  279. padLeft(countAverageCoffeeConsumption($company), $col4) .
  280. padLeft(countAverageReportsGeneration($company), $col5) .
  281. padLeft(countAverageToogreeksPerPage($company), $col6) . "\n";
  282. echo padRight("Всего", $col1) .
  283. padLeft(countTotalAmountOfEmployees($company), $col2) .
  284. padLeft(countTotalMoneyConsumption($company), $col3) .
  285. padLeft(countTotalCoffeeConsumption($company), $col4) .
  286. padLeft(countTotalReportsGeneration($company), $col5) .
  287. padLeft(countTotalToogreeksPerPage($company), $col6) . "\n";
  288. ?>
  289.  
Success #stdin #stdout #stderr 0.02s 24400KB
stdin
Standard input is empty
stdout
Департамент            сотр.     тугр.      кофе      стр.  тугр./стр.
----------------------------------------------------------------------
-
Закупок                   17    9612.5       350      3100         3.1
Продаж                    24     13550       610      3325         4.1
Рекламы                   36     16300       575      5450           3
Логистики                 24     11375       425      3850           3
-
Среднее                25.25  12709.38       490   3931.25         3.3
Всего                    101   50837.5      1960     15725        13.2
stderr
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 46
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 46
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 46
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 46
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: summary in /home/uCYQ0J/prog.php on line 187
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: summary in /home/uCYQ0J/prog.php on line 163
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 46
PHP Notice:  Undefined variable: summary in /home/uCYQ0J/prog.php on line 169
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 46
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 46
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 46
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: summary in /home/uCYQ0J/prog.php on line 175
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: summary in /home/uCYQ0J/prog.php on line 181
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: summary in /home/uCYQ0J/prog.php on line 217
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: summary in /home/uCYQ0J/prog.php on line 193
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 46
PHP Notice:  Undefined variable: summary in /home/uCYQ0J/prog.php on line 199
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 46
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 46
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 46
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: summary in /home/uCYQ0J/prog.php on line 205
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: summary in /home/uCYQ0J/prog.php on line 211
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58
PHP Notice:  Undefined variable: consumption in /home/uCYQ0J/prog.php on line 52
PHP Notice:  Undefined variable: generation in /home/uCYQ0J/prog.php on line 58