Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. class Sportowiec
  6. {
  7.     private:
  8.     string imieinazwisko, plec, dyscyplina;
  9.     int wiek;
  10.     bool medale;
  11.    
  12.     public:
  13.    
  14.     void disp()
  15.     {
  16.         string med;
  17.         if (medale == true) med = "Tak";
  18.         else med = "Nie";
  19.         cout << setw(20) << left << "Imie i nazwisko" << setw(10) << left << "Plec" << setw(6) << left << "Wiek" << setw(10) << left << "Medale" << setw(15) << left << "Dyscyplina" << endl;
  20.         cout << setw(20) << left << imieinazwisko << setw(10) << left << plec << setw(6) << left << wiek << setw(10) << left << med << setw(15) << left << dyscyplina << endl;
  21.     }
  22.    
  23.     Sportowiec()
  24.     {
  25.         imieinazwisko = "Jan Nowak";
  26.         plec = "Mezczyzna";
  27.         wiek = 22;
  28.         medale = 0;
  29.         dyscyplina = "Tyczkarz";
  30.         cout << "Konstruktor domyslny klasy sportowiec zostal wywolany" << endl;
  31.     }
  32.    
  33.     Sportowiec(string i, string p, int w, bool m, string d)
  34.     {
  35.         imieinazwisko = i;
  36.         plec = p;
  37.         wiek = w;
  38.         medale = m;
  39.         dyscyplina = d;
  40.         cout << "Konstruktor parametryczny klasy sportowiec zostal wywolany" << endl;
  41.     }
  42.        
  43.     void Nagroda()
  44.     {
  45.         if(medale==false) medale = true;
  46.     }
  47. };
  48.  
  49. class Sprinter:public Sportowiec
  50. {
  51.     private:
  52.     float rek60, wyn60, rek100, wyn100;
  53.     public:
  54.     void wyswietl()
  55.     {
  56.         Sportowiec::disp();
  57.         cout << endl;
  58.         cout << setw(15) << left << "Rekord na 60m" << setw(15) << left << "Ostatni na 60m" << setw(15) << left << "Rekord na 100m" << setw(15) << left << "Ostatni na 100m" <<  endl;
  59.         cout << setw(15) << left << rek60 << setw(15) << left << wyn60 << setw(15) << left << rek100 << setw(15) << left << wyn100 << endl;
  60.     }
  61.    
  62.     Sprinter():Sportowiec()
  63.     {
  64.         rek60 = 0;
  65.         wyn60 = 0;
  66.         rek100 = 0;
  67.         wyn100 = 0;
  68.         cout << "Konstruktor domyslny klasy sprinter zostal wywolany" << endl; 
  69.     }  
  70.    
  71.     Sprinter(float r60, float w60, float r100, float w100, string i, string p, int w, bool m, string d):Sportowiec(i,p,w,m,d)
  72.     {
  73.         rek60 = r60;
  74.         wyn60 = w60;
  75.         rek100 = r100;
  76.         wyn100 = w100;
  77.         cout << "Konstruktor parametryczny klasy sprinter zostal wywolany" << endl;
  78.     }
  79.        
  80.     void Nowy()
  81.     {
  82.         float dyst, czas;
  83.         cout << "Podaj dystant biegu (wpisz ""60"" lub ""100""):";
  84.         cin >> dyst;
  85.         cout << "Podaj czas biegu:";
  86.         cin >> czas;
  87.         if(dyst==60)
  88.         {
  89.             wyn60 = czas;
  90.             if(czas<rek60) rek60 = czas;
  91.         }
  92.         else if(dyst==100)
  93.         {
  94.             wyn100 = czas;
  95.             if(czas<rek100) rek100 = czas;
  96.         }
  97.         else cout << "Podano niepoprawny dystans!" << endl;
  98.     }
  99. };
  100.  
  101.  
  102. int main(int argc, char** argv)
  103. {
  104.     Sportowiec s1;
  105.     s1.disp();
  106.     s1.Nagroda();
  107.     s1.disp();
  108.     cout << endl;
  109.     Sprinter sp1(10,11,13,14,"Kazimierz Wielki","Mezczyzna",30,true,"Sprinter");
  110.     sp1.wyswietl();
  111.     sp1.Nowy();
  112.     sp1.wyswietl();
  113.     return 0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement