cplusplus-training/Teil_1/9. Vererbung/Lösungen/Loesung Uebung 1 - Tier.cpp
2021-10-15 08:36:02 +02:00

53 lines
939 B
C++

#include <iostream>
#include <cstdlib>
using namespace std;
class Tier
{
protected:
float anzahl;
public:
Tier(){};//Defaultkonstruktor
Tier (int anz):anzahl(anz){}; //Konstruktor mit Elementinitialisierungsliste
};
class Schlachtvieh: public Tier
{
private:
float gewicht;
public:
Schlachtvieh(int anz, float gew):Tier(anz),gewicht(gew){};
void datenausgeben()
{
cout << "Es sind " << anzahl << " Tiere mit je " << gewicht << " kg vorhanden" << endl;
}
};
class Milchvieh: public Tier
{
private:
float milchleistung;
public:
Milchvieh(int anz, float m_l):Tier(anz), milchleistung(m_l){};
void datenausgeben()
{
cout << "Es sind " << anzahl << " Tiere mit durchschnittlicher Milchleistung von " << milchleistung << " l vorhanden"<<endl;
}
};
int main()
{
Schlachtvieh Schwein(100,50);
Schwein.datenausgeben();
Milchvieh Kuh(25,5);
Kuh.datenausgeben();
system("PAUSE");
return 0;
}