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
#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;
}
Comments
Leave a comment