Question #172746

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.


Expert's answer

#include <iostream>
#include <string>
using namespace std;
class employee{
private:
	string name;
	int age;
	string designation;
	double salary;
public:
	//Constructor
	employee(){}
	//Constructor
	employee(string name,int age,string designation,double salary){
		this->name=name;
		this->age=age;
		this->designation=designation;
		this->salary=salary;
	}
	//destructor
	~employee(){}
	//Return salary
	double getSalary(){
		return salary;
	}
	//Display information about the employee
	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";
	}
};
//The start point of the program
int main (){
	string name;
	int age;
	string designation;
	double salary;
	employee employees[5];
	//Get the details of 5 employees and initialize it using Constructor.
	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";
	//print the name, designation and salary of employees
	for(int i=0;i<5;i++){
		employees[i].display();
	}
	//Find the highest salaried employee in professor grade and display their details.
	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();
	//delay
	system("pause");
	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!

LATEST TUTORIALS
APPROVED BY CLIENTS