zoukankan      html  css  js  c++  java
  • MFC中的CRect(区域)

    写一个CRect类表示一个矩形,该矩形类成员变量为:x1,y1,x2,y2,矩形左上角和右下角的坐标。然后完成以下几个成员函数:
    1. CRect(); //无参数的构造函数
    2. CRect(double x1_, double y1_, double x2_, double y2_); //带有4个参数的构造函数(矩形左上角和右下角的坐标)
    3. bool IsSquare(); //判断该矩形是否是正方形
    4. double Area(); //求该矩形的面积
    5. bool Intersecting(CRect rect); //求该矩形是否和另一个矩形是否相交,也就是当前矩形和矩形rect有重合部分

    实现:

    #include<iostream.h>
    class CRect{
    private:
    double x1;
    double x2;
    double y1;
    double y2;
    public:
    CRect();
    CRect(double x1_, double y1_, double x2_, double y2_);
    bool IsSquare();
    double Area();
    bool Intersecting(CRect rect);
    };
    CRect::CRect()
    {x1=y1=0;
    x2=y2=1;
    }
    CRect::(double x1_, double y1_, double x2_, double y2_)
    {x1=x1_;
    y1=y1_;
    x2=x2_;
    y2=y2_;
    }
    bool CRect::IsSquare()
    {if((x2-x1)==(y2-y1))
    return true;
    else return false;
    }
    double CRect::Area()
    {return ((x2-x1)*(y2-y1));
    }
    bool Intersecting(CRect rect);
    {if(rect.x1<x2||rect.y1<y2||rect.x2>x1||rect.y2>y1)
    return true;
    else return false;
    }
    int main()
    {double x1,x2,y1,y2;
    cout<<"Please input two endpoints:"<<endl;
    cin>>x1>>y1>>x2>>y2;
    CRect C1(x1,y1,x2,y2);
    CRect C2;
    if(C1.IsSquare())
    cout<<"The rect is a square!"<<endl;
    else cout<<"The rect is not a square!"<<endl;
    cout<<"The area of the rect is:"<<C1.Area()<<endl;
    if(C1.Intersecting(C2))
    cout<<"rect C1 intersecting with rect C2!"<<endl;
    else cout<<"rect C1 not intersecting with rect C2!"<<endl;
    return 0;
    }

  • 相关阅读:
    特殊字符,如Emoji表情Base64存储到数据库
    判断文本文件的编码
    很多.net 程序员不知道又非常重要的 .net高级调试技巧.调试别人的dll方法内的变量
    没想到你是这样的Linux
    PDF转成txt
    生成云图
    Data collection (imaging)
    Python Conda 软件包升级
    电镜作业2的脚本版本
    电镜作业2
  • 原文地址:https://www.cnblogs.com/buffer/p/1256281.html
Copyright © 2011-2022 走看看