#include <iostream>
#include <string>
#include <deque>
#include <map>
#include <algorithm>
#include <conio.h>
enum class Jobs
{
Director = 1,
Papersworker = 2,
Guardian = 3,
Programmer = 4
};
class Employee
{
public:
std::string FirstName;
std::string LastName;
std::string Patronymic;
double Salary;
Employee() {};
explicit Employee(std::string FirstName, std::string LastName,
std::string Patronymic, double Salary)
: FirstName(FirstName), LastName(LastName),
Patronymic(Patronymic), Salary(Salary) {}
bool operator==(Employee other) const
{
if (this->FirstName == other.FirstName &&
this->LastName == other.LastName &&
this->Patronymic == other.Patronymic)
return true;
else
return false;
}
};
class Director : public Employee
{
private:
std::string FirstName;
std::string LastName;
std::string Patronymic;
double Salary;
public:
Director() {};
using Employee::Employee;
const std::string Job = "Director";
std::deque <Employee> Employees;
void IncludeEmployee(Employee Empl)
{
this->Employees.push_back(Empl);
}
void ExcludeEmployee(Employee Empl)
{
Employees.erase(std::remove_if(
Employees.begin(),
Employees.end(),
[&](Employee i) { return i == Empl; }),
Employees.end());
}
void ChangeNameSalary(std::string FirstName, std::string LastName, std::string Patronymic, double Salary)
{
this->FirstName = FirstName;
this->LastName = LastName;
this->Patronymic = Patronymic;
this->Salary = Salary;
}
void PrintDirector()
{
std::cout << "First name\t" << "Lastname\t" << "Patronymic\t" << "Salary\n" << this->FirstName << "\t\t" << this->LastName << "\t\t" << this->Patronymic << "\t" << this->Salary << "\n" << "Employees : \n" << std::flush;
for (Employee emplo : this->Employees)
std::cout << emplo.FirstName << "\t\t" << emplo.LastName << "\t" << emplo.Patronymic << "\t" << emplo.Salary << "\n" << std::flush;
std::cout << "------------------------------------------------------------\n" << std::flush;
}
};
class Papersworker : public Employee
{
private:
std::string FirstName;
std::string LastName;
std::string Patronymic;
double Salary;
public:
Papersworker() {};
using Employee::Employee;
const std::string Job = "Papersworker";
std::map<std::string, double> Coefficient =
{
{"Director", 4.2},
{"Papersworker", 1.2},
{"Guardian", 1.5},
{"Programmer", 2.5}
};
void ChangeCoefficient(std::string Job, double NewCoefficient)
{
Coefficient[Job] = NewCoefficient;
}
void ChangeNameSalary(std::string FirstName, std::string LastName, std::string Patronymic, double Salary)
{
this->FirstName = FirstName;
this->LastName = LastName;
this->Patronymic = Patronymic;
this->Salary = Salary;
}
void PrintPapersworker()
{
std::cout << "First name\t" << "Lastname\t" << "Patronymic\t" << "Salary\n" << this->FirstName << "\t\t" << this->LastName << "\t" << this->Patronymic << "\t" << this->Salary << "\n" << std::flush;
for (const auto& i : this->Coefficient)
{
std::cout << i.first << " = " << i.second << ";\t" << std::flush;
}
std::cout << "\n------------------------------------------------------------\n" << std::flush;
}
double GetSalary(double Salary, std::string Job)
{
return Salary * this->Coefficient[Job];
}
};
class Guardian : public Employee
{
private:
std::string FirstName;
std::string LastName;
std::string Patronymic;
double Salary;
public:
Guardian() {};
using Employee::Employee;
const std::string Job = "Guardian";
std::deque <std::string> Items;
void IncludeItem(std::string Item)
{
this->Items.push_back(Item);
}
void ExcludeItem(std::string it)
{
this->Items.erase(std::remove_if(
this->Items.begin(),
this->Items.end(),
[&](std::string i) { return i == it; }),
this->Items.end());
}
void ChangeNameSalary(std::string FirstName, std::string LastName, std::string Patronymic, double Salary)
{
this->FirstName = FirstName;
this->LastName = LastName;
this->Patronymic = Patronymic;
this->Salary = Salary;
}
void PrintGuardian()
{
std::cout << "First name\t" << "Lastname\t" << "Patronymic\t" << "Salary\n" << this->FirstName << "\t" << this->LastName << "\t" << this->Patronymic << "\t" << this->Salary << "\n" << std::flush;
for (const auto& i : this->Items)
{
std::cout << i << ";\n" << std::flush;
}
std::cout << "------------------------------------------------------------\n" << std::flush;
}
};
class Programmer : public Employee
{
private:
std::string FirstName;
std::string LastName;
std::string Patronymic;
double Salary;
public:
Programmer() {};
using Employee::Employee;
const std::string Job = "Programmer";
enum Level
{
Junior,
Middle,
Senior,
Lead
};
std::deque <std::string> Technologies;
void IncludeTech(std::string Tech)
{
this->Technologies.push_back(Tech);
}
void ExcludeTech(std::string Tech)
{
this->Technologies.erase(std::remove_if(
this->Technologies.begin(),
this->Technologies.end(),
[&](std::string i) { return i == Tech; }),
this->Technologies.end());
}
void ChangeNameSalary(std::string FirstName, std::string LastName, std::string Patronymic, double Salary)
{
this->FirstName = FirstName;
this->LastName = LastName;
this->Patronymic = Patronymic;
this->Salary = Salary;
}
void PrintProgrammer()
{
std::cout << "First name\t" << "Lastname\t" << "Patronymic\t" << "Salary\n" << this->FirstName << "\t" << this->LastName << "\t" << this->Patronymic << "\t" << this->Salary << "\n" << std::flush;
for (const auto& i : this->Technologies)
{
std::cout << i << ";\n" << std::flush;
}
std::cout << "------------------------------------------------------------\n" << std::flush;
}
};
int main()
{
Director dir;
Papersworker pwr;
Guardian grd;
Programmer prg;
std::string job = "", item = "";
Jobs jobs_enum;
double coef = 0.0;
std::string fn, ln, pc;
double sr;
// char i = '0', i2 = '0';
//int jobid = 0;
while (true)
{
std::cout << "\n1 - Enter a director name and salary\n2 - Print director's attributes\n3 - Include employee for director\n4 - Exclude employee for director\n5 - Enter papersworker name and salary\n6 - Print papersworker's attributes\n7 - Add or change job's coefficient\n8 - Get salary of worker\nq - Enter a guardian's name and salary\nw - Print guardian's attributes\ne - Include item for guardian\nr - Exclude item for guardian\na - Enter a programmer's name and salary\nw - Print programmer's attributes\ne - Include technology for programmer\nr - Exclude technology for programmer\n" << std::flush;
// i = _getch();
// switch (i)
switch(getch())
{
case '1':
try
{
std::cout << "\nEnter director's first name\t" << std::flush; std::cin >> fn;
std::cout << "\nEnter director's last name\t" << std::flush; std::cin >> ln;
std::cout << "\nEnter director's patronymic\t" << std::flush; std::cin >> pc;
std::cout << "\nEnter director's salary\t" << std::flush; std::cin >> sr;
dir.ChangeNameSalary(fn, ln, pc, sr);
}
catch (...)
{
std::cout << "Bad input.\n" << std::flush;
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
break;
case '2':
dir.PrintDirector();
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
break;
case '3':
std::cout << "\n1 - Add a Papersworker\t2 - Add a Guardian\t3 - Add a Programmer\t" << std::flush; //i2 = _getch();
// switch (i2)
switch(getch())
{
case '1':
try
{
std::cout << "\nEnter papersworker's first name\t" << std::flush; std::cin >> fn;
std::cout << "\nEnter papersworker's last name\t" << std::flush; std::cin >> ln;
std::cout << "\nEnter papersworker's patronymic\t" << std::flush; std::cin >> pc;
std::cout << "\nEnter papersworker's salary\t" << std::flush; std::cin >> sr;
dir.IncludeEmployee((Employee)Papersworker(fn, ln, pc, sr));
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
catch (...)
{
std::cout << "Bad input." << std::flush;
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
break;
case '2':
try
{
std::cout << "\nEnter guardian's first name\t" << std::flush; std::cin >> fn;
std::cout << "\nEnter guardian's last name\t" << std::flush; std::cin >> ln;
std::cout << "\nEnter guardian's patronymic\t" << std::flush; std::cin >> pc;
std::cout << "\nEnter guardian's salary\t" << std::flush; std::cin >> sr;
dir.IncludeEmployee((Employee)Guardian(fn, ln, pc, sr));
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
catch (...)
{
std::cout << "Bad input.\n" << std::flush;
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
break;
case '3':
try
{
std::cout << "\nEnter programmer's first name\t" << std::flush; std::cin >> fn;
std::cout << "\nEnter programmer's last name\t" << std::flush; std::cin >> ln;
std::cout << "\nEnter programmer's patronymic\t" << std::flush; std::cin >> pc;
std::cout << "\nEnter programmer's salary\t" << std::flush; std::cin >> sr;
dir.IncludeEmployee((Employee)Programmer(fn, ln, pc, sr));
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
catch (...)
{
std::cout << "Bad input.\n" << std::flush;
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
break;
}
break;
case '4':
try
{
std::cout << "\nEnter excluding employee's first name\t" << std::flush; std::cin >> fn;
std::cout << "\nEnter excluding employee's last name\t" << std::flush; std::cin >> ln;
std::cout << "\nEnter excluding employee's patronymic\t" << std::flush; std::cin >> pc;
dir.ExcludeEmployee(Employee(fn, ln, pc, 0U));
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
catch (...)
{
std::cout << "Bad input.\n" << std::flush;
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
break;
case '5':
try
{
std::cout << "\nEnter papersworker's first name\t" << std::flush; std::cin >> fn;
std::cout << "\nEnter papersworker's last name\t" << std::flush; std::cin >> ln;
std::cout << "\nEnter papersworker's patronymic\t" << std::flush; std::cin >> pc;
std::cout << "\nEnter papersworker's salary\t" << std::flush; std::cin >> sr;
pwr.ChangeNameSalary(fn, ln, pc, sr);
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
catch (...)
{
std::cout << "Bad input.\n" << std::flush;
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
break;
case '6':
pwr.PrintPapersworker();
break;
case '7':
try
{
std::cout << "Enter a job's name (Director, Papersworker, Guardian, Programmer) or another to add:\t" << std::flush; std::cin >> job;
std::cout << "Enter a job's coefficient:\t" << std::flush; std::cin >> coef;
pwr.ChangeCoefficient(job, coef);
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
catch (...)
{
std::cout << "Bad input.\n" << std::flush;
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
break;
case '8':
std::cout << "Enter a job's id (1 - Director, 2 - Papersworker, 3 - Guardian, 4 - Programmer) to get salary:\t" << std::flush;
// jobid = _getch();
// jobs_enum = static_cast<Jobs>(jobid);
//jobs_enum = static_cast<Jobs>(_getch());
switch (static_cast<Jobs>(getch()))
{
case Jobs::Director:
try
{
std::cout << "\nEnter director's salary\t" << std::flush; std::cin >> sr;
std::cout << "\nSalary\t" << pwr.GetSalary(sr, "Director");
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
catch (...)
{
std::cout << "Bad input.\n" << std::flush;
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
break;
case Jobs::Papersworker:
try
{
std::cout << "\nEnter papersworker's salary\t" << std::flush; std::cin >> sr;
std::cout << "\nSalary\t" << pwr.GetSalary(sr, "Papersworker");
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
catch (...)
{
std::cout << "Bad input.\n" << std::flush;
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
break;
case Jobs::Guardian:
try
{
std::cout << "\nEnter guardian's salary\t" << std::flush; std::cin >> sr;
std::cout << "\nSalary\t" << pwr.GetSalary(sr, "Guardian");
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
catch (...)
{
std::cout << "Bad input.\n" << std::flush;
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
break;
case Jobs::Programmer:
try
{
std::cout << "\nEnter programmer's salary\t" << std::flush; std::cin >> sr;
std::cout << "\nSalary\t" << pwr.GetSalary(sr, "Programmer");
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
catch (...)
{
std::cout << "Bad input.\n" << std::flush;
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
break;
}
case 'q':
try
{
std::cout << "\nEnter guardian's salary\t" << std::flush; std::cin >> sr;
grd.ChangeNameSalary(fn, ln, pc, sr);
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
catch (...)
{
std::cout << "Bad input.\n" << std::flush;
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
break;
case 'w':
grd.PrintGuardian();
break;
case 'e':
try
{
std::cout << "\nEnter guardian's item to add\t" << std::flush; std::cin >> item;
grd.IncludeItem(item);
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
catch (...)
{
std::cout << "Bad input.\n" << std::flush;
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
break;
case 'r':
try
{
std::cout << "\nEnter guardian's item to exclude\t" << std::flush; std::cin >> item;
grd.ExcludeItem(item);
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
catch (...)
{
std::cout << "Bad input.\n" << std::flush;
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
break;
case 'a':
try
{
std::cout << "\nEnter programmer's first name\t" << std::flush; std::cin >> fn;
std::cout << "\nEnter programmer's last name\t" << std::flush; std::cin >> ln;
std::cout << "\nEnter programmer's patronymic\t" << std::flush; std::cin >> pc;
std::cout << "\nEnter programmer's salary\t" << std::flush; std::cin >> sr;
prg.ChangeNameSalary(fn, ln, pc, sr);
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
catch (...)
{
std::cout << "Bad input.\n" << std::flush;
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
break;
case 's':
prg.PrintProgrammer();
break;
case 'd':
try
{
std::cout << "\nEnter programmer's technology to include\t" << std::flush; std::cin >> item;
prg.IncludeTech(item);
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
catch (...)
{
std::cout << "Bad input.\n" << std::flush;
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
break;
case 'f':
try
{
std::cout << "\nEnter programmer's technology to exclude\t" << std::flush; std::cin >> item;
prg.ExcludeTech(item);
//system("timeout 5 && cls");
// system("timeout 5");
// system("cls");
}
catch (...)
{
std::cout << "Bad input.\n" << std::flush;
//system("timeout 5 && cls");
//system("timeout 5");
//system("cls");
}
break;
case '0':
exit(0);
break;
}
}
}