-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprintingComplexNumber.cpp
50 lines (45 loc) · 1014 Bytes
/
printingComplexNumber.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
#import <iostream>
using namespace std;
class complex {
private:
int real, img;
public:
complex() {
real = img = 0;
}
complex(int r, int i) {
real = r;
img = i;
}
void add(int r, complex i) {
cout<< "test";
real = r + i.real;
img = r + i.img;
cout << "After adding complex number and normal number:\n real: " << real << "\n imaginary: " << img << "i\n";
}
void add(complex r, complex i) {
real = r.real + i.real;
img = r.img + i.img;
cout << "After adding two complex numbers:\n real: " << real << "\n imaginary: " << img << "i\n";
}
};
int main() {
int r, i, n;
cout << "Enter a normal number \n";
cin>> n;
cout << "Enter Complex Number 1:\nReal:";
cin >> r;
cout << "\nImaginary :";
cin >> i;
complex comp1(r, i);
cout << "Enter complex Number 2:\nReal: ";
cin >> r;
cout << "\nImaginary :";
cin >> i;
complex comp2(r, i);
complex comp3;
complex comp4;
comp3.add(n,comp1);
comp3.add(comp2,comp1);
return 0;
}