-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday 1.cpp
More file actions
36 lines (34 loc) · 704 Bytes
/
day 1.cpp
File metadata and controls
36 lines (34 loc) · 704 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
/*复数结构体加减运算符重载*/
#include"iostream.h"
struct complex{
int real;
int imag;
complex &operator + (complex &s)
{
complex c;
c.real=real+s.real;
c.imag=imag+s.imag;
return c;
}
complex &operator += (complex &s);
friend ostream &operator<<(ostream &output, complex &s);
};
complex &complex::operator += (complex &s)
{
real+=s.real;
imag+=s.imag;
return *this;
}
ostream&operator<<(ostream &output,complex &s)
{
output << "a.real ="<<s.real<<"a.imag="<<s.imag<<endl;
return output;
}
int main(){
complex c={0,0},a,b={1,5};
a=b+b;
c+=b;
cout<<a;
cout<<"c.real ="<<c.real<<"c.imag ="<<c.imag<<endl;
cout<<"b.real ="<<b.real<<"b.imag ="<<b.imag<<endl;
}