Answer to Question #322835 in C++ for Rushikesh

Question #322835

The manager of the company has informed his assistant to enter the age

of all the workers working in production department. Among all he has to

find the employee with maximum age employee. Help the manager with

c++ program based on the concept of object oriented programming by

creating a class employee having members empid, empname, edept,eage

and display the name ,dept. and salary employee whose age is maximum.

Store the date of at least 7 employees. Make the data members of class

only public .

Constraints

Employee age should greater than 22 if constraints are not matched then

display "wrong age input


1
Expert's answer
2022-04-03T11:15:23-0400
#include<iostream>
#include<string>

using namespace std;

class Employee
{
public:
	int empid;
	string empName;
	string edept;
	int eage;
	Employee(){}
	void Assign()
	{
		cout << "Please, enter empid: ";
		cin >> empid;
		cout << "Please, enter empName: ";
		cin >> empName;
		cin.ignore(256,'\n');
		cout << "Please, enter edept: ";
		getline(cin,edept,'\n');
		do
		{
			cout << "Please, enter eage: ";
			cin >> eage;
			if (eage < 23)
			{
				cout << "Wrong age input!"<<endl;
			}
		} while (eage < 23);
	}
		
	void Display()
	{
		cout << "\nInfo about employee:"
			<< "\nempid: " << empid
			<< "\nempName: " << empName
			<< "\nedept: " << edept
			<< "\neage: " << eage;
	}
};


int main()
{
	const int N = 7;
	Employee arrEmp[N];
	for (int i = 0; i < N; i++)
	{
		cout << "Info about " << i + 1 << " employee" << endl;
		arrEmp[i].Assign();
	}
	for (int i = 0; i < N; i++)
	{
		arrEmp[i].Display();
	}
	int maxage = arrEmp[0].eage;
	int num = 0;
	for (int i = 0; i < N; i++)
	{
		if (arrEmp[i].eage > maxage)
			num = i;
	}
	cout << "\nThe employee with the maximum age is " << arrEmp[num].empName;
}

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