fork download
  1. <?php
  2. abstract class Worker{
  3.  
  4. protected $payment;
  5. protected $drink;
  6. protected $produce;
  7. protected $grade;
  8. protected $description;
  9.  
  10.  
  11. protected function getPayment($grade) {
  12. if ($grade==1){
  13. return $this->payment;
  14. }
  15. else if($grade ==2)
  16. {
  17. return $this->payment*(1/4)+($this->payment);
  18. }
  19. else if($grade==3){
  20. return $this->payment*(1/2)+($this->payment);
  21. }
  22. else if($grade ==4){ return $this->payment*(1/2)+($this->payment);}
  23. }
  24. protected function getProduce($grade){
  25. if ($grade!=4)
  26. return $this->produce;
  27. else return $this->produce*0;
  28. }
  29. protected function getDrink($grade){
  30. if ($grade==4) return $this->drink+((1/2)*$this->drink);
  31. else return $this->drink;
  32. }
  33. }
  34.  
  35. class Manager extends Worker{
  36.  
  37. public $payment = 500;
  38. public $drink = 20;
  39. public $produce = 200;
  40. public function __construct($grade) {
  41. $this->payment = $this->getPayment($grade);
  42. $this->drink = $this ->getDrink($grade);
  43. $this ->produce = $this->getProduce($grade);
  44. $this->grade = $grade;
  45. $this->description = "me" . $grade;
  46.  
  47. }
  48. public function getInfo(){
  49. $arr=[];
  50. $wrk = new Manager($this->grade);
  51. foreach($wrk as $value){
  52. $arr[]=$value;
  53. }
  54. return $arr;
  55. }
  56. }
  57.  
  58. class Marketer extends Worker{
  59.  
  60. public $payment = 400;
  61. public $drink = 15;
  62. public $produce = 150;
  63. public function __construct($grade) {
  64. $this->payment = $this->getPayment($grade);
  65. $this->drink = $this ->getDrink($grade);
  66. $this ->produce = $this->getProduce($grade);
  67. $this->grade = $grade;
  68. $this->description = "ma" . $grade;
  69.  
  70. }
  71.  
  72. public function getInfo(){
  73. $arr=[];
  74. $wrk = new Marketer($this->grade);
  75. foreach($wrk as $value){
  76. $arr[]=$value;
  77. }
  78. return $arr;
  79. }
  80. }
  81. class Engineer extends Worker{
  82. public $payment = 200;
  83. public $drink = 5;
  84. public $produce = 50;
  85.  
  86. public function __construct($grade) {
  87. $this->payment = $this->getPayment($grade);
  88. $this->drink = $this ->getDrink($grade);
  89. $this ->produce = $this->getProduce($grade);
  90. $this->grade = $grade;
  91. $this->description = "en" . $grade;
  92.  
  93. }
  94. public function getInfo(){
  95. $arr=[];
  96. $wrk = new Engineer($this->grade);
  97. foreach($wrk as $value){
  98. $arr[]=$value;
  99. }
  100. return $arr;
  101. }
  102.  
  103. }
  104. class Analyst extends Worker{
  105.  
  106. public $payment = 800;
  107. public $drink = 50;
  108. public $produce = 5;
  109. public function __construct($grade) {
  110. $this->payment = $this->getPayment($grade);
  111. $this->drink = $this ->getDrink($grade);
  112. $this ->produce = $this->getProduce($grade);
  113. $this->grade = $grade;
  114. $this->description = "an" . $grade;
  115.  
  116. }
  117. public function getInfo(){
  118. $arr=[];
  119. $wrk = new Analyst($this->grade);
  120. foreach($wrk as $value){
  121. $arr[]=$value;
  122. }
  123. return $arr;
  124. }
  125. }
  126.  
  127.  
  128. class Department{
  129.  
  130. public function FirstDep(){
  131. $dep1 = [];
  132. for ($i=0;$i<9;$i++){
  133. $a=new Manager(1);
  134. $dep1[] = $a->getInfo();
  135.  
  136. }
  137. for ($i=0;$i<3;$i++){
  138. $a=new Manager(2);
  139. $dep1[] = $a->getInfo();
  140. }
  141. for ($i=0;$i<2;$i++){
  142. $a=new Manager(3);
  143. $dep1[] = $a->getInfo();
  144. }
  145. for ($i=0;$i<2;$i++){
  146. $a=new Marketer(1);
  147. $dep1[] = $a->getInfo();
  148. }
  149. return $dep1;
  150. }
  151. public function SecondDep(){
  152. $dep1 = [];
  153. for ($i=0;$i<12;$i++){
  154. $a=new Manager(1);
  155. $dep1[] = $a->getInfo();
  156.  
  157. }
  158. for ($i=0;$i<6;$i++){
  159. $a=new Marketer(1);
  160. $dep1[] = $a->getInfo();
  161. }
  162. for ($i=0;$i<3;$i++){
  163. $a=new Analyst(1);
  164. $dep1[] = $a->getInfo();
  165. }
  166. for ($i=0;$i<2;$i++){
  167. $a=new Analyst(2);
  168. $dep1[] = $a->getInfo();
  169. }
  170. return $dep1;
  171. }
  172. public function ThirdDep(){
  173. $dep1 = [];
  174. for ($i=0;$i<15;$i++){
  175. $a=new Marketer(1);
  176. $dep1[] = $a->getInfo();
  177.  
  178. }
  179. for ($i=0;$i<10;$i++){
  180. $a=new Marketer(2);
  181. $dep1[] = $a->getInfo();
  182. }
  183. for ($i=0;$i<8;$i++){
  184. $a=new Manager(1);
  185. $dep1[] = $a->getInfo();
  186. }
  187. for ($i=0;$i<2;$i++){
  188. $a=new Engineer(1);
  189. $dep1[] = $a->getInfo();
  190. }
  191. return $dep1;
  192. }
  193. public function FourthDep(){
  194. $dep1 = [];
  195. for ($i=0;$i<13;$i++){
  196. $a=new Manager(1);
  197. $dep1[] = $a->getInfo();
  198.  
  199. }
  200. for ($i=0;$i<5;$i++){
  201. $a=new Manager(2);
  202. $dep1[] = $a->getInfo();
  203. }
  204. for ($i=0;$i<5;$i++){
  205. $a=new Engineer(1);
  206. $dep1[] = $a->getInfo();
  207. }
  208. return $dep1;
  209. }
  210.  
  211.  
  212. public function arraysum($var, $array){
  213. $sum=[];
  214.  
  215.  
  216.  
  217. foreach ($array as $value ){
  218. for ($i=0;$i<count($value[$var]);$i++){
  219. $sum[] =$value[$var];
  220. }
  221. }
  222. return array_sum($sum);
  223. }
  224.  
  225. public function ArrayMiddle($number){
  226.  
  227.  
  228. $middle = new Department();
  229. $a= $middle->arraysum($number,$middle->FirstDep());
  230. $b= $middle->arraysum($number,$middle->SecondDep());
  231. $c= $middle->arraysum($number,$middle->ThirdDep());
  232. $d= $middle->arraysum($number,$middle->FourthDep());
  233. $sum = $a+$b+$c+$d;
  234. return $sum;
  235.  
  236.  
  237. }
  238.  
  239. }
  240.  
  241. function padRight($string, $length){
  242. return $string.= str_repeat(" ", $length-mb_strlen($string));
  243.  
  244. }
  245. function padLeft($string, $length){
  246. $string = str_repeat(" ", $length-mb_strlen($string)) .$string;
  247. return $string;
  248. }
  249.  
  250. $firstdep = new Department();
  251.  
  252.  
  253. $col1 = 30;
  254. $col2 = 10;
  255. echo"<pre>";
  256. echo padRight("Департамент", $col1).
  257. padLeft("сотр", $col2).
  258. padLeft("тугр.", $col2).
  259. padLeft("кофе", $col2).
  260. padLeft("стр.", $col2).
  261. padLeft("тугр./стр", $col2). " <br>";
  262.  
  263. for ($i=0;$i<50;$i++){
  264. echo "_ ";
  265. }
  266. echo"<br>";
  267. echo"<br>";
  268. echo padRight("Закупок", $col1).
  269. padLeft(count($firstdep->FirstDep()), $col2).
  270. padLeft($firstdep->arraysum(0,$firstdep->FirstDep()), $col2).
  271. padLeft($firstdep->arraysum(1,$firstdep->FirstDep()), $col2).
  272. padLeft($firstdep->arraysum(2,$firstdep->FirstDep()), $col2).
  273. padLeft(round($firstdep->arraysum(0,$firstdep->FirstDep())/$firstdep->arraysum(2,$firstdep->FirstDep())), $col2). " <br>";
  274.  
  275. echo"<br>";
  276. echo padRight("Продаж", $col1).
  277. padLeft(count($firstdep->SecondDep()), $col2).
  278. padLeft($firstdep->arraysum(0,$firstdep->SecondDep()), $col2).
  279. padLeft($firstdep->arraysum(1,$firstdep->SecondDep()), $col2).
  280. padLeft($firstdep->arraysum(2,$firstdep->SecondDep()), $col2).
  281. padLeft(round($firstdep->arraysum(0,$firstdep->SecondDep())/$firstdep->arraysum(2,$firstdep->SecondDep())), $col2). " <br>";
  282.  
  283. echo"<br>";
  284. echo padRight("Рекламы", $col1).
  285. padLeft(count($firstdep->ThirdDep()), $col2).
  286. padLeft($firstdep->arraysum(0,$firstdep->ThirdDep()), $col2).
  287. padLeft($firstdep->arraysum(1,$firstdep->ThirdDep()), $col2).
  288. padLeft($firstdep->arraysum(2,$firstdep->ThirdDep()), $col2).
  289. padLeft(round($firstdep->arraysum(0,$firstdep->ThirdDep())/$firstdep->arraysum(2,$firstdep->ThirdDep())), $col2). " <br>";
  290.  
  291. echo"<br>";
  292. echo padRight("Логистики", $col1).
  293. padLeft(count($firstdep->FourthDep()), $col2).
  294. padLeft($firstdep->arraysum(0,$firstdep->FourthDep()), $col2).
  295. padLeft($firstdep->arraysum(1,$firstdep->FourthDep()), $col2).
  296. padLeft($firstdep->arraysum(2,$firstdep->FourthDep()), $col2).
  297. padLeft(round($firstdep->arraysum(0,$firstdep->FourthDep())/$firstdep->arraysum(2,$firstdep->FourthDep())), $col2). " <br>";
  298.  
  299. echo"<br>";
  300. $a = (count($firstdep->FirstDep())+count($firstdep->SecondDep()) +count($firstdep->ThirdDep())+count($firstdep->FourthDep()));
  301. echo padRight("Cреднее", $col1).
  302. padLeft($a/4, $col2).
  303. padLeft($firstdep->ArrayMiddle(0)/4, $col2).
  304. padLeft($firstdep->ArrayMiddle(1)/4, $col2).
  305. padLeft($firstdep->ArrayMiddle(2)/4, $col2).
  306. padLeft((round($firstdep->ArrayMiddle(0)/$firstdep->ArrayMiddle(2))), $col2). " <br>";
  307.  
  308. echo padRight("Общее", $col1).
  309. padLeft($a, $col2).
  310. padLeft($firstdep->ArrayMiddle(0), $col2).
  311. padLeft($firstdep->ArrayMiddle(1), $col2).
  312. padLeft($firstdep->ArrayMiddle(2), $col2).
  313. padLeft(12, $col2). " <br>";
  314.  
  315.  
  316.  
Success #stdin #stdout 0.02s 52488KB
stdin
Standard input is empty
stdout
<pre>Департамент                         сотр     тугр.      кофе      стр. тугр./стр <br>_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ <br><br>Закупок                               16      8675       310      3100         3 <br><br>Продаж                                23     12800       580      3325         4 <br><br>Рекламы                               35     15400       545      5450         3 <br><br>Логистики                             23     10625       385      3850         3 <br><br>Cреднее                            24.25     11875       455   3931.25         3 <br>Общее                                 97     47500      1820     15725        12 <br>