01. /* 02. * copyright and version Declaration of the program part 03. * Copyright (c) 2013, Yantai University Computer college student 04. * All rightsreserved. 05. * file name: cpoint. cpp 06. * Author: Zhao guanzhe 07. * Completion Date: April 8, April 12, 2013. * version: v1.0 09. * input Description: 10. * Problem description: 11. */# include <iostream> # include <cmath> using namespace std; class CPoint {private: double x; // abscissa double y; // ordinate public: CPoint (double xx = 0, double yy = 0): x (xx), y (yy) {} void distance1 (CPoint cp); friend void distance2 (CPoint cp1, CPoint cp2); double getx () {return x;} double gety () {return y ;}}; void CPoint: distance1 (CPoint cp) {double dist = sqrt (cp. x-x) * (cp. x-x) + (cp. y-y) * (cp. y-y); cout <"the distance between the two points is:" <dist <endl;} void distance2 (CPoint cp1, CPoint cp2) {double dist = sqrt (cp1.x-cp2.x) * (cp1.x-cp2.x) + (cp1.y-cp2.y) * (cp1.y-cp2.y )); cout <"the distance between two points is:" <dist <endl;} void distane3 (CPoint cp1, CPoint cp2) {double dis = sqrt (cp1.getx () -cp2.getx () * (cp1.getx ()-cp2.getx () + (cp1.gety ()-cp2.gety () * (cp1.gety ()-cp2.gety ())); cout <"the distance between two points is:" <dis <endl ;}int main () {CPoint cp1, cp2 (8, 6); cp1.distance1 (cp2 ); distance2 (cp1, cp2); distanc4( cp1, cp2); return 0 ;}
Running result: