#include #include #include #include using std::cin; using std::cout; using std::endl; struct My3DVector { double _x; double _y; double _z; My3DVector(double x=0, double y=0, double z=0) { _x = x; _y = y; _z = z; } double GetLength() const { return ::sqrt(_x*_x + _y*_y + _z*_z); } My3DVector operator +(const My3DVector& op2) { double newx = _x + op2._x; double newy = _y + op2._y; double newz = _z + op2._z; return My3DVector(newx, newy, newz); } My3DVector operator -(const My3DVector& op2) { double newx = _x - op2._x; double newy = _y - op2._y; double newz = _z - op2._z; return My3DVector(newx, newy, newz); } My3DVector& operator *(double alpha) {//scale double newx = _x * alpha; double newy = _y * alpha; double newz = _z * alpha; //return My3DVector(newx, newy, newz); return *this; } double operator * (const My3DVector& v) {//dot product double res = v._x * _x + v._y * _y + v._z * _z; return res; } My3DVector operator ^ (const My3DVector& op2) const { //double res = M } }; using std::ostream; ostream& operator << (ostream& os, const My3DVector& v) { os<<"x: "<