0% found this document useful (0 votes)
52 views4 pages

Assignment No. 3:-DATE: - Problem Statement

The document describes a C++ program that defines an Employee class with private data members for name, employee ID, and salary. It includes public member functions to input and display employee details. A friend function calculates the highest salary among 5 employee objects stored in an array. The friend function loops through the array, tracks the highest salary, and displays the name, ID, and salary of the employee with the highest pay. The main function initializes an array of Employee objects, inputs their details, displays them, and calls the friend function to find the highest paid employee.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views4 pages

Assignment No. 3:-DATE: - Problem Statement

The document describes a C++ program that defines an Employee class with private data members for name, employee ID, and salary. It includes public member functions to input and display employee details. A friend function calculates the highest salary among 5 employee objects stored in an array. The friend function loops through the array, tracks the highest salary, and displays the name, ID, and salary of the employee with the highest pay. The main function initializes an array of Employee objects, inputs their details, displays them, and calls the friend function to find the highest paid employee.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ASSIGNMENT NO.

3:DATE:PROBLEM STATEMENT:-Create class employee whose private data members name,


e_id, salary. Public member of this class is input () to take the details of an employee and
display () to display details of an employee. Now calculate heighst salary of 5 members
using friend function heighst () and show the details of that employee.

ALGORITHIM:heighst( )
step 1:- Read the array of object of employee
step 2:- Take the i/p i,j,val= emp[0].salary.
step 3:- Start for loop ( i=1 to 5 by 1)
step 4:check if(val<emp[i].salary) then goto step6
step 5:- val=emp[i].salary;
step 6:- Start for loop ( j=0 to5 by 1)
step 7:- check if(val==emp[j].salary) and print followings
step 8:-emp[j].name;
step 9:-emp[j].em_id;
step 10:- emp[j].salary;

Program Code:#include<iostream>
using namespace std;
class employee
{
private:
int salary;
int em_id;
char name[50];
public:
void insert();
void display();
friend void heighst(employee emp[]);
};
void employee::insert()
{
cout<<"\nenter the name";
cin>>name;
cout<<"\nenter the id";
cin>>em_id;
cout<<"\nenter the salary";
cin>>salary;
}
void employee::display()
{

cout<<"\nenter the name";


cout<<name;
cout<<"\nenter the id";
cout<<em_id;
cout<<"\nenter the salary";
cout<<salary;
}
void heighst(employee emp[])
{
int val=emp[0].salary;
for(int i=0;i<5;i++)
{
if(val<emp[i].salary)
{
val=emp[i].salary;
}
}
for(int j=0;j<5;j++)
{
if(val==emp[j].salary)
{
cout<<"\n"<<emp[j].name;
cout<<"\n"<<emp[j].em_id;
cout<<"\n"<<emp[j].salary;
}

}
int main()
{
employee emp[5],emp1;
for(int i=0;i<5;i++)
{
emp[i].insert();
}
for(int j=0;j<5;j++)
{
emp[j].display();
}
heighst(emp);
}

Output:enter the namemrinmoy


enter the id56
enter the salary2000
enter the namerohit

enter the id58


enter the salary23000
enter the namesupratim
enter the id57
enter the salary52300
enter the namekakuli
enter the id52
enter the salary52222
enter the namearijit
enter the id42
enter the salary22222
enter the namemrinmoy
enter the id56
enter the salary2000
enter the namerohit
enter the id58
enter the salary23000
enter the namesupratim
enter the id57
enter the salary52300
enter the namekakuli
enter the id52
enter the salary52222
enter the namearijit
enter the id42
enter the salary22222
supratim
57
52300

DISCUSSION:-

1. Friend function:-c++ allows the common function to be made


friendly with both the classes, thereby allowing the function to have
access to the private data of these classes. Such a function need not
be a member of any of these classes. The function can be defined
anywhere in the program. Like in our program the friend function
heighst.
2. Array of object:-in c++ we can also have array of variables that are of
the type class, such variables are called arrays of objects. These
arrays of objects are stored inside the memory in the same way as
the multi-dimensional array.

You might also like