-
Notifications
You must be signed in to change notification settings - Fork 148
/
3_CalculatorUsingoops.cpp
72 lines (57 loc) · 1.35 KB
/
3_CalculatorUsingoops.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
68
69
70
71
72
#include<iostream>
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 friends
// friend int Calculator ::sumRealComplex(Complex, Complex);
// Aliter: Declaring the entire calculator class as friend
friend class Calculator;
public:
// Setter Function
int setNumber(int n1, int n2)
{
a = n1;
b = n2;
}
// Function To Print The Result
void printNumber()
{
cout << "Your number is " << a << " + " << b << "i" << endl;
}
};
// friend int Calculator ::sumCompComplex(Complex, Complex);
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 o1, o2;
// callling setter Function
o1.setNumber(1, 4);
o2.setNumber(5, 7);
//Creating Object
Calculator calc;
int res = calc.sumRealComplex(o1, o2);
cout << "The sum of real part of o1 and o2 is " << res << endl;
int resc = calc.sumCompComplex(o1, o2);
cout << "The sum of complex part of o1 and o2 is " << resc << endl;
return 0;
}