Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Employee {
- protected:
- char name[50];
- int age;
- int experience;
- public:
- Employee( const char * name, int age, int experience) {
- strcpy(this->name,name);
- this->age = age;
- this->experience = experience;
- }
- int getAge() {
- return age;
- }
- virtual double plata() = 0;
- virtual double bonus() =0;
- virtual ~Employee() {}
- };
- bool operator == ( Employee &levo, Employee &desno) {
- return levo.getAge() == desno.getAge()&&levo.bonus() == desno.bonus();
- }
- class SalaryEmployee : public Employee {
- private:
- double basicSalary;
- public:
- SalaryEmployee(char * name, int age, int experience, int basicSalary)
- : Employee(name,age, experience) {
- this->basicSalary = basicSalary;
- }
- double bonus() {
- return (experience * basicSalary) / 100.0;
- }
- double plata() {
- return basicSalary + bonus();
- }
- };
- class HourlyEmployee : public Employee {
- private:
- int hoursWorked;
- double hourlyPay;
- public:
- HourlyEmployee(const char * name, int age, int experience, int hoursWorked, double hourlyPay)
- : Employee(name, age, experience) {
- this->hoursWorked = hoursWorked;
- this->hourlyPay = hourlyPay;
- }
- double bonus(){
- if (hoursWorked > 320) {
- return (hoursWorked - 320) * 0.5 * hourlyPay;
- }
- else
- return 0;
- }
- double plata() {
- return hoursWorked * hourlyPay + bonus();
- }
- };
- class Freelancer : public Employee {
- private:
- int num;
- double projects[10];
- public:
- Freelancer(const char * name, int age, int experience, int num, double projects[])
- : Employee(name,age,experience) {
- this->num = num;
- for (int i=0; i < num; ++i) {
- this->projects[i] = projects[i];
- }
- }
- double bonus() {
- if (num > 5) {
- return (num - 5) * 1000.0;
- }
- else
- return 0;
- }
- double plata() {
- double sum = 0;
- for (int i=0; i < num; ++i) {
- sum += projects[i];
- }
- return sum + bonus();
- }
- };
- class Company {
- private:
- char name[50];
- int number;
- Employee ** employee;
- public:
- Company( char* name) {
- number = 0;
- strcpy(this->name,name);
- employee = new Employee*[0];
- }
- Company & operator += (Employee *emp) {
- Employee ** tmp = new Employee*[number + 1];
- for (int i=0; i < number; ++i) {
- tmp[i] = employee[i];
- }
- tmp[number++] = emp;
- delete [] employee;
- employee = tmp;
- return * this;
- }
- double vkupnaPlata() {
- double sum = 0;
- for (int i=0; i < number; ++i) {
- sum += employee[i] -> plata();
- }
- return sum;
- }
- void pecatiRabotnici()
- {
- int count=0 , count1=0, count2=0;
- for(int i = 0 ; i < number ; i++){
- SalaryEmployee *s=dynamic_cast<SalaryEmployee*>(employee[i]);
- if(s!=0)
- {
- count++;
- }
- HourlyEmployee *h=dynamic_cast<HourlyEmployee*>(employee[i]);
- if(h!=0)
- {
- count1++;
- }
- Freelancer*f=dynamic_cast<Freelancer*>(employee[i]);
- if(f!=0)
- {
- count2++;
- }
- }
- cout << "Vo kompanijata " << name << " rabotat:" <<endl;
- cout<<"Salary employees: "<<count<<endl;
- cout<<"Hourly employees: "<<count1<<endl;
- cout<<"Freelancers: "<<count2<<endl;
- }
- double filtriranaPlata(Employee *emp) {
- double plata = 0;
- for (int i=0; i < number; ++i) {
- if (*emp == *employee[i]) {
- plata += employee[i] -> plata();
- }
- }
- return plata;
- }
- /* ~Company() {
- for (int i=0; i < number; ++i) {
- delete employee[i];
- }
- delete [] employee;
- }*/
- };
- 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