#include #include using namespace std; class Tier { // class-> members are private by default | struct -> members are public by default // float Einnahme = 0; // 3 globale Variablenen deklarieren und initialisieren private: float Gewicht = 0; float Tagespreis = 0; public: Tier(/**float Einnahme,**/ float Gewicht, float Tagespreis) { // this->Einnahme = Einnahme; this->Gewicht = Gewicht; this->Tagespreis = Tagespreis; } float getEinnahme() { return this->Gewicht * this->Tagespreis; } float getGewicht() { return this->Gewicht; } float getTagespreis() { return this->Tagespreis; } }; Tier* Daten_abfragen() // Deklaration und Definition der Methode Daten_abfragen { float tages_preis = 0, gewicht = 0; cout << "Wie steht der Tagespreis? " << endl; cin >> tages_preis; cout << "Wie ist das Gewicht? " << endl; cin >> gewicht; Tier *tier = new Tier(tages_preis, gewicht); return tier; } void Einnahme_berechnen(Tier *tier) // Deklaration und Definition der Methode Einnahme_berechnen { cout << "Einnahme: " << tier->getEinnahme() << endl; } int main() { Tier *tiere[2]; tiere[0] = Daten_abfragen(); // Methodenaufrufe tiere[1] = Daten_abfragen(); // Methodenaufrufe Einnahme_berechnen(tiere[0]); Einnahme_berechnen(tiere[1]); cout << endl << endl; for(Tier *tier:tiere) delete tier; system("PAUSE"); return 0; }