mirror of
https://inf-git.fh-rosenheim.de/studavrije7683/cplusplus-training.git
synced 2025-04-20 02:59:55 +00:00
52 lines
836 B
C++
52 lines
836 B
C++
#include<iostream>
|
|
#include <cstdlib>
|
|
|
|
using namespace std;
|
|
|
|
class Auto
|
|
{
|
|
private:
|
|
string marke;
|
|
int kilometerstand;
|
|
static int anzahl_fahrten;
|
|
|
|
public:
|
|
Auto(string m, int k) : marke(m), kilometerstand(k) { }
|
|
~Auto()
|
|
{
|
|
cout << endl << "Objekt entfernt. " << endl;
|
|
}
|
|
|
|
void fahren(int gefahren) //Deklaration und Definition der Methode Daten_abfragen
|
|
{
|
|
kilometerstand += gefahren;
|
|
anzahl_fahrten++;
|
|
}
|
|
|
|
void daten_ausgeben()
|
|
{
|
|
cout << marke << ", aktueller Kilometerstand: " << kilometerstand << endl;
|
|
cout << "Anzahl an Fahrten: " << anzahl_fahrten << endl;
|
|
}
|
|
|
|
};
|
|
|
|
int Auto::anzahl_fahrten = 0;
|
|
|
|
int main()
|
|
{
|
|
Auto bmw("BMW",1500);
|
|
bmw.fahren(70);
|
|
bmw.daten_ausgeben();
|
|
bmw.fahren(80);
|
|
bmw.daten_ausgeben();
|
|
bmw.fahren(250);
|
|
bmw.daten_ausgeben();
|
|
|
|
cout << endl << endl;
|
|
|
|
system("PAUSE");
|
|
return 0;
|
|
}
|
|
|