-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08_oops.cpp
More file actions
49 lines (45 loc) · 1.18 KB
/
08_oops.cpp
File metadata and controls
49 lines (45 loc) · 1.18 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
#include<iostream>
using namespace std;
//forwaord declaration
class complex;
class calculator {
public:
int add(int a , int b){
return (a + b);
}
int sumRealComplex(complex, complex);
int sumComComplex(complex, complex);
};
class complex {
int a,b;
// individual declaring function as friend
// ** friend int calculator ::sumRealComplex(complex ,complex );
//** friend int calculator ::sumComComplex(complex ,complex );
//Aliter : declearing the entire calculator class as friend.
friend class calculator;
public:
void setNumber(int n1 , int n2) { //1
a=n1;
b=n2;
}
void printNumber(){
cout<< "your number is "<<a<<" + "<<b<<"i"<<endl;
}
};
int calculator::sumRealComplex(complex o1,complex o2){
return (o1.a + o2.a);
}
int calculator::sumComComplex(complex o1,complex o2){
return (o1.b + o2.b);
}
int main(){
complex o1,o2;
o1.setNumber(1,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;
int resc = calc.sumComComplex(o1,o2);
cout<<"the sum of com part of o1 and o2 is"<<resc<<endl;
return 0;
}