fork download
  1. <!DOCTYPE HTML>
  2. <html lang="eng">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Getting started in PHP</title>
  6. </head>
  7. <body>
  8. <?php
  9.  
  10. class Department //завершен
  11. {
  12. private $name ;
  13. private $employees = array() ;
  14. function __construct( string $n )
  15. {
  16. $this -> name = $n ;
  17. }
  18. public function addEmployee( Employee $emp )
  19. {
  20. $this -> employees[] = $emp ;
  21. }
  22. public function getEmployee( int $n ) : Employee
  23. {
  24. return $this -> employees[$n] ;
  25. }
  26. public function addEmployees( array $emp )
  27. {
  28. foreach( $emp as $value ) { $this -> employees[] = $value ; }
  29. }
  30. public function getEmployees( ) : array
  31. {
  32. return $this -> employees ;
  33. }
  34. public function getName() : string
  35. {
  36. return $this -> name ;
  37. }
  38. public function countEmployees () : int
  39. {
  40. return count( $this -> employees ) ;
  41. }
  42. public function getOverallSalary () : float
  43. {
  44. $sum = 0 ;
  45. foreach( $this -> employees as $value ) { $sum += $value -> getSalary() ;}
  46. return $sum ;
  47. }
  48. public function getOverallCoffee () : float
  49. {
  50. $sum = 0 ;
  51. foreach( $this -> employees as $value ) { $sum += $value -> getCoffee() ;}
  52. return $sum ;
  53. }
  54. public function getOverallDocuments () : int
  55. {
  56. $sum = 0 ;
  57. foreach( $this -> employees as $value ) { $sum += $value -> getDocuments() ;}
  58. return $sum ;
  59. }
  60. public function salaryDocumentRatio () : float
  61. {
  62. return $this -> getOverallSalary() / $this -> getOverallDocuments() ;
  63. }
  64. }
  65.  
  66.  
  67. class Employee //завершен
  68. {
  69. private $occupation ;
  70. private $ishead ;
  71. function __construct( Occupation $occ , int $r = 1 , bool $i = false)
  72. {
  73. $this -> rank = $r ;
  74. $this -> occupation = $occ ;
  75. $this -> ishead = $i ;
  76. }
  77. public function setHead()
  78. {
  79. $this -> ishead = true ;
  80. }
  81. public function changeOccupation( Occupation $occ )
  82. {
  83. $this -> occupation = $occ ;
  84. }
  85. public function changeRank( int $r )
  86. {
  87. $this -> rank = $r ;
  88. }
  89. public function getSalary() : float
  90. {
  91. switch( $this -> rank )
  92. {
  93. case 1 : $sum = $this -> occupation -> getBaseSalary() ; break ;
  94. case 2 : $sum = ( $this -> occupation -> getBaseSalary() )*1.25 ; break ;
  95. case 3 : $sum = ( $this -> occupation -> getBaseSalary() )*1.5 ; break ;
  96. }
  97. if( $this -> ishead) { $sum *= 1.5 ;}
  98. return $sum ;
  99. }
  100. public function getDocuments() : int
  101. {
  102. return ($this -> ishead) ? 0 : $this -> occupation -> getBaseDocuments() ;
  103. }
  104. public function getCoffee() : float
  105. {
  106. return ($this -> ishead) ? ($this -> occupation -> getBaseCoffee())*2 : $this -> occupation -> getBaseCoffee() ;
  107. }
  108. }
  109.  
  110.  
  111. class Occupation //завершен
  112. {
  113. private $name ;
  114. private $base_salary ;
  115. private $base_coffee ;
  116. private $base_documents ;
  117. function __construct( string $n , float $bs , float $bc , int $bd)
  118. {
  119. $this -> name = $n ;
  120. $this -> base_salary = $bs ;
  121. $this -> base_coffee = $bc ;
  122. $this -> base_documents = $bd ;
  123. }
  124. public function getName() : string
  125. {
  126. return $this -> name ;
  127. }
  128. public function getBaseSalary() : float
  129. {
  130. return $this -> base_salary ;
  131. }
  132. public function getBaseDocuments() : int
  133. {
  134. return $this -> base_documents ;
  135. }
  136. public function getBaseCoffee() : int
  137. {
  138. return $this -> base_coffee ;
  139. }
  140. }
  141.  
  142. function createEmployees( int $n , int $r , Occupation $occ , Department $dpt )
  143. {
  144. $i = 0 ;
  145. while ( $i < $n )
  146. {
  147. $dpt -> addEmployee( new Employee( $occ , $r ) ) ;
  148. $i++ ;
  149. }
  150. }
  151.  
  152. function createReport( Department ...$dep )
  153. {
  154. $sum1 = 0 ;
  155. $sum2 = 0;
  156. $sum3 = 0;
  157. $sum4 = 0;
  158. $sum5 = 0;
  159. echo "<table><tr><td>Департамент</td><td>Сотрудники</td><td>Зарплата</td><td>Кофе</td><td>Документы</td><td>Тугр./Докум.</td></tr>" ;
  160. foreach( $dep as $value )
  161. {
  162. echo "<tr><td>" .$value -> getName() ."</td><td>" .$value -> countEmployees() ."</td><td>" .$value -> getOverallSalary() ."</td><td>" .$value -> getOverallCoffee()
  163. ."</td><td>" .$value -> getOverallDocuments() ."</td><td>" .number_format( $value -> salaryDocumentRatio() , 2 ) ."</td></tr>" ;
  164. $sum1 += $value -> countEmployees() ;
  165. $sum2 += $value -> getOverallSalary() ;
  166. $sum3 += $value -> getOverallCoffee() ;
  167. $sum4 += $value -> getOverallDocuments() ;
  168. $sum5 += number_format( $value -> salaryDocumentRatio() , 2 ) ;
  169. }
  170. echo "<tr><td>Всего</td><td>$sum1</td><td>$sum2</td><td>$sum3</td><td>$sum4</td><td>$sum5</td></tr>" ;
  171. echo "</table>" ;
  172. }
  173.  
  174.  
  175. //создаем профессии и департаменты
  176. $manager = new Occupation( 'Менеджер' , 500 , 20 , 200 ) ;
  177. $market = new Occupation( 'Маркетолог' , 400 , 15 , 150 ) ;
  178. $engineer = new Occupation( 'Инженер' , 200 , 5 , 50 ) ;
  179. $analyst = new Occupation( 'Аналитик' , 800 , 50 , 5 ) ;
  180. $buy = new Department( 'Закупок' ) ;
  181. $sales = new Department( 'Продаж' ) ;
  182. $advert = new Department( 'Рекламы' ) ;
  183. $logist = new Department( 'Логистики' ) ;
  184.  
  185. //заполняем департамен закупок
  186. createEmployees( 9 , 1 , $manager , $buy ) ;
  187. createEmployees( 3 , 2 , $manager , $buy ) ;
  188. createEmployees( 2 , 3 , $manager , $buy ) ;
  189. createEmployees( 2 , 1 , $market , $buy ) ;
  190. $head_buy = new Employee( $manager , 2 , true ) ;
  191. $buy -> addEmployee( $head_buy ) ;
  192. //заполняем департамент продаж
  193. createEmployees( 12 , 1 , $manager , $sales ) ;
  194. createEmployees( 6 , 1 , $market , $sales ) ;
  195. createEmployees( 3 , 1 , $analyst , $sales ) ;
  196. createEmployees( 2 , 2 , $analyst , $sales ) ;
  197. $head_sales = new Employee( $market , 2 , true ) ;
  198. $sales -> addEmployee( $head_sales ) ;
  199. //создаем департамент рекламы
  200. createEmployees( 15 , 1 , $market , $advert ) ;
  201. createEmployees( 10 , 2 , $market , $advert ) ;
  202. createEmployees( 8 , 1 , $manager , $advert ) ;
  203. createEmployees( 2 , 1 , $engineer , $advert ) ;
  204. $head_advert = new Employee( $market , 3 , true ) ;
  205. $advert -> addEmployee( $head_advert ) ;
  206. //создаем департамент логистики
  207. createEmployees( 13 , 1 , $manager , $logist ) ;
  208. createEmployees( 5 , 2 , $manager , $logist ) ;
  209. createEmployees( 5 , 1 , $engineer , $logist ) ;
  210. $head_logist = new Employee( $manager , 1 , true ) ;
  211. $logist -> addEmployee( $head_logist ) ;
  212.  
  213. createReport( $logist , $advert , $sales , $buy ) ;
  214. ?>
  215. </body>
  216. </html>
Success #stdin #stdout 0.02s 82560KB
stdin
Standard input is empty
stdout
<!DOCTYPE HTML>
<html lang="eng">
<head>
<meta charset="UTF-8">
<title>Getting started in PHP</title>
</head>
<body>
<table><tr><td>Департамент</td><td>Сотрудники</td><td>Зарплата</td><td>Кофе</td><td>Документы</td><td>Тугр./Докум.</td></tr><tr><td>Логистики</td><td>24</td><td>11375</td><td>425</td><td>3850</td><td>2.95</td></tr><tr><td>Рекламы</td><td>36</td><td>16300</td><td>575</td><td>5450</td><td>2.99</td></tr><tr><td>Продаж</td><td>24</td><td>13550</td><td>610</td><td>3325</td><td>4.08</td></tr><tr><td>Закупок</td><td>17</td><td>9612.5</td><td>350</td><td>3100</td><td>3.10</td></tr><tr><td>Всего</td><td>101</td><td>50837.5</td><td>1960</td><td>15725</td><td>13.12</td></tr></table> 
</body>
</html>