找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 900|回复: 0

坐标有关程序请大侠指教

[复制链接]
发表于 2009-11-5 00:39:31 | 显示全部楼层 |阅读模式 IP:江苏扬州
这有个程序看不懂,尤其是//???部分.望大侠赐教
//提示用户输入两个框架(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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-10-1 07:37 , Processed in 0.116467 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表