a) int GetX(); b) int GetY();
(6) 公有成员函数void Display();输出对象的数据成员; 程序清单:
#include
Point();
Point(int x1,int y1,int z1); Point(const Point &p);
void offert(int a,int b,int c);//实现点的偏移,参数是偏移量 void offert(Point &p);//实现点的偏移,参数Point类对象是偏移量 bool operator ==(Point &p);//判断两个点对象是否相等 void operator +=(Point &p);//判断两个点对象是否相等 void operator ++();//将当前对象自增1(前缀) void operator ++(int);//将当前对象自增1(后缀)
friend Point &operator + (Point &a, Point &b);//将两个点对象相加 friend Point &operator - (Point &a, Point &b);//将两个点对象相减 int GetX();//成员函数提供实例对象对私有数据的访问 int GetY();//成员函数提供实例对象对私有数据的访问 void Display();//输出对象的数据成员
private: };
Point::Point() {
x=1,y=2,z=3; int x; int y; int z;
}
Point::Point(int x1,int y1,int z1) { }
Point::Point(const Point &p) { }
void Point::offert(int a,int b,int c) { }
void Point::offert(Point &p) { }
bool Point::operator ==(Point &p) { }
void Point::operator +=(Point &p)
return x==p.x&&y==p.y&&z==p.z; x+=p.x; y+=p.y; z+=p.z; x+=a; y+=b; z+=c; x=p.x; y=p.y; z=p.z; x=x1; y=y1; z=z1;
{ }
void Point::operator ++() { }
void Point::operator ++(int) { }
Point &operator + (Point &a, Point &b) { }
Point &operator - (Point &a, Point &b) {
a.x-=b.x; a.y-=b.y; a.z-=b.z; a.x+=b.x; a.y+=b.y; a.z+=b.z; return a; x++; y++; z++; x++; y++; z++;
if(x==p.x&&y==p.y&&z==p.z) else
cout<<\cout<<\
}
return a;
int Point::GetX() { }
int Point::GetY() { }
void Point::Display() { } int main() {
Point a; Point b(1,4,7); Point c(a); a.Display(); b.Display(); c.Display(); a.offert(3,2,1); a.Display(); b.offert(c); b.Display(); if(a==b) else
cout<<\cout<<\
cout<<'('< if(a==c) else cout<<\cout<<\ a+=b; a+=c; a++; a.Display(); ++c; c.Display(); Point d,e; d=a+b; d.Display(); e=b-a; e.Display(); cout<<\cout<<\return 0; }运行结果: