#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) |