Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Pole
- {
- private:
- int *niza;
- int n;
- public:
- Pole ()
- {
- n = 0;
- niza = new int [0];
- }
- Pole (int *elementi,int n)
- {
- this->n = n;
- niza = new int [n];
- for(int i=0; i<n; i++)
- niza[i]=elementi[i];
- }
- int operator[] (int i)
- {
- return niza[i-1];
- }
- Pole& operator = (const Pole &p)
- {
- if(this != &p)
- {
- delete [] niza;
- n = p.n;
- niza = new int [n];
- for(int i=0; i<n; i++)
- niza[i]=p.niza[i];
- }
- return *this;
- }
- int dolzina ()
- {
- return n;
- }
- };
- int main ()
- {
- Pole pole;
- int n,a;
- cout<<"Vnesete dolzina na nizata"<<endl;
- cin>>n;
- int niza[n];
- cout<<"Vnesete gi elementite vo nizata"<<endl;
- for(int i=0; i<n; i++)
- cin>>niza[i];
- pole = Pole (niza,n);
- cout<<"Vnesete koja pozicija od elementot da bide prikazhana"<<endl;
- cin>>a;
- cout<<pole[a];
- cout<<endl<<"Dolzinata na nizata e "<<pole.dolzina()<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement