Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <list>
- #include <cstring>
- using namespace std;
- class Samochod
- {
- public:
- string nazwa;
- float masa;
- int liczbaAkumulatorow;
- Samochod() { liczbaAkumulatorow=1;masa=1000;nazwa="Zwykly";}
- virtual float ZuzyciePaliwa(){ return 0.0;}
- virtual int ZwrocLiczbeAkumulatorow(){ return 1;}
- virtual string ZwrocNazwe() { return nazwa;}
- };
- class Elektryczny :public Samochod
- {
- public:
- int dodatkoweAkumulatory;
- Elektryczny() { liczbaAkumulatorow=1;dodatkoweAkumulatory=2;nazwa="Elektryczny";masa=800;}
- Elektryczny(int k,string n) { liczbaAkumulatorow=1;dodatkoweAkumulatory=k;nazwa=n;}
- //float ZucyciePaliwa(){ return 0;}
- int ZwrocLiczbeAkumulatorow(){ return (liczbaAkumulatorow+dodatkoweAkumulatory);}
- };
- class Ropiak :public Samochod
- {
- public:
- Ropiak() {nazwa="Ropiak";masa=1000;}
- Ropiak(float m,string n) {masa=m;nazwa=n;}
- //int ZwrocLiczbeAkumulatorow(){ return liczbaAkumulatorow;}
- float ZuzyciePaliwa(){ return 3*masa;}
- };
- int main()
- {
- list<Samochod*> lst;
- lst.push_back(new Elektryczny(2,"Elektryczny.1"));
- lst.push_back(new Elektryczny(4,"Elektryczny.2"));
- lst.push_back(new Ropiak(1234,"Ropiak.1"));
- lst.push_back(new Ropiak(2300,"Ropiak.2"));
- for(Samochod *sam:lst)
- {
- cout<<"Nazwa: "<<sam->ZwrocNazwe()<<" liczba akumulatorow "<<sam->ZwrocLiczbeAkumulatorow()<<" Zuczycie paliwa:"<<sam->ZuzyciePaliwa()<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement