Advertisement
Berty97

Untitled

Jan 16th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class CPoint
  5. {
  6. public:
  7. int d;
  8. double* coord;
  9.  
  10. public:
  11. CPoint()
  12. {
  13. this->d = 0;
  14. this->coord = NULL;
  15. }
  16.  
  17. CPoint(int d1)
  18. {
  19. this->d = 0;
  20. this->coord = NULL;
  21.  
  22. this->d = d1;
  23.  
  24. if (d1)
  25. {
  26. this->d = d1;
  27. coord = new double[d];
  28. if (coord == NULL)
  29. exit(0);
  30. for (unsigned int i = 0; i < d; i++)
  31. coord[i] = 0;
  32.  
  33. }
  34. }
  35.  
  36.  
  37. CPoint(CPoint &P)
  38. {
  39. this->d = 0;
  40. this->coord = NULL;
  41.  
  42. if (P.d)
  43. {
  44. this->d = P.d;
  45. coord = new double[d];
  46. if (coord == NULL)
  47. exit(0);
  48. for (unsigned i = 0; i < d; i++)
  49. coord[i] = P.coord[i];
  50. }
  51. }
  52.  
  53. ~CPoint()
  54. {
  55. if (coord)
  56. delete[] coord;
  57. coord = NULL;
  58. }
  59.  
  60. void Compare(const CPoint &p)
  61. {
  62. int ok = 0;
  63. if (d != p.d)
  64. cout << "Punctele nu sunt din acelasi spatiu " << endl;
  65. else
  66. {
  67. if (d == p.d)
  68. for (int i = 0; i < d; i++)
  69. if (coord[i] != p.coord[i])
  70. ok = 1;
  71.  
  72. if (ok == 0)
  73. cout << "Punctele sunt identice " << endl;
  74. else
  75. cout << "Punctele nu sunt identice " << endl;
  76. }
  77. }
  78.  
  79.  
  80. void afis()
  81. {
  82. cout << "Spatiul este " << d << " dimensional " << endl;
  83. cout << "Coordonatele sunt: ";
  84. for (int i = 0; i < d; i++)
  85. cout << coord[i] << ", ";
  86. cout << endl;
  87. }
  88.  
  89. double& operator[] (int i)
  90. {
  91. for (i = 0; i < d; i++)
  92. return coord[i];
  93. }
  94.  
  95. };
  96.  
  97.  
  98. class CPoint2d : public CPoint
  99. {
  100. public:
  101. CPoint2d() : CPoint(2)
  102. {
  103.  
  104. }
  105.  
  106. CPoint2d(double x, double y) : CPoint (2)
  107. {
  108. coord[0] = x;
  109. coord[1] = y;
  110. }
  111. };
  112.  
  113.  
  114. class CPoint3d : public CPoint
  115. {
  116. public:
  117. /*CPoint3d() : CPoint(3)
  118. {
  119.  
  120. }*/
  121.  
  122. CPoint3d(double x, double y, double z) : CPoint(3)
  123. {
  124. coord[0] = x;
  125. coord[1] = y;
  126. coord[2] = z;
  127. }
  128. };
  129.  
  130.  
  131. int main()
  132.  
  133. {
  134. CPoint P13(3);
  135. P13[0] = 4;
  136. P13[1] = 5;
  137. P13[2] = 6;
  138. P13.afis();
  139.  
  140. CPoint P14(3);
  141. P14[0] = 4;
  142. P14[1] = 7;
  143. P14[2] = 6;
  144.  
  145. CPoint P15 = P14;
  146. P15.afis();
  147.  
  148.  
  149. CPoint2d P2;
  150. P2[0] = 3;
  151. P2[1] = 4;
  152. CPoint2d P22(9, 0);
  153. P22.afis();
  154.  
  155. CPoint3d P3(11, 4, 5);
  156. P3.afis();
  157. P13.Compare(P14);
  158. system("pause");
  159. return 0;
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement