[Cpp]
/*
* Copyright (c) 2013, computer College, Yantai University
* All rights reserved.
* File name: test. cpp
* Author: Fan Lulu
* Completion date: January 1, April 15, 2013
* Version: v1.0
*
* Input Description: None
* Problem description:
* Program output:
* Problem analysis:
* Algorithm Design: omitted
*/
# 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 ){}
Double distance1 (CPoint &);
Friend double distance2 (CPoint &, CPoint &);
Double getX () {return x ;}
Double getY () {return y ;}
};
Double distan2010( CPoint &, CPoint &); // defines a general function
Double CPoint: distance1 (CPoint & p) // member function definition
{
Double dx = (x-p.x), dy = y-p.y;
Return sqrt (dx * dx + dy * dy );
}
Double distance2 (CPoint & p1, CPoint & p2) // you can define a function.
{
Double dx = (p1.x-p2.x), dy = p1.y-p2.y;
Return sqrt (dx * dx + dy * dy );
}
Double distan2010( CPoint & p1, CPoint & p2) // definition of general functions
{
Double dx = (p1.getX ()-p2.getX (), dy = p1.getY ()-p2.getY ();
Return sqrt (dx * dx + dy * dy );
}
Int main ()
{CPoint p1 (10, 13), p2 (-5, 6 );
Cout <"1." <p1.distance1 (p2) <endl;
Cout <"2." <distance2 (p1, p2) <endl;
Cout <"3." <distane3 (p1, p2) <endl;
System ("pause ");
Return 0;
}
/*
* Copyright (c) 2013, computer College, Yantai University
* All rights reserved.
* File name: test. cpp
* Author: Fan Lulu
* Completion date: January 1, April 15, 2013
* Version: v1.0
*
* Input Description: None
* Problem description:
* Program output:
* Problem analysis:
* Algorithm Design: omitted
*/
# 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 ){}
Double distance1 (CPoint &);
Friend double distance2 (CPoint &, CPoint &);
Double getX () {return x ;}
Double getY () {return y ;}
};
Double distan2010( CPoint &, CPoint &); // defines a general function
Double CPoint: distance1 (CPoint & p) // member function definition
{
Double dx = (x-p.x), dy = y-p.y;
Return sqrt (dx * dx + dy * dy );
}
Double distance2 (CPoint & p1, CPoint & p2) // you can define a function.
{
Double dx = (p1.x-p2.x), dy = p1.y-p2.y;
Return sqrt (dx * dx + dy * dy );
}
Double distan2010( CPoint & p1, CPoint & p2) // definition of general functions
{
Double dx = (p1.getX ()-p2.getX (), dy = p1.getY ()-p2.getY ();
Return sqrt (dx * dx + dy * dy );
}
Int main ()
{CPoint p1 (10, 13), p2 (-5, 6 );
Cout <"1." <p1.distance1 (p2) <endl;
Cout <"2." <distance2 (p1, p2) <endl;
Cout <"3." <distane3 (p1, p2) <endl;
System ("pause ");
Return 0;
}