20

类的练习
#include<iostream>
#include<cmath>
using namespace std;
class point
{
protected:
int X , Y;
public:
point()
{
X=0;
Y=0;
}
point(int x,int y)
{
X=x;
Y=y;
cout<<"okok"<<endl;
}
void setp(int x,int y)
{
X=x;
Y=y;
}
int getX()
{
return X;
}
int getY()
{
return Y;
}
double disto()
{
return (sqrt(X*X+Y*Y));
}
double dist(point &amp;p)
{
int x;
int y;
x=X-p.X;
y=Y-p.Y;
return (sqrt(x*x+y*y));
}
void show()
{
cout<<"point("<<X<<","<<Y<<")"<<"\n";
}
};
int main()
{
point p1 , p2 , p3;
int x , y;
p1.setp(4,5);
p1.show();
cout<<p1.disto()<<endl;
p2.setp(1,1);
cout<<p1.dist(p2)<<endl;
return 0;
}
全部评论

相关推荐

07-13 14:45
南华大学 Java
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务