<?php
abstract class Employee
{
public $salary;
public $pages;
public $cofee;
public $name;
public $isHead = false;
function __construct($rank)
{
$this->rank = $rank;
}
function getSalary()
{
$extra = 1;
if ($this->isHead) {
$extra = 1.50;
}
$multiply = 1;
switch ($this->rank) {
case 2:
$multiply = 1.25;
break;
case 3:
$multiply = 1.50;
break;
}
return $this->salary * $multiply * $extra;
}
function setHead()
{
$this->isHead = true;
$this->cofee = $this->cofee*2;
$this->pages = 0;
}
}
class Manager extends Employee
{
public $name = "Менеджер";
public $salary = 500;
public $cofee = 20;
public $pages = 200;
}
class Market extends Employee
{
public $name = "Маркетолог";
public $salary = 400;
public $cofee = 15;
public $pages = 150;
}
class Engineer extends Employee
{
public $name = "Инженер";
public $salary = 200;
public $cofee = 5;
public $pages = 50;
}
class Analyst extends Employee
{
public $name = "Аналитик";
public $salary = 800;
public $cofee = 50;
public $pages = 5;
}
class Department
{
public $data;
public $name;
function workers()
{
return count($this->data); }
function cofee()
{
$cofee = 0;
foreach ($this->data as $key => $worker) {
$cofee += $worker->cofee;
}
return $cofee;
}
function costs()
{
$costs = 0;
foreach ($this->data as $worker) {
$costs += $worker->getSalary();
}
return $costs;
}
function pages()
{
$pages = 0;
foreach ($this->data as $worker) {
$pages += $worker->pages;
}
return $pages;
}
function costPerPage()
{
return round(($this->costs() / $this->pages()), 1); }
function __construct($name)
{
$this->name = $name;
}
public function addSingleEmployee($employee){
$this->data[] = $employee;
return $this->data;
}
function addEmployee
(array $data) {
foreach ($data as $employee) {
$this->data[]=$employee;
}
return $this->data;
}
function addBoss($boss)
{
$boss->setHead();
return $this->data[] = $boss;
}
}
function createEmployee($type, $rank, $quantity)
{
for ($i = 0; $i < $quantity; $i++) {
$array[] = new $type($rank);
}
return $array;
}
function padRight($name, $col)
{
$name .= " ";
}
return $name;
}
function padLeft($name, $col)
{
$name = " " . $name;
}
return $name;
}
function showDepartment($department, $col1, $col2, $col3)
{
echo padRight($department->name, $col1);
echo padLeft($department->workers(), $col2);
echo padLeft($department->costs(), $col3);
echo padLeft($department->cofee(), $col2);
echo padLeft($department->pages(), $col3);
echo padLeft($department->costPerPage(), $col3);
echo "\n";
}
$department1 = new Department('Закупок');
$department1->addEmployee(createEmployee('Manager', 1, 9));
$department1->addEmployee(createEmployee('Manager', 2, 3));
$department1->addEmployee(createEmployee('Manager', 3, 2));
$department1->addEmployee(createEmployee('Market', 1, 2));
$department1->addBoss(new Manager(2));
$department2 = new Department("Продаж");
$department2->addEmployee(createEmployee('Manager', 1, 12));
$department2->addEmployee(createEmployee('Market', 1, 6));
$department2->addEmployee(createEmployee('Analyst', 1, 3));
$department2->addEmployee(createEmployee('Analyst', 2, 2));
$department2->addBoss(new Market(2));
$department3 = new Department("Рекламы");
$department3->addEmployee(createEmployee('Market', 1, 15));
$department3->addEmployee(createEmployee('Market', 2, 10));
$department3->addEmployee(createEmployee('Manager', 1, 8));
$department3->addEmployee(createEmployee('Engineer', 1, 2));
$department3->addBoss(new Market(3));
$col1 = 20;
$col2 = 12;
$col3 = 10;
echo padRight("Департамент", $col1) . padLeft("Сотр.", $col1) . padLeft("тугр.", $col2) . padLeft("кофе", $col1) . padLeft("стр.", $col2) . padLeft("тугр./стр.", $col1) . "\n";
showDepartment($department1, $col1, $col2, $col3);
showDepartment($department2, $col1, $col2, $col3);
showDepartment($department3, $col1, $col2, $col3);
PD9waHAKCmFic3RyYWN0IGNsYXNzIEVtcGxveWVlCnsKICAgIAogICAgcHVibGljICRzYWxhcnk7CiAgICBwdWJsaWMgJHBhZ2VzOwogICAgcHVibGljICRjb2ZlZTsKICAgIHB1YmxpYyAkbmFtZTsKICAgIHB1YmxpYyAkaXNIZWFkID0gZmFsc2U7CiAgICAKICAgIAogICAgZnVuY3Rpb24gX19jb25zdHJ1Y3QoJHJhbmspCiAgICB7CiAgICAgICAgCiAgICAgICAgCiAgICAgICAgJHRoaXMtPnJhbmsgPSAkcmFuazsKICAgIH0KICAgIAogICAgZnVuY3Rpb24gZ2V0U2FsYXJ5KCkKICAgIHsKICAgICAgICAkZXh0cmEgPSAxOwogICAgICAgIGlmICgkdGhpcy0+aXNIZWFkKSB7CiAgICAgICAgICAgICRleHRyYSA9IDEuNTA7CiAgICAgICAgfQogICAgICAgICRtdWx0aXBseSA9IDE7CiAgICAgICAgc3dpdGNoICgkdGhpcy0+cmFuaykgewogICAgICAgICAgICBjYXNlIDI6CiAgICAgICAgICAgICAgICAkbXVsdGlwbHkgPSAxLjI1OwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMzoKICAgICAgICAgICAgICAgICRtdWx0aXBseSA9IDEuNTA7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgcmV0dXJuICR0aGlzLT5zYWxhcnkgKiAkbXVsdGlwbHkgKiAkZXh0cmE7CiAgICAgICAgCiAgICB9CiAgICAKICAgIGZ1bmN0aW9uIHNldEhlYWQoKQogICAgewogICAgICAgICR0aGlzLT5pc0hlYWQgPSB0cnVlOwogICAgICAgICR0aGlzLT5jb2ZlZSAgPSAkdGhpcy0+Y29mZWUqMjsKICAgICAgICAkdGhpcy0+cGFnZXMgID0gMDsKICAgICAgICAKICAgIH0KICAgIAp9CgpjbGFzcyBNYW5hZ2VyIGV4dGVuZHMgRW1wbG95ZWUKewogICAgcHVibGljICRuYW1lID0gItCc0LXQvdC10LTQttC10YAiOwogICAgcHVibGljICRzYWxhcnkgPSA1MDA7CiAgICBwdWJsaWMgJGNvZmVlID0gMjA7CiAgICBwdWJsaWMgJHBhZ2VzID0gMjAwOwp9CgpjbGFzcyBNYXJrZXQgZXh0ZW5kcyBFbXBsb3llZQp7CiAgICBwdWJsaWMgJG5hbWUgPSAi0JzQsNGA0LrQtdGC0L7Qu9C+0LMiOwogICAgcHVibGljICRzYWxhcnkgPSA0MDA7CiAgICBwdWJsaWMgJGNvZmVlID0gMTU7CiAgICBwdWJsaWMgJHBhZ2VzID0gMTUwOwp9CgpjbGFzcyBFbmdpbmVlciBleHRlbmRzIEVtcGxveWVlCnsKICAgIHB1YmxpYyAkbmFtZSA9ICLQmNC90LbQtdC90LXRgCI7CiAgICBwdWJsaWMgJHNhbGFyeSA9IDIwMDsKICAgIHB1YmxpYyAkY29mZWUgPSA1OwogICAgcHVibGljICRwYWdlcyA9IDUwOwp9CgpjbGFzcyBBbmFseXN0IGV4dGVuZHMgRW1wbG95ZWUKewogICAgcHVibGljICRuYW1lID0gItCQ0L3QsNC70LjRgtC40LoiOwogICAgcHVibGljICRzYWxhcnkgPSA4MDA7CiAgICBwdWJsaWMgJGNvZmVlID0gNTA7CiAgICBwdWJsaWMgJHBhZ2VzID0gNTsKfQoKCmNsYXNzIERlcGFydG1lbnQKewogICAgcHVibGljICRkYXRhOwogICAgcHVibGljICRuYW1lOwogICAgZnVuY3Rpb24gd29ya2VycygpCiAgICB7CiAgICAgICAgcmV0dXJuIGNvdW50KCR0aGlzLT5kYXRhKTsKICAgIH0KICAgIGZ1bmN0aW9uIGNvZmVlKCkKICAgIHsKICAgICAgICAkY29mZWUgPSAwOwogICAgICAgIGZvcmVhY2ggKCR0aGlzLT5kYXRhIGFzICRrZXkgPT4gJHdvcmtlcikgewogICAgICAgICAgIAogICAgICAgICAgICAgICAgJGNvZmVlICs9ICR3b3JrZXItPmNvZmVlOwogICAgICAgICAgICAKICAgICAgICB9CiAgICAgICAgcmV0dXJuICRjb2ZlZTsKICAgIH0KICAgIGZ1bmN0aW9uIGNvc3RzKCkKICAgIHsKICAgICAgICAkY29zdHMgPSAwOwogICAgICAgIGZvcmVhY2ggKCR0aGlzLT5kYXRhIGFzICAkd29ya2VyKSB7CiAgICAgICAgICAgIAogICAgICAgICAgICAkY29zdHMgKz0gJHdvcmtlci0+Z2V0U2FsYXJ5KCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiAkY29zdHM7CiAgICB9CiAgICBmdW5jdGlvbiBwYWdlcygpCiAgICB7CiAgICAgICAgJHBhZ2VzID0gMDsKICAgICAgICBmb3JlYWNoICgkdGhpcy0+ZGF0YSBhcyAkd29ya2VyKSB7CiAgICAgICAgICAgCiAgICAgICAgICAgICRwYWdlcyArPSAkd29ya2VyLT5wYWdlczsKICAgICAgICB9CiAgICAgICAgcmV0dXJuICRwYWdlczsKICAgIH0KICAgIGZ1bmN0aW9uIGNvc3RQZXJQYWdlKCkKICAgIHsKICAgICAgICByZXR1cm4gcm91bmQoKCR0aGlzLT5jb3N0cygpIC8gJHRoaXMtPnBhZ2VzKCkpLCAxKTsKICAgIH0KICAgIAogICAgZnVuY3Rpb24gX19jb25zdHJ1Y3QoJG5hbWUpCiAgICB7CiAgICAgICAgCiAgICAgICAgJHRoaXMtPm5hbWUgPSAkbmFtZTsKICAgICAgICAKICAgIH0KICAgcHVibGljIGZ1bmN0aW9uIGFkZFNpbmdsZUVtcGxveWVlKCRlbXBsb3llZSl7CiAgICAJJHRoaXMtPmRhdGFbXSA9ICRlbXBsb3llZTsKICAgIAlyZXR1cm4gJHRoaXMtPmRhdGE7CiAgICB9CiAgICAKICAgIGZ1bmN0aW9uIGFkZEVtcGxveWVlKGFycmF5ICRkYXRhKQogICAgewogICAgICAgIAogICAgICAgICAgICBmb3JlYWNoICgkZGF0YSBhcyAkZW1wbG95ZWUpIHsKICAgICAgICAgICAgICAgICR0aGlzLT5kYXRhW109JGVtcGxveWVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiAkdGhpcy0+ZGF0YTsKICAgICAgCiAgICB9CiAgICBmdW5jdGlvbiBhZGRCb3NzKCRib3NzKQogICAgewogICAgICAgICRib3NzLT5zZXRIZWFkKCk7CiAgICAgICAgcmV0dXJuICR0aGlzLT5kYXRhW10gPSAkYm9zczsKICAgIH0KfQoKCmZ1bmN0aW9uIGNyZWF0ZUVtcGxveWVlKCR0eXBlLCAkcmFuaywgJHF1YW50aXR5KQp7CiAgICAkYXJyYXkgPSBhcnJheSgpOwogICAgZm9yICgkaSA9IDA7ICRpIDwgJHF1YW50aXR5OyAkaSsrKSB7CiAgICAgICAgJGFycmF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