Advertisement
sellmmaahh

tut12-zad1

Aug 2nd, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdexcept>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <vector>
  6. #include "TestCurenja.h"
  7.  
  8. using namespace std;
  9.  
  10. class Vektor3d {
  11.     double x,y,z;
  12. public:
  13.  
  14.     Vektor3d () {x=0; y=0; z=0;}
  15.     Vektor3d (double x, double y, double z) {Vektor3d::x=x; Vektor3d::y=y; Vektor3d::z=z; }
  16.     void PostaviX(double x) {Vektor3d::x=x; }
  17.      void PostaviY(double y) {Vektor3d::y=y; }
  18.       void PostaviZ(double z) {Vektor3d::z=z; }
  19.     void Postavi(double x, double y, double z) {
  20.     Vektor3d::x=x; Vektor3d::y=y; Vektor3d::z=z;
  21.     }
  22.     void Ocitaj (double &x, double &y, double &z) const {
  23.     x=Vektor3d::x; y=Vektor3d::y; z=Vektor3d::z;
  24.     }
  25.  
  26.     double DajX() const {return x;}
  27.      double DajY() const {return y;}
  28.       double DajZ() const {return z;}
  29.       double DajDuzinu() const {return sqrt(x*x+y*y+z*z); }
  30.  
  31.      friend  ostream &operator <<(ostream &tok, const Vektor3d &v) {
  32.       tok<<"{"<<v.x<<","<<v.y<<","<<v.z<<"}";
  33.       return tok;
  34.       }
  35.  
  36.      friend Vektor3d &operator*= (Vektor3d &v1, int a) {
  37.      v1.x*=a; v1.y*=a; v1.z*=a;
  38.      return v1;
  39.      }
  40.  
  41.      friend Vektor3d &operator+=(Vektor3d &v1, const Vektor3d v2) {
  42.          v1.x+=v2.x; v1.y+=v2.y; v1.z+=v2.z;
  43.          return v1;
  44.      }
  45. };
  46.  
  47.     int main () {
  48.     Vektor3d v1, v2;
  49.    v1.Postavi(3,4,5);
  50.    v2.Postavi(2,1,1);
  51.     cout<<"Duzina prvog vektora: "<<v1.DajDuzinu()<<endl;
  52.     cout<<"Duzina drugog vektora: "<<v2.DajDuzinu()<<endl;
  53.     v1+=v2;
  54.     cout<<v1;
  55.     cout<<endl;
  56.     v2*=3;
  57.   cout<<v2;
  58.     return 0;
  59.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement