标签:小代码
class point { private: int x,y; public: point(int xx=0,int yy=0){x=xx;y=yy;} point(point &p); int getx(){return x;} int gety(){return y;} void dis(){cout<<"x="<<x<<" y="<<y<<endl;} }; point::point(point &p) { x=p.x; y=p.y; } class line { private : point p1,p2; double dist; public: line(point xp1,point xp2):p1(xp1),p2(xp2) { double x=double(p1.getx()-p2.getx()); double y=double(p1.gety()-p2.gety()); dist=sqrt(x*x+y*y); } double getdis(){cout<<dist<<endl;return dist;} }; int main() { point p1(1,1),p2(2,2); line l(p1,p2); l.getdis(); return 0; }
//1.41421
标签:小代码
原文地址:http://wzsts.blog.51cto.com/10251779/1761566