Advertisement
NebojshaTodorovic

OOP-lab 5 Planinarsko drustvo

Mar 20th, 2017
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4. class PlDrustvo{
  5.     private:
  6.     char *ime=new char;
  7.     int brc,brt;
  8.     public:
  9.     PlDrustvo(){}
  10.     PlDrustvo(char *i,int brT,int brC)
  11.     {
  12.        // ime=new char[strlen(i)+1];
  13.         strcpy(ime,i);
  14.         brt=brT;
  15.         brc=brC;
  16.     }
  17.     PlDrustvo(const PlDrustvo &pl)
  18.     {
  19.         ime=new char[strlen(pl.ime)+1];
  20.         //cout<<"COPY"<<pl;
  21.         strcpy(this->ime,pl.ime);
  22. //cout<<"COPY"<<ime<<" "<<pl.ime<<endl;
  23.         this->brt=pl.brt;
  24.         this->brc=pl.brc;
  25.     }
  26.    ~PlDrustvo()
  27.     {
  28.        // cout<<"POVIKAN DELETE ZA "<<this->ime<<endl;
  29.     delete []ime;
  30.     }
  31.     friend bool  operator>(PlDrustvo d1,PlDrustvo d2)
  32.     {
  33.         if(d1.brc>d2.brc)
  34.             return true;
  35.         return false;
  36.     }
  37.      friend bool  operator<(PlDrustvo d1,PlDrustvo d2)
  38.     {
  39.         return d1.brc<d2.brc;
  40.     }
  41.    /* PlDrustvo operator+(PlDrustvo a, PlDrustvo b) {
  42. PlDrustvo p;
  43. return p;
  44. }*/
  45.    friend PlDrustvo operator+(PlDrustvo pl,PlDrustvo pl1)
  46.     {
  47.         PlDrustvo p;
  48.         if(pl>pl1)
  49.         {
  50.             p.brc=pl.brc+pl1.brc;
  51.             p.ime=new char[strlen(pl.ime)+1];
  52.             strcpy(p.ime,pl.ime);
  53.                 p.brt=pl.brt;
  54.            // cout<<p.ime<<" tuj e copy povikan za p"<<endl;
  55.           //  cout<<"zavrshue +";
  56.             return p;
  57.         }
  58.         else
  59.         {
  60.             p.brc=pl.brc+pl1.brc;
  61.             p.ime=new char[strlen(pl1.ime)+1];
  62.             strcpy(p.ime,pl1.ime);
  63.                 p.brt=pl1.brt;
  64.            // cout<<p.ime<<" tuj e copy povikan za p"<<endl;
  65.           //  cout<<"zavrshue +";
  66.            
  67.             return p;
  68.         }
  69.     }
  70.     PlDrustvo & operator=(PlDrustvo const &p)
  71.     {
  72.               this->brc=p.brc;
  73.         this->brt=p.brt;
  74.          delete []this->ime;
  75.         this->ime=new char[strlen(p.ime)+1];
  76.         strcpy(ime,p.ime);
  77.      
  78.         return *this;
  79.        
  80.     }
  81.     friend ostream & operator <<(ostream &o,PlDrustvo p)
  82.     {
  83.         o<<"Ime: "<<p.ime<<" Turi: "<<p.brt<<" Clenovi: "<<p.brc<<endl;
  84.         return o;
  85.     }
  86.     friend void najmnoguClenovi(PlDrustvo *p,int n)
  87.     {
  88.         int maxbrc=0;
  89.         int red;
  90.         for(int i=0;i<n;i++)
  91.         {
  92.             if(p[i].brc>maxbrc)
  93.             {
  94.                 maxbrc=p[i].brc;
  95.                 red=i;
  96.             }
  97.         }
  98.         cout<<"Najmnogu clenovi ima planinarskoto drustvo: "<<p[red];
  99.     }
  100. };
  101. int main()
  102. {              
  103.     PlDrustvo drustva[3];
  104.     PlDrustvo pl;
  105.     for (int i=0;i<3;i++)
  106.     {
  107.         char ime[100];
  108.         int brTuri;
  109.         int brClenovi;
  110.         cin>>ime;
  111.         cin>>brTuri;
  112.         cin>>brClenovi;
  113.         PlDrustvo p(ime,brTuri,brClenovi);
  114.        // cout<<p;
  115.         drustva[i] = p;
  116.        
  117.     }
  118.    
  119.    pl = (drustva[0] + drustva[1]);
  120.     cout<<pl;
  121.    
  122.     najmnoguClenovi(drustva, 3);
  123.    
  124.     return 0;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement