-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfriend_function_program.cpp
More file actions
105 lines (88 loc) · 2.45 KB
/
friend_function_program.cpp
File metadata and controls
105 lines (88 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <iostream>
using namespace std;
class Employee {
private :
int id;
string name;
string department;
string role;
public:
void setId(int id);
void setName(string name);
void setDepartment(string department);
void setRole(string role);
int getId();
string getName();
string getDepartment();
string getRole();
friend void display(const Employee& emp);
};
void Employee::setId(int id){
this->id=id;
}
void Employee::setName(string name){
this->name=name;
}
void Employee::setDepartment(string department){
this->department=department;
}
void Employee::setRole(string role){
this->role=role;
}
int Employee::getId(){
return this->id;
}
string Employee::getName(){
return this->name;
}
string Employee::getDepartment(){
return this->department;
}
string Employee::getRole(){
return this->role;
}
void display(const Employee& emp) { // Define the display function as a friend
cout << " Employee Id :- " << emp.id << endl;
cout << " Employee Name :- " << emp.name << endl;
cout << " Employee Department :- " << emp.department << endl;
cout << " Employee Role :- " << emp.role << endl;
}
int main()
{
Employee e1;
e1.setId(1);
e1.setName("Suraj Sahani");
e1.setDepartment("Developer");
e1.setRole("Backend");
Employee e2;
e2.setId(2);
e2.setName("Amit Sahani");
e2.setDepartment("Developer");
e2.setRole("Frontend");
Employee e3;
e3.setId(3);
e3.setName("Rakesh Sahani");
e3.setDepartment("Developer");
e3.setRole("UI/UX");
cout<<" Employee Id :- "<<e1.getId()<<endl;
cout<<" Employee Name :- "<<e1.getName()<<endl;
cout<<" Employee Department :- "<<e1.getDepartment()<<endl;
cout<<" Employee Role :- "<<e1.getRole()<<endl;
cout<<"**********"<<endl;
cout<<" Employee Id :- "<<e2.getId()<<endl;
cout<<" Employee Name :- "<<e2.getName()<<endl;
cout<<" Employee Department :- "<<e2.getDepartment()<<endl;
cout<<" Employee Role :- "<<e2.getRole()<<endl;
cout<<"**********"<<endl;
cout<<" Employee Id :- "<<e3.getId()<<endl;
cout<<" Employee Name :- "<<e3.getName()<<endl;
cout<<" Employee Department :- "<<e3.getDepartment()<<endl;
cout<<" Employee Role :- "<<e3.getRole()<<endl;
cout<<"**********"<<endl;
display(e1);
cout<<"**********"<<endl;
display(e2);
cout<<"**********"<<endl;
display(e3);
return 0;
}