头文件里的东西已经省略了。就下面的一段,用矩形两个对焦坐标秋面积的。为什么面积老是0,到底是哪里错了
#include "stdafx.h"
class Point
{
public:
Point(int xx=0,int yy=0){X=xx;Y=yy;}
//Point(Point &p)
~Point(){}
void cinX(int);
void cinY(int);
int getX(){return X;}
int getY(){return y;}
private:
int X,Y;
};
Point::Point(Point &p)
{
X=p.X;
Y=p.Y;
}
void Point::cinX(int x)
{
X=x;
}
void Point::cinY(int y)
{
Y=y;
}
class Rectangle
{
public:
Rectangle(Point xp1,Point xp2);
Rectangle(Rectangle &);
int gets(){return S;}
private:
Point Lb,Rt;
int S;
};
Rectangle::Rectangle(Point xp1,Point xp2):Lb(xp1),Rt(xp2)
{
int m=int(Rt.getX()-Lb.getX());
int n=int(Rt.getY()-Lb.getY());
S=m*n;
}
Rectangle::Rectangle(Rectangle &R):P1(R.P1),P2(R.P2)
{
S=R.S;
}
int main(int argc, char* argv[])
{
Point Left_bottom,Right_top;
Rectangle R(Left_bottom,Right_top);
cout>x1>>y1>>x2>>y2;
Left_bottom.cinX(x1);
Left_bottom.cinY(y1);
Right_top.cinX(x2);
Right_top.cinY(x2);
cout<<"面积为:
"R.gets()<<endl;
printf("Hello World!\n");
return 0;
}
|