fork download
  1. <?php //департаменты и сотрудники
  2.  
  3.  
  4.  
  5.  
  6. $departmentNames = array("закупок","продаж","рекламы","логистики");
  7.  
  8. $listOfWorkersDep["закупок"] = array("ме1"=>9,"ме2"=>3,"ме3"=>2,
  9. "ма1"=>2,"ма2"=>0,"ма3"=>0,
  10. "ин1"=>0,"ин2"=>0,"ин3"=>0,
  11. "аа1"=>0,"ан2"=>0,"ан3"=>0);
  12. $listOfWorkersDep["продаж"] = array("ме1"=>12,"ме2"=>0,"ме3"=>0,
  13. "мар1"=>6,"ма2"=>0,"ма3"=>0,
  14. "ин1"=>0,"ин2"=>0,"ин3"=>0,
  15. "ан1"=>3,"ан2"=>2,"ан3"=>0);
  16. $listOfWorkersDep["рекламы"] = array("ме1"=>8,"ме2"=>0,"ме3"=>0,
  17. "ма1"=>15,"ма2"=>10,"ма3"=>0,
  18. "ин1"=>2,"ин2"=>0,"ин3"=>0,
  19. "ан1"=>0,"ан2"=>0,"ан3"=>0);
  20. $listOfWorkersDep["логистики"] = array("ме1"=>13,"мен2"=>5,"ме3"=>0,
  21. "мар1"=>0,"ма2"=>0,"ма3"=>0,
  22. "ин1"=>5,"ин2"=>0,"ин3"=>0,
  23. "ан1"=>0,"ан2"=>0,"ан3"=>0);
  24.  
  25.  
  26.  
  27. class Department
  28. {
  29. protected $name;
  30. protected $listOfWorkers = array();
  31. protected $numberOfWorkers = 0;
  32.  
  33.  
  34. public function __construct( $name )
  35. {
  36. $this->name = $name;
  37. }
  38.  
  39. public function addWorker( Worker $newWorker )
  40. {
  41. $this->listOfWorkers[] = $newWorker;
  42. $this->numberOfWorkers++;
  43. }
  44.  
  45. public function getName()
  46. {
  47. return $this->name;
  48. }
  49.  
  50. public function summonWorkers( $quantity, $type, $rank, $leadership )
  51. {
  52. $list = array();
  53. for( $i=0;$i<$quantity;$i++ )
  54. {
  55. switch($type)
  56. {
  57. case 1:
  58. $this->listOfWorkers[] = new Manager( $this, $rank, $leadership );
  59. case 2:
  60. $this->listOfWorkers[] = new Marketer( $this, $rank, $leadership );
  61. case 3:
  62. $this->listOfWorkers[] = new Engineer( $this, $rank, $leadership );
  63. case 4:
  64. $this->listOfWorkers[] = new Analyst( $this, $rank, $leadership );
  65. }
  66. }
  67. }
  68.  
  69. public function getWorkersInfos()
  70. {
  71. foreach( $this->listOfWorkers as $number=>$worker )
  72. {
  73. $worker->getInfos();
  74. }
  75. }
  76.  
  77. public function getTotalWorkers()
  78. {
  79. return $this->numberOfWorkers;
  80. }
  81.  
  82. public function getTotalSalary()
  83. {
  84. $totalSalary = 0;
  85. foreach( $this->listOfWorkers as $number=>$worker )
  86. {
  87. $totalSalary += $worker->getSalary();
  88. }
  89. return $totalSalary;
  90. }
  91.  
  92. public function getTotalCoffeeConsumption()
  93. {
  94. $totalCoffee = 0;
  95. foreach( $this->listOfWorkers as $number=>$worker )
  96. {
  97. $totalCoffee += $worker->getCoffeeConsumption();
  98. }
  99. return $totalCoffee;
  100. }
  101.  
  102. public function getTotalProduction()
  103. {
  104. $totalProduction = 0;
  105. foreach( $this->listOfWorkers as $number=>$worker )
  106. {
  107. $totalProduction += $worker->getProduction();
  108. }
  109. return $totalProduction;
  110. }
  111.  
  112. public function getDepartmentInfos()
  113. {
  114. return array($this->name,
  115. $this->getTotalWorkers(),
  116. $this->getTotalSalary(),
  117. $this->getTotalCoffeeConsumption(),
  118. $this->getTotalProduction(),
  119. round($this->getTotalSalary()/$this->getTotalProduction(),2));
  120. }
  121. }
  122.  
  123. abstract class Worker
  124. {
  125. protected $department;
  126. protected $rank;
  127. protected $isChief;
  128. protected $baseSalary;
  129. protected $coffeeConsumptionRate;
  130. protected $productionPerMount;
  131. protected $productionType;
  132.  
  133. public function __construct( Department $department, $rank, $chief )
  134. {
  135. $this->department = $department->getName();
  136. $this->rank = $rank;
  137. $this->isChief = $chief;
  138. $department->addWorker($this);
  139. }
  140.  
  141. public function getCoffeeConsumption()
  142. {
  143. if ( $this->isChief )
  144. {
  145. $coffee = $this->coffeeConsumptionRate*2;
  146. }
  147. else
  148. {
  149. $coffee = $this->coffeeConsumptionRate;
  150. }
  151. return $coffee;
  152. }
  153.  
  154. public function getSalary()
  155. {
  156. switch( $this->rank )
  157. {
  158. case 1:
  159. $salary = $this->baseSalary;
  160. break;
  161. case 2:
  162. $salary = $this->baseSalary*1.25;
  163. break;
  164. case 3:
  165. $salary = $this->baseSalary*1.5;
  166. break;
  167. }
  168.  
  169. if( $this->isChief )
  170. {
  171. $salary*= 1.5;
  172. }
  173.  
  174. return $salary;
  175. }
  176.  
  177. public function getProduction()
  178. {
  179. return $this->productionPerMount;
  180. }
  181.  
  182. public function getInfos()
  183. {
  184. echo $this->rank;
  185. echo "-го уровня ";
  186. if ($this->isChief)
  187. {
  188. echo "и начальник ";
  189. }
  190. echo "департамента ";
  191. echo $this->department;
  192. echo ", зарплата ";
  193. echo $this->getSalary();
  194. echo " тугриков в месяц, выпивает ";
  195. echo $this->getCoffeeConsumption();
  196. echo " литров кофе в месяц\n";
  197. }
  198. }
  199.  
  200. class Manager extends Worker
  201. {
  202. protected $coffeeConsumptionRate = 20;
  203. protected $baseSalary = 500;
  204. protected $productionPerMount = 200;
  205. protected $productionType = "страница отчёта";
  206.  
  207. public function getInfos()
  208. {
  209. echo "Это менеджер ";
  210. parent::getInfos();
  211. }
  212. }
  213.  
  214. class Marketer extends Worker
  215. {
  216. protected $coffeeConsumptionRate = 15;
  217. protected $baseSalary = 400;
  218. protected $productionPerMount = 150;
  219. protected $productionType = "страница отчёта";
  220.  
  221. public function getInfos()
  222. {
  223. echo "Это маркетолог ";
  224. parent::getInfos();
  225. }
  226. }
  227.  
  228. class Engineer extends Worker
  229. {
  230. protected $coffeeConsumptionRate = 5;
  231. protected $baseSalary = 200;
  232. protected $productionPerMount = 50;
  233. protected $productionType = "страница чертёжа";
  234.  
  235. public function getInfos()
  236. {
  237. echo "Это инженер ";
  238. parent::getInfos();
  239. }
  240. }
  241.  
  242. class Analyst extends Worker
  243. {
  244. protected $coffeeConsumptionRate = 50;
  245. protected $baseSalary = 800;
  246. protected $productionPerMount = 5;
  247. protected $productionType = "стратегическое исследование";
  248.  
  249. public function getInfos()
  250. {
  251. echo "Это аналитик ";
  252. parent::getInfos();
  253. }
  254. }
  255.  
  256.  
  257. function padLeft( $string,$columns )
  258. {
  259. return str_repeat(" ",$columns-mb_strlen($string)).$string;
  260. }
  261.  
  262. function printInfos( $arrayOfSomething,$columns )
  263. {
  264. foreach( $arrayOfSomething as $number=>$data )
  265. {
  266. echo padLeft( $data,$columns );
  267. }
  268. echo "\n";
  269. }
  270.  
  271.  
  272.  
  273.  
  274. $departmentList = array();
  275. foreach( $departmentNames as $i=>$name )
  276. {
  277. $departmentList[$name] = new Department($name);
  278. }
  279.  
  280. foreach( $departmentNames as $i=>$name ) //вносим работников в департаменты
  281. {
  282. $workers = $listOfWorkersDep[$name];
  283. foreach( $workers as $key=>$num)
  284. {
  285. if ( $num > 0 )
  286. {
  287. switch($key)
  288. {
  289. case "ме1":
  290. for ( $i=0;$i<$num;$i++ )
  291. {
  292. new Manager( $departmentList[$name], 1, false );
  293. }
  294. break;
  295. case "ме2":
  296. for ( $i=0;$i<$num;$i++ )
  297. {
  298. new Manager( $departmentList[$name], 2, false );
  299. }
  300. break;
  301. case "ме3":
  302. for ( $i=0;$i<$num;$i++ )
  303. {
  304. new Manager( $departmentList[$name], 3, false );
  305. }
  306. break;
  307. case "ма1":
  308. for ( $i=0;$i<$num;$i++ )
  309. {
  310. new Marketer( $departmentList[$name], 1, false );
  311. }
  312. break;
  313. case "ма2":
  314. for ( $i=0;$i<$num;$i++ )
  315. {
  316. new Marketer( $departmentList[$name], 2, false );
  317. }
  318. break;
  319. case "ма3":
  320. for ( $i=0;$i<$num;$i++ )
  321. {
  322. new Marketer( $departmentList[$name], 3, false );
  323. }
  324. break;
  325. case "ин1":
  326. for ( $i=0;$i<$num;$i++ )
  327. {
  328. new Engineer( $departmentList[$name], 1, false );
  329. }
  330. break;
  331. case "ин2":
  332. for ( $i=0;$i<$num;$i++ )
  333. {
  334. new Engineer( $departmentList[$name], 2, false );
  335. }
  336. break;
  337. case "ин3":
  338. for ( $i=0;$i<$num;$i++ )
  339. {
  340. new Engineer( $departmentList[$name], 3, false );
  341. }
  342. break;
  343. case "ан1":
  344. for ( $i=0;$i<$num;$i++ )
  345. {
  346. new Analyst( $departmentList[$name], 1, false );
  347. }
  348. break;
  349. case "ан2":
  350. for ( $i=0;$i<$num;$i++ )
  351. {
  352. new Analyst( $departmentList[$name], 2, false );
  353. }
  354. break;
  355. case "ан3":
  356. for ( $i=0;$i<$num;$i++ )
  357. {
  358. new Analyst( $departmentList[$name], 3, false );
  359. }
  360. break;
  361. }
  362. }
  363. }
  364. }
  365.  
  366. //добавляем начальников департаментов
  367. new Manager( $departmentList["закупок"], 2, true );
  368. new Marketer( $departmentList["продаж"], 2, true );
  369. new Marketer( $departmentList["рекламы"], 3, true );
  370. new Manager( $departmentList["логистики"], 1, true );
  371.  
  372.  
  373.  
  374. printInfos(array("Департамент","Работников","Зарплата","Расход кофе","Результат(стр)","Расход на стр"),15);
  375.  
  376. foreach( $departmentNames as $i=>$name )
  377. {
  378. $arrayOfInfos[$i]=$departmentList[$name]->getDepartmentInfos();
  379. printInfos($arrayOfInfos[$i],15);
  380. }
  381.  
  382. $totalInfos = array("итого",0,0,0,0,0);
  383.  
  384. foreach( $arrayOfInfos as $key=>$data )
  385. {
  386. for( $i=1;$i<6;$i++ )
  387. {
  388. $totalInfos[$i] += $data[$i];
  389. }
  390. }
  391.  
  392. $totalInfos[5] = round($totalInfos[2]/$totalInfos[4],2);
  393.  
  394. printInfos($totalInfos,15);
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
    Департамент     Работников       Зарплата    Расход кофе Результат(стр)  Расход на стр
        закупок             17         9612.5            350           3300           2.91
         продаж             18          11150            520           2575           4.33
        рекламы             36          16300            575           5600           2.91
      логистики             19           8250            325           3050            2.7
          итого             90        45312.5           1770          14525           3.12