-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtut27.cpp
More file actions
51 lines (43 loc) · 1.05 KB
/
tut27.cpp
File metadata and controls
51 lines (43 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
#include<bits/stdc++.h>
using namespace std;
// forward declaration
class Complex;
class Calculator{
public:
int add(int a,int b){
return (a+b);
}
int sumRealComplex(Complex ,Complex );
int sumCompComplex(Complex, Complex);
};
class Complex
{
int a, b;
// individually declaring functions as friend
// friend int Calculator:: sumRealComplex(Complex ,Complex );
// friend int Calculator:: sumCompComplex(Complex ,Complex );
// Ailter: Declaring the entire calculator class as friend
friend class Calculator;
public:
void setnumber(int n1, int n2)
{
a = n1;
b = n2;
}
void printnumber()
{
cout << "Your number is " << a << " + " << b << "i";
}
};
int Calculator:: sumRealComplex(Complex o1, Complex o2){
return(o1.a+o2.a);
}
int main(){
Complex o1,o2;
o1.setnumber(2,4);
o2.setnumber(5,7);
Calculator calc;
int res =calc.sumRealComplex(o1,o2);
cout<<"the sum of real part of o1 and o2 is "<<res<<endl;
return 0;
}