Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // laborki 5.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <conio.h>
- #include <vector>
- class DoRegulacjiWysokosci
- {
- public:
- float wysokosc;
- virtual void ZmienWysokoscO(const float o);
- virtual const float Wysokosc() const;
- };
- class DoWyswietlaniaStanu
- {
- public:
- virtual void WyswietlStan() const;
- };
- class SrodekTransportu : public DoRegulacjiWysokosci, public DoWyswietlaniaStanu
- {
- };
- void ZmienWysokoscO(std::vector<SrodekTransportu*> &T,const float o)
- {
- std::vector<SrodekTransportu*>::const_iterator it=T.begin();
- std::vector<SrodekTransportu*>::const_iterator endit=T.end();
- for(; it !=endit; ++it)
- {
- (*it)->ZmienWysokoscO(o);
- (*it)->WyswietlStan();
- }
- }
- ////////////////////
- class Samochod : public SrodekTransportu
- {
- void ZmienWysokoscO(const float o);
- const float Wysokosc() const;
- void WyswietlStan() const;
- };
- void Samochod::ZmienWysokoscO(float o)
- {
- Samochod::wysokosc=0;
- }
- const float Samochod::Wysokosc() const
- {
- return Samochod::wysokosc;
- }
- void Samochod::WyswietlStan() const
- {
- printf("Samochod - Wysokosc :%f", Wysokosc());
- }
- //////////////////////////
- class Samolot : public SrodekTransportu
- {
- void ZmienWysokoscO(const float o);
- const float Wysokosc() const;
- void WyswietlStan() const;
- };
- void Samolot::ZmienWysokoscO(const float o)
- {
- if(o>0) Samolot::wysokosc=o;
- if(o<=0) Samolot::wysokosc=0;
- }
- const float Samolot::Wysokosc() const
- {
- return Samolot::wysokosc;
- }
- void Samolot::WyswietlStan() const
- {
- printf("Samolot - Wysokosc :%f", Wysokosc());
- }
- ////////////////////////////////
- class OkretPodwodny : public SrodekTransportu
- {
- void ZmienWysokoscO(const float o);
- const float Wysokosc() const;
- void WyswietlStan() const;
- };
- void OkretPodwodny::ZmienWysokoscO(const float o)
- {
- if(o<0) OkretPodwodny::wysokosc=o;
- if(o>=0) OkretPodwodny::wysokosc=0;
- }
- const float OkretPodwodny::Wysokosc() const
- {
- return OkretPodwodny::wysokosc;
- }
- void OkretPodwodny::WyswietlStan() const
- {
- printf("Okret Podwodny - Glebokosc :%f", Wysokosc());
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- OkretPodwodny *A1;
- OkretPodwodny *A2;
- OkretPodwodny *A3;
- Samolot *A4;
- Samolot *A5;
- Samolot *A6;
- Samochod *A7;
- Samochod *A8;
- Samochod *A9;
- std::vector<SrodekTransportu*> T;
- T.push_back(A1);
- T.push_back(A2);
- T.push_back(A3);
- T.push_back(A4);
- T.push_back(A5);
- T.push_back(A6);
- T.push_back(A7);
- T.push_back(A8);
- T.push_back(A9);
- ZmienWysokoscO(T,1);
- _getch();
- return 0;
- }
Add Comment
Please, Sign In to add comment