Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- // vashiot kod ovde
- void string_copy(char* dest, const char* source, int length) {
- strncpy(dest, source, length);
- dest[length] = 0;
- }
- class Ucesnik {
- private:
- char* ime;
- bool pol;
- int vozrast;
- public:
- Ucesnik(const char* _ime = "", const bool _pol = false, const int _vozrast = 0) {
- ime = new char[strlen(_ime+1)];
- string_copy(ime, _ime, strlen(_ime));
- pol = _pol;
- vozrast = _vozrast;
- }
- Ucesnik(const Ucesnik& obj) {
- ime = new char(strlen(obj.ime+1));
- string_copy(ime, obj.ime, strlen(obj.ime));
- pol = obj.pol;
- vozrast = obj.vozrast;
- }
- Ucesnik& operator=(const Ucesnik& obj) {
- if(this != &obj) {
- delete [] ime;
- ime = new char(strlen(obj.ime+1));
- string_copy(ime, obj.ime, strlen(obj.ime));
- pol = obj.pol;
- vozrast = obj.vozrast;
- }
- return *this;
- }
- bool operator>(const Ucesnik& obj) {
- return vozrast > obj.vozrast;
- }
- friend ostream& operator<<(ostream& out, const Ucesnik& obj) {
- out << obj.ime << endl;
- out << (obj.pol ? "mashki" : "zhenski") << endl;
- out << obj.vozrast << endl;
- return out;
- }
- int getVozrast() { return vozrast; }
- ~Ucesnik() {
- delete [] ime;
- }
- };
- class Maraton {
- char lokacija[100];
- Ucesnik* ucesnici;
- int broj_ucesnici;
- public:
- Maraton() {
- strcpy(lokacija, "\0");
- ucesnici = NULL;
- broj_ucesnici = 0;
- }
- Maraton(const char* _lokacija) {
- string_copy(lokacija, _lokacija, 100);
- ucesnici = NULL;
- broj_ucesnici = 0;
- }
- Maraton(const Maraton& obj) {
- string_copy(lokacija, obj.lokacija, 100);
- broj_ucesnici = obj.broj_ucesnici;
- ucesnici = new Ucesnik[broj_ucesnici];
- for(int i = 0; i < broj_ucesnici; ++i) {
- ucesnici[i] = obj.ucesnici[i];
- }
- }
- Maraton& operator+=(const Ucesnik& obj) {
- Ucesnik* temp = new Ucesnik[broj_ucesnici+1];
- for(int i = 0; i < broj_ucesnici; ++i) {
- temp[i] = ucesnici[i];
- }
- //cout << "doaga" << endl;
- delete [] ucesnici;
- ucesnici = temp;
- ucesnici[broj_ucesnici++] = obj;
- return *this;
- }
- double prosecnoVozrast() {
- double zbir_godini = 0.0;
- for(int i = 0; i < broj_ucesnici; ++i) {
- zbir_godini += ucesnici[i].getVozrast();
- }
- return zbir_godini / broj_ucesnici;
- }
- void pecatiPomladi(Ucesnik& u) {
- for(int i = 0; i < broj_ucesnici; ++i) {
- if(ucesnici[i].getVozrast() < u.getVozrast()) {
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement