【求指导】求指导代码的简洁性和算法。
MyPoint.h文件
#ifndef MYPOINT_H
#define MYPOINT_H
class myPoint
{
public:
myPoint();
myPoint(float f_x ,float f_y);
bool judgePoint(); //判断该点是否符合要求
bool judgeIsEqual(myPoint &a); //判断两点是否重合
void setX(float f_x);
void setY(float f_y);
float getX();
float getY();
private :
float x; //点的横坐标x
float y; //点的横坐标y
};
#endif
MyPoint.cpp文件
#include "MyPoint.h"
//myPoint的构造函数
myPoint::myPoint()
{
}
myPoint::myPoint(float f_x ,float f_y)
{
x = f_x;
y = f_y;
}
//x,y的setter 和getter
void myPoint::setX(float f_x)
{
x = f_x;
}
void myPoint::setY(float f_y)
{
y = f_y;
}
float myPoint::getX()
{
return x;
}
float myPoint::getY()
{
return y;
}
//判断该点是否符合要求 符合返回ture,否则返回false
bool myPoint::judgePoint()
{
return (x > 0 && x<20.0) && (y > 0 && y <20.0);
}
//判断两点是否重合 重合返回false,否则返回true
bool myPoint::judgeIsEqual(myPoint &a )
{
if ( a.x == x && y == a.y)
{
return false;
}
else
return true;
}
MyRectangle.h文件
#ifndef MYRECTANGLE_H #define MYRECTANGLE_H #include "MyPoint.h" #include <math.h> #inclu