mirror of
https://inf-git.fh-rosenheim.de/studavrije7683/cplusplus-training.git
synced 2026-06-29 01:23:21 +00:00
Initial commit
This commit is contained in:
+54
@@ -0,0 +1,54 @@
|
||||
#include<iostream>
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Tier
|
||||
{
|
||||
|
||||
private:
|
||||
float Einnahme;
|
||||
float Gewicht;
|
||||
float Tagespreis;
|
||||
|
||||
void Daten_abfragen() //Deklaration und Definition der Methode Daten_abfragen
|
||||
{
|
||||
cout << "Wie steht der Tagespreis? " << endl;
|
||||
cin >> Tagespreis;
|
||||
cout << "Wie ist das Gewicht? " << endl;
|
||||
cin >> Gewicht;
|
||||
}
|
||||
|
||||
public:
|
||||
//Konstruktor
|
||||
Tier()
|
||||
{
|
||||
Daten_abfragen();
|
||||
};
|
||||
Tier(float g, float t):Gewicht(g), Tagespreis(t){ }
|
||||
|
||||
//Methode
|
||||
void Einnahme_berechnen() //Deklaration und Definition der Methode Einnahme_berechnen
|
||||
{
|
||||
Einnahme = Gewicht*Tagespreis;
|
||||
cout << "Einnahme: " << Einnahme << endl;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
Tier schwein(19,2.5);
|
||||
cout << "Schwein ";
|
||||
schwein.Einnahme_berechnen();
|
||||
|
||||
Tier kuh;
|
||||
cout << "Kuh ";
|
||||
kuh.Einnahme_berechnen();
|
||||
|
||||
cout << endl << endl;
|
||||
|
||||
system("PAUSE");
|
||||
return 0;
|
||||
}
|
||||
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user