1015. 复数的比较

题目描述:建立一个复数类,实数和虚数是其私有数据成员。建立一个>(大于号)的运算符重载,比较两个复数间模的大小。
输入格式:测试输入包含若干测试用例,每个测试用例占一行。每个测试用例包括四个数字,前两个数字分别表示第一个复数的实部和虚部,第三个和第四个数字分别表示第二个复数的实部和虚部。每个数字之间用空格间隔。当读入一个测试用例是0 0 0 0时输入结束,相应的结果不要输出。
输出格式:对每个测试用例输出一行。当第一个复数的模大于第二个复数的模时,输出 true ,当第一个复数的模小于或等于第二个复数的模时,输出false
输入样例:
   3 5 4 0
   0 3 4 1
   0 0 0 0
输出样例:
   true

   false


#include<iostream>
#include<math.h>
using namespace std;
class test
{
      float a;
      float b;
      public:
             void operator >(test& y);
             bool set(){  cin>>a>>b;
                          if(a==b&&a==0)
                            return 0;
                          return 1;}
};

void test::operator >(test& y)
{
     float t1,t2;
     t1=sqrt(a*a+b*b);
     t2=sqrt(y.a*y.a+y.b*y.b);
     if(t1>t2)
       cout<<"true"<<endl;
       else
         cout<<"false"<<endl;
}
int main()
{
    test t1,t2;
    int flag=0,temp;
    flag=t1.set();
    temp=t2.set();
    if(temp==flag&&flag==0)
      flag=0;
      else
        flag=1;
    while(flag)
    {
      t1>t2;
    flag=t1.set();
    temp=t2.set();
    if(temp==flag&&flag==0)
      flag=0;
      else
        flag=1;
    }
    return 0;
}


<?xml version="1.0" encoding="UTF-8"?> <svg width="2866" xmlns:cge="http://iec.ch/TC57/2005/SVG-schema#" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2866 2027" height="2027"> <defs> <symbol id="terminal:端子" preserveAspectRatio="xMidYMid"> <circle cx="0.0" cy="0.0" r="1.0" visibility="hidden" stroke-width="1"/> </symbol> <symbol id="PolePSR:铁塔直线杆塔@0" preserveAspectRatio="xMidYMid" viewBox="0 0 14.0 14.0"> <use x="7.0" y="7.0" terminal-index="0" xlink:href="#terminal:端子"/> <polygon stroke="rgb(0,0,0)" points="1.0,1.0 13.0,1.0 13.0,13.0 1.0,13.0" stroke-width="1" fill="none"/> <line y1="1.3" y2="12.7" x1="12.7" x2="1.3" stroke="rgb(0,0,0)" stroke-width="1"/> <line y1="1.3" y2="12.7" x1="1.3" x2="12.7" stroke="rgb(0,0,0)" stroke-width="1"/> </symbol> <symbol id="Disconnector:柱上隔离开关@0" preserveAspectRatio="xMidYMid" viewBox="0 0 20.4 42.0"> <use x="10.2" y="1.0" terminal-index="0" xlink:href="#terminal:端子"/> <use x="10.2" y="41.0" terminal-index="1" xlink:href="#terminal:端子"/> <line y1="27.5" y2="41.0" x1="10.2" x2="10.2" stroke="rgb(0,255,0)" stroke-width="1"/> <line y1="10.3" y2="1.0" x1="10.2" x2="10.2" stroke="rgb(0,255,0)" stroke-width="1"/> <line y1="10.3" y2="10.3" x1="7.2" x2="13.2" stroke="rgb(0,255,0)" stroke-width="1"/> <line y1="26.4" y2="9.4" x1="10.0" x2="1.0" stroke="rgb(0,255,0)" stroke-width="1"/> </symbol> <symbol id="Disconnector:柱上隔离开关@1" preserveAspectRatio="xMidYMid" viewBox="0 0 20.4 42.0"> <use x="10.2" y="1.0" terminal-index="0" xlink:href="#terminal:端子"/> <use x="10.2" y="41.0" terminal-index="1" xlink:href="#terminal:端子"/> <line y1="27.5" y2="41.0" x1="10.2" x2="10.2" stroke="rgb(255,0,0)" stroke-width="1"/> <line y1="10.3" y2="1.0" x1="10.2" x2="10.2" stroke="rgb(255,0,0)" stroke-width="1"/> <line y1="10.3" y2="10.3" x1="7.2" x2="13.2" stroke="rgb(255,0,0)" stroke-width="1"/> <line y1="26.2" y2="8.8" x1="10.1" x2="5.9" stroke="rgb(255,0,0)" stroke-width="1"/> </symbol> <symbol id="Breaker:普通断路器@0" preserveAspectRatio="xMidYMid" viewBox="0 0 27.7 42.6"> <use x="13.9" y="1.1" terminal-index="0" xlink:href="#terminal:端子"/> <use x="13.9" y="41.1" terminal-index="1" xlink:href="#terminal:端子"/> <line y1="1.1" y2="10.6" x1="13.9" x2="13.9" stroke="rgb(0,255,0)" stroke-width="1"/> <line y1="41.1" y2="26.0" x1="13.9" x2="13.9" stroke="rgb(0,255,0)" stroke-width="1"/> <line y1="25.0" y2="10.1" x1="13.7" x2="4.9" stroke="rgb(0,255,0)" stroke-width="1"/> <line y1="8.1" y2="13.2" x1="17.9" x2="9.8" stroke="rgb(0,255,0)" stroke-width="1"/> <line y1="8.1" y2="13.1" x1="9.9" x2="17.9" stroke="rgb(0,255,0)" stroke-width="1"/> </symbol> <symbol id="Breaker:普通断路器@1" preserveAspectRatio="xMidYMid" viewBox="0 0 27.7 42.6"> <use x="13.9" y="1.1" terminal-index="0" xlink:href="#terminal:端子"/> <use x="13.9" y="41.1" terminal-index="1" xlink:href="#terminal:端子"/> <line y1="1.1" y2="10.6" x1="13.9" x2="13.9" stroke="rgb(255,0,0)" stroke-width="1"/> <line y1="8.1" y2="13.2" x1="17.9" x2="9.8" stroke="rgb(255,0,0)" stroke-width="1"/> <line y1="8.1" y2="13.1" x1="9.9" x2="17.9" stroke="rgb(255,0,0)" stroke-width="1"/> <polyline stroke="rgb(255,0,0)" points="13.9,41.2 13.9,25.2 7.9,8.1" stroke-width="1" fill="none"/> </symbol> <symbol id="Breaker:普通断路器@4" preserveAspectRatio="xMidYMid" viewBox="0 0 27.7 42.6"> <use x="13.9" y="1.1" terminal-index="0" xlink:href="#terminal:端子"/> <use x="13.9" y="41.3" terminal-index="1" xlink:href="#terminal:端子"/> <polygon stroke="rgb(255,0,255)" points="1.0,41.6 24.7,41.6 24.8,1.1 1.0,1.0" stroke-width="1" fill="rgb(255,255,112)"/> <line y1="1.1" y2="10.7" x1="13.9" x2="13.9" stroke="rgb(255,0,255)" stroke-width="1"/> <line y1="41.1" y2="26.1" x1="13.9" x2="14.0" stroke="rgb(255,0,255)" stroke-width="1"/> <line y1="25.1" y2="10.1" x1="13.7" x2="4.9" stroke="rgb(255,0,255)" stroke-width="1"/> <line y1="8.1" y2="13.2" x1="17.9" x2="9.9" stroke="rgb(255,0,255)" stroke-width="1"/> <line y1="8.1" y2="13.1" x1="9.9" x2="17.9" stroke="rgb(255,0,255)" stroke-width="1"/> </symbol> <symbol id="PolePSR:水泥杆直线杆塔@0" preserveAspectRatio="xMidYMid" viewBox="0 0 14.0 14.0"> <use x="7.0" y="7.0" terminal-index="0" xlink:href="#terminal:端子"/> <circle cx="7.0" cy="7.0" stroke="rgb(0,0,0)" r="6.0" stroke-width="1" fill="none"/> </symbol> <symbol id="Breaker:变电断路器@0" preserveAspectRatio="xMidYMid" viewBox="0 0 12.3 22.0"> <use x="6.1" y="0.6" terminal-index="0" xlink:href="#terminal:端子"/> <use x="6.1" y="21.6" terminal-index="1" xlink:href="#terminal:端子"/> <polygon stroke="rgb(255,0,0)" points="1.0,1.0 11.0,1.0 11.0,21.0 1.0,21.0" stroke-width="1" fill="none"/> </symbol> <symbol id="Breaker:变电断路器@1" preserveAspectRatio="xMidYMid" viewBox="0 0 12.3 22.0"> <use x="6.1" y="0.6" terminal-index="0" xlink:href="#terminal:端子"/> <use x="6.1" y="21.6" terminal-index="1" xlink:href="#terminal:端子"/> <polygon stroke="rgb(255,0,0)" points="1.2,1.0 11.2,1.0 11.2,21.0 1.2,21.0" stroke-width="1" fill="rgb(255,0,0)"/> </symbol> </defs> <g id="HeadClass"> <rect x="0" width="2866" y="0" FeederName="10kV羊街古城村线" stroke="rgb(255,255,255)" FeederID="547240133021800" stroke-width="4" height="2027" fill-opacity="1" fill="rgb(255,255,255)"/> </g> <g id="SubstationClass"> <g id="547240133044200"> <polygon stroke="rgb(0,0,0)" points="610.3,1056.8 610.3,960.8 816.3,960.8 816.3,1056.8" stroke-width="2" fill="none"/> <metadata> <cge:PSR_Ref ObjectID="SUBST_544050322075002" ObjectName="35kV大庄变"/> </metadata> </g> </g> <g id="OtherClass"/> <g id="PolePSRClass"> <g id="547240133025700"> <use x="886.3" width="14.0" y="1008.8" xlink:href="#PolePSR:铁塔直线杆塔@0" transform="rotate(0.0,893.2,1015.8) scale(1.00000000,1.00000000) translate(0.0,0.0)" height="14.0"/> <metadata> <cge:PSR_Ref ObjectID="POLE_547050068712004" ObjectName=""/> </metadata> </g> <g id="547240133036000"> <use x="1050.3" width="14.0" y="1008.8" xlink:href="#PolePSR:铁塔直线杆塔@0" transform="rotate(0.0,1057.2,1015.8) scale(1.00000000,1.00000000) translate(0.0,0.0)" height="14.0"/> <metadata> <cge:PSR_Ref ObjectID="POLE_547220660325100" ObjectName=""/> </metadata> </g> <g id="547240133036800"> <use x="1317.3" width="14.0" y="1008.8" xlink:href="#PolePSR:铁塔直线杆塔@0" transform="rotate(0.0,1324.2,1015.8) scale(1.00000000,1.00000000) translate(0.0,0.0)" height="14.0"/> <metadata> <cge:PSR_Ref ObjectID="POLE_547220660326100" ObjectName=""/> </metadata> </g> <g id="547240133037600"> <use x="1561.3" width="14.0" y="1008.8" xlink:href="#PolePSR:铁塔直线杆塔@0" transform="rotate(0.0,1568.2,1015.8) scale(1.00000000,1.00000000) translate(0.0,0.0)" height="14.0"/> <metadata> <cge:PSR_Ref ObjectID="POLE_547220660328400" ObjectName=""/> </metadata> </g> <g id="547240133039600"> <use x="1890.3" width="14.0" y="1009.0" xlink:href="#PolePSR:水泥杆直线杆塔@0" transform="rotate(0.0,1897.2,1016.0) scale(1.00000000,1.00000000) translate(0.0,0.0)" height="14.0"/> <metadata> <cge:PSR_Ref ObjectID="POLE_547050068424804" ObjectName=""/> </metadata> </g> <g id="547240133040400"> <use x="2102.3" width="14.0" y="1009.0" xlink:href="#PolePSR:水泥杆直线杆塔@0" transform="rotate(0.0,2109.2,1016.0) scale(1.00000000,1.00000000) translate(0.0,0.0)" height="14.0"/> <metadata> <cge:PSR_Ref ObjectID="POLE_547050068408704" ObjectName=""/> </metadata> </g> <g id="547240133041200"> <use x="2358.3" width="14.0" y="1008.8" xlink:href="#PolePSR:铁塔直线杆塔@0" transform="rotate(0.0,2365.2,1015.8) scale(1.00000000,1.00000000) translate(0.0,0.0)" height="14.0"/> <metadata> <cge:PSR_Ref ObjectID="POLE_547050068397504" ObjectName="10kV羊街古城村线10kV大草线"/> </metadata> </g> </g> <g id="DisconnectorClass"> <g id="547240133038400"> <use x="1578.0" width="20.4" y="994.8" xlink:href="#Disconnector:柱上隔离开关@1" transform="rotate(270.0,1588.2,1015.8) scale(1.00000000,1.00000000) translate(0.0,0.0)" height="42.0"/> <metadata> <cge:PSR_Ref ObjectID="SWITCH_547220660329200" ObjectName="G011"/> </metadata> </g> </g> <g id="BreakerClass"> <g id="547240133039000"> <use x="1614.4" width="27.7" y="994.5" xlink:href="#Breaker:普通断路器@1" transform="rotate(270.0,1628.3,1015.8) scale(1.00000000,1.00000000) translate(0.0,0.0)" height="42.6"/> <metadata> <cge:PSR_Ref ObjectID="SWITCH_547220660330200" ObjectName="10kV羊街古城村线#19杆G01断路器"/> </metadata> </g> <g id="547240133043100"> <use x="707.2" width="12.3" y="1004.8" xlink:href="#Breaker:变电断路器@1" transform="rotate(90.0,713.3,1015.8) scale(1.00000000,1.00000000) translate(0.0,0.0)" height="22.0"/> <metadata> <cge:PSR_Ref ObjectID="SWITCH_535220034655000" ObjectName="072"/> </metadata> </g> </g> <g id="ConnectiveLineClass"> <g id="547240133038001"> <path stroke="none" stroke-width="1" d="M1568.3,1015.8 L1568.3,1015.8" fill="rgb(0,0,0)"/> <metadata> <cge:CN_Ref LinkObjectIDnd="547240133037600@0" LinkObjectIDznd="547240133038400@0"/> </metadata> </g> <g id="547240133038801"> <path stroke="none" stroke-width="1" d="M1608.3,1015.8 L1608.3,1015.8" fill="rgb(0,0,0)"/> <metadata> <cge:CN_Ref LinkObjectIDnd="547240133038400@1" LinkObjectIDznd="547240133039000@0"/> </metadata> </g> </g> 这段代码是什么意思
最新发布
06-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值