题目描述:建立一个复数类,实数和虚数是其私有数据成员。建立一个>(大于号)的运算符重载,比较两个复数间模的大小。tip:输入可以不为整数
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
class rl
{
private:
double x,y;
public:
void set(double n=0,double m=0)
{
x=n;y=m;
}
friend rl operator>(rl &a,rl &b);
};
rl operator>(rl &a,rl &b)
{
double value1=sqrt(a.x*a.x+a.y*a.y);
double value2=sqrt(b.x*b.x+b.y*b.y);
if(value1>value2){cout<<"true"<<endl;}
else{cout<<"false"<<endl;}
}
int main()
{
double n1,m1,n2,m2=0;
for(;;)
{
cin>>n1>>m1>>n2>>m2;
if(n1==0&&n2==0&&m1==0&&m2==0){break;}
rl r1,r2,r3;
r1.set(n1,m1);r2.set(n2,m2);r3.set();
r1>r2;
}
return 0;
}