Advertisement
Guest User

Untitled

a guest
Apr 16th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4.  
  5.  
  6. class Sportowiec {
  7.  
  8. protected:
  9.     std::string imie;
  10.     std::string nazwisko;
  11.     int wiek;
  12.     std::string kraj;
  13.     std::string dyscyplina;
  14.    
  15. public:
  16.     Sportowiec(){}
  17.  
  18.     Sportowiec(std::string imie, std::string nazwisko, int wiek, std::string kraj, std::string dyscyplina) {
  19.         this->imie = imie;
  20.         this->nazwisko = nazwisko;
  21.         this->wiek = wiek;
  22.         this->kraj = kraj;
  23.         this->dyscyplina = dyscyplina;
  24.     }
  25.  
  26.     virtual int getIdKlasy() = 0;
  27.     virtual void setDodatkoweInformacje(std::string str1, std::string str2) = 0;
  28.     virtual void setDodatkoweInformacje(std::string str1) = 0;
  29.    
  30.  
  31.     bool isSetString(std::string str) {
  32.         if (str.length() > 0)
  33.             return true;
  34.         else return false;
  35.  
  36.     }
  37.  
  38.  
  39.  
  40.     virtual void drukujWizytowke() {
  41.         std::cout << "Sportowiec, dane: " << std::endl;
  42.         std::cout << "Imie : " << imie << std::endl;
  43.         std::cout << "Nazwisko : " << nazwisko << std::endl;
  44.         std::cout << "Wiek : " << wiek << std::endl;
  45.         std::cout << "Kraj : " << kraj <<std::endl;
  46.         std::cout << "Dyscyplina : " << dyscyplina<<std::endl;
  47.  
  48.     }
  49.  
  50.  
  51.  
  52.  
  53.     friend std::ostream& operator << (std::ostream& out, Sportowiec& s);
  54.  
  55.  
  56.  
  57. };
  58.  
  59.  
  60.  
  61. class Pilkarz : public Sportowiec {
  62.  
  63. private:
  64.     std::string pozycja;
  65.     std::string zespolLigowy;
  66.     int idKlasy;
  67.  
  68.  
  69. public:
  70.  
  71.     Pilkarz() {}
  72.     Pilkarz(std::string imie, std::string nazwisko, int wiek, std::string kraj) :
  73.         Sportowiec(imie, nazwisko, wiek, kraj, "piłka nożna") {
  74.         idKlasy = 0;
  75.     };
  76.  
  77.  
  78.  
  79.     int getIdKlasy() {
  80.         return idKlasy;
  81.     }
  82.     void setDodatkoweInformacje(std::string pozycja, std::string zespolLigowy){
  83.         this->pozycja = pozycja;
  84.         this->zespolLigowy = zespolLigowy;
  85.  
  86.     }
  87.  
  88.     void setDodatkoweInformacje(std::string str1) {}
  89.    
  90.     void drukujWizytowke() {
  91.         Sportowiec::drukujWizytowke();
  92.         if (Sportowiec::isSetString(pozycja)) {
  93.             std::cout << "Pozycja Pilkarza: " << pozycja << std::endl;
  94.         }
  95.  
  96.         if (Sportowiec::isSetString(zespolLigowy)) {
  97.         std::cout << "Zespol Ligowy: " << zespolLigowy << std::endl;
  98.         }
  99.  
  100.     }
  101.  
  102.  
  103.  
  104.  
  105. };
  106.  
  107.  
  108.  
  109. class Plywak : public Sportowiec {
  110.  
  111. private:
  112.     std::string styl;
  113.     int idKlasy;
  114.  
  115. public:
  116.  
  117.     Plywak() {}
  118.     Plywak(std::string imie, std::string nazwisko, int wiek, std::string kraj) :
  119.         Sportowiec(imie, nazwisko, wiek, kraj, "pływanie") {
  120.         idKlasy = 1;
  121.     };
  122.  
  123.     int getIdKlasy() {
  124.         return idKlasy;
  125.     }
  126.  
  127.     void setDodatkoweInformacje(std::string str1, std::string str2) {};
  128.  
  129.     void setDodatkoweInformacje(std::string styl) {
  130.         this->styl = styl;
  131.  
  132.     }
  133.  
  134.    
  135.     void drukujWizytowke(){
  136.         Sportowiec::drukujWizytowke();
  137.         if (Sportowiec::isSetString(styl)) {
  138.             std::cout << "Styl z najwiekszymi osiagami: " << styl << std::endl;
  139.  
  140.         }
  141.  
  142.     }
  143.  
  144.  
  145.  
  146. };
  147.  
  148.  
  149.  
  150. class Zawody {
  151.  
  152. private:
  153.     std::string miejsce;
  154.     int liczbaZawodnikow;
  155.     Sportowiec* sportowcy[20];
  156.  
  157. public:
  158.  
  159.     Zawody(){}
  160.     Zawody(std::string miejsce) {
  161.         this->miejsce = miejsce;
  162.         liczbaZawodnikow = 0;
  163.     }
  164.  
  165.     void dodajZawodnika(Sportowiec *s) {
  166.         sportowcy[liczbaZawodnikow++] = s;
  167.  
  168.     }
  169.  
  170.  
  171.     friend std::ostream& operator << (std::ostream& out, Zawody& z) {
  172.         for (int i = 0; i < z.liczbaZawodnikow; i++) {
  173.             if( (z.sportowcy[i]->getIdKlasy()) == 0)
  174.                 out << *static_cast<Pilkarz *>(z.sportowcy[i]) << std::endl;
  175.  
  176.             else
  177.                 out << *static_cast<Plywak *>(z.sportowcy[i]) << std::endl;
  178.  
  179.         }
  180.        
  181.         return out;
  182.     }
  183.  
  184.  
  185. };
  186.  
  187.  
  188.  
  189. std::ostream& operator << (std::ostream& out, Sportowiec& s) {
  190.     s.drukujWizytowke();
  191.     return out;
  192. }
  193.  
  194. int main() {
  195.  
  196.     Pilkarz PanPilkarz1("Huan", "Gonzales", 16, "Norwegia");
  197.    
  198.     Pilkarz PanPilkarz2("Biorn", "Neallsoean", 28, "Boliwia");
  199.     PanPilkarz2.setDodatkoweInformacje("Napastnik", "Lecha Gdansk");
  200.  
  201.     Plywak PanPływak1("Mustafa", "Mufasa", 100, "Czechy");
  202.  
  203.     Plywak PanPływak2("Musta", "Mufa", 10, "Słowacja");
  204.  
  205.     PanPływak2.setDodatkoweInformacje("dowolny");
  206.    
  207.  
  208.     Zawody Zawody1("Kartuzy");
  209.     Zawody1.dodajZawodnika(&PanPilkarz1);
  210.     Zawody1.dodajZawodnika(&PanPilkarz2);
  211.     Zawody1.dodajZawodnika(&PanPływak1);
  212.     Zawody1.dodajZawodnika(&PanPływak2);
  213.  
  214.     std::cout << Zawody1;
  215.  
  216.  
  217.  
  218.  
  219.     system("PAUSE");
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement