Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- using namespace std;
- class PlDrustvo{
- private:
- char *ime;
- int brojTuri;
- int clenovi;
- public:
- PlDrustvo(){
- ime=NULL;
- brojTuri=0;
- clenovi=0;
- }
- PlDrustvo(char *ime,int brojTuri,int clenovi){
- this->ime=new char [strlen(ime)+1];
- strcpy(this->ime,ime);
- this->brojTuri=brojTuri;
- this->clenovi=clenovi;
- }
- PlDrustvo(const PlDrustvo& p){
- this->ime=new char [strlen(p.ime)+1];
- strncpy(this->ime,p.ime,strlen(p.ime)+1);
- this->brojTuri=p.brojTuri;
- this->clenovi=p.clenovi;
- }
- PlDrustvo& operator=(const PlDrustvo &p){
- if(this!=&p){
- delete [] this->ime;
- this->ime=new char [strlen(p.ime)+1];
- strcpy(this->ime,p.ime);
- this->brojTuri=p.brojTuri;
- this->clenovi=p.clenovi;
- }
- return *this;
- }
- PlDrustvo operator+(const PlDrustvo &p){
- PlDrustvo p1;
- if(*this>p){
- delete [] p1.ime;
- p1.ime=new char [strlen(this->ime)+1];
- strncpy(p1.ime,this->ime,strlen(this->ime)+1);
- p1.brojTuri=this->brojTuri;
- p1.clenovi=this->clenovi+p.clenovi;
- } else {
- delete [] p1.ime;
- p1.ime=new char [strlen(p.ime)+1];
- strncpy(p1.ime,p.ime,strlen(p.ime)+1);
- p1.brojTuri=p.brojTuri;
- p1.clenovi=this->clenovi+p.clenovi;
- }
- return p1;
- }
- ~PlDrustvo(){
- delete [] ime;
- }
- friend ostream& operator<<( ostream& output,PlDrustvo &p){
- output<<"Ime: "<<p.ime<<" Turi: "<<p.brojTuri<<" Clenovi: "<<p.clenovi<<endl;
- return output;
- }
- bool operator<(const PlDrustvo& p){
- return this->clenovi<p.clenovi;
- }
- bool operator>(const PlDrustvo& p){
- return this->clenovi>p.clenovi;
- }
- };
- void najmnoguClenovi(PlDrustvo* drustva,int n){
- PlDrustvo max=drustva[0];
- for(int i=1;i<n;i++){
- if(drustva[i]>max){
- max=drustva[i];
- }
- }
- cout<<"Najmnogu clenovi ima planinarskoto drustvo: "<<max;
- }
- int main()
- {
- PlDrustvo drustva[3];
- PlDrustvo pl;
- for (int i=0;i<3;i++)
- {
- char ime[100];
- int brTuri;
- int brClenovi;
- cin>>ime;
- cin>>brTuri;
- cin>>brClenovi;
- PlDrustvo p(ime,brTuri,brClenovi);
- drustva[i] = p;
- }
- pl = (drustva[0] + drustva[1]);
- cout<<pl;
- najmnoguClenovi(drustva, 3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement