Facebook
From xd, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 281
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5. class wektor
  6. {
  7.  
  8.     public:
  9.     double x,y,z;
  10.     void toString();
  11.     wektor();
  12.     wektor(double,double,double);
  13.     wektor operator+(wektor&);
  14.     double operator*(wektor&);
  15.     wektor operator/(wektor&);
  16.     friend ostream& operator<<(ostream&, const wektor&);
  17.     friend istream& operator<<(istream& ,wektor&);
  18. };
  19. wektor::wektor()
  20. {
  21.     x=1;
  22.     y=1;
  23.     z=1;
  24. }
  25. wektor::wektor(double x,double y,double z)
  26. {
  27.     this->x=x;
  28.     this->y=y;
  29.     this->z=z;
  30. }
  31. void wektor::toString()
  32. {
  33.     cout<<"x="<<x<<"  y="<<y<<"  z="<<z<<endl;
  34. }
  35. wektor wektor::operator+(wektor&k)
  36. {
  37.     wektor tmp;
  38.     tmp.x=this->y+k.x;
  39.     tmp.y=this->y+k.y;
  40.     tmp.z=this->z+k.z;
  41.     return tmp;
  42. }
  43. double wektor::operator*(wektor&k)
  44. {
  45.  
  46.     return this->x*k.x + this->y*k.y + this->z*k.z;
  47.  
  48. }
  49.  wektor wektor:: operator/(wektor&k)
  50.  {
  51.      wektor tmp;
  52.     tmp.x=this->y*k.z-this->z*k.y;
  53.     tmp.y=this->x*k.z-this->z*k.x;
  54.     tmp.z=this->x*k.y-this->y*k.x;
  55.     return tmp;
  56.  
  57.  }
  58.  ostream& operator<<(ostream &os,const wektor &w )
  59.  {
  60.      os<<"{"<<w.x<<" "<<w.y<<" "<<w.z<<" "<<"}"<<endl;
  61.  }
  62.  istream& operator>>(istream &is,wektor &w)
  63.  {
  64.      is>>w.x>>w.y>>w.z;
  65.      return is;
  66.  }
  67.  
  68. int main()
  69. {
  70.     wektor a,b(2,2,2),c,d;
  71.     a.toString();
  72.     b.toString();
  73.     c=a+b;
  74.     cout<<"suma: ";
  75.     c.toString();
  76.     cout <<"iloczyn skalarany: "<<a*b << "\tstopnie: " <<atan(a*b)*(180.0/M_PI)<<endl;
  77.    d=a/b;
  78.    cout<<"iloczyn wektorowy: ";
  79.     d.toString();
  80.     return 0;
  81. }
  82.