Math, asked by sss5888, 4 months ago

1
Program to define a class employee' having data members
emp- id , emp- name and emp- salary. Accept & display
data for employees having salary greater then
25,0001-​

Answers

Answered by remixvideo7860
2

Answer:

Find employee with highest salary - C++ Program

Home > CPP Programs > CPP Functions Programs

« PreviousNext »

Programs

C++ Programs using Functions

Area and Perimeter

Area and circumference

Fahrenheit to Centigrade

Centigrade to Fahrenheit

Fibonacci series

Swap using call-by-value

Swap with call-by-reference

Bubble sort

Area using function overloading

Greater no. with Inline function

Program on recursive function

Highest paid employee

No. with maximum digit sum

Q. Write a C++ program to accept records of 'n' employee and store it in an array. Class employee contains eno, ename[20], salary attributes. Overload search() function as follows:

a. int search(employee e [], int n, int eno);

b. int search(employee e [], int n, char ename[]);

c. int search(employee e [], int n, float salary);

Which displays all employees whose sal > salary.

Answer:

#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;

Similar questions