C++初学者求助,帮忙看这段简单的程序,不耽误时间的。求高手帮帮忙

[复制链接]
查看11 | 回复1 | 2010-12-23 16:59:27 | 显示全部楼层 |阅读模式
头文件里的东西已经省略了。就下面的一段,用矩形两个对焦坐标秋面积的。为什么面积老是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;
}

回复

使用道具 举报

千问 | 2010-12-23 16:59:27 | 显示全部楼层
输入坐标时只改变了Left_bottom,Right_top中的X、Y,没有改变R中Lb,Rt中的X、Y把Rectangle R(Left_bottom,Right_top);放到cout<<"面积为:
"R.gets()<<endl;前面就行了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行