Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // VectorClass
- //
- // Created by Олег on 20.03.17.
- // Copyright © 2017 Олег. All rights reserved.
- //
- #include <iostream>
- #include <math.h>
- using namespace std;
- class VectorClass
- {
- private:
- float x,y,length;
- int* vector;
- public:
- VectorClass()
- {
- this->set(rand()% (100 - 1 + 1) + 1,rand()% (100 - 1 + 1) + 1);
- }
- VectorClass(VectorClass const &VectorClass2)
- {
- printf("\nСкопированный вектор - ");
- this->set(VectorClass2.x, VectorClass2.y);
- }
- VectorClass(float x,float y)
- {
- this->set(x, y);
- }
- //Перегружаем операторы
- friend ostream& operator<<(ostream& os, const VectorClass &v)
- {
- os << "Vector:[" << v.x << ":" << v.y << "] ";
- return os;
- }
- friend istream& operator>> ( istream& is, VectorClass &v)
- {
- printf("Введите X: ");
- is >> v.x;
- printf("Введите Y: ");
- is >> v.y;
- v.VectorToArray();
- return is;
- }
- bool operator==(const VectorClass &VectorClass2)
- {
- if(this->x == VectorClass2.x && this->y == VectorClass2.y)
- return true;
- else
- return false;
- }
- int operator*(const VectorClass &VectorClass2)
- {
- if(IsNullVector(VectorClass2))
- return echo("nv");
- return (this->x * VectorClass2.x) + (this->y * VectorClass2.y);
- }
- int operator*(int k)
- {
- if(IsNullVector() && k > 0)
- return echo("nv");
- return (this->x * k) + (this->y * k);
- }
- int operator[](int i)
- {
- return this->vector[i];
- }
- int operator+(const VectorClass &VectorClass2)
- {
- return (this->x + VectorClass2.x) * (this->y + VectorClass2.y);
- }
- int operator-(const VectorClass &VectorClass2)
- {
- return (this->x - VectorClass2.x) * (this->y - VectorClass2.y);
- }
- bool echo(string type)
- {
- if(type == "nv")
- printf("ОШИБКА! Один из векторов нулевой!");
- return true;
- }
- void set(float x = 0, float y = 0)
- {
- this->x = x;
- this->y = y;
- this->init();
- }
- void init()
- {
- cout << *this << "СОЗДАН" << endl;
- this->length = pow(pow(this->x,2) + pow(this->y,2),0.5);
- this->VectorToArray();
- }
- void VectorToArray()
- {
- // if(*this->vector)
- // delete [] this->vector;
- for(int x = 0; x < this->y-1; x++)
- this->vector[x] = this->x+x;
- }
- bool IsNullVector(const VectorClass &Vector = VectorClass())
- {
- if(this->length <= 0 || Vector.length <= 0)
- return true;
- else
- return false;
- }
- };
- int main() {
- cout << "[#V1] = "; VectorClass V1;
- cout << "[#V1] "; cin >> V1;
- cout << "[#V1]"; cout << V1;
- cout << V1[1];
- // int xy[2];
- //
- // //v1
- // printf("\nВведите x для вектора V1:");
- // cin >> xy[0];
- // printf("Введите y для вектора V1:");
- // cin >> xy[1];
- // VectorClass Vector1(xy[0],xy[1]);
- //
- // //V2
- // printf("\nВведите x для вектора V2:");
- // cin >> xy[0];
- // printf("Введите y для вектора V2:");
- // cin >> xy[1];
- // VectorClass Vector2(xy[0],xy[1]);
- //
- // //V3
- // VectorClass Vector3(Vector1);
- //
- // printf("\nСумма V1 + V2 = %d; \nСкалярной произведение V1 * V3 = %d; \nV1 * 2 = %d\n",
- // Vector2+Vector1,Vector1*Vector3,Vector1*2);
- //
- // 1
- // if(Vector3 == Vector1)
- // printf("\nV3 и V1 равны\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement