-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6.2.cpp
More file actions
44 lines (41 loc) · 702 Bytes
/
6.2.cpp
File metadata and controls
44 lines (41 loc) · 702 Bytes
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
// 6.2 wap in c++ find the maximum between two different classes using friend function
#include <iostream>
using namespace std;
class second;
class first
{
int fx;
public:
void inputf(int x)
{
fx = x;
}
friend void max(first, second);
};
class second
{
int sx;
public:
void inputs(int x)
{
sx = x;
}
friend void max(first, second);
};
void max(first a, second b)
{
if (a.fx > b.sx)
cout << a.fx << " is greater than " << b.sx;
else
cout << b.sx << " is greater than " << a.fx;
}
int main()
{
class first f;
class second s;
f.inputf(40);
s.inputs(30);
max(f, s);
}
// Output:
// 40 is greater than 30