fork(2) download
  1. <?php
  2. class Company
  3. {
  4. const NAME_COMPANY = 'vector';
  5. public $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.  
  78.  
  79. class Departament
  80. {
  81. private $departament_name;
  82. private $workers = array();
  83.  
  84. public function __construct($name)
  85. {
  86. $this->set_Departament_Name($name);
  87. }
  88.  
  89. public function get_Departament_Name()
  90. {
  91. return $this->departament_name;
  92. }
  93.  
  94. public function set_Departament_Name($name)
  95. {
  96. $this->departament_name = $name;
  97. }
  98.  
  99. public function add_Workers($count, $rank, $proffesion, $is_Head)
  100. {
  101. for ($i = 0; $i < $count; $i++) {
  102. $worker = new $proffesion($rank, $is_Head);
  103. $this->workers[] = $worker;
  104. }
  105. }
  106.  
  107. public function get_Sum_Workers()
  108. {
  109. return count($this->workers);
  110. echo count($this->workers->salary);
  111. }
  112.  
  113. public function get_Sum_Salary()
  114. {
  115. foreach ($this->workers as $worker) {
  116. $sum_salary = $sum_salary+$worker->get_Salary($worker);
  117. }
  118. return $sum_salary;
  119. }
  120.  
  121. public function get_Sum_Coffee()
  122. {
  123. foreach ($this->workers as $worker) {
  124. $sum_coffee += $worker->get_Coffee($worker);
  125. }
  126. return $sum_coffee;
  127. }
  128.  
  129. public function get_Sum_Pages()
  130. {
  131. foreach ($this->workers as $worker) {
  132. $sum_pages += $worker->get_Pages($worker);
  133. }
  134. return $sum_pages;
  135. }
  136.  
  137. public function get_Salary_For_Page()
  138. {
  139. $salary = $this->get_Sum_Salary();
  140. $pages = $this->get_Sum_Pages();
  141. return round($salary/$pages, 3);
  142. }
  143. }
  144.  
  145.  
  146. abstract class Worker
  147. {
  148. private $rank;
  149. private $proffesion;
  150. private $is_Head;
  151. private $salary;
  152. private $consumed_coffee;
  153. private $made_pages;
  154.  
  155. public function __construct($rank, $proffesion, $is_Head, $salary, $consumed_coffe, $made_pages)
  156. {
  157. $this->set_Rank($rank);
  158. $this->set_Proffesion($proffesion);
  159. $this->set_Is_Head($is_Head);
  160. $this->set_Salary($salary);
  161. $this->set_Consumed_Coffee($consumed_coffe);
  162. $this->set_Made_Pages($made_pages);
  163. }
  164.  
  165. public function set_Rank($rank)
  166. {
  167. $this->rank = $rank;
  168. }
  169.  
  170. public function set_Proffesion($proffesion)
  171. {
  172. $this->proffesion = $proffesion;
  173. }
  174.  
  175. public function set_Is_Head($is_Head)
  176. {
  177. $this->is_Head = $is_Head;
  178. }
  179.  
  180. public function set_Salary($salary)
  181. {
  182. $this->salary = $salary;
  183. }
  184.  
  185. public function set_Consumed_Coffee($consumed_coffee)
  186. {
  187. $this->consumed_coffee = $consumed_coffee;
  188. }
  189.  
  190. public function set_Made_Pages($made_pages)
  191. {
  192. $this->made_pages = $made_pages;
  193. }
  194.  
  195. public function get_Salary($worker)
  196. {
  197. $rank = $this->rank;
  198. if ($rank == 1) {
  199. $coef_salary = 1;
  200. }elseif ($rank == 2) {
  201. $coef_salary = 1.25;
  202. }elseif ($rank == 3) {
  203. $coef_salary = 1.5;
  204. }
  205. if ($this->is_Head == true) {
  206. $coef_head = 1.5;
  207. }else{
  208. $coef_head = 1;
  209. }
  210. return $this->salary*$coef_salary*$coef_head;
  211. }
  212.  
  213. public function get_Coffee($worker)
  214. {
  215. if ($this->is_Head == true) {
  216. $coef_head = 2;
  217. }else{
  218. $coef_head = 1;
  219. }
  220. return $this->consumed_coffee*$coef_head;
  221. }
  222.  
  223. public function get_Pages($worker)
  224. {
  225. if ($this->is_Head == true) {
  226. $coef_head = 0;
  227. }else{
  228. $coef_head = 1;
  229. }
  230. return $this->made_pages*$coef_head;
  231. }
  232. }
  233.  
  234. class Manager extends Worker
  235. {
  236. public function __construct($rank, $is_Head)
  237. {
  238. parent::__construct($rank, 'Marketer', $is_Head, 500, 20, 200);
  239. }
  240. }
  241.  
  242. class Marketer extends Worker
  243. {
  244. public function __construct($rank, $is_Head)
  245. {
  246. parent::__construct($rank, 'Marketer', $is_Head, 400, 15, 150);
  247. }
  248. }
  249. class Engineer extends Worker
  250. {
  251. public function __construct($rank, $is_Head)
  252. {
  253. parent::__construct($rank, 'Marketer', $is_Head, 200, 5, 50);
  254. }
  255. }
  256. class Analyst extends Worker
  257. {
  258. public function __construct($rank, $is_Head)
  259. {
  260. parent::__construct($rank, 'Marketer', $is_Head, 800, 50, 5);
  261. }
  262. }
  263.  
  264. $company = new Company;
  265.  
  266. $departament_purchase = new Departament("Purchase");
  267. $departament_purchase->add_Workers(9, 1, 'Manager', false);
  268. $departament_purchase->add_Workers(3, 2, 'Manager', false);
  269. $departament_purchase->add_Workers(2, 3, 'Manager', false);
  270. $departament_purchase->add_Workers(2, 1, 'Marketer', false);
  271. $departament_purchase->add_Workers(1, 2, 'Manager', true);
  272. $company->add_departament($departament_purchase);
  273.  
  274. $departament_sales = new Departament("Sales");
  275. $departament_sales->add_Workers(12, 1, 'Manager', false);
  276. $departament_sales->add_Workers(6, 1, 'Marketer', false);
  277. $departament_sales->add_Workers(3, 1, 'Analyst', false);
  278. $departament_sales->add_Workers(2, 2, 'Analyst', false);
  279. $departament_sales->add_Workers(1, 2, 'Marketer', true);
  280. $company->add_departament($departament_sales);
  281.  
  282. $departament_advertising = new Departament("advertising");
  283. $departament_advertising->add_Workers(15, 1, 'Marketer', false);
  284. $departament_advertising->add_Workers(10, 2, 'Marketer', false);
  285. $departament_advertising->add_Workers(8, 1, 'Manager', false);
  286. $departament_advertising->add_Workers(2, 1, 'Engineer', false);
  287. $departament_advertising->add_Workers(1, 3, 'Marketer', true);
  288. $company->add_departament($departament_advertising);
  289.  
  290. $departament_logistics = new Departament("Logistics");
  291. $departament_logistics->add_Workers(13, 1, 'Manager', false);
  292. $departament_logistics->add_Workers(5, 2, 'Manager', false);
  293. $departament_logistics->add_Workers(5, 1, 'Engineer', false);
  294. $departament_logistics->add_Workers(1, 1, 'Manager', true);
  295. $company->add_departament($departament_logistics);
  296.  
  297. function padRight($string, $length)
  298. {
  299. $long_string = strlen ($string);
  300. $x = $length-$long_string;
  301. $space = str_repeat(" ",$x);
  302. echo $string.$space;
  303. }
  304.  
  305. function padLeft($string, $length)
  306. {
  307. $long_string = strlen ($string);
  308. $x = $length-$long_string;
  309. $space = str_repeat(" ",$x);
  310. echo $space.$string;
  311. }
  312. $col1 = 12;
  313. $col2 = 12;
  314. $col3 = 16;
  315.  
  316. // Заголовок таблицы
  317. echo padRight ("Departaments",$col1).
  318. padLeft("Workers", $col2) .
  319. padLeft("Salary", $col2) .
  320. padLeft("Coffee", $col2) .
  321. padLeft("Pages", $col2) .
  322. padLeft("Salary/Pages", $col3) ."\n";
  323.  
  324. echo "----------------------------------------------------------------------\n";
  325. foreach ($company->departaments as $departament) {
  326. echo padRight($departament->get_Departament_Name(), $col2);
  327. echo padLeft($departament->get_Sum_Workers(), $col2);
  328. echo padLeft($departament->get_Sum_Salary(), $col2);
  329. echo padLeft($departament->get_Sum_Coffee(), $col2);
  330. echo padLeft($departament->get_Sum_Pages(), $col2);
  331. echo padLeft($departament->get_Salary_For_Page(), $col3)."\n";
  332. }
  333. echo "----------------------------------------------------------------------\n";
  334. echo padRight('Average', $col2);
  335. echo padLeft($company->get_Average_Workers(), $col2);
  336. echo padLeft($company->get_Average_Salary(), $col2);
  337. echo padLeft($company->get_Average_Coffee(), $col2);
  338. echo padLeft($company->get_Average_Pages(), $col2);
  339. echo padLeft($company->get_Average_Salary_For_Page(), $col3)."\n";
  340. echo "----------------------------------------------------------------------\n";
  341. echo padRight('VSEGO', $col2);
  342. echo padLeft($company->get_Count_Workers(), $col2);
  343. echo padLeft($company->get_Count_Salary(), $col2);
  344. echo padLeft($company->get_Count_Coffee(), $col2);
  345. echo padLeft($company->get_Count_Pages(), $col2);
  346. echo padLeft($company->get_Count_Salary_For_Page(), $col3)."\n";
  347.  
  348.  
  349.  
Success #stdin #stdout #stderr 0.01s 82880KB
stdin
Standard input is empty
stdout
Departaments     Workers      Salary      Coffee       Pages    Salary/Pages
----------------------------------------------------------------------
Purchase              17      9612.5         350        3100           3.101
Sales                 24       13550         610        3325           4.075
advertising           36       16300         575        5450           2.991
Logistics             24       11375         425        3850           2.955
----------------------------------------------------------------------
Average            25.25   12709.375         490     3931.25          3.2805
----------------------------------------------------------------------
VSEGO                101     50837.5        1960       15725          13.122
stderr
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_coffee in /home/4gP9VM/prog.php on line 124
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_coffee in /home/4gP9VM/prog.php on line 124
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_coffee in /home/4gP9VM/prog.php on line 124
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_coffee in /home/4gP9VM/prog.php on line 124
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: count_workers in /home/4gP9VM/prog.php on line 15
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: count_salary in /home/4gP9VM/prog.php on line 28
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_coffee in /home/4gP9VM/prog.php on line 124
PHP Notice:  Undefined variable: count_coffee in /home/4gP9VM/prog.php on line 41
PHP Notice:  Undefined variable: sum_coffee in /home/4gP9VM/prog.php on line 124
PHP Notice:  Undefined variable: sum_coffee in /home/4gP9VM/prog.php on line 124
PHP Notice:  Undefined variable: sum_coffee in /home/4gP9VM/prog.php on line 124
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: count_pages in /home/4gP9VM/prog.php on line 54
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: count_salary_for_page in /home/4gP9VM/prog.php on line 67
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: count_workers in /home/4gP9VM/prog.php on line 15
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: count_salary in /home/4gP9VM/prog.php on line 28
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_coffee in /home/4gP9VM/prog.php on line 124
PHP Notice:  Undefined variable: count_coffee in /home/4gP9VM/prog.php on line 41
PHP Notice:  Undefined variable: sum_coffee in /home/4gP9VM/prog.php on line 124
PHP Notice:  Undefined variable: sum_coffee in /home/4gP9VM/prog.php on line 124
PHP Notice:  Undefined variable: sum_coffee in /home/4gP9VM/prog.php on line 124
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: count_pages in /home/4gP9VM/prog.php on line 54
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: count_salary_for_page in /home/4gP9VM/prog.php on line 67
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132
PHP Notice:  Undefined variable: sum_salary in /home/4gP9VM/prog.php on line 116
PHP Notice:  Undefined variable: sum_pages in /home/4gP9VM/prog.php on line 132