C++中关于两个点的数据类型是CPoint怎么办

2025-01-21 08:52:33
推荐回答(2个)
回答1:

#include
using namespace std;
class CPoint
{public:
CPoint(){x=0;y=0;}
float GetX(){return x;}
float GetY(){return y;}
void SetX(float a){x=a;}
void SetY(float b){y=b;}
private:
float x,y;
};
class CRectangle
{public:
CRectangle()
{
L.SetX(2);
L.SetY(5);
R.SetX(6);
R.SetY(8);
}
void SetLPoint(float c,float d)
{
cout<<"修改左下角坐标"< cin>>c>>d;
L.SetX(c);
L.SetY(d);
}
void SetRPoint(float e,float f)
{
cout<<"修改右上角坐标"< cin>>e>>f;
R.SetX(e);
R.SetY(f);
}
float GetPerimeter(){return 2*(R.GetX()+R.GetY()-L.GetX()-L.GetY());}
float GetArea(){return (R.GetX()-L.GetX())*(R.GetY()-L.GetY());}
private:
CPoint R,L;
};
int main()
{
CRectangle a_rectagnle;
cout<<"周长1="< cout<<"面积1="< a_rectagnle.SetLPoint(4,6);
a_rectagnle.SetRPoint(7,9);
cout<<"周长2="< cout<<"面积2="<
return 0;

}

回答2:

又是作业题!