Answer to Question #182755 in C++ for Jainab

Question #182755

Suppose there is XYZ Company and there are different departments like: production, marketing, finance, sales etc. Manager of the company want to know about the detail of the employees who are highly paid from each department. Write a program using the concept of classes to implement the same.


1
Expert's answer
2021-04-20T01:11:02-0400
#include <iostream>
using namespace std;
class Department{
    public:
    string name;
    Department(){};
    Department(string s){
        name = s;
    }
};
class Production: public Department{
    public:
    Production():Department("Production"){}
};
class Marketing: public Department{
    public:
    Marketing():Department("Marketing"){}
};
class Finance: public Department{
    public:
    Finance():Department("Finance"){}
};
class Sales: public Department{
    public:
    Sales():Department("Sales"){}
};
class Employee{
    public:
    string name;
    int salary;
    Department department;
    Employee(){}
    Employee(string s, int sal, Department dep){
        name = s;
        salary = sal;
        department = dep;
    }
    void showDetails(){
        cout<<"Name: "<<this->name<<endl<<"Salary: "<<this->salary<<endl<<"Department: "<<this->department.name;
    }
};
int main(){
    Employee employees[4] = {Employee("John", 15000, Production()), Employee("James", 16000, Finance()), 
                            Employee("Peter", 10000, Sales()), Employee("Andrew", 12000, Marketing())};
    int max_sal = 0;
    Employee max;
    for(int i = 0; i < 4; i++){
        if(employees[i].salary > max_sal){
            max_sal = employees[i].salary;
            max = employees[i];
        }
    }
    cout<<"Employee with maximum salary is;\n";
    max.showDetails();
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS