Advertisement
ruchamcimatke

asdf

May 23rd, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <list>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. class Samochod
  10. {
  11. public:
  12.  
  13. string nazwa;
  14. float masa;
  15. int liczbaAkumulatorow;
  16. Samochod() { liczbaAkumulatorow=1;masa=1000;nazwa="Zwykly";}
  17. virtual float ZuzyciePaliwa(){ return 0.0;}
  18. virtual int ZwrocLiczbeAkumulatorow(){ return 1;}
  19. virtual string ZwrocNazwe() { return nazwa;}
  20. };
  21.  
  22.  
  23. class Elektryczny :public Samochod
  24. {
  25. public:
  26. int dodatkoweAkumulatory;
  27. Elektryczny() { liczbaAkumulatorow=1;dodatkoweAkumulatory=2;nazwa="Elektryczny";masa=800;}
  28. Elektryczny(int k,string n) { liczbaAkumulatorow=1;dodatkoweAkumulatory=k;nazwa=n;}
  29. //float ZucyciePaliwa(){ return 0;}
  30. int ZwrocLiczbeAkumulatorow(){ return (liczbaAkumulatorow+dodatkoweAkumulatory);}
  31. };
  32.  
  33.  
  34. class Ropiak :public Samochod
  35. {
  36.  
  37. public:
  38. Ropiak() {nazwa="Ropiak";masa=1000;}
  39. Ropiak(float m,string n) {masa=m;nazwa=n;}
  40. //int ZwrocLiczbeAkumulatorow(){ return liczbaAkumulatorow;}
  41. float ZuzyciePaliwa(){ return 3*masa;}
  42. };
  43.  
  44.  
  45. int main()
  46. {
  47. list<Samochod*> lst;
  48. lst.push_back(new Elektryczny(2,"Elektryczny.1"));
  49. lst.push_back(new Elektryczny(4,"Elektryczny.2"));
  50. lst.push_back(new Ropiak(1234,"Ropiak.1"));
  51. lst.push_back(new Ropiak(2300,"Ropiak.2"));
  52. for(Samochod *sam:lst)
  53. {
  54. cout<<"Nazwa: "<<sam->ZwrocNazwe()<<" liczba akumulatorow "<<sam->ZwrocLiczbeAkumulatorow()<<" Zuczycie paliwa:"<<sam->ZuzyciePaliwa()<<endl;
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement