Answer to Question #264573 in C++ for DANISH

Question #264573

Write a program which reads salaries of 10 employees of an organization. The program will tell, what the maximum salary is and what the minimum salary is 


1
Expert's answer
2021-11-12T16:31:50-0500
#include<iostream>
#include<string.h>
using namespace std;

class Employee
{
        public:
                int eno;
                char ename[100];
                float salary;
        public:
                void accept_details()
                {
                        cout<<"\n Enter Employee Details";
                        cout<<"\n -------------------------------------------";
                        cout<<"\n Enter Employee Id           :  ";
                        cin>>eno;
                        cout<<"\n Enter Employee Name     :  ";
                        cin>>ename;
                        cout<<"\n Enter Salary                     :  ";
                        cin>>salary;
                }
                int search(int empno);       //Function Overloading
                int search(char *empname); //search() function is overloaded
                int search(float empsalary);
};
int Employee :: search(int empno)
{
        if(eno==empno)
        {
                cout<<"\n Displaying Information \n";
                cout<<"\n Employee Name       :   "<<ename;
                cout<<"\n Salary                       :   "<<salary<<endl;
        }
        return 0;
}
int Employee :: search(char *empname)
{
        if(strcmp(ename,empname)==0)
        {
                cout<<"\n Displaying Information \n";
                cout<<"\n Employee Id         :   "<<eno;
                cout<<"\n Salary                   :   "<<salary;
        }
        return 0;
}
int Employee :: search(float empsalary)
{
        if(salary==empsalary)
        {
                cout<<"\n Displaying Information \n";
                cout<<"\n Employee Id             :   "<<eno;
                cout<<"\n Employee Name       :   "<<ename;
        }
        return 0;
}
int main()
{
        Employee *emp;
        int cnt, i, max;
        char name[100];
        int eno;
        float sal;
        cout<<"\n Enter No. of Employee Details You Want  :  ";
        cin>>cnt;
        emp=new Employee[cnt];
        for(i=0;i<cnt;i++)
        {
                emp[i].accept_details();
        }
        cout<<"\n -------------------------------------------";
        cout<<"\n\n Search Employee by Id         :   ";
        cin>>eno;
        for(i=0;i<cnt;i++)
        {
                emp[i].search(eno);
        }
        cout<<"\n -------------------------------------------";
        cout<<"\n\n Search Employee by Name       :   ";
        cin>>name;
        for(i=0;i<cnt;i++)
        {
                emp[i].search(name);
        }
        cout<<"\n -------------------------------------------";
        cout<<"\n\n Search Employee by Salary     :   ";
        cin>>sal;
        for(i=0;i<cnt;i++)
        {        emp[i].search(sal);
        }
        max=emp[0].salary;
        for(i=0;i<cnt;i++)
        {
                if(emp[i].salary>max)
                {
                        max=emp[i].salary;
                }
        }
        for(i=0;i<cnt;i++)
        {
                if(emp[i].salary==max)
                {
                        cout<<"\n ------------------------------------------------\n";
                        cout<<"\n Maximum Salary of Employee Name is : "<<emp[i].ename;
                        cout<<"\n And Salary is : "<<emp[i].salary;
                }

        }
        return 0;
}

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