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