您的位置:首页 > 编程语言 > PHP开发

定义点TPoint类,获取点的纵坐标,对点进行平移动

2013-10-21 10:53 211 查看
#include<iostream>
using namespace std;

class TPoint{
private:
int x,y;
public:
TPoint(int x=0,int y=0)
{
this->x=x;
this->y=y;
}
int Getx()
{
return x;
}
int Gety()
{
return y;
}
void Movepoint(int addx,int addy)
{
this->x+=addx;
this->y+=addy;
}
TPoint(TPoint &p)
{
x=p.x;
y=p.y;
}
void Showpoint()
{
cout << "("<< x<<","<<y<<")"<<endl;
}
};

int main()
{
int x,y,a,b;
cout << "input the coordinate of a point: ";
cin >>x>>y;
TPoint T1(x,y);
TPoint T2(T1);
cout <<"this point is:";
T2.Showpoint();
cout << "this point's ordinate is:"<<T2.Gety()<<endl;
cout <<"move the point,input two numbers :";
cin >>a>>b;
T2.Movepoint(a,b);
cout <<"the point after move is:";
T2.Showpoint();
return 0;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: