Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- using namespace std;
- class PlDrustvo {
- char *ime;
- int turi;
- int clenovi;
- public:
- PlDrustvo(const char *name = "", int t=0, int n=0){
- ime = new char[strlen(name)+1];
- strcpy(ime, name);
- turi = t;
- clenovi = n;
- }
- PlDrustvo(const PlDrustvo &pl){
- ime = new char[strlen(pl.ime)+1];
- strcpy(ime, pl.ime);
- turi = pl.turi;
- clenovi = pl.clenovi;
- }
- ~PlDrustvo(){delete[] ime;}
- PlDrustvo &operator=(const PlDrustvo &pl){
- if(this!=&pl){
- delete[] ime;
- ime = new char[strlen(pl.ime)+1];
- strcpy(ime, pl.ime);
- turi = pl.turi;
- clenovi = pl.clenovi;
- }
- return *this;
- }
- bool operator>(const PlDrustvo &pl){
- return (clenovi > pl.clenovi);
- }
- bool operator<(const PlDrustvo &pl){
- return (clenovi < pl.clenovi);
- }
- PlDrustvo operator+(const PlDrustvo &pl){
- PlDrustvo p;
- p.clenovi = clenovi + pl.clenovi;
- delete[] p.ime;
- if(*this > pl){
- p.ime = new char[strlen(ime)+1];
- strcpy(p.ime, ime);
- p.turi = turi;
- }
- else{
- p.ime = new char[strlen(pl.ime)+1];
- strcpy(p.ime, pl.ime);
- p.turi = pl.turi;
- }
- return p;
- }
- friend ostream &operator<<(ostream &o, const PlDrustvo &pl){
- return o << "Ime: " << pl.ime << " Turi: " << pl.turi << " Clenovi: " << pl.clenovi << endl;
- }
- friend void najmnoguClenovi(PlDrustvo*, int);
- };
- void najmnoguClenovi(PlDrustvo *pl, int n){
- int maxi = 0;
- int max = 0;
- for(int i=0; i < n; i++){
- if(pl[i].clenovi > max){
- maxi = i;
- max = pl[i].clenovi;
- }
- }
- cout << "Najmnogu clenovi ima planinarskoto drustvo: " << pl[maxi];
- }
- 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