第二小組

          復數類實現 by freeyun

           

          class  complex
          {
                
          double  real,imag;
                complex ()    
          {}
                complex(
          double  r,double  i)
                     
          {   real=r;
                         imag
          =i;
                     }
           
                complex     addition(complex x,complex   y)
                     
          {   this.real=x.real+y.real;
                         
          this.imag=x.imag+y.imag;
                         
          return(this) ;
                      }


               complex      subtraction(complex x,complex   y)       
                    
          {   this.real=x.real-y.real;
                         
          this.imag=x.imag-y.imag;
                         
          return(this) ;              
                     }


               complex     multiplication(complex x,complex   y)
                    
          {    this.real=(x.real)*(y.real)-(x.imag)*(y.imag);
                         
          this.imag=(x.real)*(y.imag)+(x.imag)*(y.real);
                         
          return(this) ;             
                     }


                complex     division(complex x,complex   y)
                    
          {    this.real=((x.real)*(y.real)+(x.imag)*(y.imag))/((y.real)*(y.real)+(y.imag)*(y.imag));
                         
          this.imag=((x.imag)*(y.real)-(x.real)*(y.imag))/((y.real)*(y.real)+(y.imag)*(y.imag));
                         
          return(this) ;
                    }


          }
                         

          public    class   C
          {  
              
          public  static  void  main(String    args[])
               
          {   
                  complex   c1
          =new  complex(2,4);
                  complex   c2
          =new  complex(4,8);
                  complex   c
          =new   complex();
                   c.addition(c1,c2);
                   System.
          out.println("c=c1(2,4)+c2(4,8)"+" "+c.real+","+c.imag);
                   c.subtraction(c1,c2);
                   System.
          out.println("c=c1(2,4)-c2(4,8)"+" "+c.real+","+c.imag);
                   c.multiplication(c1,c2);
                   System.
          out.println("c=c1(2,4)*c2(4,8)"+" "+c.real+","+c.imag);
                   c.division(c1,c2);
                   System.
          out.println("c=c1(2,4)/c2(4,8)"+" "+c.real+","+c.imag);
                }

          }
           




          name     C.java
          運行結果:c=c1(2,4)+c2(4,8)     6.0 ,12.0
                              c=c1(2,4)-c2(4,8)    -2.0 ,-4.0
                              c=c1(2,4)*c2(4,8)    -24.0,32.0
                              c=c1(2,4)/c2(4,8)      0.5,0.0

          求助:為什么我在函數中用getReal,getImag分別返回各函數的實部和虛部實現不了?

          posted on 2005-07-29 00:16 第二小組 閱讀(1025) 評論(2)  編輯  收藏 所屬分類: 小組交流

          Feedback

          # re: 復數類實現 by freeyun 2005-07-29 00:27 第二小組

          什么問題,不明白.
          為什么實現不了?  回復  更多評論   

          # re: 復數類實現 by freeyun 2005-11-02 14:34 hh

          我也是學java的怎么就入不了門那 請高人指點 謝謝  回復  更多評論   


          主站蜘蛛池模板: 绵阳市| 惠来县| 靖宇县| 兴山县| 新安县| 扎鲁特旗| 瓮安县| 宁河县| 武隆县| 娱乐| 赤峰市| 社旗县| 泸西县| 申扎县| 商水县| 邹城市| 郸城县| 二连浩特市| 白水县| 巴林左旗| 额敏县| 阳城县| 北辰区| 璧山县| 营口市| 永宁县| 江津市| 新河县| 修武县| 丰县| 荣昌县| 原平市| 濮阳县| 柞水县| 东港市| 赣州市| 扶沟县| 江永县| 肇庆市| 合作市| 措勤县|