//20、定义一个复数类,并为其重载>>和<<运算符,使得复数对象可以整体输入输出,并给出main()对该类进行应用。
#include"iostream"
using namespace std;
class complex1
{
private:
int real,iamg;
public:
//complex1(int x=0,int y=0):real(x),iamg(y){}
friend ostream &operator<<(ostream &out,complex1 &c);
friend istream &operator>>(istream &in,complex1 &c);
};
int main()
{
complex1 c1;
cin>>c1;
cout<<c1;
return 0;
}
istream &operator>>(istream &in,complex1 &c)
{
in>>c.real;
in>>c.iamg;
return in;
}
ostream &operator<<(ostream &out,complex1 &c)
{
out<<c.real;
if(c.iamg>0)
out<<"+";
out<<c.iamg<<"i"<<endl;
return out;
}