<?php
class Department
{
public function createEmployee($amount, $profession, $rank, $chief = 0)
{
for($i=1; $i <= $amount; $i++) {
$this->employees[] = new Employee($profession, $rank, $chief);
}
}
public function __construct($name)
{
$this->name = $name;
}
public function DepartmentEmployeersNumber()
{
return count($this->employees); }
public function DepartmentPayment()
{
$departmentPayment = 0;
foreach ($this->employees as $employee) {
$departmentPayment += $employee->payment;
}
return $departmentPayment;
}
public function DepartmentCoffeeSpending()
{
$departmentCoffee = 0;
foreach ($this->employees as $employee) {
$departmentCoffee += $employee->coffee;
}
return $departmentCoffee;
}
public function DepartmentPages()
{
$departmentPages = 0;
foreach ($this->employees as $employee) {
$departmentPages += $employee->pages;
}
return $departmentPages;
}
public function DepartmentEfficiency()
{
return round ($this->DepartmentPayment() / $this->DepartmentPages(), 1); }
}
class Employee
{
public $payment;
public $coffee;
public $pages;
public $rank;
public function __construct($profession, $rank, $chief = 0)
{
$this->rank = $rank;
if ($profession == 'manager') {
$this->payment = 500;
$this->coffee = 20;
$this->pages = 200;
} elseif ($profession == 'marketer') {
$this->payment = 400;
$this->coffee = 15;
$this->pages = 150;
} elseif ($profession == 'engineer') {
$this->payment = 200;
$this->coffee = 5;
$this->pages = 50;
} elseif ($profession == 'analyst') {
$this->payment = 800;
$this->coffee = 50;
$this->pages = 5;
}
if ($this->rank == 2) {
$this->payment *= 1.25;
} elseif ($this->rank == 3) {
$this->payment *= 1.5;
}
if ($chief == 1) {
$this->payment *= 1.5;
$this->coffee *= 2;
$this->pages = 0;
}
}
}
$purchases = new Department('Закупок');
$purchases->createEmployee(9, 'manager', 1);
$purchases->createEmployee(3, 'manager', 2);
$purchases->createEmployee(2, 'manager', 3);
$purchases->createEmployee(2, 'marketer', 1);
$purchases->createEmployee(1, 'manager', 2, 1);
$employees[] = $purchases;
$sales = new Department('Продаж');
$sales->createEmployee(12, 'manager', 1);
$sales->createEmployee(6, 'marketer', 1);
$sales->createEmployee(3, 'analyst', 1);
$sales->createEmployee(2, 'analyst', 2);
$sales->createEmployee(1, 'marketer', 2, 1);
$employees[] = $sales;
$advertising = new Department('Рекламы');
$advertising->createEmployee(15, 'marketer', 1);
$advertising->createEmployee(10, 'marketer', 2);
$advertising->createEmployee(8, 'manager', 1);
$advertising->createEmployee(2, 'engineer', 1);
$advertising->createEmployee(1, 'marketer', 3, 1);
$employees[] = $advertising;
$logistics = new Department('Логистики');
$logistics->createEmployee(13, 'manager', 1);
$logistics->createEmployee(5, 'manager', 2);
$logistics->createEmployee(5, 'engineer', 1);
$logistics->createEmployee(1, 'manager', 1, 1);
$employees[] = $logistics;
$col1 = 14;
$col2 = 5;
$col3 = 10;
$col4 = 9;
$col5 = 7;
$col6 = 13;
function padLeft($string, $length)
{
echo $space . $string;
}
function padRight($string, $length)
{
echo $string . $space;
}
echo padRight("Департамент", $col1) .
padLeft("сотр.", $col2) .
padLeft("тугр.", $col3) .
padLeft("кофе", $col4) .
padLeft("стр.", $col5) .
padLeft("тугр./стр.\n", $col6);
$totalEmployees = 0;
$totalPayment = 0;
$totalCoffeeSpending = 0;
$totalPages = 0;
$totalEfficiency = 0;
foreach ($employees as $department) {
echo padRight($department->name, $col1) .
padLeft($department->DepartmentEmployeersNumber(), $col2) .
padLeft($department->DepartmentPayment(), $col3) .
padLeft($department->DepartmentCoffeeSpending(), $col4) .
padLeft($department->DepartmentPages(), $col5) .
padLeft($department->DepartmentEfficiency(), $col6) .
"\n";
$totalEmployees += $department->DepartmentEmployeersNumber();
$totalPayment += $department->DepartmentPayment();
$totalCoffeeSpending += $department->DepartmentCoffeeSpending();
$totalPages += $department->DepartmentPages();
$totalEfficiency += $department->DepartmentEfficiency();
}
echo padRight("Среднее", $col1) .
padLeft
(floor($totalEmployees / count($employees)), $col2) . padLeft
(floor($totalPayment / count($employees)), $col3) . padLeft
(floor($totalCoffeeSpending / count($employees)), $col4) . padLeft
(floor($totalPages / count($employees)), $col5) . padLeft
(floor($totalEfficiency / count($employees)), $col6) . "\n";
echo padRight("Всего", $col1) .
padLeft($totalEmployees, $col2) .
padLeft($totalPayment, $col3) .
padLeft($totalCoffeeSpending, $col4) .
padLeft($totalPages, $col5) .
padLeft($totalEfficiency, $col6) .
"\n";
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7CgpjbGFzcyBEZXBhcnRtZW50CnsKCXB1YmxpYyBmdW5jdGlvbiBjcmVhdGVFbXBsb3llZSgkYW1vdW50LCAkcHJvZmVzc2lvbiwgJHJhbmssICRjaGllZiA9IDApIAogICAgewogICAgICAgIGZvcigkaT0xOyAkaSA8PSAkYW1vdW50OyAkaSsrKSB7CiAgICAgICAgICAgICR0aGlzLT5lbXBsb3llZXNbXSA9IG5ldyBFbXBsb3llZSgkcHJvZmVzc2lvbiwgJHJhbmssICRjaGllZik7CiAgICAgICAgfQogICAgfQogICAgCiAgICBwdWJsaWMgZnVuY3Rpb24gX19jb25zdHJ1Y3QoJG5hbWUpIAogICAgewogICAgCSR0aGlzLT5uYW1lID0gJG5hbWU7CiAgICB9CiAgICAKICAgIHB1YmxpYyBmdW5jdGlvbiBEZXBhcnRtZW50RW1wbG95ZWVyc051bWJlcigpCiAgICB7CiAgICAJcmV0dXJuIGNvdW50KCR0aGlzLT5lbXBsb3llZXMpOwogICAgfQogICAgCiAgICBwdWJsaWMgZnVuY3Rpb24gRGVwYXJ0bWVudFBheW1lbnQoKQogICAgewogICAgCSRkZXBhcnRtZW50UGF5bWVudCA9IDA7CiAgICAJZm9yZWFjaCAoJHRoaXMtPmVtcGxveWVlcyBhcyAkZW1wbG95ZWUpIHsKICAgIAkJJGRlcGFydG1lbnRQYXltZW50ICs9ICRlbXBsb3llZS0+cGF5bWVudDsKICAgIAl9CiAgICAJcmV0dXJuICRkZXBhcnRtZW50UGF5bWVudDsKICAgIH0KICAgIAogICAgcHVibGljIGZ1bmN0aW9uIERlcGFydG1lbnRDb2ZmZWVTcGVuZGluZygpIAogICAgewogICAgCSRkZXBhcnRtZW50Q29mZmVlID0gMDsKICAgIAlmb3JlYWNoICgkdGhpcy0+Z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