Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2342543
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:09:14

#include
class Three3D
{
  public:
  Three3D(double x1,double y1,double z1);
  Three3D();
  Three3D & operator+(Three3D &n);
  Three3D& operator-(Three3D &n);
  void show();
  private:
  double x;
  double y;
  double z;
};
//类的实现
Three3D::Three3D()
{x=0;
y=0;
z=0;
}
Three3D::Three3D(double x1,double y1,double z1)
{
  x=x1;
  y=y1;
  z=z1;
}
Three3D &Three3D::operator+(Three3D&n)
{
  double a=0,b=0,c=0;
  a=x+n.x;
  b=y+n.y;
  c=z+n.z;
return Three3D(a,b,c);
}
Three3D &Three3D::operator-(Three3D &n)
{
  double a=0,b=0,c=0;
  a=x-n.x;
  b=y-n.y;
  c=z-n.z;
return Three3D(a,b,c);
}
void Three3D::show()
{
  cout<<"("<}//主函数
void main()
{
   Three3D p1(8,7,4),p2(2,4,5);
   Three3D p3,p4;
    p3=p1+p2;
cout<<"p1+p2=";
    p3.show();
     p4=p1-p2;
cout<<"p1-p2=";
     p4.show();
}
 


--------------------next---------------------

阅读(1503) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~