-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtut27.cpp
More file actions
64 lines (54 loc) · 1.24 KB
/
tut27.cpp
File metadata and controls
64 lines (54 loc) · 1.24 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
62
63
64
#include <iostream>
using namespace std;
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;
public:
// friend int calculator::sumrealcomplex(complex o1, complex o2);
// friend int calculator::sumcompcomplex(complex o1, complex o2);
friend class calculator;
void setnumber(int n1, int n2)
{
a = n1;
b = n2;
}
void printnumber()
{
cout << "Your complex number is " << a << " + " << b << "i" << endl;
}
};
int calculator::sumrealcomplex(complex o1, complex o2)
{
return (o1.a + o2.a);
}
int calculator::sumcompcomplex(complex o1, complex o2)
{
return (o1.b + o2.b);
}
int main()
{
complex c1, c2;
c1.setnumber(4, 6);
c1.printnumber();
c2.setnumber(5, 8);
c2.printnumber();
calculator c3;
int plus = c3.add(5, 9);
cout << "The sum of 5 and 9 is :" << plus << endl;
int res = c3.sumrealcomplex(c1, c2);
cout << "The real number of complex is :" << res << endl;
int resc = c3.sumcompcomplex(c1,c2);
cout << "The complex number of complex is :" << resc << endl;
return 0;
}