Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- class Sportowiec {
- protected:
- std::string imie;
- std::string nazwisko;
- int wiek;
- std::string kraj;
- std::string dyscyplina;
- public:
- Sportowiec(){}
- Sportowiec(std::string imie, std::string nazwisko, int wiek, std::string kraj, std::string dyscyplina) {
- this->imie = imie;
- this->nazwisko = nazwisko;
- this->wiek = wiek;
- this->kraj = kraj;
- this->dyscyplina = dyscyplina;
- }
- virtual int getIdKlasy() = 0;
- virtual void setDodatkoweInformacje(std::string str1, std::string str2) = 0;
- virtual void setDodatkoweInformacje(std::string str1) = 0;
- bool isSetString(std::string str) {
- if (str.length() > 0)
- return true;
- else return false;
- }
- virtual void drukujWizytowke() {
- std::cout << "Sportowiec, dane: " << std::endl;
- std::cout << "Imie : " << imie << std::endl;
- std::cout << "Nazwisko : " << nazwisko << std::endl;
- std::cout << "Wiek : " << wiek << std::endl;
- std::cout << "Kraj : " << kraj <<std::endl;
- std::cout << "Dyscyplina : " << dyscyplina<<std::endl;
- }
- friend std::ostream& operator << (std::ostream& out, Sportowiec& s);
- };
- class Pilkarz : public Sportowiec {
- private:
- std::string pozycja;
- std::string zespolLigowy;
- int idKlasy;
- public:
- Pilkarz() {}
- Pilkarz(std::string imie, std::string nazwisko, int wiek, std::string kraj) :
- Sportowiec(imie, nazwisko, wiek, kraj, "piłka nożna") {
- idKlasy = 0;
- };
- int getIdKlasy() {
- return idKlasy;
- }
- void setDodatkoweInformacje(std::string pozycja, std::string zespolLigowy){
- this->pozycja = pozycja;
- this->zespolLigowy = zespolLigowy;
- }
- void setDodatkoweInformacje(std::string str1) {}
- void drukujWizytowke() {
- Sportowiec::drukujWizytowke();
- if (Sportowiec::isSetString(pozycja)) {
- std::cout << "Pozycja Pilkarza: " << pozycja << std::endl;
- }
- if (Sportowiec::isSetString(zespolLigowy)) {
- std::cout << "Zespol Ligowy: " << zespolLigowy << std::endl;
- }
- }
- };
- class Plywak : public Sportowiec {
- private:
- std::string styl;
- int idKlasy;
- public:
- Plywak() {}
- Plywak(std::string imie, std::string nazwisko, int wiek, std::string kraj) :
- Sportowiec(imie, nazwisko, wiek, kraj, "pływanie") {
- idKlasy = 1;
- };
- int getIdKlasy() {
- return idKlasy;
- }
- void setDodatkoweInformacje(std::string str1, std::string str2) {};
- void setDodatkoweInformacje(std::string styl) {
- this->styl = styl;
- }
- void drukujWizytowke(){
- Sportowiec::drukujWizytowke();
- if (Sportowiec::isSetString(styl)) {
- std::cout << "Styl z najwiekszymi osiagami: " << styl << std::endl;
- }
- }
- };
- class Zawody {
- private:
- std::string miejsce;
- int liczbaZawodnikow;
- Sportowiec* sportowcy[20];
- public:
- Zawody(){}
- Zawody(std::string miejsce) {
- this->miejsce = miejsce;
- liczbaZawodnikow = 0;
- }
- void dodajZawodnika(Sportowiec *s) {
- sportowcy[liczbaZawodnikow++] = s;
- }
- friend std::ostream& operator << (std::ostream& out, Zawody& z) {
- for (int i = 0; i < z.liczbaZawodnikow; i++) {
- if( (z.sportowcy[i]->getIdKlasy()) == 0)
- out << *static_cast<Pilkarz *>(z.sportowcy[i]) << std::endl;
- else
- out << *static_cast<Plywak *>(z.sportowcy[i]) << std::endl;
- }
- return out;
- }
- };
- std::ostream& operator << (std::ostream& out, Sportowiec& s) {
- s.drukujWizytowke();
- return out;
- }
- int main() {
- Pilkarz PanPilkarz1("Huan", "Gonzales", 16, "Norwegia");
- Pilkarz PanPilkarz2("Biorn", "Neallsoean", 28, "Boliwia");
- PanPilkarz2.setDodatkoweInformacje("Napastnik", "Lecha Gdansk");
- Plywak PanPływak1("Mustafa", "Mufasa", 100, "Czechy");
- Plywak PanPływak2("Musta", "Mufa", 10, "Słowacja");
- PanPływak2.setDodatkoweInformacje("dowolny");
- Zawody Zawody1("Kartuzy");
- Zawody1.dodajZawodnika(&PanPilkarz1);
- Zawody1.dodajZawodnika(&PanPilkarz2);
- Zawody1.dodajZawodnika(&PanPływak1);
- Zawody1.dodajZawodnika(&PanPływak2);
- std::cout << Zawody1;
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement