Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class TabIntArr
- {
- int tabsIntInArr[10];
- int curTabLenght;
- static int allObjects;
- public:
- int set (int * tablica, int dlugosc);
- int get (int indeks);
- void wypisz();
- static int ile();
- TabIntArr();
- ~TabIntArr();
- };
- int main()
- {
- int ar[] = {1,2,3,4,5,6};
- TabIntArr * a;
- TabIntArr * b;
- TabIntArr * c;
- a = new TabIntArr;
- b = new TabIntArr;
- c = new TabIntArr;
- a -> set( ar , sizeof(ar)/sizeof(ar[0]));
- a -> wypisz();
- delete a;
- cout << "Tyle zostalo obiektow: " << TabIntArr::ile() << endl;
- return 0;
- }
- int TabIntArr::allObjects = 0;
- int TabIntArr::get(int indeks)
- {
- if(indeks <= curTabLenght)
- {
- return tabsIntInArr[indeks];
- }
- else if(indeks < 0)
- {
- cout << "Przekroczono rozmiar tablicy - indeks jest ujemny" << endl;
- }
- else
- {
- cout << "Przekroczono rozmiar tablicy - indeks wykracza po za zakres" << endl;
- }
- }
- int TabIntArr::set(int * tablica, int dlugosc)
- {
- int tabsIntInArrLength = sizeof(tabsIntInArr)/sizeof(tabsIntInArr[0]);
- if(tabsIntInArrLength == 0)
- {
- cout << "Przekroczono rozmiar tablicy - bazowa tablica jest pusta" << endl;
- return -1;
- }
- if(dlugosc > tabsIntInArrLength)
- {
- cout << "Przekroczono rozmiar tablicy - nowa tablica jest zbyt duza" << endl;
- return -1;
- }
- for (int i = 0; i < dlugosc; i++)
- {
- tabsIntInArr[i] = tablica[i];
- }
- curTabLenght = dlugosc;
- }
- void TabIntArr::wypisz()
- {
- cout << "Wypisuje dane" << endl;
- for(int i = 0; i < curTabLenght; i++)
- {
- cout << tabsIntInArr[i] << endl;
- }
- }
- int TabIntArr::ile()
- {
- return TabIntArr::allObjects;
- }
- TabIntArr::TabIntArr()
- {
- TabIntArr::allObjects++;
- }
- TabIntArr::~TabIntArr()
- {
- TabIntArr::allObjects--;
- }
Add Comment
Please, Sign In to add comment