Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- //abstract Employee
- class Employee{
- protected:
- char name[50];
- int age;
- int exp;
- public:
- Employee(){
- strcpy(this->name, "None");
- this->age = 0;
- this->exp = 0;
- }
- Employee(const char * name, const int age, const int exp){
- strcpy(this->name, name);
- this->age = age;
- this->exp = exp;
- }
- virtual ~Employee(){}
- virtual const double bonus() = 0;
- virtual const double plata() = 0;
- const int getAge(){
- return this->age;
- }
- };
- //Derived classes
- class SalaryEmployee : public Employee{
- private:
- double baseSalary;
- public:
- SalaryEmployee(){
- this->baseSalary = 0.0;
- }
- SalaryEmployee(const char * name, const int age, const int exp, const double baseSalary) : Employee(name, age, exp){
- this->baseSalary = baseSalary;
- }
- ~SalaryEmployee(){}
- const double bonus(){
- return (this->baseSalary * this->exp) / 100;
- }
- const double plata(){
- return this->baseSalary + this->bonus();
- }
- };
- class HourlyEmployee : public Employee{
- private:
- int totalHours;
- double salaryPerHour;
- public:
- HourlyEmployee(){
- this->totalHours = 0;
- this->salaryPerHour = 0.0;
- }
- HourlyEmployee(const char * name, const int age, const int exp, const int totalHours, const double salaryPerHour) : Employee(name, age, exp){
- this->totalHours = totalHours;
- this->salaryPerHour = salaryPerHour;
- }
- ~HourlyEmployee(){}
- const double bonus(){
- if(this->totalHours > 320){
- return (this->totalHours - 320) * (this->salaryPerHour * 0.5);
- } else
- return 0.0;
- }
- const double plata(){
- return (this->totalHours * this->salaryPerHour) + this->bonus();
- }
- };
- class Freelancer : public Employee{
- private:
- int doneProjects;
- double * money;
- public:
- Freelancer (){
- this->doneProjects = 0;
- this->money = new double[0];
- }
- Freelancer (const char * name, const int age, const int exp, const int doneProjects, const double * money) : Employee(name, age, exp){
- this->doneProjects = doneProjects;
- this->money = new double[this->doneProjects];
- for(int i=0; i<this->doneProjects; i++)
- this->money[i] = money[i];
- }
- ~Freelancer (){
- delete [] this->money;
- }
- const double bonus(){
- if(this->doneProjects > 5){
- return (this->doneProjects - 5) * 1000;
- } else
- return 0.0;
- }
- const double plata(){
- double totalSalary = 0.0;
- for(int i=0; i<this->doneProjects; i++)
- totalSalary += this->money[i];
- return totalSalary + this->bonus();
- }
- };
- bool operator==(Employee *left, Employee &right){
- if((left->getAge() == right.getAge())&&left->bonus() == right.bonus())
- return true;
- else
- return false;
- }
- //class Company
- class Company{
- private:
- char name[50];
- int noEmployees;
- Employee ** emps;
- public:
- Company(){
- strcpy(this->name, "None");
- this->noEmployees = 0;
- this->emps = new Employee *[0];
- }
- Company(const char * name){
- strcpy(this->name, name);
- this->noEmployees = 0;
- this->emps = new Employee *[0];
- }
- ~Company(){
- //delete [] this->emps;
- }
- Company &operator += (Employee * orig){
- Employee ** tmp = new Employee *[this->noEmployees+1];
- for(int i=0; i<this->noEmployees; i++)
- tmp[i] = this->emps[i];
- tmp[this->noEmployees++] = orig;
- delete [] this->emps;
- this->emps = tmp;
- return *this;
- }
- double vkupnaPlata(){
- double totalSalary = 0.0;
- for(int i=0; i<this->noEmployees; i++)
- totalSalary += this->emps[i]->plata();
- return totalSalary;
- }
- double filtriranaPlata(Employee *emp){
- double totalFiltered = 0.0;
- for(int i=0; i<this->noEmployees; i++){
- if(this->emps[i] == *emp)
- totalFiltered += this->emps[i]->plata();
- }
- return totalFiltered;
- }
- const void pecatiRabotnici(){
- int salaryEmps = 0; int hourlyEmps = 0; int freelancerEmps = 0;
- for(int i=0; i<this->noEmployees; i++){
- SalaryEmployee *a = dynamic_cast<SalaryEmployee *>(this->emps[i]);
- HourlyEmployee *b = dynamic_cast<HourlyEmployee *>(this->emps[i]);
- Freelancer *c = dynamic_cast<Freelancer *>(this->emps[i]);
- if(a)
- salaryEmps++;
- else if(b)
- hourlyEmps++;
- else if(c)
- freelancerEmps++;
- }
- cout << "Vo kompanijata " << this->name << " rabotat:" << endl;
- cout << "Salary employees: " << salaryEmps << endl;
- cout << "Hourly employees: " << hourlyEmps << endl;
- cout << "Freelancers: " << freelancerEmps << endl;
- }
- };
- //main
- 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