Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ***********elektrofahrzeug.cpp***********
- #include <iostream>
- #include "elektrofahrzeug.h"
- using namespace std;
- void Elektrofahrzeug::ausgabe() {
- cout << "Maximale Energie: " << eMax << endl << "Durschnittsverbrauch: "
- << avgUse
- << endl << "Ladung: " << charge << endl << "Kilometerstand: "
- << kmStand << endl << "Höchstgeschwindigkeit: " << vMax << endl;
- }
- float Elektrofahrzeug::giveEMax() {
- return eMax;
- }
- float Elektrofahrzeug::giveAvgUse() {
- return avgUse;
- }
- float Elektrofahrzeug::giveCharge() {
- return charge;
- }
- float Elektrofahrzeug::giveKmStand() {
- return kmStand;
- }
- int Elektrofahrzeug::giveVMax() {
- return vMax;
- }
- void Elektrofahrzeug::setAvgUse(float newAvgUse) {
- if (newAvgUse > 0) {
- avgUse = newAvgUse;
- } else {
- cout << "Fehler falsche Eingabe für Durchschnittsverbrauch" << endl;
- avgUse = 12.5;
- }
- }
- void Elektrofahrzeug::setVMax(int newVMax) {
- if (newVMax > 0) {
- vMax = newVMax;
- } else {
- cout << "Fehler falsche Eingabe für Höchstgeschwindigkeit" << endl;
- vMax = 160;
- }
- }
- void Elektrofahrzeug::setEMax(float newEMax) {
- if (newEMax > 0) {
- eMax = newEMax;
- if (newEMax < charge) {
- charge = newEMax;
- }
- } else {
- cout << "Fehler falsche Eingabe für maximale Energie" << endl;
- eMax = 80;
- }
- }
- void Elektrofahrzeug::setCharge(float newCharge) {
- if (newCharge >= 0 && newCharge <= eMax) {
- charge = newCharge;
- if (eMax < newCharge) {
- charge = eMax;
- }
- } else {
- cout << "Fehler falsche Eingabe für maximale Energie" << endl;
- eMax = 80;
- }
- }
- double Elektrofahrzeug::giveChargeStatus() {
- return (charge / eMax);
- }
- float Elektrofahrzeug::fullCharge() {
- float temp;
- temp = eMax - charge;
- charge = eMax;
- return (eMax - temp);
- }
- float Elektrofahrzeug::maximaleReichweite() {
- float temp;
- temp = 100 / avgUse; //Reichweite pro kW/h
- return (temp * charge);
- }
- float Elektrofahrzeug::verbrauchFuerStrecke(float strecke, float verbrauch) {
- float temp = verbrauch / 100; //Verbrauch für 1km
- return (temp * strecke);
- }
- *********elektrofahrzeug.h**********
- /*
- * elektrofahrzeug.h
- *
- * Created on: 05.12.2019
- * Author: smjowuch
- */
- #ifndef ELEKTROFAHRZEUG_H_
- #define ELEKTROFAHRZEUG_H_
- class Elektrofahrzeug {
- private:
- float eMax; //größer 0
- float avgUse; //größer 0
- float charge; //größer 0
- float kmStand; //nicht neg
- int vMax; //größer 0
- public:
- //Konstruktoren
- Elektrofahrzeug() :
- eMax(80), avgUse(12.5), charge(50), kmStand(30000), vMax(160) {
- }
- //Funktionen
- void ausgabe();
- float giveEMax();
- float giveAvgUse();
- float giveCharge();
- float giveKmStand();
- int giveVMax();
- void setAvgUse(float newAvgUse);
- void setVMax(int newVMax);
- void setEMax(float newEMax);
- void setCharge(float newCharge);
- double giveChargeStatus();
- float fullCharge();
- float maximaleReichweite();
- float verbrauchFuerStrecke(float strecke, float verbrauch);
- };
- #endif /* ELEKTROFAHRZEUG_H_ */
- ******blatt07.cpp**********
- #include <iostream>
- using namespace std;
- #include "elektrofahrzeug.h"
- int main() {
- Elektrofahrzeug eAuto;
- eAuto.ausgabe();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement