fork(1) download
  1. #include <iostream>
  2.  
  3. class Vector3d
  4. {
  5. private:
  6. double m_x, m_y, m_z;
  7. friend class Point3d;
  8. public:
  9. Vector3d(double x = 0.0, double y = 0.0, double z = 0.0)
  10. : m_x(x), m_y(y), m_z(z)
  11. {
  12.  
  13. }
  14.  
  15. void print()
  16. {
  17. std::cout << "Vector(" << m_x << " , " << m_y << " , " << m_z << ")\n";
  18. }
  19. };
  20.  
  21.  
  22. class Point3d
  23. {
  24. private:
  25. double m_x, m_y, m_z;
  26.  
  27. public:
  28. Point3d(double x = 0.0, double y = 0.0, double z = 0.0)
  29. : m_x(x), m_y(y), m_z(z)
  30. {
  31.  
  32. }
  33.  
  34. void print()
  35. {
  36. std::cout << "Point(" << m_x << " , " << m_y << " , " << m_z << ")\n";
  37. }
  38.  
  39. void moveByVector(Vector3d &v);
  40. };
  41.  
  42. void Point3d::moveByVector(Vector3d& v)
  43. {
  44. m_x += v.m_x;
  45. m_y += v.m_y;
  46. m_z += v.m_z;
  47. }
  48.  
  49. int main()
  50. {
  51. Point3d p(1.0, 2.0, 3.0);
  52. Vector3d v(2.0, 2.0, -3.0);
  53.  
  54. p.print();
  55. p.moveByVector(v);
  56. p.print();
  57.  
  58. return 0;
  59. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
Point(1 , 2 , 3)
Point(3 , 4 , 0)