LAB-4

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

19CSE201 – Advanced Programming

Lab Experiments for week1

4)Create a class Employee with members empno , name , deptname and


designation as private variables. Create a friend function ListDeptWise
to list all employees for a given dept.
AIM:
To create a class Employee with members empno , name , deptname
and designation as private variables and using a friend function
ListDeptWise to list all employees for a given dept

ALGORITHM:
1)START
2)Create a class Employee with empno,name,deptname and
designation as data members as private(Default).
3)Create a string edptname to read the department name.
4)Create a friend function ListDeptWise() for listing the details of
employees for a given dept
5)Declare Object of class in main function and Print the output using
member function display()
6)STOP

PROGRAM:
#include <iostream>
#include <string>
using namespace std;
class employee {
int EmpNo;
string Name;
string DeptName;
string Designation;
public:
void emp(int eno, string enm, string edpt, string edesig) {

EmpNo = eno;
Name = enm;
DeptName = edpt;
Designation = edesig;
}
void Display() {

cout << "employee number :" << EmpNo << "\n";


cout << "Name is :" << Name << "\n";
cout << "Department is :" << DeptName << "\n";
cout << "Designation is :" << Designation<< "\n\n";
}

friend void ListDeptWise(employee[]);


};
void ListDeptWise(employee empyee[]) {
string edptname;
cout << "Enter the department name: ";
cin >> edptname;
cout << "\n";
for(int i = 0; i < 10; ++i)
{
if(empyee[i].DeptName == edptname)
{
empyee[i].Display();
}
}
}
int main() {

employee obj[10];
obj[1].emp(1, "Aruna", "Network", "Boss");
obj[2].emp(2, "Charan", "Designing", "Clerk");
obj[3].emp(3, "Vishnu", "Accounts", "CEO");
obj[4].emp(4, "Bindu", "Network", "Boss");
obj[5].emp(5, "Rohit", "Accounts", "CAO");
obj[6].emp(6, "Prathima", "Network", "Informer");
obj[7].emp(7, "Nithin", "Network", "Clerk");
obj[8].emp(8, "Ruchitha", "Network", "Boss");
obj[9].emp(9, "Meera", "Designing", "Informer");
obj[0].emp(10, "Sowmya", "Accounts", "CEO");
ListDeptWise(obj);
return 0;
}

OUTPUT:
Department is :Network

employee number :4

Name is :Bindu

Department is :Network

Designation is :Boss

employee number :6

Name is :Prathima

Department is :Network

Designation is :Informer

employee number :7

Name is :Nithin

Department is :Network

Designation is :Clerk
employee number :8

Name is :Ruchitha

Department is :Network

Designation is :Boss

...Program finished with exit code 0

Press ENTER to exit console.

RESULT:

Program is executed successfully and the employee details have been


printed in output for a given department using friend function.

You might also like