c10-8.cpp
来自「谭浩强C程序设计习题答案」· C++ 代码 · 共 32 行
CPP
32 行
#include <iostream>
using namespace std;
class Complex
{public:
friend ostream& operator << (ostream&,Complex&);
friend istream& operator >> (istream&,Complex&);
private:
double real;
double imag;
};
ostream& operator << (ostream& output,Complex& c)
{output<<"("<<c.real<<"+"<<c.imag<<"i)";
return output;
}
istream& operator >> (istream& input,Complex& c)
{cout<<"input real part and imaginary part of complex number:";
input>>c.real>>c.imag;
return input;
}
int main()
{Complex c1,c2;
cin>>c1>>c2;
cout<<"c1="<<c1<<endl;
cout<<"c2="<<c2<<endl;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?