Facebook
From Ungracious Leopard, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 123
  1.  
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <math.h>
  5.  
  6. using namespace std;
  7.  
  8.  
  9.  int matrix_count=0;
  10.  int vectors_count=0;
  11. class vector
  12. {
  13. private:
  14.     int *x;
  15.     int size_vector;
  16.  
  17. public:
  18.     vector()
  19.     {
  20.         const int size=5;
  21.         size_vector=size;
  22.         x=new int[size_vector];
  23.         for(int i=0; i<size_vector; i++)
  24.         {
  25.             x[i]=0;
  26.         }
  27.         vectors_count++;
  28.     }
  29.  
  30.     vector(const int _n)
  31.     {
  32.         size_vector=_n;
  33.         x=new int[size_vector];
  34.         for(int i=0; i<size_vector; i++)
  35.         {
  36.             x[i]=5;
  37.         }
  38.         ++vectors_count;
  39.     }
  40.  
  41.     vector(const int _n, int _value):size_vector(_n)
  42.     {
  43.         x=new int[size_vector];
  44.         for(int i=0; i<size_vector; i++)
  45.         {
  46.             x[i]=_value;
  47.         }
  48.         ++vectors_count;
  49.     }
  50.  
  51.     vector(const vector &other)
  52.     {
  53.         this->x=new int[other.size_vector];
  54.         for(int i=0; i<other.size_vector; i++)
  55.         {
  56.             this->x[i]=other.x[i];
  57.         }
  58.         ++vectors_count;
  59.     }
  60.  
  61.     void operator = (const vector &other)
  62.     {
  63.         this->size_vector=other.size_vector;
  64.         if(this->x != nullptr )
  65.         {
  66.             delete[] this->x;
  67.         }
  68.         this->x=new int[other.size_vector];
  69.         for(int i=0; i<other.size_vector; i++)
  70.         {
  71.             this->x[i]=other.x[i];
  72.         }
  73.     }
  74.  
  75.     vector &operator ~()
  76.     {
  77.         for(int i=0; i<this->size_vector; i++)
  78.         {
  79.             this->x[i]=~(this->x[i]);
  80.         }
  81.         return *this;
  82.     }
  83.  
  84.     bool operator!=(const vector &other)
  85.     {
  86.         for(int i=0; i<this->size_vector; i++)
  87.         {
  88.             if(this->x[i]!=other.x[i]) return true;
  89.             else return false;
  90.         }
  91.     }
  92.  
  93.      vector& operator -()
  94.      {
  95.         for(int i=0; i<this->size_vector; i++)
  96.         {
  97.             this->x[i]=-(this->x[i]);
  98.         }
  99.         return *this;
  100.      }
  101. /*
  102.  
  103.  
  104.      vector operator+(const vector &other)
  105.     {
  106.         for(int i=0; i<this->size_vector; i++)
  107.         {
  108.             this->x[i] = this->x[i]+other.x[i];
  109.         }
  110.         return *this;
  111.     } */
  112.  
  113.     void print()
  114.     {
  115.         for (int i=0; i<this->size_vector; i++)
  116.         {
  117.             cout<<x[i]<<" ";
  118.         }
  119.         cout<<"n";
  120.     }
  121.     friend ostream& operator<< (ostream &out, const vector &other);
  122.     friend class matrix;
  123.     ~vector(){--vectors_count;delete[] x;}
  124.  
  125. };
  126.  
  127. ostream &operator<< (ostream &out, const vector &other)
  128. {
  129.     for(int i=0; i<other.size_vector; i++)
  130.     {
  131.       out << other.x[i]<< " ";
  132.     }
  133.     return out;
  134.  
  135. }
  136.  
  137. class matrix
  138. {
  139. private:
  140.     vector *arr;
  141.     int vector_count;
  142. public:
  143.     matrix()
  144.     {
  145.         const int size=5;
  146.         vector_count=size;
  147.         arr=new vector[vector_count];
  148.         for(int i=0; i<vector_count; i++)
  149.         {
  150.             arr[i]=5;
  151.         }
  152.     }
  153.  
  154.     matrix(int _n)
  155.     {
  156.         arr=new vector[vector_count];
  157.         for(int i=0; i<vector_count; i++)
  158.         {
  159.             arr[i]=5;
  160.         }
  161.         ++matrix_count;
  162.     }
  163.  
  164.     matrix(const int _n, const int _value):vector_count(_n)
  165.     {
  166.         arr=new vector[vector_count];
  167.         for(int i=0; i<vector_count; i++)
  168.         {
  169.             arr[i]=_value;
  170.         }
  171.         ++matrix_count;
  172.     }
  173.  
  174.     matrix(const matrix &other)
  175.     {
  176.         this->arr=new vector[other.vector_count];
  177.         for(int i=0; i<other.vector_count; i++)
  178.         {
  179.             this->arr[i]=other.arr[i];
  180.         }
  181.         ++matrix_count;
  182.     }
  183.  
  184.     void operator = (const matrix &other)
  185.     {
  186.            this->vector_count=other.vector_count;
  187.             if(this->arr != nullptr)
  188.             {
  189.                 delete[] this->arr;
  190.             }
  191.         this->arr=new vector[other.vector_count];
  192.         for(int i=0; i<other.vector_count; i++)
  193.         {
  194.             this->arr[i]=other.arr[i];
  195.         }
  196.     }
  197.  
  198.     matrix &operator ++()
  199.     {
  200.         vector *temp=new vector[this->vector_count];
  201.         for(int i=0; i<this->vector_count; i++)
  202.         {
  203.             temp[i]=arr[i];
  204.         }
  205.         delete[] this->arr;
  206.         ++vector_count;
  207.         arr=new vector[vector_count];
  208.         for(int i=0; i<(this->vector_count)-1; i++)
  209.         {
  210.             arr[i]=temp[i];
  211.         }
  212.         delete[] temp;
  213.         return *this;
  214.     }
  215.     matrix &operator --()
  216.     {
  217.         vector *temp=new vector[this->vector_count];
  218.         for(int i=0; i<this->vector_count; i++)
  219.         {
  220.             temp[i]=arr[i];
  221.         }
  222.         delete[] this->arr;
  223.         --vector_count;
  224.         arr=new vector[vector_count];
  225.         for(int i=0; i<(this->vector_count)-1; i++)
  226.         {
  227.             arr[i]=temp[i];
  228.         }
  229.         delete[] temp;
  230.         return *this;
  231.     }
  232.  
  233.     bool operator !() const
  234.     {
  235.         if(this->vector_count != 0) return true;
  236.         else return false;
  237.     }
  238.  
  239.     matrix &operator~()
  240.     {
  241.         for(int i=0; i<this->vector_count; i++)
  242.         {
  243.             this->arr[i]=~(this->arr[i]);
  244.         }
  245.         return *this;
  246.     }
  247.  
  248.     matrix &operator-()
  249.     {
  250.         for(int i=0; i<this->vector_count; i++)
  251.         {
  252.             return (-arr[i]);
  253.         }
  254.  
  255.     }
  256.     /*
  257.     matrix& operator+(const matrix &other)
  258.     {
  259.         for(int i=0; i<this->vector_count; i++)
  260.         {
  261.             this->arr[i] = this->arr[i]+other.arr[i];
  262.         }
  263.     return *this;
  264.     } */
  265.  
  266.     int getSize()
  267.     {
  268.         return vector_count;
  269.     }
  270.     friend ostream& operator<<(ostream &out, const matrix &other);
  271.     ~matrix(){--matrix_count; delete[] arr;}
  272. };
  273.  
  274. ostream &operator<<(ostream &outs, const matrix &other)
  275. {
  276.     for(int i=0; i<other.vector_count; i++)
  277.     {
  278.       outs << "n"<<other.arr[i];
  279.     }
  280.     return outs;
  281.  
  282. }
  283.  
  284. int main(int argc, char *argv[])
  285. {
  286.  vector obj1(4,4);
  287.  matrix obj2(4,5);
  288.  cout<<obj1;
  289.  cout<<"n"<<~obj1;
  290.  cout<<"n"<<obj2;
  291.  cout<<"n"<<(obj2);
  292.  cout<<"n"<<++obj2;
  293.  cout<<"n"<<(--obj2);
  294.  /*cout<<"n"<<obj2;
  295.  cout<<"n"<<++obj2;
  296.  cout<<"n"<<--obj2;
  297.  cout<<"nn"<<!obj2;
  298.   */
  299.  
  300.  return 0;
  301. }
  302.  

Replies to Untitled rss

Title Name Language When
Re: Untitled Gray Owl text 3 Years ago.