Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Jacht
- {
- public:
- Jacht():liczbaZagli(0)
- {
- }
- Jacht(int zagle):liczbaZagli(0)
- {
- ustawLiczbeZagli(zagle);
- }
- void ustawLiczbeZagli(int zagle)
- {
- if(zagle >0) liczbaZagli=zagle;
- }
- int getLiczbaZagli()
- {
- return liczbaZagli;
- }
- virtual void pokazInfo()
- {
- cout<<"Ilosc zagli = " <<liczbaZagli<<endl;
- }
- private:
- int liczbaZagli;
- };
- class JachtMotorowy : public Jacht
- {
- public:
- JachtMotorowy(): pojemnoscSilnika(0)
- {
- }
- JachtMotorowy(int pojemnosc): pojemnoscSilnika(0)
- {
- ustawPojemnoscSilnika(pojemnosc);
- }
- void ustawPojemnoscSilnika(int poj)
- {
- if(poj>0) pojemnoscSilnika=poj;
- }
- double getPojemnoscSilnika()
- {
- return pojemnoscSilnika;
- }
- virtual void pokazInfo()override{
- cout<<"Pojemnosc silnika = " <<pojemnoscSilnika<<endl;
- }
- private:
- double pojemnoscSilnika;
- };
- int main()
- {
- Jacht *tab[4];
- tab[ 0 ] = new Jacht( 2 );
- tab[ 1 ] = new JachtMotorowy( 3000 );
- tab[ 2 ] = new Jacht( 4 );
- tab[ 3 ] = new JachtMotorowy( 5000 );
- for( int i = 0; i < 4; ++i ) tab[ i ]->pokazInfo();
- delete [] tab;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment