1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| #include<iostream> #include<math.h> using namespace std; class Point { private: int x,y; public: Point(int xx,int yy) {x=xx;y=yy;} int getx() {return x;} int gety() {return y;} }; class Line { private: Point p1,p2; double len; public: Line(Point _p1,Point _p2):p1(_p1),p2(_p2)
{ cout<<"初始化"<<endl; } double getlen() { int dx,dy; dx=p2.getx()-p1.getx(); dy=p2.gety()-p1.gety(); return(sqrt(dx*dx+dy*dy)); } };
int main() { class Point p1(2,2); class Point p2(5,4); class Line l1 (p1,p2); cout<<l1.getlen()<<endl; return 0; }
|