关于C++面向对象程序设计的一个程序!!!

来源:百度知道 编辑:UC知道 时间:2024/05/09 09:37:42
问题:写一个程序,定义一个矩形Rectangle,它由左上角坐标长和宽描述,这个类的公用成员函数Is In or Out用于判断一个输入坐标,是否在一个矩形的对象内,如果是,返回true,否则返回false.
希望用C++面向对象程序涉及中的一些基础,如类和对象,预算符重载,继承和派生,多态性和虚函数。当然,不要求全部,涉及部分就够了,不要太深的。

# include <iostream>
# include <iomanip>
using namespace std;
struct Rectangle
{
double x1,y1;//左上角坐标
double x2,y2;//右上角坐标
}r;
void Init()
{
cout<<"Input the signal of the square:"<<endl;
cin>>r.x1>>r.y1;
cin>>r.x2>>r.y2;
}
bool Trial(double x,double y)
{
bool b=true;
if ((x>r.x1&&x<r.x2)&&(y>r.y1&&y<r.y2))
cout<<"It's in the square."<<endl;
else
{
cout<<"It isn't in the square."<<endl;
b=false;
}
return b;
}
int main(int argc,char* argv[])
{
double x,y;
bool b
Init();
cout<<"Input a signal:"<<endl;
cin>>x>>y;
b=Trial(x,y);
return 0;
}