-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex.cpp
More file actions
39 lines (30 loc) · 689 Bytes
/
Copy pathcomplex.cpp
File metadata and controls
39 lines (30 loc) · 689 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
#include<iostream>
using namespace std;
class Complex{
int real;
int imaginary;
public:
Complex(int r , int i){
real = r;
imaginary = i;
}
void showNum(){
// cout << "Real : " << real << "\n" << "Imaginary : " << imaginary << endl;
cout << real << "+" << imaginary << "i" << endl;
}
Complex operator + (Complex &obj){
int realRes = this-> real + obj.real;
int imgRes = this-> imaginary + obj.imaginary;
Complex c3(realRes,imgRes);
return c3;
}
};
int main(){
Complex c1(3,4);
Complex c2(4,5);
c1.showNum();
c2.showNum();
Complex c3 = c1 + c2;
c3.showNum();
return 0;
}