-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path28.cpp
67 lines (54 loc) · 1.26 KB
/
28.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
#include <iostream>
using namespace std;
class Complex;
class Calculator
{
public:
int add(int a, int b)
{
return (a + b);
}
int sumRealComplex(Complex, Complex);
int sumImgComplex(Complex, Complex);
};
class Complex
{
int a, b;
// Individually declaring functions as friends
// friend int Calculator ::sumRealComplex(Complex m, Complex n);
// friend int Calculator ::sumImgComplex(Complex m, Complex n);
// Declaring entire class as friends
friend class Calculator;
public:
void setData(int v1, int v2)
{
a = v1;
b = v2;
};
void Print(void)
{
cout << "The complex no. is " << a << " + " << b << "i" << endl;
}
};
int Calculator ::sumRealComplex(Complex m, Complex n)
{
return (m.a + n.a);
};
int Calculator ::sumImgComplex(Complex m, Complex n)
{
return (m.b + n.b);
};
int main()
{
Complex c1, c2;
c1.setData(5, 7);
c2.setData(3, 4);
c1.Print();
c2.Print();
Calculator calc;
int Reresult = calc.sumRealComplex(c1, c2);
int Imgresult = calc.sumImgComplex(c1, c2);
cout << "The sum of real parts of c1 and c2 is " << Reresult << endl;
cout << "The sum of imaginary parts of c1 and c2 is " << Imgresult << endl;
return 0;
}