<?php
class Employee
{
public $salary;
public $coffee;
public $pages;
public $rank;
public function __construct($profession, $rank = 1)
{
switch ($profession) {
case 'manager':
$this->salary = 500 * $rank;
$this->pages = 200;
$this->coffee = 20;
$this->rank = $rank;
break;
case 'engineer':
$this->salary = 200 * $rank;
$this->pages = 50;
$this->coffee = 5;
$this->rank = $rank;
break;
case 'analyst':
$this->salary = 800 * $rank;
$this->pages = 5;
$this->coffee = 50;
$this->rank = $rank;
break;
case 'marketer':
$this->salary = 400 * $rank;
$this->pages = 150;
$this->coffee = 15;
$this->rank = $rank;
break;
default: exit("Profession \"$profession\" not found."); }
}
}
class Report
{
public $departmentName;
public $salary;
public $coffee;
public $pages;
public $employeeCount;
}
class Department
{
public $employees;
public $name;
public function __construct
(array $employees, $name) {
$this->employees = $employees;
$this->name = $name;
}
public function getReport()
{
$report = new Report;
foreach ($this->employees as $employee) {
$report->salary += $employee[0]->salary * $employee[1];
$report->coffee += $employee[0]->coffee * $employee[1];
$report->pages += $employee[0]->pages * $employee[1];
$report->employeeCount += $employee[1];
}
$report->departmentName = $this->name;
return $report;
}
}
$manager1 = new Employee('manager', 1);
$manager2 = new Employee('manager', 1.25);
$manager3 = new Employee('manager', 1.5);
$marketer1 = new Employee('marketer', 1);
$marketer2 = new Employee('marketer', 1.25);
$analyst1 = new Employee('analyst', 1);
$analyst2 = new Employee('analyst', 1.25);
$engineer1 = new Employee('engineer', 1);
$procurement = new Department
(array( ), 'Закупок');
$selling = new Department
(array( ), 'Продаж');
$advertisement = new Department
(array( ), 'Рекламы');
$logistics = new Department
(array( ), 'Логистики');
foreach (array($procurement, $selling, $advertisement, $logistics) as $department) { $summary[] = $department->getReport();
}
echo "Департамент:\t\tсотр.\t\tтугр.\t\tкофе\t\tстр.\t\tтугр./стр.\n";
echo "--------------------------------------------------------------------------------------\n";
foreach ($summary as $report) {
echo "$report->departmentName\t\t\t\t$report->employeeCount\t\t$report->salary\t\t$report->coffee\t\t$report->pages\t\t";
echo round($report->salary / $report->pages, 1); echo "\n";
}
PD9waHAKCmNsYXNzIEVtcGxveWVlCnsKICAgIHB1YmxpYyAkc2FsYXJ5OwogICAgcHVibGljICRjb2ZmZWU7CiAgICBwdWJsaWMgJHBhZ2VzOwogICAgcHVibGljICRyYW5rOwoKICAgIHB1YmxpYyBmdW5jdGlvbiBfX2NvbnN0cnVjdCgkcHJvZmVzc2lvbiwgJHJhbmsgPSAxKQogICAgewogICAgICAgIHN3aXRjaCAoJHByb2Zlc3Npb24pIHsKICAgICAgICAgICAgY2FzZSAnbWFuYWdlcic6CiAgICAgICAgICAgICAgICAkdGhpcy0+c2FsYXJ5ID0gNTAwICogJHJhbms7CiAgICAgICAgICAgICAgICAkdGhpcy0+cGFnZXMgPSAyMDA7CiAgICAgICAgICAgICAgICAkdGhpcy0+Y29mZmVlID0gMjA7CiAgICAgICAgICAgICAgICAkdGhpcy0+cmFuayA9ICRyYW5rOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgJ2VuZ2luZWVyJzoKICAgICAgICAgICAgICAgICR0aGlzLT5zYWxhcnkgPSAyMDAgKiAkcmFuazsKICAgICAgICAgICAgICAgICR0aGlzLT5wYWdlcyA9IDUwOwogICAgICAgICAgICAgICAgJHRoaXMtPmNvZmZlZSA9IDU7CiAgICAgICAgICAgICAgICAkdGhpcy0+cmFuayA9ICRyYW5rOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgJ2FuYWx5c3QnOgogICAgICAgICAgICAgICAgJHRoaXMtPnNhbGFyeSA9IDgwMCAqICRyYW5rOwogICAgICAgICAgICAgICAgJHRoaXMtPnBhZ2VzID0gNTsKICAgICAgICAgICAgICAgICR0aGlzLT5jb2ZmZWUgPSA1MDsKICAgICAgICAgICAgICAgICR0aGlzLT5yYW5rID0gJHJhbms7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgY2FzZSAnbWFya2V0ZXInOgogICAgICAgICAgICAgICAgJHRoaXMtPnNhbGFyeSA9IDQwMCAqICRyYW5rOwogICAgICAgICAgICAgICAgJHRoaXMtPnBhZ2VzID0gMTUwOwogICAgICAgICAgICAgICAgJHRoaXMtPmNvZmZlZSA9IDE1OwogICAgICAgICAgICAgICAgJHRoaXMtPnJhbmsgPSAkcmFuazsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBkZWZhdWx0OiBleGl0KCJQcm9mZXNzaW9uIFwiJHByb2Zlc3Npb25cIiBub3QgZm91bmQuIik7CiAgICAgICAgfQogICAgfQp9CgpjbGFzcyBSZXBvcnQKewogICAgcHVibGljICRkZXBhcnRtZW50TmFtZTsKICAgIHB1YmxpYyAkc2FsYXJ5OwogICAgcHVibGljICRjb2ZmZWU7CiAgICBwdWJsaWMgJHBhZ2VzOwogICAgcHVibGljICRlbXBsb3llZUNvdW50Owp9CgpjbGFzcyBEZXBhcnRtZW50CnsKICAgIHB1YmxpYyAkZW1wbG95ZWVzOwogICAgcHVibGljICRuYW1lOwoKICAgIHB1YmxpYyBmdW5jdGlvbiBfX2NvbnN0cnVjdChhcnJheSAkZW1wbG95ZWVzLCAkbmFtZSkKICAgIHsKICAgICAgICAkdGhpcy0+ZW1wbG95ZWVzID0gJGVtcGxveWVlczsKICAgICAgICAkdGhpcy0+bmFtZSA9ICRuYW1lOwogICAgfQoKICAgIHB1YmxpYyBmdW5jdGlvbiBnZXRSZXBvcnQoKQogICAgewogICAgICAgICRyZXBvcnQgPSBuZXcgUmVwb3J0OwogICAgICAgIGZvcmVhY2ggKCR0aGlzLT5lbXBsb3llZXMgYXMgJGVtcGxveWVlKSB7CiAgICAgICAgICAgICRyZXBvcnQtPnNhbGFyeSArPSAkZW1wbG95ZWVbMF0tPnNhbGFyeSAqICRlbXBsb3llZVsxXTsKICAgICAgICAgICAgJHJlcG9ydC0+Y29mZmVlICs9ICRlbXBsb3llZVswXS0+Y29mZmVlICogJGVtcGxveWVlWzFdOwogICAgICAgICAgICAkcmVwb3J0LT5wYWdlc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