Seal_of_approval

p25e7

May 25th, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. ifstream in ("input.txt");
  9.  
  10. class Vector3D
  11. {
  12.     private:
  13.  
  14.     int x;
  15.     int y;
  16.     int z;
  17.  
  18.     public:
  19.  
  20.     static int count;
  21.  
  22.     Vector3D(int a, int b, int c): x(a), y(b), z(c)
  23.     {
  24.         count++;
  25.     }
  26.  
  27.     Vector3D(): x(0), y(0), z(0)
  28.     {
  29.         count++;
  30.     }
  31.  
  32.     Vector3D(const Vector3D &vec): x(vec.x), y(vec.y), z(vec.z)
  33.     {
  34.         count++;
  35.     }
  36.  
  37.     void readVector()
  38.     {
  39.         in >> this->x;
  40.         in >> this->y;
  41.         in >> this->z;
  42.     }
  43.  
  44.     void showVector()
  45.     {
  46.         std::cout << "vector ( " << this->x << " , " << this->y << " , " << this->z << " )\n\n";
  47.     }
  48.  
  49.     static void calcLenghth_new(Vector3D a, Vector3D b)
  50.     {
  51.         if (a.compareVector(b) == 1 )
  52.         {
  53.             cout << "first vector more second vector\n\n";
  54.         }
  55.         else
  56.         {
  57.             cout << "first vector less second vector\n\n";
  58.         }
  59.     }
  60.  
  61.     double calcLength()
  62.     {
  63.         return sqrt( (double)(this->x*this->x + this->y*this->y + this->z*this->z) );
  64.     }
  65.  
  66.     int compareVector(Vector3D second)
  67.     {
  68.         if (this->calcLength() == second.calcLength())
  69.         {
  70.             return -1;
  71.         }
  72.         else if (this->calcLength() > second.calcLength())
  73.         {
  74.             return 1;
  75.         }
  76.         else
  77.         {
  78.             return 0;
  79.         }
  80.  
  81.         return -2;
  82.     }
  83.  
  84.     Vector3D operator +(Vector3D second)
  85.     {
  86.         return Vector3D(this->x+second.x ,this->y+second.y , this->z+second.z );
  87.     }
  88.  
  89.     Vector3D operator -(Vector3D second)
  90.     {
  91.         return Vector3D(this->x-second.x ,this->y-second.y , this->z-second.z );
  92.     }
  93.  
  94.     int operator *(Vector3D second)
  95.     {
  96.         return (this->x*second.x + this->y*second.y + this->z*second.z);
  97.     }
  98.  
  99.     Vector3D operator &(Vector3D second)
  100.     {
  101.         return Vector3D( (this->y*second.z)-(second.y*this->z) , (this->x*second.z)-(second.x*this->z) , (this->x*second.y)-(second.x*this->y) );
  102.     }
  103.  
  104.     ~Vector3D(void)
  105.     {
  106.  
  107.     }
  108.  
  109. };
  110.  
  111. int Vector3D::count = 0;
  112.  
  113. int main()
  114. {
  115.     int n; in >> n;
  116.     vector <Vector3D> array_vectors(n);
  117.     for (int i = 0; i < n; i++)
  118.     {
  119.         array_vectors[i].readVector();
  120.     }
  121.  
  122.     array_vectors[0].showVector();
  123.  
  124.     array_vectors[1].showVector();
  125.  
  126.     cout << "Length of first vector is " << array_vectors[0].calcLength() << endl << endl;
  127.  
  128.     cout << "Length of second vector is " << array_vectors[1].calcLength() << endl << endl;
  129.  
  130.     switch (array_vectors[0].compareVector(array_vectors[1]))
  131.     {
  132.         case -1: cout << "first vector equal second vector\n\n"; break;
  133.         case 1: cout << "first vector more second vector\n\n"; break;
  134.         case 0: cout << "first vector less second vector\n\n"; break;
  135.         case -2: cout << "Hello, it is feature (or bug) :)\n\n"; break;
  136.         default: cout << "Warning!\n\n";
  137.     }
  138.  
  139.     cout << "Summ of vectors is : ";
  140.  
  141.     (array_vectors[0] + array_vectors[1]).showVector();
  142.  
  143.     cout << "Definitely of vectors is : ";
  144.  
  145.     (array_vectors[0] - array_vectors[1]).showVector();
  146.  
  147.     cout << "ScalMultiply of vectors is : " << array_vectors[0]*array_vectors[1] <<"\n\n";
  148.  
  149.     cout << "VecMultiply of vectors is : ";
  150.  
  151.     (array_vectors[0]&array_vectors[1]).showVector();
  152.  
  153.     Vector3D greatest_vec(array_vectors[0]);
  154.     for (int i=0; i<n-1; i++)
  155.     {
  156.         if ( !(array_vectors[i].compareVector(array_vectors[i+1]) ) )
  157.         {
  158.             greatest_vec=array_vectors[i+1];
  159.         }
  160.     }
  161.     cout << "Greatest ";
  162.     greatest_vec.showVector();
  163.     cout << endl;
  164.  
  165.     Vector3D::calcLenghth_new(array_vectors[0], array_vectors[1]);
  166.  
  167.     in.close();
  168.  
  169.     return 0;
  170. }
Advertisement
Add Comment
Please, Sign In to add comment