fork download
  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4.  
  5. class Point
  6. {
  7. public:
  8. Point()
  9. {
  10. x = 0;
  11. y = 0;
  12. }
  13. Point(double x, double y)
  14. {
  15. this->x = x;
  16. this->y = y;
  17. }
  18. double getX()
  19. {
  20. return x;
  21. }
  22. double getY()
  23. {
  24. return y;
  25. }
  26. void setX(double x)
  27. {
  28. this->x = x;
  29. }
  30. void setY(double y)
  31. {
  32. this->y = y;
  33. }
  34. private:
  35. double x;
  36. double y;
  37. };
  38.  
  39. class PointPair : public Point
  40. {
  41. public:
  42. PointPair()
  43. {
  44. p1 = 0;
  45. p2 = 0;
  46. dist = 0;
  47. }
  48. Point * p1()
  49. {
  50. return p1;
  51. }
  52. Point * p2()
  53. {
  54. return p2;
  55. }
  56. void setP1(Point * p)
  57. {
  58. p1 = p;
  59. }
  60. void setP2(Point * p)
  61. {
  62. p2 = p;
  63. }
  64. void setDistance(double d)
  65. {
  66. dist = d;
  67. }
  68. private:
  69. Point* p1;
  70. Point* p2;
  71. double dist;
  72. };
  73.  
  74. int main()
  75. {
  76. double x;
  77. double y;
  78. // int count = 0;
  79. vector<Point> plotPoints;
  80.  
  81. do
  82. {
  83. cout << "Enter (x,y) Coordinates ((-1, -1) to stop): ";
  84. cin >> x >> y;
  85. cout << x << " " << y << endl;
  86. if ((x == -1) || (y == -1))
  87. {
  88. cout << "-1 -1 Entered. Calculating closest points..." << endl;
  89. break;
  90. }
  91. else
  92. {
  93. plotPoints.push_back(Point(x, y));
  94. }
  95.  
  96. } while (x != -1 || y != -1);
  97.  
  98.  
  99. cout << plotPoints.size() << " number of points entered. "<< endl;
  100.  
  101.  
  102. system("pause");
  103. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:69:9: error: 'Point* PointPair::p1' conflicts with a previous declaration
  Point* p1;
         ^
prog.cpp:48:10: note: previous declaration 'Point* PointPair::p1()'
  Point * p1()
          ^
prog.cpp:70:9: error: 'Point* PointPair::p2' conflicts with a previous declaration
  Point* p2;
         ^
prog.cpp:52:10: note: previous declaration 'Point* PointPair::p2()'
  Point * p2()
          ^
prog.cpp: In constructor 'PointPair::PointPair()':
prog.cpp:44:6: error: invalid use of member function (did you forget the '()' ?)
   p1 = 0;
      ^
prog.cpp:45:6: error: invalid use of member function (did you forget the '()' ?)
   p2 = 0;
      ^
prog.cpp: In member function 'Point* PointPair::p1()':
prog.cpp:50:10: error: cannot convert 'PointPair::p1' from type 'Point* (PointPair::)()' to type 'Point*'
   return p1;
          ^
prog.cpp: In member function 'Point* PointPair::p2()':
prog.cpp:54:10: error: cannot convert 'PointPair::p2' from type 'Point* (PointPair::)()' to type 'Point*'
   return p2;
          ^
prog.cpp: In member function 'void PointPair::setP1(Point*)':
prog.cpp:58:6: error: invalid use of member function (did you forget the '()' ?)
   p1 = p;
      ^
prog.cpp: In member function 'void PointPair::setP2(Point*)':
prog.cpp:62:6: error: invalid use of member function (did you forget the '()' ?)
   p2 = p;
      ^
stdout
Standard output is empty