fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdio>
  4.  
  5.  
  6. using namespace std;
  7.  
  8.  
  9. class Point
  10. {
  11. double x, y, z;
  12.  
  13. public:
  14. // constructor from 3 values
  15. Point(double x, double y, double z);
  16.  
  17. // method display
  18. void display();
  19.  
  20. double getX() { return x ; };
  21. double getY() { return y ; };
  22. double getZ() { return z ; };
  23. };
  24.  
  25. // constructor from 3 values
  26. Point::Point(double x, double y, double z)
  27. : x(x), y(y), z(z)
  28. {}
  29.  
  30. void Point::display()
  31. {
  32. cout << "Point(" << x << ", " << y << ", " << z << ")\n";
  33. }
  34.  
  35.  
  36.  
  37. class Line
  38. {
  39. Point pnt1, pnt2;
  40.  
  41. public:
  42. // constructor from 2 points
  43. Line(Point& pnt1, Point& pnt2);
  44.  
  45. // method display line
  46. void display();
  47. };
  48.  
  49. // constructor from 2 points
  50. Line::Line(Point& _pnt1, Point& _pnt2)
  51. : pnt1(_pnt1), pnt2(_pnt2)
  52. {}
  53.  
  54. // method display line
  55. void Line::display()
  56. {
  57. cout << "Line(Point(" << pnt1.getX() << ", " << pnt1.getY() << ", " << pnt1.getZ() << ")" << ", Point(" << pnt2.getX() << ", " << pnt2.getY() << ", " << pnt2.getZ() << ")\n";
  58. }
  59.  
  60. int main()
  61. {
  62. // initialise object Point
  63. cout << endl << "Point initialisation:" << endl;
  64.  
  65. Point pnt = Point(0.0, 0.0, 0.0);
  66. cout << "pnt = "; pnt.display();
  67.  
  68. Point pnt2 = Point(1.0, 1.0, 1.0);
  69. cout << "pnt2 = "; pnt2.display();
  70.  
  71. // initialising object Line
  72. cout << "Line initialisation:" << endl;
  73.  
  74. Line line = Line(pnt, pnt2);
  75. line.display();
  76.  
  77. return 0;
  78. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
Point initialisation:
pnt = Point(0, 0, 0)
pnt2 = Point(1, 1, 1)
Line initialisation:
Line(Point(0, 0, 0), Point(1, 1, 1)