Falu

Untitled

Jun 25th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Jacht
  6. {
  7. public:
  8.  
  9.     Jacht():liczbaZagli(0)
  10.     {
  11.  
  12.     }
  13.  
  14.     Jacht(int zagle):liczbaZagli(0)
  15.     {
  16.         ustawLiczbeZagli(zagle);
  17.     }
  18.  
  19.     void ustawLiczbeZagli(int zagle)
  20.     {
  21.         if(zagle >0) liczbaZagli=zagle;
  22.     }
  23.  
  24.     int getLiczbaZagli()
  25.     {
  26.         return liczbaZagli;
  27.     }
  28.  
  29.     virtual void pokazInfo()
  30.     {
  31.         cout<<"Ilosc zagli = " <<liczbaZagli<<endl;
  32.     }
  33. private:
  34.  
  35.     int liczbaZagli;
  36. };
  37.  
  38. class JachtMotorowy : public Jacht
  39. {
  40. public:
  41.  
  42.     JachtMotorowy(): pojemnoscSilnika(0)
  43.     {
  44.  
  45.     }
  46.  
  47.     JachtMotorowy(int pojemnosc): pojemnoscSilnika(0)
  48.     {
  49.         ustawPojemnoscSilnika(pojemnosc);
  50.     }
  51.  
  52.     void ustawPojemnoscSilnika(int poj)
  53.     {
  54.         if(poj>0) pojemnoscSilnika=poj;
  55.     }
  56.  
  57.     double getPojemnoscSilnika()
  58.     {
  59.         return pojemnoscSilnika;
  60.     }
  61.  
  62.     virtual void pokazInfo()override{
  63.         cout<<"Pojemnosc silnika = " <<pojemnoscSilnika<<endl;
  64.     }
  65.  
  66. private:
  67.    double pojemnoscSilnika;
  68. };
  69.  
  70.  
  71. int main()
  72. {
  73.     Jacht *tab[4];
  74.    tab[ 0 ] = new Jacht( 2 );
  75.    tab[ 1 ] = new JachtMotorowy( 3000 );
  76.    tab[ 2 ] = new Jacht( 4 );
  77.    tab[ 3 ] = new JachtMotorowy( 5000 );
  78.  
  79.    for( int i = 0; i < 4; ++i  )   tab[ i ]->pokazInfo();
  80.  
  81.     delete [] tab;
  82.  
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment