SHARE
TWEET

Untitled

MeehoweCK May 31st, 2020 878 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class TablicaInt
  6. {
  7.     friend ostream& operator<<(ostream&, TablicaInt&);
  8.     int* tablica;
  9.     unsigned wielkosc;
  10. public:
  11.     TablicaInt(unsigned);
  12.     int& operator[](unsigned);
  13. };
  14.  
  15. TablicaInt::TablicaInt(unsigned rozmiar) : wielkosc(rozmiar)
  16. {
  17.     tablica = new int[wielkosc];
  18.     for(unsigned i = 0; i < wielkosc; ++i)
  19.         tablica[i] = 0;
  20. }
  21.  
  22. int& TablicaInt::operator[](unsigned i)
  23. {
  24.     if(i < wielkosc)
  25.         return tablica[i];
  26.     cout << "brak wartosci\n";
  27. }
  28.  
  29. ostream& operator<<(ostream& str, TablicaInt& tablica)
  30. {
  31.     for(unsigned i = 0; i < tablica.wielkosc; ++i)
  32.         str << tablica[i] << '\t';
  33.     return str;
  34. }
  35.  
  36. int main()
  37. {
  38.     TablicaInt tablica(6);
  39.     tablica[1] = 10;
  40.     tablica[2] = 5;
  41.     cout << tablica << endl;
  42.     cout << tablica[2] << endl;
  43.     return 0;
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top