64,654
社区成员
发帖
与我相关
我的任务
分享
#include <iostream.h>
#include <math.h>
class CPoint
{
private:
double nPosX,nPosY;
public:
CPoint(double x, double y)
{
nPosX = x;
nPosY = y;
}
void ShowPos()
{
cout<<"当前位置: x = "<<nPosX<<" , y = "<<nPosY<<endl;
}
};
class CLine: public CPoint
{
private:
double nLength;
public:
CLine()
{
nLength = 0;
}
double LineLength(double x1, double y1, double x2, double y2)
{
nLength = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
return nLength;
}
};
class CRect: public CPoint
{
private:
double dWideL;
double dHeightL;
public:
CRect()
{
dWideL = 0;
dheightL = 0;
}
double RectSL(double WideL, double HeightL)
{
return 2*(WideL + HeightL);
}
};
int main()
{
CPoint LU(0.0,1.0);
CPoint LD(0.0,0.0);
CPoint RU(1.0,1.0);
CPoint RD(1.0,0.0);
CLine Wide;
CLine Length;
CRect One;
double AWide;
double ALength;
double P;
AWide = Wide.LineLength(0.0,1.0,1.0,1.0);
ALength = Length.LineLength(0.0,1.0,0.0,0.0);
P = One.RectSL(AWide, ALength);
return 0;
}