-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht7.cpp
More file actions
61 lines (51 loc) · 1.05 KB
/
Copy patht7.cpp
File metadata and controls
61 lines (51 loc) · 1.05 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
/*
properties of friend
1. not in scope of class
2. can be invoved without the help of object
3.usually contains the objects as arguments
4. can be declared inside public or private
*/
#include <iostream>
using namespace std;
class complex;
class calculator
{
public:
int add(int a, int b)
{
return a + b;
}
int sumrealcomplex(complex, complex);
};
class complex
{
int a, b;
//friend int calculator::sumrealcomplex(complex o1, complex o2);
friend class calculator;
public:
void read(int x, int y)
{
a = x;
b = y;
}
void print()
{
cout << "complex no are " << a << " + " << b << " i " << endl;
}
};
int calculator::sumrealcomplex(complex o1, complex o2)
{
return o1.a + o2.a;
}
int main()
{
complex c1, c2;
c1.read(2, 4);
c1.print();
c2.read(3, 7);
c2.print();
calculator c;
int res = c.sumrealcomplex(c1, c2);
cout << "the sum of real and img part is" << res << endl;
return 0;
}