坐标有关程序请大侠指教
这有个程序看不懂,尤其是//???部分.望大侠赐教//提示用户输入两个框架(frame)左上角和右下角的坐标,并判断两个框架是否重叠.如果重叠,
//则将面积较大的那个框架的4个坐标值各缩进1.每个坐标点(x,y)用一个结构类型来描述
//程序:
#include (iostream.h)
struct spoint
{
int x,y;
};
struct sframe
{
spoint topleft,bttomright;
};
void main()
{
sframe frame1,frame2;
bool overlapped;
long area1,area2;
cout<<"enter topleft coordinates for the first frame:";
cin>>frame1.topleft.x>>frame1.topleft.y;
cout<<"enter bottom right coordinates for the first frame:";
cin>>frame1.bottomright.x>>frame1.bottomright.y;
cout<<"enter topleft coordinates for the second frame:";
cin>>frame2.topleft.x>>frame2.topleft.y;
cout<<"enter botoomright coordinates for the second frame:";
cin>>frame2.bottomright.x>>frame2.bottomright.y;
//check if the frames are overlapped
overlapped=true;//assume they are overlapped
if(frame2.topleft.x>frame1.bottomright.x)////////////?????????
overlapped=false;//////////////////////////???????以及下面
if(frame2.bottomright.x<frame1.topleft.x)
overlapped=false;
if(frame2.bottomright.y>frame1.topleft.y)
overlapped=false;
if(frame2.topleft.y<frame1.bottomright.y)
overlapped=false;
if(voerlapped)
{
cout<<"the two frames are overlaped.">>endl;
area1=(frame1.bottomright.x-frame1.topleft.x)*(frame1.topleft.y-
frame1.bottomright.y);
area2=(frame2.bottomright.x-frame2.topleft.x)*(frame2.topleft.y-
frame2.bottomright.y);
if(areal>area2)
{
frame1.topleft.x+=1;
frame1.bottomright.x-=1;
frame1.topleft.y-=1;
frame.bottomright.y+=1;
}
else
{
frame2.topleft.x+=1;
frame2.bottomright.x-=1;
frame2.topleft.y-=1;
frame2.bottomright.y+=1;
}
}
else
cout<<"the two frames are not overlapped."<<endl;
cout<<"frame1:("<<frame1.topleft.x<<","<<frame1.topleft.y<<")",("<<
frame1.bottomright.x<<","<<frame1.bottomright.y<<")"<<endl;
cout<<"frame2:("<<frame2.topleft.x<<","<<frame2.topleft.y<<")",("<<
frame2.bottomright.x<<","<<frame2.bottomright.y<<")"<<endl;
}
//程序运行结果:
//enter top left coordinates for the first frame:10 30
//enter bottom right coordinates for the first frame:20 20
//enter top left coordinates for the second frame:15 45
//enter botoomright coordinates for the second frame:35 25
//the two frames are overlaped.
//frame1:(10,30),(20),20)
//frame2:(16,44),(34,26)
//press any key to continue