Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Employee{
- protected:
- char ime[50];
- int exp;
- int god;
- public:
- Employee(char * ime="", int exp=0,int god=0)
- {
- strcpy(this->ime,ime);
- this->exp=exp;
- this->god=god;
- }
- virtual double plata()=0;
- virtual double bonus()=0;
- int get_god()
- {
- return god;
- }
- virtual ~Employee(){}
- virtual int getType()=0;
- };
- class SalaryEmployee:public Employee{
- private:
- int salary;
- public:
- SalaryEmployee(char * ime="", int exp=0,int god=0,int salary=0)
- :Employee(ime,exp,god)
- {
- this->salary=salary;
- }
- double bonus()
- {
- return (salary*exp)/100;
- }
- double plata()
- {
- return salary+bonus();
- }
- int getType()
- {
- return 1;
- }
- };
- class HourlyEmployee:public Employee{
- private:
- int totalhours;
- int pay_per_hour;
- public:
- HourlyEmployee(char * ime="", int exp=0,int god=0,int totalhours=0,int pay_per_hour=0)
- :Employee(ime,exp,god)
- {
- this->totalhours=totalhours;
- this->pay_per_hour=pay_per_hour;
- }
- double bonus()
- {
- if(totalhours>320)
- {
- return (pay_per_hour*0.5)*(totalhours-320);
- }
- else
- return 0;
- }
- double plata()
- {
- return (totalhours*pay_per_hour)+bonus();
- }
- int getType()
- {
- return 2;
- }
- };
- class Freelancer:public Employee{
- private:
- int broj_proekti;
- double sumi[100];
- public:
- Freelancer(char * ime="", int exp=0,int god=0,int broj_proekti=0,double *sumi=0)
- :Employee(ime,exp,god)
- {
- this->broj_proekti=broj_proekti;
- for(int i=0;i<broj_proekti;i++)
- {
- this->sumi[i]=sumi[i];
- }
- }
- double bonus()
- {
- if(broj_proekti>5) return (broj_proekti-5)*1000;
- else return 0;
- }
- double plata()
- {
- double total=0;
- for(int i=0;i<broj_proekti;i++)
- {
- total+=sumi[i];
- }
- return total+bonus();
- }
- int getType()
- {
- return 3;
- }
- };
- class Company{
- private:
- char ime[50];
- int brVrab;
- Employee ** employees;
- public:
- Company(char *ime)
- {
- this->employees = new Employee *[0];
- this->brVrab=0;
- strcpy(this->ime,ime);
- }
- Company &operator +=(Employee *c)
- {
- Employee **tmp = new Employee*[brVrab+1];
- for(int i=0;i<brVrab;i++)
- {
- tmp[i]=employees[i];
- }
- tmp[brVrab++]=c;
- delete [] employees;
- employees=tmp;
- return *this;
- }
- double vkupnaPlata()
- {
- double total=0;
- for(int i=0;i<brVrab;i++)
- {
- total+=employees[i]->plata();
- }
- return total;
- }
- double filtriranaPlata(Employee *emp)
- {
- double vkupno=0;
- for(int i=0;i<brVrab;i++)
- {
- if(employees[i]==emp)
- {
- vkupno+=employees[i]->plata();
- }
- }
- }
- void pecatiRabotnici()
- {
- int sal_e=0;
- int hour_e=0;
- int free=0;
- for(int i=0;i<brVrab;i++)
- {
- if(employees[i]->getType()==1)
- {
- sal_e++;
- }
- if(employees[i]->getType()==2)
- {
- hour_e++;
- }
- if(employees[i]->getType()==3)
- {
- free++;
- }
- }
- cout<<"Vo kompanijata Smetkovodstveno_biro_Ekonomik rabotat:"<<endl;
- cout<<"Salary employees: "<<sal_e<<endl;
- cout<<"Hourly employees: "<<hour_e<<endl;
- cout<<"Freelancers: "<<free<<endl;
- }
- };
- bool operator==(Employee &e,Employee &emp) {
- if((e.get_god()==emp.get_god())&&(e.bonus()==emp.bonus())) return true;
- else return false;
- }
- int main() {
- char name[50];
- cin >> name;
- Company c(name);
- int n;
- cin >> n;
- char employeeName[50];
- int age;
- int experience;
- int type;
- for (int i=0; i <n; ++i) {
- cin >> type;
- cin >> employeeName >> age >> experience;
- if (type == 1) {
- int basicSalary;
- cin >> basicSalary;
- c += new SalaryEmployee(employeeName, age, experience, basicSalary);
- }
- else if (type == 2) {
- int hoursWorked;
- int hourlyPay;
- cin >> hoursWorked >> hourlyPay;
- c += new HourlyEmployee(employeeName, age, experience, hoursWorked, hourlyPay);
- }
- else {
- int numProjects;
- cin >> numProjects;
- double projects[10];
- for (int i=0; i < numProjects; ++i) {
- cin >> projects[i];
- }
- c += new Freelancer(employeeName, age, experience, numProjects, projects);
- }
- }
- c.pecatiRabotnici();
- cout << "Vkupnata plata e: " << c.vkupnaPlata() << endl;
- Employee * emp = new HourlyEmployee("Petre_Petrov",31,6,340,80);
- cout << "Filtriranata plata e: " << c.filtriranaPlata(emp);
- delete emp;
- }
Add Comment
Please, Sign In to add comment