Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int gID = 1;
- int gRef = 20;
- class Datum {
- int d, m, g;
- public:
- Datum(int dan = 0, int mjesec = 0, int godina = 0){
- d = dan;
- m = mjesec;
- g = godina;
- }
- };
- class Kolekcija{
- int * _niz;
- int _trenutno;
- int _max;
- // specijalni slucajevi
- const int _ID;
- int & _referenca;
- Datum _datumKreiranja;
- public:
- Kolekcija() :_ID(0), _referenca(gRef), _datumKreiranja() {
- _trenutno = 0;
- _max = 5;
- _niz = new int[_max];
- }
- Kolekcija(int vrijednost):_ID(gID), _referenca(gRef),_datumKreiranja(10,4,1995){
- _trenutno = 0;
- _max = 5;
- _niz = new int[_max];
- _niz[_trenutno] = vrijednost;
- _trenutno++;
- }
- Kolekcija(Kolekcija & org):_ID(org._ID), _referenca(org._referenca), _datumKreiranja(org._datumKreiranja){
- _trenutno = org._trenutno;
- _max = org._max;
- _niz = new int[_max];
- for (int i = 0; i < _max; i++)
- _niz[i] = org._niz[i];
- }
- ~Kolekcija(){
- delete[]_niz;
- _niz = nullptr;
- }
- void ispis(){
- if (_trenutno != 0){
- for (int i = 0; i < _trenutno; i++){
- cout << _niz[i] << "\t";
- }
- cout << endl;
- }
- else cout << "Prazna kolekcija.\n";
- }
- void dodajElement(int element){
- if (_trenutno == _max){
- _max += 5;
- int * temp = new int[_max];
- for (int i = 0; i < _trenutno; i++)
- temp[i] = _niz[i];
- delete[]_niz;
- _niz = temp;
- }
- _niz[_trenutno] = element;
- _trenutno++;
- }
- };
- int main(){
- Kolekcija a(5);
- a.ispis();
- a.dodajElement(6);
- a.dodajElement(9);
- a.ispis();
- Kolekcija b(a);
- b.ispis();
- system("pause > null");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement