呵,可能是我想复杂了吧,下面代码有40行,远远超过了10行。
#include
using namespace std;
class Point3D
{
private:
int x, y, z;
public:
Point3D();
Point3D(int, int, int);
int getX(); int getY(); int getZ();
void setX(int); void setY(int); void setZ(int);
};
Point3D::Point3D()
{ this->x = 0; this->y = 0; this->z = 0;}
Point3D::Point3D(int x, int y, int z)
{ this->x = x; this->y = y; this->z = z;}
int Point3D::getX() { return this->x;}
int Point3D::getY() { return this->y;}
int Point3D::getZ() { return this->z;}
void Point3D::setX(int x) { this->x = x;}
void Point3D::setY(int y) { this->y = y;}
void Point3D::setZ(int z) { this->z = z;}
float getDistance(Point3D a, Point3D b)
{
float x, y, z;
x = a.getX() - b.getX();
y = a.getY() - b.getY();
z = a.getZ() - b.getZ();
return sqrt(x * x + y * y + z * z);
}
int main(int argc, char *argv[])
{
Point3D pa;
Point3D pb(0, 0, 3);
cout << "Distance = " << getDistance(pa, pb) << endl;
system("Pause");
return 0;
}
服了你了,把高中数学书拿出来看看,里面有算法的公式,然后把变量定义了,80%不就完了,用不了10行代码就可以搞定的