Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class point
- {
- double xyz[3];
- public:
- point ()
- {
- this->xyz[0] = 0.0;
- this->xyz[1] = 0.0;
- this->xyz[2] = 0.0;
- }
- point (double *xyz)
- {
- this->xyz[0] = xyz[0];
- this->xyz[1] = xyz[1];
- this->xyz[2] = xyz[2];
- }
- point (double x,double y, double z)
- {
- this->xyz[0]=x;
- this->xyz[1]=y;
- this->xyz[2]=z;
- }
- friend ostream& operator<<(ostream& out,const point& p)
- {
- return out<<p.xyz[0]<<"\t"<<p.xyz[1]<<"\t"<<p.xyz[2]<<"\n";
- }
- const double& operator [] (int a)
- {
- return xyz[a];
- }
- };
- int main()
- {
- double x[2][3] = {{1.0, 1.0, 1.0},
- {1.0, 2.0, 3.0}};
- point p1(x[0]), p2(x[1]);
- const point p3(0.4, 0.2, 0.1);
- cout << p1 << ", " << p2 << '\n';
- cout << p3[0] << ' ' << p3[1] << ' ' << p3[2] << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement