|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <iostream>
using namespace std;
class Point {
public:
Point() {x = 0; y = 0; }
Point(double xv,double yv) {x = xv;y = yv;}
Point(Point& pt) { x = pt.x; y = pt.y; }
double getx() { return x; }
double gety() { return y; }
double Area() { return 0; }
void Show() { cout<<"x="<<x<<' '<<"y="<<y<<endl; }
private:
double x,y;
};
class Rectangle:public Point
{
double length,width;
public:
Rectangle(double x,double y, double l,double w):
Point(x,y){length=l,width=w;}
double getl(){return length;}
double getw(){return width;}
double Area(){return width*length;}
double Perimeter(){return 2*(width+length);}
void Show(){ cout<<"Top is"<<" "<<getx()<<endl;
cout<<"Left is"<<" "<<gety()<<endl;
cout<<"Length is"<<" "<<getl()<<endl;
cout<<"Width is"<<" "<<getw()<<endl;
cout<<"Perimeter is"<<" "<<Perimeter()<<endl;
cout<<"Area is"<<Area()<<endl;
}
void position(Point &pt)
{
double x1=getx(); double y1=gety();
cout<<x1<<" "<<y1<<endl;
Point:: Point(pt);
cout<<getx();//[font=微软雅黑]为什么这时候的x、y的值没有改变
if(getx()<x1||gety()>y1||getx()>x1+length||gety()<y1-width)
cout<<" 该点在图形外 "<<endl;
if((getx()==x1&&gety()==y1)||(getx()==x1&&(gety()==y1-width))||((getx()==x1+length)&&gety()==y1)||((getx()==x1+length)&&(gety()==y1-width)))
cout<<"该点在图形上"<<endl;
else
cout<<"该点在图形内"<<endl;
}
};
int main()
{
double x,y;
Rectangle test(1,2,3,4);
test.Show();
cout<<"请输入你想测试的点: x,y"<<endl;
cin>>x>>y;
Point test1(100,100);
test1.Show();
test. position(test1);
system("pause");
return 0;
}
|
|