<?php
header("Content-Type: text/plain; charset=utf-8"); ?>
<?php
//объявление классов >>
abstract class Employee
{
public $salary;
public $coffee;
public $reports;
public $rank;
public function __construct($rank, $isDirector)
{
$this->rank = $rank;
if ($isDirector == 1) {
$this->salary *= 1.5;
$this->coffee *= 2;
$this->reports *= 0;
}
if ($rank == 2) {
$this->salary *= 1.25;
} elseif ($rank == 3) {
$this->salary *= 1.5;
}
}
}
class Engineer extends Employee
{
public $salary = 200;
public $coffee = 5;
public $reports = 50;
}
class Marketolog extends Employee
{
public $salary = 400;
public $coffee = 15;
public $reports = 150;
}
class Manager extends Employee
{
public $salary = 500;
public $coffee = 20;
public $reports = 200;
}
class Analyst extends Employee
{
public $salary = 800;
public $coffee = 50;
public $reports = 5;
}
class Department
{
public $name;
public $count;
public $salary;
public $coffee;
public $reports;
public $repSal;
public $workers = array(); public function __construct($name, $array)
{
$this->workers = $array;
$this->name = $name;
$this->salary = $this->getSalary();
$this->coffee = $this->getCoffee();
$this->reports = $this->getReports();
}
public function getCount()
{
return count($this->workers); }
public function getSalary()
{
$sumSalary = 0;
foreach ($this->workers as $worker) {
$sumSalary += $worker->salary;
}
return $sumSalary;
}
public function getCoffee()
{
$sumCoffee = 0;
foreach ($this->workers as $worker) {
$sumCoffee += $worker->coffee;
}
return $sumCoffee;
}
public function getReports()
{
$sumReports = 0;
foreach ($this->workers as $worker) {
$sumReports += $worker->reports;
}
return $sumReports;
}
public function getSalaryReports()
{
return $this->getSalary() / $this->getReports();
}
}
//Создание работников(объектов) внутри департамента >>
function getEmployee($rank, $class, $count, $isDirector = 0)
{
for ($i = 1; $i <= $count; $i++) {
$employee = new $class($rank, $isDirector);
$employees[] = $employee;
}
return $employees;
}
$ma = 'Marketolog';
$me = 'Manager';
$an = 'Analyst';
$in = 'Engineer';
$procurement = new Department
('Procurement', array_merge(getEmployee
(1, $me, 9), getEmployee
(2, $me, 3), getEmployee
(3, $me, 2), getEmployee
(1, $ma, 2), getEmployee
(2, $me, 1, 1))); $sales = new Department
('Sales dp', array_merge(getEmployee
(1, $me, 12), getEmployee
(1, $ma, 6), getEmployee
(1, $an, 3), getEmployee
(2, $an, 2), getEmployee
(2, $ma, 1, 1))); $advertising = new Department
('Advertising', array_merge(getEmployee
(1, $ma, 15), getEmployee
(2, $ma, 10), getEmployee
(1, $me, 8), getEmployee
(1, $in, 2), getEmployee
(3, $ma, 1, 1))); $logistic = new Department
('Logistic', array_merge(getEmployee
(1, $me, 13), getEmployee
(2, $me, 5), getEmployee
(1, $in, 5), getEmployee
(1, $me, 1, 1))); $procurement,
$sales,
$advertising,
$logistic
);
//Создание функций для вывода таблицы на экран и подсчет суммы по департаментам
function padRight($string, $arg)
{
if ($count <= 0) {
return $string;
}
return $string . $space;
}
function padLeft($string, $arg)
{
if ($count <= 0) {
return $string;
}
return $space . $string;
}
$text = 'Департамент сотр. тугр кофе стр. туг/стр.';
$col1 = 22;
$col2 = 11;
function getShow($array)
{
global $col1;
global $col2;
foreach ($array as $k => $str) {
if ($k == 0) {
echo padRight($str, $col1);
} else {
echo padLeft($str, $col2);
}
}
echo "\n";
}
//Вывод на экран>>
getShow($textAr);
$count = 0;
$coffee = 0;
$salary = 0;
$reports = 0;
$repSal = 0;
foreach ($departments as $department) {
echo padRight($department->name, $col1);
echo padLeft
($department->count, $col2); $count += $department->count; echo padLeft($department->salary, $col2);
$salary += $department->salary;
echo padLeft($department->coffee, $col2);
$coffee += $department->coffee;
echo padLeft($department->reports, $col2);
$reports += $department->reports;
echo padLeft($department->repSal, $col2) . "\n";
$repSal += $department->repSal;
}
$repSal /= 4;
'Всего',
$count,
$salary,
$coffee,
$reports,
$repSal
);
getShow($total);
PD9waHAKaGVhZGVyKCJDb250ZW50LVR5cGU6IHRleHQvcGxhaW47IGNoYXJzZXQ9dXRmLTgiKTsKPz4gCjw/cGhwCgptYl9pbnRlcm5hbF9lbmNvZGluZygiVVRGLTgiKTsKLy/QvtCx0YrRj9Cy0LvQtdC90LjQtSDQutC70LDRgdGB0L7Qsi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gZXh0ZW5kcyBFbXBsb3llZQp7CiAgICBwdWJsaWMgJHNhbGFyeSA9IDgwMDsKICAgIHB1YmxpYyAkY29mZmVlID0gNTA7CiAgICBwdWJsaWMgJHJlcG9ydHMgPSA1Owp9CmNsYXNzIERlcGFydG1lbnQKewogICAgcHVibGljICRuYW1lOwogICAgcHVibGljICRjb3VudDsKICAgIHB1YmxpYyAkc2FsYXJ5OwogICAgcHVibGljICRjb2ZmZWU7CiAgICBwdWJsaWMgJHJlcG9ydHM7CiAgICBwdWJsaWMgJHJlcFNhbDsKICAgIHB1YmxpYyAkd29ya2VycyA9IGFycmF5KCk7CiAgICBwdWJsaWMgZnVuY3Rpb24gX19jb25zdHJ1Y3QoJG5hbWUsICRhcnJheSkKICAgIHsKICAgICAgICAkdGhpcy0+d29ya2VycyA9ICRhcnJheTsKICAgICAgICAkdGhpcy0+bmFtZSAgICA9ICRuYW1lOwogICAgICAgICR0aGlzLT5jb3VudCAgID0gY291bnQoJHRoaXMtPndvcmtlcnMpOwogICAgICAgICR0aGlzLT5zYWxhcnkgID0gJHRoaXMtPmdldFNhbGFyeSgpOwogICAgICAgICR0aGlzLT5jb2ZmZWUgID0gJHRoaXMtPmdldENvZmZlZSgpOwogICAgICAgICR0aGlzLT5yZXBvcnRzID0gJHRoaXMtPmdldFJlcG9ydHMoKTsKICAgICAgICAkdGhpcy0+cmVwU2FsICA9IG51bWJlcl9mb3JtYXQoJHRoaXMtPmdldFNhbGFyeVJlcG9ydHMoKSwgMik7CiAgICB9CiAgICBwdWJsaWMgZnVuY3Rpb24gZ2V0Q291bnQoKQogICAgewogICAgICAgIHJldHVybiBjb3VudCgkdGhpcy0+d29ya2Vycyk7CiAgICB9CiAgICBwdWJsaWMgZnVuY3Rpb24gZ2V0U2FsYXJ5KCkKICAgIHsKICAgICAgICAkc3VtU2FsYXJ5ID0gMDsKICAgICAgICBmb3JlYWNoICgkdGhpcy0+d29ya2VycyBhcyAkd29ya2VyKSB7CiAgICAgICAgICAgICRzdW1TYWxhcnkgKz0gJHdvcmtlci0+c2FsYXJ5OwogICAgICAgIH0KICAgICAgICByZXR1cm4gJHN1bVNhbGFyeTsKICAgIH0KICAgIHB1YmxpYyBmdW5jdGlvbiBnZXRDb2ZmZWUoKQogICAgewogICAgICAgICRzdW1Db2ZmZWUgPSAwOwogICAgICAgIGZvcmVhY2ggKCR0aGlzLT53b3JrZXJzIGFzICR3b3JrZXIpIHsKICAgICAgICAgICAgJHN1bUNvZmZlZSArPSAkd29ya2VyLT5jb2ZmZWU7CiAgICAgICAgfQogICAgICAgIHJldHVybiAkc3VtQ29mZmVlOwogICAgfQogICAgcHVibGljIGZ1bmN0aW9uIGdldFJlcG9ydHMoKQogICAgewogICAgICAgICRzdW1SZXBvcnRzID0gMDsKICAgICAgICBmb3JlYWNoICgkdGhpcy0+d29ya2VycyBhcyAkd29ya2VyKSB7CiAgICAgICAgICAgICRzdW1SZXBvcnRzICs9ICR3b3JrZXItPnJlcG9ydHM7CiAgICAgICAgfQogICAgICAgIHJldHVybiAkc3VtUmVwb3J0czsKICAgIH0KICAgIHB1YmxpYyBmdW5jdGlvbiBnZXRTYWxhcnlSZXBvcnRzKCkKICAgIHsKICAgICAgICByZXR1cm4gJHRoaXMtPmdldFNhbGFyeSgpIC8gJHRoaXMtPmdldFJlcG9ydHMoKTsKICAgIH0KICAgIAp9CgovL9Ch0L7Qt9C00LDQvdC40LUg0YDQsNCx0L7RgtC90LjQutC+0LIo0L7QsdGK0LXQutGC0L7Qsikg0LLQvdGD0YLRgNC4INC00LXQv9Cw0YDRgtCw0LzQtdC90YLQsCA+PgpmdW5jdGlvbiBnZXRFbXBsb3llZSgkcmFuaywgJGNsYXNzLCAkY291bnQsICRpc0RpcmVjdG9yID0gMCkKewogICAgJGVtcGxveWVlcyA9IGFycmF5KCk7CiAgICBmb3IgKCRpID0gMTsgJGkgPD0gJGNvdW50OyAkaSsrKSB7CiAgICAgICAgJGVtcGxveWVlICAgID0gbmV3ICRjbGFzcygkc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