C++ 程序 给个理由
来源:百度知道 编辑:UC知道 时间:2024/08/22 10:22:32
#include<iostream.h>
int xx,yy;
class rectangle
{
private:
int x,y;
public:
static int a;
void build()
{
x=xx;
y=yy;
}
static int area(rectangle p1,rectangle p2)
{
cout<<p1.x<<" "<<p2.x<<endl;
a=(p2.x-p1.x)*(p2.y-p2.y);
if(a<0)
{
a=-a;
}
cout<<a<<endl;
return(a);
}
};
int rectangle::a=0;
void main()
{int b;
rectangle p1;
cin>>xx;
cin>>yy;
p1.build();
rectangle p2;
cin>>xx;
cin>>yy;
p2.build();
b=rectangle::area(p1,p2);
cout<<b<<endl;
}
怎么做 a都是0 为什么啊
int xx,yy;
class rectangle
{
private:
int x,y;
public:
static int a;
void build()
{
x=xx;
y=yy;
}
static int area(rectangle p1,rectangle p2)
{
cout<<p1.x<<" "<<p2.x<<endl;
a=(p2.x-p1.x)*(p2.y-p2.y);
if(a<0)
{
a=-a;
}
cout<<a<<endl;
return(a);
}
};
int rectangle::a=0;
void main()
{int b;
rectangle p1;
cin>>xx;
cin>>yy;
p1.build();
rectangle p2;
cin>>xx;
cin>>yy;
p2.build();
b=rectangle::area(p1,p2);
cout<<b<<endl;
}
怎么做 a都是0 为什么啊
a=(p2.x-p1.x)*(p2.y-p2.y);//这里 p2.y-p2.y肯定是0啊
改为 a=(p2.x-p1.x)*(p2.y-p1.y); 具体如下:
#include<iostream.h>
int xx,yy;
class rectangle
{
private:
int x,y;
public:
static int a;
void build()
{
x=xx;
y=yy;
}
static int area(rectangle p1,rectangle p2)
{
cout<<p1.x<<" "<<p2.x<<endl;
a=(p2.x-p1.x)*(p2.y-p1.y);
if(a<0)
{
a=-a;
}
cout<<a<<endl;
return(a);
}
};
int rectangle::a=0;
void main()
{
int b;
rectangle p1;
cin>>xx;
cin>>yy;
p1.build();
rectangle p2;
cin>>xx;
cin>>yy;
p2.build();
b=rectangle::area(p1,p2);
cout<<b<<endl;
}