Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <iomanip>
- 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";
- }
- friend istream& operator >> (istream& s, point& p1)
- {
- double x,y,z;
- s >> x>> y>> z;
- p1.xyz[0]=x;
- p1.xyz[1]=y;
- p1.xyz[2]=z;
- return s;
- }
- const double& operator [] (int a) const
- {
- return xyz[a];
- }
- double distance(point p) const
- {
- double x1,y1,z1,x2,y2,z2,d;
- x1=this->xyz[0];
- y1=this->xyz[1];
- z1=this->xyz[2];
- x2=p.xyz[0];
- y2=p.xyz[1];
- z2=p.xyz[2];
- d= sqrt(pow((x1-x2),2)+pow((y1-y2),2)+pow((z1-z2),2));
- return d;
- }
- point operator + (const point p) const
- {
- point pp(this->xyz[0]+p.xyz[0],this->xyz[1]+p.xyz[1],this->xyz[2]+p.xyz[2]);
- return pp;
- }
- point operator - (const point p) const
- {
- point pp(this->xyz[0]-p.xyz[0],this->xyz[1]-p.xyz[1],this->xyz[2]-p.xyz[2]);
- return pp;
- }
- };
- point operator * (double a, point &p)
- {
- return point(p[0]*a,p[1]*a,p[2]*a);
- }
- point operator * (point &p, double a)
- {
- return point(p[0]*a,p[1]*a,p[2]*a);
- }
- string operator < (point& p1,const point& p2)
- {
- if (p1.distance(point())<p2.distance(point()))
- return "Prawy punkt jest wiekszy";
- else
- return "Lewy punkt jest wiekszy";
- }
- string operator > (point& p1,const point& p2)
- {
- if (p1.distance(point())>p2.distance(point()))
- return "Lewy punkt jest wiekszy";
- else
- return "Prawy punkt jest wiekszy";
- }
- string operator == (point& p1,const point& p2)
- {
- if (p1.distance(point())==p2.distance(point()))
- return "Punkty sa rowne";
- else
- return "Punkty sa rozne";
- }
- 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';
- cout << p1.distance(point()) << ", "<< p3.distance(p1) << '\n';
- cout << p1 + p2 << ", " << p1 - p3 << '\n';
- cout << 3.14 * p2 << ", " << p2 * 3.14 << '\n';
- cout << (p1 < p3) << ", " << (p1 == point(1.0, 1.0, 1.0)) << '\n';
- cin >> p1;
- cout << p1 << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement