- #include <iostream>
- #include <stdio.h>
- #include <math.h>
- using namespace std;
- int matrix_count=0;
- int vectors_count=0;
- class vector
- {
- private:
- int *x;
- int size_vector;
- public:
- vector()
- {
- const int size=5;
- size_vector=size;
- x=new int[size_vector];
- for(int i=0; i<size_vector; i++)
- {
- x[i]=0;
- }
- vectors_count++;
- }
- vector(const int _n)
- {
- size_vector=_n;
- x=new int[size_vector];
- for(int i=0; i<size_vector; i++)
- {
- x[i]=5;
- }
- ++vectors_count;
- }
- vector(const int _n, int _value):size_vector(_n)
- {
- x=new int[size_vector];
- for(int i=0; i<size_vector; i++)
- {
- x[i]=_value;
- }
- ++vectors_count;
- }
- vector(const vector &other)
- {
- this->x=new int[other.size_vector];
- for(int i=0; i<other.size_vector; i++)
- {
- this->x[i]=other.x[i];
- }
- ++vectors_count;
- }
- void operator = (const vector &other)
- {
- this->size_vector=other.size_vector;
- if(this->x != nullptr )
- {
- delete[] this->x;
- }
- this->x=new int[other.size_vector];
- for(int i=0; i<other.size_vector; i++)
- {
- this->x[i]=other.x[i];
- }
- }
- vector &operator ~()
- {
- for(int i=0; i<this->size_vector; i++)
- {
- this->x[i]=~(this->x[i]);
- }
- return *this;
- }
- bool operator!=(const vector &other)
- {
- for(int i=0; i<this->size_vector; i++)
- {
- if(this->x[i]!=other.x[i]) return true;
- else return false;
- }
- }
- vector& operator -()
- {
- for(int i=0; i<this->size_vector; i++)
- {
- this->x[i]=-(this->x[i]);
- }
- return *this;
- }
- /*
- vector operator+(const vector &other)
- {
- for(int i=0; i<this->size_vector; i++)
- {
- this->x[i] = this->x[i]+other.x[i];
- }
- return *this;
- } */
- void print()
- {
- for (int i=0; i<this->size_vector; i++)
- {
- cout<<x[i]<<" ";
- }
- cout<<"n";
- }
- friend ostream& operator<< (ostream &out, const vector &other);
- friend class matrix;
- ~vector(){--vectors_count;delete[] x;}
- };
- ostream &operator<< (ostream &out, const vector &other)
- {
- for(int i=0; i<other.size_vector; i++)
- {
- out << other.x[i]<< " ";
- }
- return out;
- }
- class matrix
- {
- private:
- vector *arr;
- int vector_count;
- public:
- matrix()
- {
- const int size=5;
- vector_count=size;
- arr=new vector[vector_count];
- for(int i=0; i<vector_count; i++)
- {
- arr[i]=5;
- }
- }
- matrix(int _n)
- {
- arr=new vector[vector_count];
- for(int i=0; i<vector_count; i++)
- {
- arr[i]=5;
- }
- ++matrix_count;
- }
- matrix(const int _n, const int _value):vector_count(_n)
- {
- arr=new vector[vector_count];
- for(int i=0; i<vector_count; i++)
- {
- arr[i]=_value;
- }
- ++matrix_count;
- }
- matrix(const matrix &other)
- {
- this->arr=new vector[other.vector_count];
- for(int i=0; i<other.vector_count; i++)
- {
- this->arr[i]=other.arr[i];
- }
- ++matrix_count;
- }
- void operator = (const matrix &other)
- {
- this->vector_count=other.vector_count;
- if(this->arr != nullptr)
- {
- delete[] this->arr;
- }
- this->arr=new vector[other.vector_count];
- for(int i=0; i<other.vector_count; i++)
- {
- this->arr[i]=other.arr[i];
- }
- }
- matrix &operator ++()
- {
- vector *temp=new vector[this->vector_count];
- for(int i=0; i<this->vector_count; i++)
- {
- temp[i]=arr[i];
- }
- delete[] this->arr;
- ++vector_count;
- arr=new vector[vector_count];
- for(int i=0; i<(this->vector_count)-1; i++)
- {
- arr[i]=temp[i];
- }
- delete[] temp;
- return *this;
- }
- matrix &operator --()
- {
- vector *temp=new vector[this->vector_count];
- for(int i=0; i<this->vector_count; i++)
- {
- temp[i]=arr[i];
- }
- delete[] this->arr;
- --vector_count;
- arr=new vector[vector_count];
- for(int i=0; i<(this->vector_count)-1; i++)
- {
- arr[i]=temp[i];
- }
- delete[] temp;
- return *this;
- }
- bool operator !() const
- {
- if(this->vector_count != 0) return true;
- else return false;
- }
- matrix &operator~()
- {
- for(int i=0; i<this->vector_count; i++)
- {
- this->arr[i]=~(this->arr[i]);
- }
- return *this;
- }
- matrix &operator-()
- {
- for(int i=0; i<this->vector_count; i++)
- {
- return (-arr[i]);
- }
- }
- /*
- matrix& operator+(const matrix &other)
- {
- for(int i=0; i<this->vector_count; i++)
- {
- this->arr[i] = this->arr[i]+other.arr[i];
- }
- return *this;
- } */
- int getSize()
- {
- return vector_count;
- }
- friend ostream& operator<<(ostream &out, const matrix &other);
- ~matrix(){--matrix_count; delete[] arr;}
- };
- ostream &operator<<(ostream &outs, const matrix &other)
- {
- for(int i=0; i<other.vector_count; i++)
- {
- outs << "n"<<other.arr[i];
- }
- return outs;
- }
- int main(int argc, char *argv[])
- {
- vector obj1(4,4);
- matrix obj2(4,5);
- cout<<obj1;
- cout<<"n"<<~obj1;
- cout<<"n"<<obj2;
- cout<<"n"<<(obj2);
- cout<<"n"<<++obj2;
- cout<<"n"<<(--obj2);
- /*cout<<"n"<<obj2;
- cout<<"n"<<++obj2;
- cout<<"n"<<--obj2;
- cout<<"nn"<<!obj2;
- */
- return 0;
- }