-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComplex Number Subtraction.cpp
More file actions
51 lines (39 loc) · 957 Bytes
/
Copy pathComplex Number Subtraction.cpp
File metadata and controls
51 lines (39 loc) · 957 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
40
41
42
43
44
45
46
47
48
49
50
51
#include<iostream>
using namespace std;
//Complex Number Subtraction
class Complex{
public:
float real, imag;
Complex(): real(0), imag(0){}
// Complex(float r, float i): real(r), imag(i){} Don't need anymore
Complex operator - (Complex c){
Complex temp;
temp.real = real - c.real;
temp.imag = imag - c.imag;
return temp;
}
void input(){
cout<< "Real part: ";
cin>>real;
cout<< "Imaginary part: ";
cin>>imag;
}
void display(){
if(imag > 0){
cout<<real<<"+"<<imag<<"i"<<endl;
}else{
cout<<real<<imag<<"i"<<endl;
}
}
};
int main(){
Complex c1, c2, c3;
cout<<"First complex number:\n";
c1.input();
cout<<"Second complex number:\n";
c2.input();
c3 = c1 - c2;
cout<<"Resulted complex number: ";
c3.display();
return 0;
}