-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy_constructor.cpp
More file actions
43 lines (43 loc) · 900 Bytes
/
Copy pathcopy_constructor.cpp
File metadata and controls
43 lines (43 loc) · 900 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
#include<iostream>
using namespace std;
class complex{
private:
float real,image;
public:
complex(float r=0,float i=0):real(r),image(i){ }
void display(){
cout<<real<<"+"<<image<<"i"<<endl;
}
complex operator-(){
return complex(-real,-image);
}
complex operator++(){
++real;
++image;
return *this;
}
complex operator+(const complex& obj){
return complex(real+obj.real,image+obj.image);
}
complex operator-(const complex& obj){
return complex(real-obj.real,image-obj.image);
}};
int main(){
complex c1(3,4),c2(1,2),c3;
cout<<"original complex numbers:"<<endl;
cout<<"c1=";c1.display();
cout<<"c2=";c2.display();
c3=-c1;
cout<<"\nAfter unary - on c1:"<<endl;
cout<<"c3=";c3.display();
++c1;
cout<<"\n After unary ++ on c1:"<<endl;
cout<<"c1=";c1.display();
c3=c1+c2;
cout<<"\nAfter c1+c2:"<<endl;
cout<<"c3=";c3.display();
c3=c1-c2;
cout<<"\nAfter c1-c2:"<<endl;
cout<<"c3=";c3.display();
return 0;
}