Answer to Question #185664 in C++ for Jagadeeshwaran

Question #185664

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)



1
Expert's answer
2021-04-29T19:21:31-0400
#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;
}

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