Advertisement
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 vozrast;
- public:
- Ucesnik(const char *_ime = " ", bool _pol = true, int _vozrast = 15){
- ime = new char[strlen(_ime) + 1];
- strcpy(ime, _ime);
- pol = _pol;
- vozrast = _vozrast;
- }
- Ucesnik(const Ucesnik &u){
- //delete [] ime;
- ime = new char[strlen(u.ime) + 1];
- strcpy(ime, u.ime);
- pol = u.pol;
- vozrast = u.vozrast;
- }
- ~Ucesnik(){delete [] ime;}
- bool operator>(const Ucesnik &u){
- return vozrast > u.vozrast;
- }
- const Ucesnik& operator=(const Ucesnik &u){
- //delete [] ime;
- ime = new char [strlen(u.ime) + 1];
- strcpy(ime, u.ime);
- pol = u.pol;
- vozrast = u.vozrast;
- return *this;
- }
- friend ostream& operator<<(ostream& os, const Ucesnik &u);
- int getVozrast(){
- return vozrast;
- }
- };
- class Maraton{
- private:
- char lokacija[100];
- Ucesnik *ucesnici;
- int n;
- public:
- Maraton(){}
- Maraton(char *_lokacija){
- strcpy(lokacija, _lokacija);
- n=0;
- }
- Maraton(const Maraton &m){
- delete [] ucesnici;
- strcpy(lokacija, m.lokacija);
- n = m.n;
- ucesnici = new Ucesnik [n];
- for(int i = 0; i<n;i++){
- ucesnici[i] = m.ucesnici[i];
- }
- }
- ~Maraton(){delete [] ucesnici;}
- Maraton & operator+=(const Ucesnik u){
- Ucesnik *temp = new Ucesnik[n];
- for(int i = 0; i < n; i++){
- temp[i] = ucesnici[i];
- }
- delete [] ucesnici;
- ucesnici = new Ucesnik[n+1];
- for(int i = 0; i < n; i++){
- ucesnici[i] = temp[i];
- }
- ucesnici[n] = u;
- n++;
- return *this;
- }
- float prosecnoVozrast(){
- float zbir = 0;
- for(int i = 0; i<n; i++){
- zbir += ucesnici[i].getVozrast();
- }
- return zbir / n;
- }
- void pecatiPomladi(Ucesnik &u){
- for(int i = 0; i < n; i ++){
- if(u > ucesnici[i]){
- cout << ucesnici[i];
- }
- }
- }
- };
- ostream& operator<<(ostream& os, const Ucesnik &u){
- os << u.ime << endl;
- if(u.pol){os << "maski" << endl;} else {os << "zhenski"<<endl;}
- cout << u.vozrast << endl;
- return os;
- }
- 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