Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Kolekcija{
- int * _niz;
- int _trenutno;
- int _max;
- public:
- Kolekcija(int max = 5){
- _trenutno = 0;
- _max = max;
- _niz = new int[_max];
- }
- Kolekcija(Kolekcija & org){
- _trenutno = org._trenutno;
- _max = org._max;
- _niz = new int[_max];
- for (int i = 0; i < _trenutno; i++)
- _niz[i] = org._niz[i];
- }
- ~Kolekcija(){
- delete[]_niz;
- _niz = nullptr;
- }
- void operator += (int element){
- if (_trenutno == _max){
- _max += 5;
- int * temp = new int [_max];
- for (int i = 0; i < _trenutno; i++)
- temp[i] = _niz[i];
- }
- _niz[_trenutno] = element;
- _trenutno++;
- }
- void ispis(){
- cout << "---------------------------------------\n";
- for (int i = 0; i < _trenutno; i++)
- {
- cout << _niz[i] << " | ";
- }
- cout << "\n---------------------------------------\n";
- }
- friend ostream & operator << (ostream & COUT, Kolekcija & obj);
- int getTrenutno()const{ return _trenutno; };
- int operator [] (int i){
- if (i >= 0 && i < _trenutno){
- return _niz[i];
- }
- }
- Kolekcija operator = (Kolekcija & drugi){
- if (this != &drugi){
- delete[]_niz;
- _trenutno = drugi._trenutno;
- _max = drugi._max;
- _niz = new int[_max];
- for (int i = 0; i < _trenutno; i++)
- _niz[i] = drugi._niz[i];
- }
- return *this;
- }
- bool operator == (Kolekcija & drugi){
- if (this == &drugi) return true;
- if (_trenutno != drugi._trenutno) return false;
- for (int i = 0; i < _trenutno; i++){
- if (_niz[i] != drugi._niz[i]) return false;
- }
- return true;
- }
- bool operator != (Kolekcija & drugi){
- if (this == &drugi) return false;
- if (_trenutno != drugi._trenutno) return true;
- for (int i = 0; i < _trenutno; i++){
- if (_niz[i] != drugi._niz[i]) return true;
- }
- return false;
- }
- };
- ostream & operator << (ostream & COUT, Kolekcija & obj){
- cout << "---------------------------------------\n";
- for (int i = 0; i < obj._trenutno; i++)
- {
- cout << obj._niz[i] << " | ";
- }
- cout << "\n---------------------------------------\n";
- return COUT;
- }
- Kolekcija operator + (Kolekcija & a, Kolekcija & b){
- Kolekcija temp;
- for (int i = 0; i < a.getTrenutno(); i++)
- temp += a[i];
- for (int i = 0; i < b.getTrenutno(); i++)
- temp += b[i];
- return temp;
- }
- int main(){
- cout << "a" << endl;
- Kolekcija a;
- a += 15;
- a += 33;
- a += 72;
- cout << a;
- cout << "b" << endl;
- Kolekcija b;
- b += 1;
- b += 69;
- cout << b;
- cout << "c = a + b" << endl;
- Kolekcija c = a + b;
- cout << c;
- cout << "c = a" << endl;
- c = a;
- cout << c;
- cout << "---------------------------" << endl;
- if (a != a) cout << "a != a TACNO" << endl;
- else cout << "a != a NETACNO" << endl;
- system("pause > null");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement