问题写在//后面了,实在搞不懂,求助
#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;
}
voidposition(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;
}
getx不是取出x的值吗?为什么会变? BngThea 发表于 2018-5-8 21:14
getx不是取出x的值吗?为什么会变?
Point:: Point(pt);
这个不是改变了x,y的值了吗? 机械之心max 发表于 2018-5-9 14:51
Point:: Point(pt);
这个不是改变了x,y的值了吗?
你生成的这个point对象又没有拿来用 BngThea 发表于 2018-5-9 15:01
你生成的这个point对象又没有拿来用
我明白了,多谢
页:
[1]