<?php
error_reporting(-1);
abstract class AbstractWorker{
public $rank;
public $isBoss;
public $count;
public $coffee;
public $salary;
public $pages;
public function __construct($count, $rank, $isBoss) {
$this->rank = $rank;
$this->count = $count;
$this->isBoss = $isBoss;
}
public function CalculationOfInformation($rank, $isBoss){
if ($this->rank == 2){
$this->salary = $this->salary * 1.25 * $this->count;
} elseif ($this->rank == 3){
$this->salary = $this->salary * 1.5 * $this->count;
} else {
$this->salary = $this->salary * $this->count;
}
$this->coffee = $this->coffee * $this->count;
$this->pages = $this->pages * $this->count;
if ($this->isBoss == 1){
$this->salary *= 1.5;
$this->coffee *= 2;
$this->pages = 0;
}
}
public function getInformation($value){
return $value;
}
}
class Manager extends AbstractWorker{
public $coffee = 20;
public $salary = 500;
public $pages = 200;
}
class Marketer extends AbstractWorker{
public $coffee = 15;
public $salary = 400;
public $pages = 150;
}
class Engineer extends AbstractWorker{
public $coffee = 5;
public $salary = 200;
public $pages = 50;
}
class Analyst extends AbstractWorker{
public $coffee = 50;
public $salary = 800;
public $pages = 5;
}
class Department{
public $name;
public $workers = array();
public function __construct($name) {
$this->name = $name;
}
public function addWorkers(AbstractWorker $worker){
$worker->CalculationOfInformation($worker->rank, $worker->isBoss);
$this->workers[] = $worker;
}
public function getInformarion (){
$informarion = array($this->name, 0, 0, 0, 0, 0);
foreach ($this->workers as $worker) {
$informarion[1] += $worker->getInformation($worker->count);
$informarion[2] += $worker->getInformation($worker->salary);
$informarion[3] += $worker->getInformation($worker->coffee);
$informarion[4] += $worker->getInformation($worker->pages);
}
$informarion[5] = round($informarion[2] / $informarion[4], 1);
return $informarion;
}
}
class Company{
public $departments = array();
public function addDepartment(Department $department){
$this->departments[] = $department;
}
private function padLeft($value, $columnLength){
echo $value;
echo str_repeat(" ", $columnLength - mb_strlen($value));
}
private function calculatiotOfOutput(array $informarion){
$col1 = 15;
$col2 = 8;
$col3 = 10;
$col4 = 8;
$col5 = 8;
$col6 = 15;
echo $this->padLeft($informarion[0], $col1) .
$this->padLeft($informarion[1], $col2) .
$this->padLeft($informarion[2], $col3) .
$this->padLeft($informarion[3], $col4) .
$this->padLeft($informarion[4], $col5) .
$this->padLeft($informarion[5], $col6) . "\n";
}
public function printInformationOfDepartment(){
$columbNames = array("Департамент", "сотр.", "тугр.", "кофе", "стр.", "тугр./стр.");
$this->calculatiotOfOutput($columbNames);
echo "\n";
foreach ($this->departments as $department) {
$informarion = $department->getInformarion();
$this->calculatiotOfOutput($informarion);
}
echo "\n";
$totalInformation = array("", 0, 0, 0, 0, 0);
foreach ($this->departments as $department) {
$informarion = $department->getInformarion();
$totalInformation[1] += $informarion[1];
$totalInformation[2] += $informarion[2];
$totalInformation[3] += $informarion[3];
$totalInformation[4] += $informarion[4];
$totalInformation[5] += $informarion[5];
}
$totalInformation[0] = "Всего";
$averageInformation = array("", 0, 0, 0, 0, 0);
for ($i = 1; $i < 6; $i++){
$averageInformation[$i] = round($totalInformation[$i] / count($this->departments), 1);
}
$averageInformation[0] = "Среднее";
$this->calculatiotOfOutput($averageInformation);
$this->calculatiotOfOutput($totalInformation);
}
}
$vektor = new Company;
$vektor->addDepartment(new Department("Закупок"));
$vektor->addDepartment(new Department("Продаж"));
$vektor->addDepartment(new Department("Рекламы"));
$vektor->addDepartment(new Department("Логистики"));
$vektor->departments[0]->addWorkers(new Manager(9, 1, 0));
$vektor->departments[0]->addWorkers(new Manager(3, 2, 0));
$vektor->departments[0]->addWorkers(new Manager(2, 3, 0));
$vektor->departments[0]->addWorkers(new Marketer(2, 1, 0));
$vektor->departments[0]->addWorkers(new Manager(1, 2, 1));
$vektor->departments[1]->addWorkers(new Manager(12, 1, 0));
$vektor->departments[1]->addWorkers(new Marketer(6, 1, 0));
$vektor->departments[1]->addWorkers(new Analyst(3, 1, 0));
$vektor->departments[1]->addWorkers(new Marketer(2, 2, 0));
$vektor->departments[1]->addWorkers(new Marketer(1, 2, 1));
$vektor->departments[2]->addWorkers(new Marketer(15, 1, 0));
$vektor->departments[2]->addWorkers(new Marketer(10, 2, 0));
$vektor->departments[2]->addWorkers(new Manager(8, 1, 0));
$vektor->departments[2]->addWorkers(new Engineer(2, 1, 0));
$vektor->departments[2]->addWorkers(new Marketer(1, 3, 1));
$vektor->departments[3]->addWorkers(new Manager(13, 1, 0));
$vektor->departments[3]->addWorkers(new Manager(5, 2, 0));
$vektor->departments[3]->addWorkers(new Engineer(5, 1, 0));
$vektor->departments[3]->addWorkers(new Manager(1, 1, 1));
$vektor->printInformationOfDepartment();
- Output for 7.0.0 - 7.0.25, 7.1.0 - 7.1.20, 7.2.6 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
- Департамент сотр. тугр. кофе стр. тугр./стр.
Закупок 17 9612.5 350 3100 3.1
Продаж 24 12550 540 3615 3.5
Рекламы 36 16300 575 5450 3
Логистики 24 11375 425 3850 3
Среднее 25.3 12459.4 472.5 4003.8 3.2
Всего 101 49837.5 1890 16015 12.6
- Output for 8.3.5
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Департамент сотр. тугр. кофе стр. тугр./стр.
Закупок 17 9612.5 350 3100 3.1
Продаж 24 12550 540 3615 3.5
Рекламы 36 16300 575 5450 3
Логистики 24 11375 425 3850 3
Среднее 25.3 12459.4 472.5 4003.8 3.2
Всего 101 49837.5 1890 16015 12.6
preferences:
194.85 ms | 403 KiB | 180 Q