kilolilo

vector

Mar 13th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. class vector{
  5. public:
  6.     int x,y,z;
  7.     vector(int x1,int y1,int z1):x(x1),y(y1),z(z1){}
  8.     vector add(vector other){
  9.         return vector(x + other.x, y + other.y, z + other.z);
  10.     }
  11.     float dot(vector oth){
  12.         return x*oth.x + y*oth.y + z*oth.z;
  13.     }
  14.     vector cross(vector ot){
  15.          return vector (z * ot.y - y * ot.z, x*ot.z - z-ot.x, y*ot.x - x*ot.y);
  16.     }
  17.  
  18.     void print(){
  19.         cout<< x << '\t' << y << '\t'<< z << endl;
  20.     }
  21. };
  22.  
  23. int main()
  24. {
  25.     vector a(1,0,0);
  26.     a.print();
  27.     vector b(0,1,0);
  28.     b.print();
  29.     vector c = a.add(b);
  30.     c.print();
  31.     float d=a.dot(b);
  32.     cout<<d<<endl;
  33.     vector s= a.cross(b);
  34.     s.print();
  35. }
Add Comment
Please, Sign In to add comment