Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // vashiot kod ovde
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Ucesnik{
- private:
- char *ime;
- bool pol;
- int age;
- public:
- Ucesnik(char *ime="",bool pol=false,int age=0)
- {
- this->pol=pol;
- this->age=age;
- this->ime = new char [strlen(ime)+1]; // Alocirame niza od charovi
- strcpy(this->ime,ime); //Otkako napravivme alokacija soodvetno ja prefrlame vrednosta
- }
- Ucesnik(Ucesnik &u)
- {
- this->pol=u.pol;
- this->age=u.age;
- this->ime = new char [strlen(u.ime)+1];
- strcpy(this->ime,u.ime);
- }
- Ucesnik &operator=(Ucesnik &u)
- {
- if(this!=&u)
- {
- delete [] ime;
- this->pol=u.pol;
- this->age=u.age;
- this->ime = new char [strlen(u.ime)+1];
- strcpy(this->ime,u.ime);
- }
- return *this;
- }
- friend bool operator>(Ucesnik &u,Ucesnik &u1);
- friend ostream &operator<<(ostream &out,Ucesnik &u)
- {
- if(u.pol==0)
- out<<u.ime<<endl<<"zhenski"<<endl;
- else
- out<<u.ime<<endl<<"mashki"<<endl;
- out<<u.age<<endl;
- return out;
- }
- int get_age()
- {
- return age;
- }
- ~Ucesnik()
- {
- //delete [] ime;
- }
- };
- bool operator >(Ucesnik &u,Ucesnik &u1)
- {
- if(u.get_age()>u1.get_age())
- return true;
- else return false;
- }
- class Maraton{
- char lokacija[100];
- Ucesnik *ucesnici;
- int broj;
- public:
- Maraton(char * lokacija="",Ucesnik *ucesnici=0,int broj=0)
- {
- strcpy(this->lokacija,lokacija);
- this->broj=broj;
- this->ucesnici = new Ucesnik[broj];
- for (int i=0;i<broj;i++)
- {
- this->ucesnici[i]=ucesnici[i];
- }
- }
- Maraton(Maraton &m)
- {
- strcpy(this->lokacija,m.lokacija);
- this->broj=m.broj;
- this->ucesnici = new Ucesnik[m.broj];
- for (int i=0;i<broj;i++)
- {
- this->ucesnici[i]=m.ucesnici[i];
- }
- }
- Maraton &operator=(Maraton &m)
- {
- if(this!=&m)
- {
- strcpy(this->lokacija,m.lokacija);
- this->broj=m.broj;
- this->ucesnici = new Ucesnik[m.broj];
- delete [] ucesnici;
- for (int i=0;i<broj;i++)
- {
- this->ucesnici[i]=m.ucesnici[i];
- }
- }
- return *this;
- }
- Maraton &operator +=(Ucesnik &u)
- {
- Ucesnik *tmp = new Ucesnik[broj+1];
- for(int i=0;i<broj;i++)
- {
- tmp[i]=ucesnici[i];
- }
- tmp[broj++]=u;
- delete [] ucesnici;
- ucesnici=tmp;
- return *this;
- }
- float prosecnoVozrast()
- {
- float prosek;
- for(int i=0;i<broj;i++)
- {
- prosek+=ucesnici[i].get_age();
- }
- return prosek/broj;
- }
- void pecatiPomladi(Ucesnik &u)
- {
- int brojac=0;
- for(int i=0;i<broj;i++)
- {
- if(u.get_age()>ucesnici[i].get_age())
- cout<<ucesnici[i];
- }
- }
- ~Maraton()
- {
- //delete [] ucesnici;
- }
- };
- int main() {
- char ime[100];
- bool maski;
- int vozrast, n;
- cin >> n;
- char lokacija[100];
- cin >> lokacija;
- 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.prosecnoVozrast() << endl;
- for(int i = 0; i < n; ++i) {
- delete u[i];
- }
- delete [] u;
- return 0;
- }
Add Comment
Please, Sign In to add comment