fork(1) download
  1. <?php
  2. class Company
  3. {
  4. const NAME_COMPANY = 'vector';
  5. private $departaments = array();
  6.  
  7. public function add_departament($departament)
  8. {
  9. $this->departaments [] = $departament;
  10. }
  11.  
  12. public function get_Count_Workers()
  13. {
  14. foreach ($this->departaments as $departament) {
  15. $count_workers += $departament->get_Sum_Workers();
  16. }
  17. return $count_workers;
  18. }
  19.  
  20. public function get_Average_Workers()
  21. {
  22. return $this->get_Count_Workers()/count($this->departaments);
  23. }
  24.  
  25. public function get_Count_Salary()
  26. {
  27. foreach ($this->departaments as $departament) {
  28. $count_salary += $departament->get_Sum_Salary();
  29. }
  30. return $count_salary;
  31. }
  32.  
  33. public function get_Average_Salary()
  34. {
  35. return $this->get_Count_Salary()/count($this->departaments);
  36. }
  37.  
  38. public function get_Count_Coffee()
  39. {
  40. foreach ($this->departaments as $departament) {
  41. $count_coffee += $departament->get_Sum_Coffee();
  42. }
  43. return $count_coffee;
  44. }
  45.  
  46. public function get_Average_Coffee()
  47. {
  48. return $this->get_Count_Coffee()/count($this->departaments);
  49. }
  50.  
  51. public function get_Count_Pages()
  52. {
  53. foreach ($this->departaments as $departament) {
  54. $count_pages += $departament->get_Sum_Pages();
  55. }
  56. return $count_pages;
  57. }
  58.  
  59. public function get_Average_Pages()
  60. {
  61. return $this->get_Count_Pages()/count($this->departaments);
  62. }
  63.  
  64. public function get_Count_Salary_For_Page()
  65. {
  66. foreach ($this->departaments as $departament) {
  67. $count_salary_for_page += $departament->get_Salary_For_Page();
  68. }
  69. return $count_salary_for_page;
  70. }
  71.  
  72. public function get_Average_Salary_For_Page()
  73. {
  74. return $this->get_Count_Salary_For_Page()/count($this->departaments);
  75. }
  76.  
  77. public function print_Info()
  78. {
  79. $col2 = 12;
  80. $col3 = 15;
  81. foreach ($this->departaments as $departament) {
  82. echo padRight($departament->get_Departament_Name(), $col2);
  83. echo padLeft($departament->get_Sum_Workers(), $col2);
  84. echo padLeft($departament->get_Sum_Salary(), $col2);
  85. echo padLeft($departament->get_Sum_Coffee(), $col2);
  86. echo padLeft($departament->get_Sum_Pages(), $col2);
  87. echo padLeft($departament->get_Salary_For_Page(), $col3)."\n";
  88. }
  89. }
  90.  
  91. //Cократить в каждом департаменте 40% (округляя в большую сторону) инженеров,
  92. //преимущественно самого низкого ранга. Если инженер является боссом, вместо него
  93. //надо уволить другого инженера, не босса.
  94. public function Destruction_Workers($count_in_percent, $proffesion)
  95. {
  96. foreach ($this->departaments as $departament) {
  97. $count_workers = $departament->get_Workers_For_Destruction($count_in_percent, $proffesion);
  98. }
  99. }
  100. }
  101.  
  102.  
  103. class Departament
  104. {
  105. private $departament_name;
  106. private $workers = array();
  107.  
  108. public function __construct($name)
  109. {
  110. $this->set_Departament_Name($name);
  111. }
  112.  
  113. public function get_Departament_Name()
  114. {
  115. return $this->departament_name;
  116. }
  117.  
  118. public function set_Departament_Name($name)
  119. {
  120. $this->departament_name = $name;
  121. }
  122.  
  123. public function add_Workers($count, $rank, $proffesion, $is_Head)
  124. {
  125. for ($i = 0; $i < $count; $i++) {
  126. $worker = new $proffesion($rank, $is_Head);
  127. $this->workers[] = $worker;
  128. }
  129. }
  130.  
  131. public function get_Sum_Workers()
  132. {
  133. return count($this->workers);
  134. echo count($this->workers->salary);
  135. }
  136.  
  137. public function get_Sum_Salary()
  138. {
  139. foreach ($this->workers as $worker) {
  140. $sum_salary = $sum_salary+$worker->get_Salary($worker);
  141. }
  142. return $sum_salary;
  143. }
  144.  
  145. public function get_Sum_Coffee()
  146. {
  147. foreach ($this->workers as $worker) {
  148. $sum_coffee += $worker->get_Coffee($worker);
  149. }
  150. return $sum_coffee;
  151. }
  152.  
  153. public function get_Sum_Pages()
  154. {
  155. foreach ($this->workers as $worker) {
  156. $sum_pages += $worker->get_Pages($worker);
  157. }
  158. return $sum_pages;
  159. }
  160.  
  161. public function get_Salary_For_Page()
  162. {
  163. $salary = $this->get_Sum_Salary();
  164. $pages = $this->get_Sum_Pages();
  165. return round($salary/$pages, 3);
  166. }
  167.  
  168. public function get_Workers_For_Destruction($count_in_percent,$proffesion)
  169. {
  170. foreach ($this->workers as $worker) {
  171. if ($worker->get_Proffesion() == $proffesion) {
  172. $count_workers ++;
  173. }
  174. }
  175. $sum_to_destroy = $count_workers - (floor($count_workers/$count_in_percent));
  176. $i = 0;
  177. foreach ($this->workers as $worker) {
  178. if ($worker->get_Proffesion() == $proffesion && $i < $sum_to_destroy) {
  179. unset($worker);
  180. }
  181. }
  182. }
  183. }
  184.  
  185.  
  186. abstract class Worker
  187. {
  188. private $rank;
  189. private $proffesion;
  190. private $is_Head;
  191. private $salary;
  192. private $consumed_coffee;
  193. private $made_pages;
  194.  
  195. public function __construct($rank, $proffesion, $is_Head, $salary, $consumed_coffe, $made_pages)
  196. {
  197. $this->set_Rank($rank);
  198. $this->set_Proffesion($proffesion);
  199. $this->set_Is_Head($is_Head);
  200. $this->set_Salary($salary);
  201. $this->set_Consumed_Coffee($consumed_coffe);
  202. $this->set_Made_Pages($made_pages);
  203. }
  204.  
  205. public function set_Rank($rank)
  206. {
  207. $this->rank = $rank;
  208. }
  209.  
  210. public function set_Proffesion($proffesion)
  211. {
  212. $this->proffesion = $proffesion;
  213. }
  214.  
  215. public function set_Is_Head($is_Head)
  216. {
  217. $this->is_Head = $is_Head;
  218. }
  219.  
  220. public function set_Salary($salary)
  221. {
  222. $this->salary = $salary;
  223. }
  224.  
  225. public function set_Consumed_Coffee($consumed_coffee)
  226. {
  227. $this->consumed_coffee = $consumed_coffee;
  228. }
  229.  
  230. public function set_Made_Pages($made_pages)
  231. {
  232. $this->made_pages = $made_pages;
  233. }
  234.  
  235. public function get_Salary($worker)
  236. {
  237. $rank = $this->rank;
  238. if ($rank == 1) {
  239. $coef_salary = 1;
  240. }elseif ($rank == 2) {
  241. $coef_salary = 1.25;
  242. }elseif ($rank == 3) {
  243. $coef_salary = 1.5;
  244. }
  245. if ($this->is_Head == true) {
  246. $coef_head = 1.5;
  247. }else{
  248. $coef_head = 1;
  249. }
  250. return $this->salary*$coef_salary*$coef_head;
  251. }
  252.  
  253. public function get_Coffee($worker)
  254. {
  255. if ($this->is_Head == true) {
  256. $coef_head = 2;
  257. }else{
  258. $coef_head = 1;
  259. }
  260. return $this->consumed_coffee*$coef_head;
  261. }
  262.  
  263. public function get_Pages($worker)
  264. {
  265. if ($this->is_Head == true) {
  266. $coef_head = 0;
  267. }else{
  268. $coef_head = 1;
  269. }
  270. return $this->made_pages*$coef_head;
  271. }
  272.  
  273. public function get_Proffesion()
  274. {
  275. return $this->proffesion;
  276. }
  277. }
  278.  
  279. class Manager extends Worker
  280. {
  281. public function __construct($rank, $is_Head)
  282. {
  283. parent::__construct($rank, 'Manager', $is_Head, 500, 20, 200);
  284. }
  285. }
  286.  
  287. class Marketer extends Worker
  288. {
  289. public function __construct($rank, $is_Head)
  290. {
  291. parent::__construct($rank, 'Marketer', $is_Head, 400, 15, 150);
  292. }
  293. }
  294. class Engineer extends Worker
  295. {
  296. public function __construct($rank, $is_Head)
  297. {
  298. parent::__construct($rank, 'Engineer', $is_Head, 200, 5, 50);
  299. }
  300. }
  301. class Analyst extends Worker
  302. {
  303. public function __construct($rank, $is_Head)
  304. {
  305. parent::__construct($rank, 'Analyst', $is_Head, 800, 50, 5);
  306. }
  307. }
  308.  
  309. $company = new Company;
  310.  
  311. $departament_purchase = new Departament("Purchase");
  312. $departament_purchase->add_Workers(9, 1, 'Manager', false);
  313. $departament_purchase->add_Workers(3, 2, 'Manager', false);
  314. $departament_purchase->add_Workers(2, 3, 'Manager', false);
  315. $departament_purchase->add_Workers(2, 1, 'Marketer', false);
  316. $departament_purchase->add_Workers(1, 2, 'Manager', true);
  317. $company->add_departament($departament_purchase);
  318.  
  319. $departament_sales = new Departament("Sales");
  320. $departament_sales->add_Workers(12, 1, 'Manager', false);
  321. $departament_sales->add_Workers(6, 1, 'Marketer', false);
  322. $departament_sales->add_Workers(3, 1, 'Analyst', false);
  323. $departament_sales->add_Workers(2, 2, 'Analyst', false);
  324. $departament_sales->add_Workers(1, 2, 'Marketer', true);
  325. $company->add_departament($departament_sales);
  326.  
  327. $departament_advertising = new Departament("advertising");
  328. $departament_advertising->add_Workers(15, 1, 'Marketer', false);
  329. $departament_advertising->add_Workers(10, 2, 'Marketer', false);
  330. $departament_advertising->add_Workers(8, 1, 'Manager', false);
  331. $departament_advertising->add_Workers(2, 1, 'Engineer', false);
  332. $departament_advertising->add_Workers(1, 3, 'Marketer', true);
  333. $company->add_departament($departament_advertising);
  334.  
  335. $departament_logistics = new Departament("Logistics");
  336. $departament_logistics->add_Workers(13, 1, 'Manager', false);
  337. $departament_logistics->add_Workers(5, 2, 'Manager', false);
  338. $departament_logistics->add_Workers(5, 1, 'Engineer', false);
  339. $departament_logistics->add_Workers(1, 1, 'Manager', true);
  340. $company->add_departament($departament_logistics);
  341.  
  342. function padRight($string, $length)
  343. {
  344. $long_string = strlen ($string);
  345. $x = $length-$long_string;
  346. $space = str_repeat(" ",$x);
  347. echo $string.$space;
  348. }
  349.  
  350. function padLeft($string, $length)
  351. {
  352. $long_string = strlen ($string);
  353. $x = $length-$long_string;
  354. $space = str_repeat(" ",$x);
  355. echo $space.$string;
  356. }
  357. $col1 = 12;
  358. $col2 = 12;
  359. $col3 = 16;
  360.  
  361. $company->Destruction_Workers(1.4, Engineer);
  362. echo "ВСего работников ".$company->get_Count_Workers();
  363.  
  364.  
  365. /**
  366. // Заголовок таблицы
  367. echo padRight ("Departaments",$col1).
  368.   padLeft("Workers", $col2) .
  369.   padLeft("Salary", $col2) .
  370.   padLeft("Coffee", $col2) .
  371.   padLeft("Pages", $col2) .
  372.   padLeft("Salary/Pages", $col3) ."\n";
  373.  
  374. echo "----------------------------------------------------------------------\n";
  375. $company->print_Info();
  376. echo "----------------------------------------------------------------------\n";
  377. echo padRight('Average', $col2);
  378. echo padLeft($company->get_Average_Workers(), $col2);
  379. echo padLeft($company->get_Average_Salary(), $col2);
  380. echo padLeft($company->get_Average_Coffee(), $col2);
  381. echo padLeft($company->get_Average_Pages(), $col2);
  382. echo padLeft($company->get_Average_Salary_For_Page(), $col3)."\n";
  383. echo "----------------------------------------------------------------------\n";
  384. echo padRight('VSEGO', $col2);
  385. echo padLeft($company->get_Count_Workers(), $col2);
  386. echo padLeft($company->get_Count_Salary(), $col2);
  387. echo padLeft($company->get_Count_Coffee(), $col2);
  388. echo padLeft($company->get_Count_Pages(), $col2);
  389. echo padLeft($company->get_Count_Salary_For_Page(), $col3)."\n";
  390. **/
  391.  
  392.  
  393.  
  394.  
  395.  
Success #stdin #stdout #stderr 0s 82880KB
stdin
Standard input is empty
stdout
ВСего работников 101
stderr
PHP Notice:  Use of undefined constant Engineer - assumed 'Engineer' in /home/o5k8ht/prog.php on line 361
PHP Notice:  Undefined variable: count_workers in /home/o5k8ht/prog.php on line 175
PHP Notice:  Undefined variable: count_workers in /home/o5k8ht/prog.php on line 175
PHP Notice:  Undefined variable: count_workers in /home/o5k8ht/prog.php on line 175
PHP Notice:  Undefined variable: count_workers in /home/o5k8ht/prog.php on line 175
PHP Notice:  Undefined variable: count_workers in /home/o5k8ht/prog.php on line 172
PHP Notice:  Undefined variable: count_workers in /home/o5k8ht/prog.php on line 172
PHP Notice:  Undefined variable: count_workers in /home/o5k8ht/prog.php on line 15