Advertisement
Guest User

PlDrustvo

a guest
Apr 23rd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. /*
  6. +
  7. -
  8. ++
  9. --
  10. +=
  11. -=
  12. >
  13. <
  14. ==
  15. >>
  16. <<
  17. >=
  18. <=
  19. */
  20.  
  21.  
  22. class PlDrustvo{
  23. private:
  24.     char *ime;
  25.     int brturi;
  26.     int brclenovi;
  27.  
  28. public:
  29.     PlDrustvo(){
  30.     ime=new char[0];
  31.     brturi=0;
  32.     brclenovi=0;
  33.     }
  34.     PlDrustvo(char *ime1,int brturi1, int brclenovi1){
  35.      ime=new char[strlen(ime1)+1];
  36.      strcpy(ime,ime1);
  37.      brturi=brturi1;
  38.      brclenovi=brclenovi1;
  39.     }
  40.     PlDrustvo(const PlDrustvo &p){
  41.      ime=new char[strlen(p.ime)+1];
  42.      strcpy(ime,p.ime);
  43.      brturi=p.brturi;
  44.      brclenovi=p.brclenovi;
  45.  
  46.     }
  47.      PlDrustvo operator =(const PlDrustvo &p){
  48.                  if(this!=&p){
  49.      ime=new char[strlen(p.ime)+1];
  50.      strcpy(ime,p.ime);
  51.      brturi=p.brturi;
  52.      brclenovi=p.brclenovi;
  53.                  }
  54.                  return *this;
  55.     }
  56.  
  57.     ~PlDrustvo(){
  58.      delete[] ime;
  59.     }
  60.  
  61.     PlDrustvo operator+(const PlDrustvo &p){
  62.         if(brclenovi>p.brclenovi){
  63.               PlDrustvo novoDrustvo(ime,brturi,brclenovi+p.brclenovi);
  64.               return novoDrustvo;
  65.         }else if(brclenovi<p.brclenovi){
  66.            PlDrustvo novoDrustvo(p.ime,p.brturi,brclenovi+p.brclenovi);
  67.            return novoDrustvo;
  68.         }
  69.     }
  70.    bool operator >(int vrednost){
  71.    if(brclenovi>vrednost){
  72.     return true;
  73.    }else{
  74.    return false;
  75.    }
  76.    }
  77.     bool operator <(const PlDrustvo &p){
  78.    if(brclenovi<p.brclenovi){
  79.     return true;
  80.    }else{
  81.    return false;
  82.    }
  83.    }
  84.  
  85.     friend ostream& operator <<(ostream &o,const PlDrustvo &p){
  86.      o<<p.ime<<" "<<p.brturi<<" "<<p.brclenovi<<endl;
  87.      return o;
  88.     }
  89.     int getClenovi(){
  90.     return brclenovi;
  91.     }
  92.  
  93. };
  94.  
  95.  
  96. void najmnoguClenovi(PlDrustvo *pd,int n){
  97.  int maxClenovi=-99999;
  98.  int cuvajIndeks;
  99.  for(int i=0;i<n;i++){
  100.      if(pd[i]>maxClenovi){
  101.         maxClenovi=pd[i].getClenovi();
  102.         cuvajIndeks=i;
  103.  }
  104.  }
  105.  cout<<pd[cuvajIndeks];
  106.  
  107. }
  108.  
  109. int main()
  110. {
  111.  PlDrustvo drustva[3];
  112.  PlDrustvo pl;
  113.  
  114.  for (int i=0;i<3;i++)
  115.  {
  116.  char ime[100];
  117.  int brTuri;
  118.  int brClenovi;
  119.  cin>>ime;
  120.  cin>>brTuri;
  121.  cin>>brClenovi;
  122.  PlDrustvo p(ime,brTuri,brClenovi);
  123.  drustva[i] = p;
  124.  }
  125.  pl = (drustva[0] + drustva[1]);
  126.  cout<<pl;
  127.  najmnoguClenovi(drustva, 3);
  128.  
  129.  return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement