Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<cmath>
- using namespace std;
- class Vector
- {
- private:
- int x;
- int y;
- int z;
- public:
- Vector() : x(0), y(0), z(0)
- {}
- Vector(int x, int y, int z) : x(x), y(y), z(z)
- {}
- float Length()
- {
- return sqrt(float(x*x + y*y + z*z));
- }
- float ScalarProduct()
- {
- return float(x + y + z);
- }
- void Compare(Vector temp)
- {
- if (this->Length() < temp.Length())
- cout << "one < two" << endl;
- if (this->Length() > temp.Length())
- {
- cout << "one > two" << endl;
- }
- if (this->Length() == temp.Length()) cout << "one = two" << endl;
- }
- void SetData(int x, int y)
- {
- this->x = x;
- this->y = y;
- this->z = z;
- }
- void ShowVector(string info)
- {
- cout << "Координаты вектора " << info << " = (" << x << " , " << y << " , " << z << " ) " << endl;
- }
- Vector operator +(Vector temp)
- {
- return Vector(x + temp.x, y + temp.y, z + temp.z);
- }
- Vector operator -(Vector temp)
- {
- return Vector(x - temp.x, y - temp.y, z - temp.z);
- }
- Vector operator * (Vector temp)
- {
- return Vector(x * temp.x, y *temp.y, z * temp.z);
- }
- Vector VectorProduct(Vector temp)
- {
- return Vector( (y*temp.z - z*temp.y), (x*temp.z - z*temp.x) ,( x * temp.y - y *temp.x) );
- }
- };
- int main()
- {
- setlocale(0, "");
- Vector one(1, 1, 0);
- Vector two(2, 3, 0);
- one.ShowVector("one");
- two.ShowVector("two");
- cout << "Длина первого вектора = " << one.Length() << endl;
- cout << "Длина второго вектора = " << two.Length() << endl;
- Vector three = one + two;
- three.ShowVector("three");
- cout << "Длина третьего вектора = " << three.Length() << endl;
- Vector four = one - two;
- four.ShowVector("four");
- cout << "Длина четвёртого вектора = " << four.Length() << endl;
- Vector scalar = one * two;
- scalar.ShowVector("scalar");
- cout << "Скалярное произведение = " << scalar.ScalarProduct() << endl;
- Vector vector = one.VectorProduct(two);
- vector.ShowVector("vector");
- one.Compare(two);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement