-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathb36.cpp
More file actions
52 lines (37 loc) · 899 Bytes
/
b36.cpp
File metadata and controls
52 lines (37 loc) · 899 Bytes
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
#include <iostream>
#include <string>
using namespace std;
class Complex
{
int a, b;
public:
void setnumber(int n1, int n2)
{
a = n1;
b = n2;
}
friend Complex sumcomplex(Complex o1, Complex o2);
void printnumber()
{
cout << "the number is " << a << "+" << b << "i";
}
};
Complex sumcomplex(Complex o1, Complex o2)
{
Complex o3;
o3.setnumber((o1.a + o2.a), (o1.b + o2.b)); // WE CANNOT ACCESS A AND B AS A AND B IS PRIVATE AND
// CAN BE ACCESSED ONLY IN CLASS
// HERE WE USE FRIEND FUNCTIONS FOT THIS CAUSE..
return o3;
}
int main()
{
Complex c1, c2, sum;
c1.setnumber(1, 4);
c2.setnumber(5, 8);
c1.printnumber();
c2.printnumber();
sum = sumcomplex(c1, c2);
sum.printnumber();
return 0;
}