Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. ***********elektrofahrzeug.cpp***********
  2. #include <iostream>
  3. #include "elektrofahrzeug.h"
  4. using namespace std;
  5.  
  6. void Elektrofahrzeug::ausgabe() {
  7. cout << "Maximale Energie: " << eMax << endl << "Durschnittsverbrauch: "
  8. << avgUse
  9. << endl << "Ladung: " << charge << endl << "Kilometerstand: "
  10. << kmStand << endl << "Höchstgeschwindigkeit: " << vMax << endl;
  11. }
  12.  
  13. float Elektrofahrzeug::giveEMax() {
  14. return eMax;
  15. }
  16. float Elektrofahrzeug::giveAvgUse() {
  17. return avgUse;
  18. }
  19. float Elektrofahrzeug::giveCharge() {
  20. return charge;
  21. }
  22. float Elektrofahrzeug::giveKmStand() {
  23. return kmStand;
  24. }
  25. int Elektrofahrzeug::giveVMax() {
  26. return vMax;
  27. }
  28. void Elektrofahrzeug::setAvgUse(float newAvgUse) {
  29. if (newAvgUse > 0) {
  30. avgUse = newAvgUse;
  31. } else {
  32. cout << "Fehler falsche Eingabe für Durchschnittsverbrauch" << endl;
  33. avgUse = 12.5;
  34. }
  35. }
  36.  
  37. void Elektrofahrzeug::setVMax(int newVMax) {
  38. if (newVMax > 0) {
  39. vMax = newVMax;
  40. } else {
  41. cout << "Fehler falsche Eingabe für Höchstgeschwindigkeit" << endl;
  42. vMax = 160;
  43. }
  44. }
  45.  
  46. void Elektrofahrzeug::setEMax(float newEMax) {
  47. if (newEMax > 0) {
  48. eMax = newEMax;
  49. if (newEMax < charge) {
  50. charge = newEMax;
  51. }
  52. } else {
  53. cout << "Fehler falsche Eingabe für maximale Energie" << endl;
  54. eMax = 80;
  55. }
  56. }
  57. void Elektrofahrzeug::setCharge(float newCharge) {
  58. if (newCharge >= 0 && newCharge <= eMax) {
  59. charge = newCharge;
  60. if (eMax < newCharge) {
  61. charge = eMax;
  62. }
  63. } else {
  64. cout << "Fehler falsche Eingabe für maximale Energie" << endl;
  65. eMax = 80;
  66. }
  67. }
  68. double Elektrofahrzeug::giveChargeStatus() {
  69. return (charge / eMax);
  70. }
  71. float Elektrofahrzeug::fullCharge() {
  72. float temp;
  73. temp = eMax - charge;
  74. charge = eMax;
  75. return (eMax - temp);
  76. }
  77. float Elektrofahrzeug::maximaleReichweite() {
  78. float temp;
  79. temp = 100 / avgUse; //Reichweite pro kW/h
  80. return (temp * charge);
  81. }
  82. float Elektrofahrzeug::verbrauchFuerStrecke(float strecke, float verbrauch) {
  83. float temp = verbrauch / 100; //Verbrauch für 1km
  84. return (temp * strecke);
  85. }
  86.  
  87.  
  88. *********elektrofahrzeug.h**********
  89. /*
  90. * elektrofahrzeug.h
  91. *
  92. * Created on: 05.12.2019
  93. * Author: smjowuch
  94. */
  95.  
  96. #ifndef ELEKTROFAHRZEUG_H_
  97. #define ELEKTROFAHRZEUG_H_
  98.  
  99. class Elektrofahrzeug {
  100. private:
  101. float eMax; //größer 0
  102. float avgUse; //größer 0
  103. float charge; //größer 0
  104. float kmStand; //nicht neg
  105. int vMax; //größer 0
  106.  
  107. public:
  108. //Konstruktoren
  109. Elektrofahrzeug() :
  110. eMax(80), avgUse(12.5), charge(50), kmStand(30000), vMax(160) {
  111. }
  112.  
  113. //Funktionen
  114. void ausgabe();
  115. float giveEMax();
  116. float giveAvgUse();
  117. float giveCharge();
  118. float giveKmStand();
  119. int giveVMax();
  120. void setAvgUse(float newAvgUse);
  121. void setVMax(int newVMax);
  122. void setEMax(float newEMax);
  123. void setCharge(float newCharge);
  124. double giveChargeStatus();
  125. float fullCharge();
  126. float maximaleReichweite();
  127. float verbrauchFuerStrecke(float strecke, float verbrauch);
  128. };
  129.  
  130. #endif /* ELEKTROFAHRZEUG_H_ */
  131.  
  132.  
  133. ******blatt07.cpp**********
  134. #include <iostream>
  135. using namespace std;
  136. #include "elektrofahrzeug.h"
  137.  
  138. int main() {
  139.  
  140. Elektrofahrzeug eAuto;
  141. eAuto.ausgabe();
  142.  
  143. return 0;
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement