Advertisement
OMEGAHEAD_MonkoX

2

Oct 2nd, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class IntArray{
  6.     private:
  7.         int n;
  8.     public:
  9.         int *a = new int;
  10.         IntArray(int _n){
  11.             n = _n;
  12.             //cout << _n << endl;
  13.         }
  14.         friend istream & operator >> (istream &, IntArray &);
  15.         friend ostream & operator << (ostream &, const IntArray &);
  16.         int & operator [](int )const ;
  17.         int size(){
  18.             return n;
  19.         }
  20.         ~IntArray(){
  21.            
  22.         }
  23.    
  24. };
  25.  
  26. int &IntArray::operator [](int i) const
  27. {
  28.     return a[i];
  29. }
  30.  
  31.  
  32. istream & operator >> (istream & in, IntArray & a)
  33. {
  34.     int _n = a.n;
  35.     for (auto i = 0; i < _n; ++i)
  36.     {
  37.         in >> a[i];
  38.     }
  39.     return in;
  40.  
  41.    
  42. }
  43. ostream & operator <<(ostream & out, const IntArray & a)
  44. {
  45.     int _n = a.n;
  46.     for (auto i = 0; i < _n; ++i)
  47.     {
  48.         out << a[i] << " ";
  49.     }
  50.     return out;
  51. }
  52.  
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement