-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq27.cpp
83 lines (74 loc) · 2.12 KB
/
q27.cpp
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
/* WAP to define 2 classes, Emp1 and Emp2
* Data members: Name, DOJ, Dept, Salary, etc.
* Member functions: Input and output
*
* Display details of employee who has higher salary using friend function as a
* bridge
*/
#include <iostream>
using namespace std;
class Emp1;
class Emp2;
class Emp1 {
string name, dept, doj;
float salary;
public:
Emp1() {
cout << "Enter employee 1 name: ";
cin >> name;
cout << "Enter employee 1 dept: ";
cin >> dept;
cout << "Enter employee 1 DOJ: ";
cin >> doj;
cout << "Enter employee 1 salary: ";
cin >> salary;
}
void display_details();
friend void show_higher_salary(Emp1& e1, Emp2& e2);
};
void Emp1::display_details() {
cout << "\tEmployee name: " << name << endl;
cout << "\tEmployee dept: " << dept << endl;
cout << "\tEmployee doj: " << doj << endl;
cout << "\tEmployee salary: " << salary << endl;
}
class Emp2 {
string name, dept, doj;
float salary;
public:
Emp2() {
cout << "Enter employee 2 name: ";
cin >> name;
cout << "Enter employee 2 dept: ";
cin >> dept;
cout << "Enter employee 2 DOJ: ";
cin >> doj;
cout << "Enter employee 2 salary: ";
cin >> salary;
}
void display_details();
friend void show_higher_salary(Emp1& e1, Emp2& e2);
};
void Emp2::display_details() {
cout << "\tEmployee name: " << name << endl;
cout << "\tEmployee dept: " << dept << endl;
cout << "\tEmployee doj: " << doj << endl;
cout << "\tEmployee salary: " << salary << endl;
}
void show_higher_salary(Emp1& e1, Emp2& e2) {
if (e1.salary > e2.salary) {
cout << "\nEmployee 1 has higher salary! \n";
e1.display_details();
} else if (e1.salary < e2.salary) {
cout << "\nEmployee 2 has higher salary! \n";
e2.display_details();
} else {
cout << "Both salaries are equal!" <<endl;
}
}
int main() {
Emp1 e1;
Emp2 e2;
show_higher_salary(e1, e2);
return 0;
}