Advertisement
naskedvi

T12 - zad.1.

Jun 6th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. class Vektor3d{
  4.     double x,y,z;
  5. public:
  6.     Vektor3d(){x=0; y=0; z=0;}
  7.     Vektor3d(double a, double b, double c){x=a; y=b; z=c;}
  8.     void PostaviX (double x){Vektor3d::x=x;}
  9.     void PostaviY(double y){Vektor3d::y=y;}
  10.     void PostaviZ(double z){Vektor3d::z=z;}
  11.     void Ocitaj(double &x, double &y, double &z)
  12.     {x=Vektor3d::x; y=Vektor3d::y; z=Vektor3d::z;}
  13.     friend std::ostream& operator<<(std::ostream &tok, const Vektor3d &v)
  14.       { return tok<<"("<<v.x<<","<<v.y<<","<<v.z<<")"; }
  15.     double DajX() const{return x;}
  16.     double DajY() const{return y;}
  17.     double DajZ() const{return z;}
  18.     friend Vektor3d operator+(const Vektor3d &a, const Vektor3d &b)
  19.     {return {a.x+b.x, a.y+b.y, a.z+b.z};}
  20.     Vektor3d &operator+=(const Vektor3d &v)
  21.     {this->x+=v.x; this->y+=v.y; this->z+=v.z; return *this;}
  22.     Vektor3d &operator*=(const Vektor3d &v)
  23.     {this->x*=v.x; this->y*=v.y; this->z*=v.z; return *this;}
  24.  
  25. };
  26. int main(){
  27.     Vektor3d a(1,2,3),b(10,10,10),c;
  28.     c=a+b; std::cout<<c;
  29.     Vektor3d v(a);
  30.     v*=a; std::cout<<v;
  31.  
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement