-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFriend_Functions_1.cpp
68 lines (57 loc) · 1.46 KB
/
Friend_Functions_1.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
// author: jaydattpatel
//friend function
#include <iostream>
using namespace std;
class Rect
{
//by default private variable and function if not mention it is private or public
int a, b; // a is the variable to store width and b is the variable to store height
int x = 77;
protected:
int z = 55;
public:
int y = 88;
void setvalue(int c, int d)
{
a = c;
b = d;
};
int area ()
{return (a * b);}
friend class t_class;
friend Rect duplicate(Rect);
friend void find_max(Rect);
};
class t_class
{
public:
void react_print(Rect &r)
{
cout<<"\nx,y and z of Rect accessed by t_class: "<<r.x<<" "<<r.y<<" "<<r.z;
}
};
Rect duplicate (Rect rectparam)
{
Rect r;
r.a = rectparam.a;
r.b = rectparam.b;
return (r);
}
void find_max(Rect t)
{
int max;
max = (t.a>t.b)?(t.a):(t.b);
cout<<"Maximum Number is "<<max;
}
int main ()
{
Rect r1, r2;
r1.setvalue(4,7);
cout <<"r1.area(): "<<r1.area()<<endl;
r2 = duplicate (r1);
cout <<"r2.area(): "<<r2.area()<<endl;
find_max(r1);
t_class tt;
tt.react_print(r1);
return 0;
}