Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class CPoint
- {
- public:
- int d;
- double* coord;
- public:
- CPoint()
- {
- this->d = 0;
- this->coord = NULL;
- }
- CPoint(int d1)
- {
- this->d = 0;
- this->coord = NULL;
- this->d = d1;
- if (d1)
- {
- this->d = d1;
- coord = new double[d];
- if (coord == NULL)
- exit(0);
- for (unsigned int i = 0; i < d; i++)
- coord[i] = 0;
- }
- }
- CPoint(CPoint &P)
- {
- this->d = 0;
- this->coord = NULL;
- if (P.d)
- {
- this->d = P.d;
- coord = new double[d];
- if (coord == NULL)
- exit(0);
- for (unsigned i = 0; i < d; i++)
- coord[i] = P.coord[i];
- }
- }
- ~CPoint()
- {
- if (coord)
- delete[] coord;
- coord = NULL;
- }
- void Compare(const CPoint &p)
- {
- int ok = 0;
- if (d != p.d)
- cout << "Punctele nu sunt din acelasi spatiu " << endl;
- else
- {
- if (d == p.d)
- for (int i = 0; i < d; i++)
- if (coord[i] != p.coord[i])
- ok = 1;
- if (ok == 0)
- cout << "Punctele sunt identice " << endl;
- else
- cout << "Punctele nu sunt identice " << endl;
- }
- }
- void afis()
- {
- cout << "Spatiul este " << d << " dimensional " << endl;
- cout << "Coordonatele sunt: ";
- for (int i = 0; i < d; i++)
- cout << coord[i] << ", ";
- cout << endl;
- }
- double& operator[] (int i)
- {
- for (i = 0; i < d; i++)
- return coord[i];
- }
- };
- class CPoint2d : public CPoint
- {
- public:
- CPoint2d() : CPoint(2)
- {
- }
- CPoint2d(double x, double y) : CPoint (2)
- {
- coord[0] = x;
- coord[1] = y;
- }
- };
- class CPoint3d : public CPoint
- {
- public:
- /*CPoint3d() : CPoint(3)
- {
- }*/
- CPoint3d(double x, double y, double z) : CPoint(3)
- {
- coord[0] = x;
- coord[1] = y;
- coord[2] = z;
- }
- };
- int main()
- {
- CPoint P13(3);
- P13[0] = 4;
- P13[1] = 5;
- P13[2] = 6;
- P13.afis();
- CPoint P14(3);
- P14[0] = 4;
- P14[1] = 7;
- P14[2] = 6;
- CPoint P15 = P14;
- P15.afis();
- CPoint2d P2;
- P2[0] = 3;
- P2[1] = 4;
- CPoint2d P22(9, 0);
- P22.afis();
- CPoint3d P3(11, 4, 5);
- P3.afis();
- P13.Compare(P14);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement