# 第二小组

## 复数类实现 by freeyun

class  complex
{

double  real,imag;
complex ()
{}
complex(
double  r,double  i)

{   real=r;
imag
=i;
}

{   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();
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)    -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

posted on 2005-07-29 00:16 第二小组 阅读(993) 评论(2)  编辑  收藏 所属分类: 小组交流

### Feedback

#### #re: 复数类实现 by freeyun 2005-11-02 14:34 hh

 只有注册用户登录后才能发表评论。 网站导航: 相关文章: