帮我看下这个c++程序错在哪里?
题目是这样的:色剂并测试一个名为rectangle的矩形类,其属性为矩形的左下角与右下角两个点的坐标,并计算矩形的面积。
下面是我写的代码:
#include <iostream>
#include <cmath>
using namespace std;
class point //点类
{
private:
int x;int y;
public:
point()
{
x=0;y=0;
cout<<"point构造函数调用1"<<endl;
}
point(int xx,int yy)
{
x=xx;y=yy;
cout<<"point构造函数调用2"<<endl;
}
point(point &p);
int getx()
{
return x;
}
int gety()
{
return y;
}
};
point::point(point &p)
{x=p.x;
y=p.x;
cout<<"point拷贝函数的调用"<<endl;
}
class rectangle //矩形类
{
private:
point p1;point p2;
//int x,y;
int m;
public:
rectangle(point pp1,point pp2);
rectangle(rectangle &r);
int mj();
};
rectangle::rectangle(point pp1,point pp2):p1(pp1),p2(pp2)
{ // p1=pp1;p2=pp2;
int x=abs(p1.getx()-p2.getx());
int y=abs(p1.gety() -p2.gety()) ;
m=x*y;
cout<<"rectangle构造函数调用1"<<endl;
}
rectangle::rectangle(rectangle &r)
{
m=r.m;//y=r.y;
cout<<"rectangle拷贝函数的调用"<<endl;
}
int rectangle::mj()
{
return m;
}
void main()
{ int x1,x2,y1,y2;
cout<<"输入第一个点的坐标:"<<endl;
cin>>x1>>y1;
point pp1(x1,y1);
cout<<"输入第二个点的坐标:"<<endl;
cin>>x2>>y2;
point pp2(x2,y2);
rectangle rr(pp1,pp2);
rectangle re(rr);
cout<<rr.mj() <<endl;
cout<<re.mj()<<endl;
}
帮我看下这个c++程序错在哪里?
说下错的原因。
谢谢!