Write a C++ Program, using classes, that stores the five-employee data (name, age, salary,
designation). Write a function to take input from the user and also write a function to find
the name, age and designation of the employee having maximum salary.
using namespace std;
#define NO_OF_EMPLOYEE 5
struct Employee
{
string Name;
int Age;
string Desig;
int Salary;
};
struct Employee E[NO_OF_EMPLOYEE];
class Emp
{
public:
void getInfo(int n)
{
cout<<"\nEnter Name : "; cin>>E[n].Name;
cout<<"\nEnter Age : "; cin>>E[n].Age;
cout<<"\nEnter Salary : "; cin>>E[n].Salary;
cout<<"\nEnter Desig. : "; cin>>E[n].Desig;
}
void ViewInfo(int n)
{
int r;
cout<<"\nName\t\tAge\t\tDesig.\t\tSalary";
for(r=0;r<n;r++)
{
cout<<"\n"<<E[r].Name<<"\t\t"<<E[r].Age<<"\t\t"<<E[r].Desig<<"\t\t"<<E[r].Salary;
}
}
int MaxSalary(int n)
{
int r,m,i;
m = E[0].Salary; i=0;
for(r=0;r<n;r++)
{
if(m <= E[r].Salary) {m = E[r].Salary; i= r;}
}
return(i);
}
};
main(void)
{
int n=0,Flag=1,r;
class Emp Em;
while(Flag)
{
cout<<"\nPress 1 to add an employee";
cout<<"\nPress 2 to view employee information";
cout<<"\nPress 3 to view employee with max. salary";
cout<<"\nPress 0 to Quit";
cout<<"\nSelect Option (0 to 3): "; cin>>Flag;
while(Flag<0 || Flag>3)
{
cout<<"\nSelect Option (0 to 3): "; cin>>Flag;
}
if(Flag==1)
{
if(n<NO_OF_EMPLOYEE)
{
Em.getInfo(n);
n++;
cout<<"\n\nEmployee added successfully.";
}
else cout<<"\nNo more employee could be added as Max. Employee Count = "<<NO_OF_EMPLOYEE;
}
if(Flag==2)
{
Em.ViewInfo(n);
}
if(Flag==3)
{
r = Em.MaxSalary(n);
cout<<"\n\nMax. Salary Employee:";
cout<<"\nName\t\tAge\t\tDesig.\t\tSalary";
cout<<"\n"<<E[r].Name<<"\t\t"<<E[r].Age<<"\t\t"<<E[r].Desig<<"\t\t"<<E[r].Salary;
}
}
}
Comments
Leave a comment