#include using namespace std; template class Wektor3 { private: T* w; public: // konstruktor Wektor3(T x=0, T y=0, T z=0) { w = new T[3]; w[0] = x; w[1] = y; w[2] = z; } // destruktor ~Wektor3() { delete [] w; } // metody double getX() const { return w[0]; } double getY() const { return w[1]; } double getZ() const { return w[2]; } // PRZECIAZANIE OPERATOROW: // dodawanie Wektor3& operator+(const Wektor3& v) { Wektor3* s = new Wektor3; s->w[0] = w[0] + v.w[0]; s->w[1] = w[1] + v.w[1]; s->w[2] = w[2] + v.w[2]; return *s; } // odejmowanie Wektor3& operator-(const Wektor3& v) { Wektor3* s = new Wektor3; s->w[0] = w[0] - v.w[0]; s->w[1] = w[1] - v.w[1]; s->w[2] = w[2] - v.w[2]; return *s; } // iloczyn skalarny double operator*(Wektor3& v) { return w[0]*v.w[0]+w[1]*v.w[1]+w[2]*v.w[2]; } // iloczyn wektorowy Wektor3& operator&(const Wektor3& v) { Wektor3* s = new Wektor3; s->w[0] = w[1]*v.w[2]-w[2]*v.w[1]; s->w[1] = w[2]*v.w[0]-w[0]*v.w[2]; s->w[2] = w[0]*v.w[1]-w[1]*v.w[0]; return *s; } // mnozenie z prawej Wektor3& operator*(double d) { Wektor3* s = new Wektor3; s->w[0] = w[0]*d; s->w[1] = w[1]*d; s->w[2] = w[2]*d; return *s; } // mnozenie z lewej; friend Wektor3& operator*(T d, Wektor3& v){ Wektor3* s = new Wektor3; s->w[0] = v.w[0]*d; s->w[1] = v.w[1]*d; s->w[2] = v.w[2]*d; return *s; } // przeciazony operator "<<" friend ostream& operator<<(ostream& e, const Wektor3& v) { cout << "wektor: x=" << v.getX() << "; y=" << v.getY() << "; z=" << v.getZ(); return e; } //wprowadzanie friend istream& operator>>(istream& i, const Wektor3& v){ i>>v.w[0]>>v.w[1]>>v.w[2]; return i; } }; int main() { float n; Wektor3 a; cout<<"podaj wspolrzedne a: \n"; cin>>a; Wektor3 b; cout<<"podaj wspolrzedne b: \n"; cin>>b; cout << "Utworzony b: \n" << b << endl; cout << "Utworzony a: \n" << a << endl; cout << "Suma a+b: " << (a+b) << endl; cout << "Roznica a-b: " << (a-b) << endl; cout << "Iloczyn skalarny a*b: " << (a*b) << endl; cout << "Iloczyn wektorowy : " << (a&b) << endl; cout<<"\n\nprzez jaka liczbe pomnozyc wektory?\n"<<"podaj n: "; cin>>n; cout << "Iloczyn "<