cpoint

时间:2021-10-18 15:17:06
 #include<iostream>
#include<math.h>
using namespace std;
class CPoint
{
public:
int cpoint()
{
x = ;
y = ;
return ;
}
int cpoint(double a , double b)
{
x=a;
y=b;
return ;
}
double GetX()
{
return x;
}
double GetY()
{
return y;
}
int SetX(double a)
{
x=a;
return ;
}
int SetY(double a)
{
y=a;
return ;
}
private:
double x,y;
};
class CRectangle:public CPoint
{
private:
CPoint cp1,cp2;
public:
int crectangle()
{
cp1.cpoint();
cp2.cpoint();
return ;
}
int crectangle( const CPoint& c1,const CPoint& c2)
{
cp1 = c1;
cp2 = c2;
return ;
}
int SetLPoint( const CPoint& c1)
{
cp1 = c1;
return ;
}
int SetRPoint( const CPoint& c2)
{
cp2 = c2;
return ;
}
double GetPerimeter()
{
double X1,X2,Y1,Y2;
X1 = cp1.GetX();
X2 = cp2.GetX();
Y1 = cp1.GetY();
Y2 = cp2.GetY();
return (fabs(X1 - X2) + fabs(Y1 - Y2)) * ;
}
double GetArea()
{
return fabs(cp1.GetX() - cp2.GetX()) * fabs(cp1.GetY() - cp2.GetY());
}
};
int main()
{
CRectangle * a_rectagnle = new CRectangle ;
CPoint c1 , c2 ;
c1.cpoint( , );
c2.cpoint( , );
a_rectagnle->crectangle( c1,c2 );
cout << "perimeter = " << a_rectagnle->GetPerimeter() << endl;
cout << "area = " << a_rectagnle->GetArea() << endl;
c1.cpoint(,);
a_rectagnle->SetLPoint( c1 );
c2.cpoint( , );
a_rectagnle->SetRPoint( c2 );
cout << "perimeter = " << a_rectagnle->GetPerimeter() << endl;
cout << "area = " << a_rectagnle->GetArea() << endl;
delete a_rectagnle;
return ;
}