-
Notifications
You must be signed in to change notification settings - Fork 0
/
12.cpp
48 lines (46 loc) · 1.05 KB
/
12.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
#include <iostream>
using namespace std;
class Complex
{
private:
int real;
int imaginary;
public:
Complex(int r=0,int i=0)
{
real=r;
imaginary=i;
}
Complex operator+(Complex x)
{
Complex temp;
temp.real=real+x.real;
temp.imaginary=imaginary+x.imaginary;
return temp;
}
int getReal()
{
return real;
}
int getImaginary()
{
return imaginary;
}
};
int main()
{
cout<<"\t\tComplex Number Calculator:"<<endl;
cout<<"\t\t--------------------------"<<endl;
int real,img;
cout<<"Enter the real and imaginary part of the first Complex number(a+bi):";
cin>>real>>img;
Complex c1(real,img);
cout<<"Enter the real and imaginary part of the second Complex number(c+di):";
cin>>real>>img;
Complex c2(real,img);
Complex c3;
cout<<"Sum of both the complex number results in:";
c3= c1+c2;
std::cout << c3.getReal()<<"+"<<c3.getImaginary()<<"i"<< std::endl;
return 0;
}