Advertisement
CzarnyBarszcz

Untitled

Dec 16th, 2020 (edited)
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class point
  6. {
  7.     double xyz[3];
  8.    
  9. public:
  10.     point ()
  11.     {
  12.         this->xyz[0] = 0.0;
  13.         this->xyz[1] = 0.0;
  14.         this->xyz[2] = 0.0;
  15.     }
  16.     point (double *xyz)
  17.     {
  18.         this->xyz[0] = xyz[0];
  19.         this->xyz[1] = xyz[1];
  20.         this->xyz[2] = xyz[2];
  21.     }
  22.     point (double x,double y, double z)
  23.     {
  24.         this->xyz[0]=x;
  25.         this->xyz[1]=y;
  26.         this->xyz[2]=z;
  27.     }
  28.     friend ostream& operator<<(ostream& out,const point& p)
  29.     {
  30.         return out<<p.xyz[0]<<"\t"<<p.xyz[1]<<"\t"<<p.xyz[2]<<"\n";
  31.     }
  32.     const double& operator [] (int a)
  33.     {
  34.         return xyz[a];
  35.     }
  36.  
  37. };
  38.  
  39. int main()
  40. {
  41. double x[2][3] = {{1.0, 1.0, 1.0},
  42.  {1.0, 2.0, 3.0}};
  43.  point p1(x[0]), p2(x[1]);
  44.  const point p3(0.4, 0.2, 0.1);
  45.  cout << p1 << ", " << p2 << '\n';
  46.     cout << p3[0] << ' ' << p3[1] << ' ' << p3[2] << '\n';
  47.  
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement