高分求助C++高手进

来源:百度知道 编辑:UC知道 时间:2024/05/15 10:05:28
定义描述二维坐标系中点(x,y)的类Point,重载递增运算符“++”和递减运算符“--”。并区分这两种运算符的前置和后置运算。编写Main()函数,完整测试Point类的正确性。
麻烦写出完整的程序课运行程序。谢啦!

#include<stdio.h>
#include<stdlib.h>

class CPoint
{
public:
double x;
double y;

public:
CPoint():x(0),y(0){}
CPoint(double x1, double y1):x(x1),y(y1)
{
}
public:
CPoint& operator++() //++a,前置自加
{
printf("前置自加 \n");
++x;
++y;
return *this;
}
CPoint operator++(int b)//a++,后置自加
{
CPoint cTemp = *this;
x++;
y++;
printf("后置自加 \n");
return cTemp;
}

CPoint& operator--() //--a,前置自减
{
--x;
--y;
printf("前置自减 \n");
return *this;
}
CPoint operator--(int b)//a--,后置自加减
{