Advertisement
Guest User

Untitled

a guest
Apr 16th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.41 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. class Sportowiec {
  4. protected:
  5.     std::string imie;
  6.     std::string nazwisko;
  7.     int wiek;
  8.     std::string kraj;
  9.     std::string dyscyplina;
  10. public:
  11.     Sportowiec(std::string imie, std::string nazwisko,int wiek,std::string kraj, std::string dyscyplina) {
  12.         this->imie = imie;
  13.         this->nazwisko = nazwisko;
  14.         this->wiek = wiek;
  15.         this->kraj = kraj;
  16.         this->dyscyplina = dyscyplina;
  17.     };
  18.  
  19.     virtual void setDodatkoweInfromacja(std::string arg1, std::string arg2) = 0;
  20.  
  21.     bool isSetString(std::string arg1) {
  22.         if (arg1.length() > 0) {
  23.             return true;
  24.         }
  25.         else return false;
  26.     }
  27.  
  28.     virtual std::string drukujWizytowke() {
  29.         std::cout << "Imie: " << imie << std::endl;
  30.         std::cout << "Nazwisko: " << nazwisko << std::endl;
  31.         std::cout << "Wiek: " << wiek << std::endl;
  32.         std::cout << "Kraj: " << kraj << std::endl;
  33.         std::cout << "Dyscyplina: " << dyscyplina << std::endl;
  34.     }
  35.     friend std::ostream & operator << (std::ostream &out, Sportowiec &s);
  36. };
  37.  
  38. class Pilkarz : public Sportowiec {
  39. private:
  40.     std::string pozycja;
  41.     std::string zespolLigowy;
  42. public:
  43.     Pilkarz(std::string imie, std::string nazwisko, int wiek, std::string kraj, std::string dyscyplina) : Sportowiec(imie, nazwisko, wiek, kraj, "pilka nozna") {}
  44.    
  45.     void setDodatkoweInfromacja(std::string arg1, std::string arg2) {
  46.         this->pozycja = arg1;
  47.         this->zespolLigowy = arg2;
  48.     }
  49.  
  50.     std::string drukujWizytowke() {
  51.         Sportowiec::drukujWizytowke();
  52.  
  53.         if (isSetString(pozycja))
  54.         {
  55.             std::cout << "Pozycja: " << pozycja << std::endl;
  56.         }
  57.         if (isSetString(zespolLigowy))
  58.         {
  59.             std::cout << "Zespol ligowy: " << zespolLigowy << std::endl;
  60.         }
  61.     }
  62. };
  63.  
  64. class Plywak : public Sportowiec {
  65. private:
  66.     std::string styl;
  67. public:
  68.     Plywak(const std::string imie, std::string nazwisko, int wiek, std::string kraj, std::string dyscyplina) : Sportowiec(imie, nazwisko, wiek, kraj, "plywanie") {}
  69.  
  70.      void setDodatkoweInformacje(std::string arg) {
  71.         this->styl = arg;
  72.     }
  73.  
  74.      std::string drukujWizytowke() {
  75.          Sportowiec::drukujWizytowke();
  76.  
  77.          if (isSetString(styl))
  78.          {
  79.              std::cout << "Styl: " << styl << std::endl;
  80.          }
  81.      }
  82. };
  83.  
  84. std::ostream & operator << (std::ostream &out, Sportowiec &s) {
  85.     return out << s.drukujWizytowke();
  86. }
  87. using namespace std;
  88. int main()
  89. {
  90.    
  91.  
  92.     Pilkarz nowy1("Seba" ,"Nowak", 18, "polska");
  93.     nowy1.setDodatkoweInfromacja("napastnik", "");
  94.     Plywak nowy2("Damian", "Kowall");
  95.    
  96.     return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement