1. Create a class Company with Private members as staffName[20] (character array for name), stDesig[15] (character array for designation), staffSalary(integer type variable for salary) and selectData[2] (a static class member array of integer type, used for identifying staff with highest and lowest salary). A function to find and store numbers in selectData to identify the person with highest salary and one with lowest salary. Public members of class are: a function to initialize staffName, stDesig&staffSalary with values taken at runtime. A function result() to display all details of staff members with highest and lowest salary. Create a program for entering data for 5 staff members and display the details of staff having highest and lowest salary.
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int minnum= INT_MAX;
int maxnum = INT_MIN;
class Company{
char staffName[20];
char stDesign[15];
int staffSalary;
static int selectData[2];
public:
void input()
{
cout<<"Enter name : ";
cin>>staffName;
cout<<"Enter designation : ";
cin>>stDesign;
cout<<"Enter salary : ";
cin>>staffSalary;
if(Company::selectData[0] < staffSalary)
{
Company::selectData[0] = staffSalary;
}
if(Company::selectData[1] > staffSalary)
{
Company::selectData[1] = staffSalary;
}
}
int getSal()
{
return staffSalary;
}
static int maxsal()
{
return Company::selectData[0];
}
static int minsal()
{
return Company::selectData[1];
}
void display()
{
cout<<"Name : "<<staffName<<endl;
cout<<"Designation : "<<stDesign<<endl;
cout<<"Salary : "<<staffSalary<<endl;
}
};
int Company::selectData[2]={INT_MIN,INT_MAX};
int main()
{
int n;
cout<<"Enter number of employees : ";
cin>>n;
Company c[n];
cout<<endl<<"Enter Details"<<endl;
cout<<"---------------------"<<endl;
for(int i=0; i<n; i++)
{
c[i].input();
cout<<endl;
}
cout<<endl<<endl<<"Displaying Employee Records"<<endl;
cout<<"---------------------------------------"<<endl;
for(int i=0; i<n; i++)
{
c[i].display();
cout<<endl;
}
cout<<"Maximum Salary"<<setw(20)<<"Minimum Salary"<<endl;
cout<<Company::maxsal()<<" "<<setw(20)<<Company::minsal();
cout<<endl<<endl;
for(int i=0; i<n; i++)
{
if(c[i].getSal() == Company::maxsal())
{
c[i].display();
break;
}
}
cout<<endl<<endl;
for(int i=0; i<n; i++)
{
if(c[i].getSal() == Company::minsal())
{
c[i].display();
break;
}
}
}
Comments
Thanks for your answer It really helped me
Leave a comment