Create a class called employee with the following details as variables within it.
1. Name of the employee
2. Age
3. Designation
4. Salary
Get the details of 5 employees and initialize it using Constructor. Release resources using destructor. print the name, designation and salary of employees, Find the highest salaried employee in professor grade and display their details.
(Initialize the class members using constructors and destroy the objects by using destructor)
#include <iostream>
#include <string>
using namespace std;
class employee{
private:
string name;
int age;
string designation;
double salary;
public:
employee(){}
employee(string name,int age,string designation,double salary){
this->name=name;
this->age=age;
this->designation=designation;
this->salary=salary;
}
//destructor
~employee(){}
double getSalary(){
return salary;
}
void display(){
cout<<"The name: "<<this->name<<"\n";
cout<<"The age: "<<this->age<<"\n";
cout<<"The salary: "<<this->designation<<"\n";
cout<<"The name: "<<this->salary<<"\n\n";
}
};
int main (){
string name;
int age;
string designation;
double salary;
employee employees[5];
for(int i=0;i<5;i++){
cout<<"Enter the name: ";
getline(cin,name);
cout<<"Enter the age: ";
cin>>age;
cout<<"Enter the designation: ";
getline(cin,designation);
getline(cin,designation);
cout<<"Enter the salary: ";
cin>>salary;
employees[i]=employee(name,age,designation,salary);
getline(cin,name);
cout<<"\n";
}
cout<<"\n\n";
for(int i=0;i<5;i++){
employees[i].display();
}
employee highestSalariedEmployee=employees[0];
for(int i=1;i<5;i++){
if(highestSalariedEmployee.getSalary()<employees[i].getSalary()){
highestSalariedEmployee=employees[i];
}
}
cout<<"\nThe highest salaried employee: \n";
highestSalariedEmployee.display();
return 0;
}
Comments
Leave a comment