西安交大C++堂练习12.docVIP

  • 15
  • 0
  • 约1.65万字
  • 约 21页
  • 2016-10-21 发布于贵州
  • 举报
西安交大C堂练习12

西安交通大学实验报告 实验目的 (1)掌握构造函数的使用。 (2)掌握指向对象的指针的使用。 (3)了解析构函数。 实验内容 (-)实验题目一:定义并实现三维空间的Point3D类,包括x、y、z三个成员变量,一个计算空间中两个点之间的距离的成员函数,并编写合适的构造函数和析构函数。 程序源代码 #includeiostream #includecmath using namespace std; class Point3D { private: double x,y,z; public: Point3D(double a,double b,double c) { x=a;y=b;z=c; } Point3D(Point3D A) { x=A.x;y=A.y;z=A.z; } double distance(Point3D A) { double d=0; d=(x-A.x)*(x-A.x)+(y-A.y)*(y-A.y)+(z-A.z)*(z-A.z); return sqrt(d); } void show() { cout(x,y,z)endl; } ~Point3D() { coutThis is the destructor function\n; coutPoint \n; show(); } }

文档评论(0)

1亿VIP精品文档

相关文档