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.
#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;
}
Comments
Leave a comment