#include "stdafx.h"
#include <iostream>
using namespace std;
class Point_And_Rectangle
{
public:
Point_And_Rectangle(float X,float Y) //构造函数
{
length=X; //长度
width=Y; //宽度
}
void init()
{
cout<<"矩阵长;"<<length<<",宽为:"<<width<<endl;
cout<<"请输入被测点的x坐标:";
cin>>X;
cout<<"请输入被测点的Y坐标:";
cin>>Y;
cout<<endl;
}
void output()
{
if(PointInRectangle()==false)
cout<<"被测点的矩形外\n";
else
cout<<"被测点在矩形内\n";
}
bool PointInRectangle()
{
if(X<0||X>length||Y<0||Y>width)
return false;
else
return true;
}
private:
float length;
float width;
float X;
float Y;
};
int _tmain(int argc, _TCHAR* argv[])
{
int goon;
Point_And_Rectangle m(10,20.5);
do
{
m.init();
m.output();
cout<<"是否继续?0-否,1-是"<<endl;
cin>>goon;
}while(goon==1);
getchar();
return 0;
}
7-120 矩形范围(判断一个点是否超出矩形范围)
最新推荐文章于 2025-02-25 09:04:02 发布