Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <cstring>
- using namespace std;
- class Ucesnik {
- private:
- char* ime;
- bool pol;
- int vozrast;
- public:
- Ucesnik(const char* ime = "", bool pol = false, int vozrast = 0)
- {
- this->ime = new char[strlen(ime) + 1];
- strcpy(this->ime, ime);
- this->pol = pol;
- this->vozrast = vozrast;
- }
- Ucesnik(Ucesnik& ob)
- {
- delete[]this->ime;
- this->ime = new char[strlen(ob.ime) + 1];
- strcpy(this->ime, ob.ime);
- this->pol = ob.pol;
- this->vozrast = ob.vozrast;
- }
- ~Ucesnik()
- {
- delete[]this->ime;
- }
- Ucesnik operator=(Ucesnik& ob)
- {
- if (this != &ob)
- {
- delete[]this->ime;
- this->ime = new char[strlen(ob.ime) + 1];
- strcpy(this->ime, ob.ime);
- this->pol =ob.pol;
- this->vozrast = ob.vozrast;
- }
- return *this;
- }
- int getVozrast()
- {
- return this->vozrast;
- }
- bool operator>(Ucesnik& ob)
- {
- return this->vozrast > ob.vozrast;
- }
- friend ostream& operator<<(ostream& out, Ucesnik& ob)
- {
- out << ob.ime << endl;
- if (ob.pol)
- out << "Maski" << endl;
- else
- out << "Zenski" << endl;
- out << ob.vozrast << endl;
- return out;
- }
- };
- class Maraton {
- private:
- char lokacija[100];
- Ucesnik** niza;
- int br_ucesnici;
- public:
- Maraton(char* lokacija = "")
- {
- strcpy(this->lokacija, lokacija);
- this->niza = NULL;
- this->br_ucesnici = 0;
- }
- ~Maraton()
- {
- delete[]this->niza;
- }
- Maraton operator+=(Ucesnik&ob)
- {
- Ucesnik*temp=new Ucesnik[this->br_ucesnici+1];
- copy(this->niza, this->niza + this->br_ucesnici, temp);
- temp[this->br_ucesnici++]=ob;
- delete[]this->niza;
- //this->niza = temp;
- return *this;
- }
- double proscena_vozrast()
- {
- int zbir = 0;
- for (int i = 0; i < this->br_ucesnici; ++i)
- {
- zbir += this->niza[i]->getVozrast();
- return zbir / ((double)(this->br_ucesnici));
- }
- }
- void pecatiPomladi(Ucesnik& u)
- {
- for (int i = 0; i < this->br_ucesnici; ++i)
- if (this->niza[i])
- cout << this->niza[i];
- }
- };
- int main()
- {
- char ime[100];
- bool maski;
- int vozrast;
- int n;
- cin>>n;
- char lokacija[100];
- Maraton m(lokacija);
- Ucesnik **u=new Ucesnik*[n];
- for(int i=0;i<n;i++)
- {
- cin>>ime>>maski>>vozrast;
- u[i]=new Ucesnik(ime,maski,vozrast);
- m+=*u[i];
- }
- m.pecatiPomladi(*u[n-1]);
- cout<<m.proscena_vozrast()<<endl;
- for(int i=0;i<n;i++)
- {
- delete u[i];
- }
- delete []u;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment