|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<iostream>
using namespace std;
class complex
{
double real, image;
public:
complex(double r = 0, double i = 0)
{
real = r;
image = i;
}
void show()
{
if (image > 0)
{
if (image == 1)
{
cout << real << "+" << "i" << endl;
}
else
cout << real << "+" << image << "i" << endl;
}
else if (image < 0)
{
if (image == -1)
{
cout << real << "-" << endl;
}
else
cout << real << "-" << image << "i" << endl;
}
}
friend istream& operator>>(istream& myin, complex& c);
friend ostream& operator<<(ostream& myout, const complex& c);
};
istream& operator>>(istream& myin, complex& c)
{
cin >> c;
return myin;
}
ostream& operator<<(ostream&myout, const complex&c)
{
if (c.image > 0)
{
if (c.image == 1)
{
cout << c.real << "+" << "i" << endl;
}
else
cout << c.real << "+" << c.image << "i" << endl;
}
else if (c.image < 0)
{
if (c.image == -1)
{
cout << c.real << "-" << endl;
}
else
cout << c.real << "-" << c.image << "i" << endl;
}
return myout;
} |
|