Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include "stdafx.h"
- #include <iostream>
- using namespace std;
- class Zbior
- {
- public:
- Zbior(): r(0), tab(NULL)
- {}
- bool czy_jest(int v);
- int rozmiar() const
- {
- return r;
- }
- Zbior & operator << (int element);
- int operator[](int n)
- {
- return tab[n];
- }
- private:
- int * tab;
- int r;
- };
- bool Zbior::czy_jest(int v)
- {
- for (int i = 0; i < r; i++)
- {
- if (tab[i] == v)
- {
- return true;
- }
- }
- return false;
- }
- Zbior & Zbior::operator << (int element)
- {
- int i, * nowa = new int[r+1];
- for (i = 0; i < r; i++)
- {
- nowa[i] = tab[i];
- }
- nowa[i] = element;
- r++;
- delete [] tab;
- tab = nowa;
- return (*this);
- }
- int main()
- {
- Zbior a;
- a << 15;
- a << 30;
- a << 45;
- cout << "\nZbior a:\n";
- for (int i = 0; i < a.rozmiar(); i++)
- {
- cout << a[i] << " ";
- }
- bool wynik = a.czy_jest(10);
- bool wynik2 = a.czy_jest(30);
- cout << "\n\nCzy istnieje 10 - " << wynik << endl;
- cout << "Czy istnieje 30 - " << wynik2 << endl;
- /* cout << "\n\nCzy istnieje 10 - ";
- if (a.czy_jest(10) == true)
- {
- cout << "jest\n";
- }
- else
- {
- cout << "nie ma\n";
- }
- cout << "Czy istnieje 30 - ";
- if (a.czy_jest(30) == true)
- {
- cout << "jest\n";
- }
- else
- {
- cout << "nie ma\n";
- }
- */
- //cin.get();
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement