Guest User

Untitled

a guest
Aug 4th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #pragma once
  2. #include <cmath>
  3.  
  4. class Point1d {
  5. protected:
  6. double* PosX;
  7. public:
  8. Point1d(double x) {
  9. *PosX = x;
  10. }
  11. virtual ~Point1d() {
  12. delete PosX;
  13. }
  14. virtual double x() { return *PosX; }
  15. virtual void SetX(double value) { *PosX = value; }
  16. double CountDistance(Point1d OtherPoint) {
  17. return fabs(OtherPoint.x() - *PosX);
  18. }
  19. void SetPoint(double x) {
  20. *PosX = x;
  21. }
  22. };
  23.  
  24. class Point2d : public Point1d {
  25. protected:
  26. double* PosY;
  27.  
  28. public:
  29. Point2d(double x, double y):
  30. Point1d{ x } {
  31. *PosY = y;
  32. }
  33.  
  34. virtual ~Point2d() {
  35. delete PosX;
  36. delete PosY;
  37. }
  38. void SetPoint(double x, double y) {
  39. *PosX = x;
  40. *PosY = y;
  41. }
  42. virtual double x() { return *PosX; }
  43. virtual double y() { return *PosY; }
  44. virtual void SetX(double value) { *PosX = value; }
  45. virtual void SetY(double value) { *PosY = value; }
  46. double CountDistance(Point2d OtherPoint) {
  47. return sqrt(pow(Point1d::CountDistance(OtherPoint), 2) + pow(OtherPoint.y() - *PosY, 2));
  48. }
  49. };
  50.  
  51. class Point3d : public Point2d {
  52. protected:
  53. double* PosZ;
  54. public:
  55. Point3d() = default;
  56. Point3d(double x, double y, double z):
  57. Point2d{ x,y } {
  58. *PosZ = z;
  59. }
  60. ~Point3d() {
  61. delete PosX;
  62. delete PosY;
  63. delete PosZ;
  64. }
  65. virtual double x() { return *PosX; }
  66. virtual double y() { return *PosY; }
  67. virtual double z() { return *PosZ; }
  68. virtual void SetX(double value) { *PosX = value; }
  69. virtual void SetY(double value) { *PosY = value; }
  70. virtual void SetZ(double value) { *PosZ = value; }
  71. void SetPoint(double x, double y, double z) {
  72. *PosX = x;
  73. *PosY = y;
  74. *PosZ = z;
  75. }
  76. double CountDistance(Point3d OtherPoint) {
  77. return sqrt(pow(Point2d::CountDistance(OtherPoint), 2) + pow(OtherPoint.z() - *PosZ, 2));
  78. }
  79. };
Advertisement
Add Comment
Please, Sign In to add comment