Guest User

Untitled

a guest
Oct 17th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class Auto{
  4. public:
  5. Auto(int tankgroesse, float tankinhalt, float verbrauch);
  6.  
  7. void info()const;
  8.  
  9. bool fahren(int km);
  10. void tanken(float liter);
  11.  
  12. private:
  13. int tankgroesse_;
  14. float tankinhalt_;
  15. float verbrauch_;
  16. };
  17.  
  18. Auto::Auto(int tankgroesse, float tankinhalt, float verbrauch):
  19. tankgroesse_(tankgroesse),
  20. tankinhalt_(tankinhalt),
  21. verbrauch_(verbrauch)
  22. {}
  23.  
  24. void Auto::info()const{
  25. std::cout << "In den Tank passen " << tankgroesse_ << " Liter Treibstoff.\n";
  26. std::cout << "Aktuell sind noch " << tankinhalt_ << " Liter im Tank.\n";
  27. std::cout << "Der Wagen verbraucht " << verbrauch_ << " Liter pro 100 km.\n";
  28. std::cout << std::endl;
  29. }
  30.  
  31. bool Auto::fahren(int km){
  32. std::cout << "Fahre " << km << " km.\n";
  33. tankinhalt_ -= verbrauch_*km/100;
  34.  
  35. if(tankinhalt_ < 0.0f){
  36. tankinhalt_ = 0.0f;
  37.  
  38. std::cout << "Mit dem aktuellen Tankinhalt schaffen Sie die Fahrt leider nicht.\n";
  39. std::cout << "Der Wagen ist unterwegs liegengeblieben, Zeit zu tanken!\n";
  40. }
  41.  
  42. std::cout << std::endl;
  43. }
Add Comment
Please, Sign In to add comment