fork download
  1. <?php
  2.  
  3. //mb_internal_encoding('utf-8');
  4.  
  5. abstract class Department {
  6.  
  7. protected $depList = array();
  8. protected $depName;
  9.  
  10. public function getName() {
  11. return $this->depName;
  12. }
  13.  
  14. public function getTotalCoffee() {
  15. $totalCoffee = 0;
  16. foreach ($this->depList as $key) {
  17. $totalCoffee += $key->getCoffee();
  18. }
  19. return $totalCoffee;
  20. }
  21.  
  22. public function getTotalSalary(){
  23. $totalSalary = 0;
  24. foreach ($this->depList as $key) {
  25. $totalSalary += $key->getSalary();
  26. }
  27. return $totalSalary;
  28. }
  29.  
  30. public function addPeople($object){
  31. if (is_object($object)) {
  32. return array_push($this->depList, $object);
  33. } else return 'Ошибка';
  34.  
  35. }
  36.  
  37. public function getTotalPeople(){
  38. return count($this->depList);
  39. }
  40.  
  41. public function getTotalPages(){
  42. $totalPages = 0;
  43. foreach ($this->depList as $key) {
  44. $totalPages += $key->getPages();
  45. } return $totalPages;
  46. }
  47. public function getRatio($moneh, $pages){
  48. if (!$pages == 0) {
  49. return round($moneh/$pages, 2);
  50. } else return 0;
  51. }
  52. }
  53.  
  54. class Purchasing extends Department {
  55. protected $depName = "Закупок";
  56. }
  57.  
  58. class Sales extends Department {
  59. protected $depName = "Продаж";
  60. }
  61.  
  62. class Ads extends Department {
  63. protected $depName = "Маркетинга";
  64. }
  65.  
  66. class Logistics extends Department {
  67. protected $depName = "Логистики";
  68. }
  69.  
  70.  
  71.  
  72. abstract class Employee {
  73.  
  74. protected $rank; //1 - 0%, 2 - 25%, 3 - 50%
  75. protected $baseRate;
  76. protected $coffee;
  77. protected $isBoss = false; //Босс получает на 50% больше бабла, пьет в два раза больше кофе
  78. protected $reportPage; //и не делает отчеты
  79.  
  80. public function __construct($rank, $isBoss){
  81. if ($rank < 4 && $rank > 0) {
  82. $this->rank = $rank;
  83. } else $this->rank = 'Ошибка';
  84. if (is_bool($isBoss) === true) {
  85. $this->isBoss = $isBoss;
  86. } else $this->isBoss = 'Ошибка';
  87. }
  88.  
  89. public function getSalary(){ //Была мысль сделать что-то в стиле if (isBoss) return getSalary()*1.50; но не знаю как реализовать
  90. if (!$this->isBoss){ //В общем получилось ТУПО
  91. if ($this->rank == 3) {
  92. return $this->baseRate*1.50;
  93. } else if ($this->rank == 2) {
  94. return $this->baseRate*1.25;
  95. } else return $this->baseRate;
  96. } else if ($this->rank == 3) {
  97. return $this->baseRate*1.50*1.50;
  98. } else if ($this->rank == 2) {
  99. return $this->baseRate*1.25*1.50;
  100. } else return $this->baseRate*1.50;
  101. }
  102. public function getCoffee(){
  103. if (!$this->isBoss) {
  104. return $this->coffee;
  105. } else return $this->coffee*2;
  106. }
  107. public function getPages(){
  108. if (!$this->isBoss){
  109. return $this->reportPage;
  110. } else return 0;
  111. }
  112. }
  113.  
  114. class Manager extends Employee {
  115.  
  116. protected $baseRate = 500;
  117. protected $coffee = 20;
  118. protected $reportPage = 200;
  119.  
  120.  
  121. }
  122.  
  123. class Marketer extends Employee {
  124.  
  125. protected $baseRate = 400;
  126. protected $coffee = 15;
  127. protected $reportPage = 150;
  128.  
  129. }
  130.  
  131. class Engeneer extends Employee {
  132.  
  133. protected $baseRate = 200;
  134. protected $coffee = 5;
  135. protected $reportPage = 50;
  136.  
  137. }
  138.  
  139. class Analytic extends Employee {
  140.  
  141. protected $baseRate = 800;
  142. protected $coffee = 50;
  143. protected $reportPage = 5;
  144.  
  145. }
  146.  
  147.  
  148. function padLeft($string, $length) {
  149. $spaces = $length - mb_strlen($string);
  150. if ($spaces > 0) {
  151. for ($i = 0; $i<$spaces; $i++) {
  152. $string = " ".$string;
  153. }
  154. }
  155. else {
  156. $string = mb_substr($string, 0, $length);
  157. }
  158. return $string;
  159. }
  160.  
  161. function padRight($string, $length) {
  162. $spaces = $length - mb_strlen($string);
  163. if ($spaces>0) {
  164. for ($i=0; $i<$spaces; $i++) {
  165. $string .= " ";
  166. }
  167. }
  168. else {
  169. $string = mb_substr($string, 0, $length);
  170. }
  171. return $string;
  172. }
  173.  
  174. $col1 = 20;
  175. $col2 = 10;
  176. $col3 = 10;
  177. $col4 = 10;
  178. $col5 = 10;
  179. $col6 = 14;
  180.  
  181. $salesDep = new Sales();
  182. $purchasingDep = new Purchasing();
  183. $logisticsDep = new Logistics();
  184. $adsDep = new Ads();
  185.  
  186. for ($i = 0; $i < 15; $i++) { //супер ТУПО
  187. if ($i < 8) $purchasingDep->addPeople(new Manager(1, false));
  188. if ($i < 3) $purchasingDep->addPeople(new Manager(2, false));
  189. if ($i < 2) $purchasingDep->addPeople(new Manager(3, false));
  190. if ($i < 2) $purchasingDep->addPeople(new Marketer(1, false));
  191. if ($i < 1) $purchasingDep->addPeople(new Manager(2, true));
  192. if ($i < 12) $salesDep->addPeople(new Manager(1, false));
  193. if ($i < 6) $salesDep->addPeople(new Marketer(1, false));
  194. if ($i < 3) $salesDep->addPeople(new Analytic(1, false));
  195. if ($i < 2) $salesDep->addPeople(new Analytic(2, false));
  196. if ($i < 1) $salesDep->addPeople(new Marketer(2, true));
  197.  
  198. $adsDep->addPeople(new Marketer(1, false));
  199. if ($i < 10) $adsDep->addPeople(new Marketer(2, false));
  200. if ($i < 8) $adsDep->addPeople(new Manager(1, false));
  201. if ($i < 2) $adsDep->addPeople(new Engeneer(1, false));
  202. if ($i < 1) $adsDep->addPeople(new Marketer(3, true));
  203.  
  204. if ($i < 13) $logisticsDep->addPeople(new Manager(1, false));
  205. if ($i < 5) $logisticsDep->addPeople(new Manager(2, false));
  206. if ($i < 5) $logisticsDep->addPeople(new Engeneer(1, false));
  207. if ($i < 1) $logisticsDep->addPeople(new Manager(1, true));
  208.  
  209. }
  210.  
  211.  
  212. $arrayOfDeps = array($salesDep, $purchasingDep, $adsDep, $logisticsDep);
  213.  
  214.  
  215. class CountTotal {
  216. public $totalPeople;
  217. public $totalSalary;
  218. public $totalCoffee;
  219. public $totalPages;
  220. public $totalRatio;
  221.  
  222. function __construct($deps){
  223. foreach ($deps as $dep) {
  224. $this->totalPeople += $dep->getTotalPeople();
  225. $this->totalSalary += $dep->getTotalSalary();
  226. $this->totalCoffee += $dep->getTotalCoffee();
  227. $this->totalPages += $dep->getTotalPages();
  228. $this->totalRatio += $dep->getRatio($dep->getTotalSalary(), $dep->getTotalPages());
  229. }
  230. }
  231. public function getMedPeople() {
  232. return round($this->totalPeople/4);
  233. }
  234. public function getMedSalary() {
  235. return round($this->totalSalary/4);
  236. }
  237. public function getMedCoffee() {
  238. return round($this->totalCoffee/4);
  239. }
  240. public function getMedPages() {
  241. return round($this->totalPages/4);
  242. }
  243. public function getMedRatio() {
  244. return round($this->totalRatio/4);
  245. }
  246. }
  247.  
  248. $summary = new CountTotal($arrayOfDeps);
  249.  
  250.  
  251. echo padRight("Департамент", $col1).
  252. padLeft("сотр.", $col2).
  253. padLeft("бабки", $col3).
  254. padLeft("кофе", $col4).
  255. padLeft("стр.", $col5).
  256. padLeft("бабки/кофе", $col6)."\n\n";
  257.  
  258. foreach ($arrayOfDeps as $key) {
  259. echo padRight($key->getName(), $col1).
  260. padLeft($key->getTotalPeople(), $col2).
  261. padLeft($key->getTotalSalary(), $col3).
  262. padLeft($key->getTotalCoffee(), $col4).
  263. padLeft($key->getTotalPages(), $col5).
  264. padLeft($key->getRatio($key->getTotalSalary(), $key->getTotalPages()), $col6)."\n";
  265. }
  266.  
  267. echo padRight("Среднее", $col1).
  268. padLeft($summary->getMedPeople(), $col2).
  269. padLeft($summary->getMedSalary(), $col3).
  270. padLeft($summary->getMedCoffee(), $col4).
  271. padLeft($summary->getMedPages(), $col5).
  272. padLeft($summary->getMedRatio(), $col6)."\n";
  273. echo padRight("Всего", $col1).
  274. padLeft($summary->totalPeople, $col2).
  275. padLeft($summary->totalSalary, $col3).
  276. padLeft($summary->totalCoffee, $col4).
  277. padLeft($summary->totalPages, $col5).
  278. padLeft($summary->totalRatio, $col6)."\n";
Runtime error #stdin #stdout #stderr 0s 82880KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Fatal error:  Uncaught Error: Call to undefined function mb_strlen() in /home/woXodr/prog.php:162
Stack trace:
#0 /home/woXodr/prog.php(251): padRight('\xD0\x94\xD0\xB5\xD0\xBF\xD0\xB0\xD1\x80\xD1\x82\xD0\xB0\xD0...', 20)
#1 {main}
  thrown in /home/woXodr/prog.php on line 162