Answer to Question #191442 in C++ for Madeshwaran

Question #191442

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)


Runtime Input :

Sri Ram 32 Prof. 70000

Skathi 31 Prof. 50000

Sanjay 29 AP 39050

Shiva 27 AP 37200

Guna 17 AP 25150


Output :

Employee Details:

Sri Ram Prof. 70000

Skathi ASP 50000

Sanjay AP 39050

Shiva AP 37200

Guna AP 25150


Highest Salaried Employee:

Sri Ram 32 Prof. 70000


1
Expert's answer
2021-05-10T17:18:20-0400
#include<bits/stdc++.h>
using namespace std;
class Employee
{
    string nm,dsg;
    int age;
    float salary;
public:
    Employee(){}
    Employee(string name,int age,string designation,double salary)
    {
		this->nm=name;
		this->age=age;
		this->dsg=designation;
		this->salary=salary;
	}
    ~Employee(){}
    float access_salary()
    {
        return salary;
    }
    void display()
    {
		cout<<this->nm<<" ";
		cout<<this->age<<" ";
		cout<<this->dsg<<" ";
		cout<<this->salary<<" \n";
	}


};
float highest_salary(float s[],int n)
{
    float maxx;
    maxx=s[0];
    for(int i=0;i<n;i++)
    {
        if(maxx<s[i])
        {
            maxx=s[i];
        }
    }
    return maxx;
}
int main()
{
    Employee e[5];
    string nm,dsg;
    int age;
    float salary;
    int i;
    for(i=0;i<5;i++)
    {
		cout<<"Enter the name: ";
		getline(cin,nm);
		cout<<"Enter the age: ";
		cin>>age;
		cout<<"Enter the designation: ";
		getline(cin,dsg);
		getline(cin,dsg);
		cout<<"Enter the salary: ";
		cin>>salary;
		e[i]=Employee(nm,age,dsg,salary);
		getline(cin,nm);
		cout<<"\n";
	}
	for(i=0;i<5;i++)
    {
		e[i].display();
	}
	Employee highestSalariedEmployee=e[0];
	for(int i=1;i<5;i++)
    {
		if(highestSalariedEmployee.access_salary()<e[i].access_salary())
		{
			highestSalariedEmployee=e[i];
		}
	}
	cout<<"\nThe highest salaried employee: \n";
	highestSalariedEmployee.display();
}

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