Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <cmath>
- using namespace std;
- ifstream in ("input.txt");
- class Vector3D
- {
- private:
- int x;
- int y;
- int z;
- public:
- static int count;
- Vector3D(int a, int b, int c): x(a), y(b), z(c)
- {
- count++;
- }
- Vector3D(): x(0), y(0), z(0)
- {
- count++;
- }
- Vector3D(const Vector3D &vec): x(vec.x), y(vec.y), z(vec.z)
- {
- count++;
- }
- void readVector()
- {
- in >> this->x;
- in >> this->y;
- in >> this->z;
- }
- void showVector()
- {
- std::cout << "vector ( " << this->x << " , " << this->y << " , " << this->z << " )\n\n";
- }
- static void calcLenghth_new(Vector3D a, Vector3D b)
- {
- if (a.compareVector(b) == 1 )
- {
- cout << "first vector more second vector\n\n";
- }
- else
- {
- cout << "first vector less second vector\n\n";
- }
- }
- double calcLength()
- {
- return sqrt( (double)(this->x*this->x + this->y*this->y + this->z*this->z) );
- }
- int compareVector(Vector3D second)
- {
- if (this->calcLength() == second.calcLength())
- {
- return -1;
- }
- else if (this->calcLength() > second.calcLength())
- {
- return 1;
- }
- else
- {
- return 0;
- }
- return -2;
- }
- Vector3D operator +(Vector3D second)
- {
- return Vector3D(this->x+second.x ,this->y+second.y , this->z+second.z );
- }
- Vector3D operator -(Vector3D second)
- {
- return Vector3D(this->x-second.x ,this->y-second.y , this->z-second.z );
- }
- int operator *(Vector3D second)
- {
- return (this->x*second.x + this->y*second.y + this->z*second.z);
- }
- Vector3D operator &(Vector3D second)
- {
- 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) );
- }
- ~Vector3D(void)
- {
- }
- };
- int Vector3D::count = 0;
- int main()
- {
- int n; in >> n;
- vector <Vector3D> array_vectors(n);
- for (int i = 0; i < n; i++)
- {
- array_vectors[i].readVector();
- }
- array_vectors[0].showVector();
- array_vectors[1].showVector();
- cout << "Length of first vector is " << array_vectors[0].calcLength() << endl << endl;
- cout << "Length of second vector is " << array_vectors[1].calcLength() << endl << endl;
- switch (array_vectors[0].compareVector(array_vectors[1]))
- {
- case -1: cout << "first vector equal second vector\n\n"; break;
- case 1: cout << "first vector more second vector\n\n"; break;
- case 0: cout << "first vector less second vector\n\n"; break;
- case -2: cout << "Hello, it is feature (or bug) :)\n\n"; break;
- default: cout << "Warning!\n\n";
- }
- cout << "Summ of vectors is : ";
- (array_vectors[0] + array_vectors[1]).showVector();
- cout << "Definitely of vectors is : ";
- (array_vectors[0] - array_vectors[1]).showVector();
- cout << "ScalMultiply of vectors is : " << array_vectors[0]*array_vectors[1] <<"\n\n";
- cout << "VecMultiply of vectors is : ";
- (array_vectors[0]&array_vectors[1]).showVector();
- Vector3D greatest_vec(array_vectors[0]);
- for (int i=0; i<n-1; i++)
- {
- if ( !(array_vectors[i].compareVector(array_vectors[i+1]) ) )
- {
- greatest_vec=array_vectors[i+1];
- }
- }
- cout << "Greatest ";
- greatest_vec.showVector();
- cout << endl;
- Vector3D::calcLenghth_new(array_vectors[0], array_vectors[1]);
- in.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment