brsjak

Stip - sesta

Sep 10th, 2016
652
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Pole
  5. {
  6. private:
  7.     int *niza;
  8.     int n;
  9. public:
  10.     Pole ()
  11.     {
  12.         n = 0;
  13.         niza = new int [0];
  14.     }
  15.     Pole (int *elementi,int n)
  16.     {
  17.         this->n = n;
  18.         niza = new int [n];
  19.         for(int i=0; i<n; i++)
  20.             niza[i]=elementi[i];
  21.     }
  22.     int operator[] (int i)
  23.     {
  24.         return niza[i-1];
  25.     }
  26.     Pole& operator = (const Pole &p)
  27.     {
  28.         if(this != &p)
  29.         {
  30.             delete [] niza;
  31.             n = p.n;
  32.             niza = new int [n];
  33.             for(int i=0; i<n; i++)
  34.                 niza[i]=p.niza[i];
  35.         }
  36.         return *this;
  37.     }
  38.     int dolzina ()
  39.     {
  40.         return n;
  41.     }
  42. };
  43.  
  44. int main ()
  45. {
  46.     Pole pole;
  47.     int n,a;
  48.     cout<<"Vnesete dolzina na nizata"<<endl;
  49.     cin>>n;
  50.     int niza[n];
  51.     cout<<"Vnesete gi elementite vo nizata"<<endl;
  52.     for(int i=0; i<n; i++)
  53.         cin>>niza[i];  
  54.     pole = Pole (niza,n);
  55.     cout<<"Vnesete koja pozicija od elementot da bide prikazhana"<<endl;
  56.     cin>>a;
  57.     cout<<pole[a];
  58.     cout<<endl<<"Dolzinata na nizata e "<<pole.dolzina()<<endl;
  59.     return 0;
  60. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×