-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram to Perform Complex Operations using Overloading.cpp
More file actions
82 lines (72 loc) · 1.19 KB
/
Program to Perform Complex Operations using Overloading.cpp
File metadata and controls
82 lines (72 loc) · 1.19 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* C++ Program to Perform Complex Operations using Overloading */
#include <iostream>
using namespace std;
class Complex
{
private:
double a;
double b;
public:
Complex(double=1.0,double=1.0); // Constructor;
void set(double,double);
void print();
Complex operator+(Complex);
Complex operator++();
Complex operator++(int);
};
Complex::Complex(double r, double i)
{
set(r,i);
}
void Complex::print()
{
if (b<0)
cout <<"\n"<< a << "" << b <<"i"<<endl;
else
cout <<"\n"<< a << "+" << b <<"i"<<endl;
}
void Complex::set(double r, double i)
{
a = r;
b = i;
}
// Prefix Exm.
Complex Complex::operator+(Complex R)
{
Complex tmp;
tmp.a = a + R.a;
tmp.b = b + R.b;
return tmp;
}
// Prefix Exm.
Complex Complex::operator++()
{
a++;
b++;
return *this;
}
// Postfix Exm.
Complex Complex::operator++(int x)
{
a++;
b++;
return *this;
}
int main()
{
Complex A(3,4), B(5,-6);
A.print();
B.print();
Complex C;
C= A+B;
C.print();
++A;
cout <<endl;
A.print();
C = ++A;
C.print();
A++;
A.print();
//system("pause");
return 0;
}