mirror of
https://inf-git.fh-rosenheim.de/studavrije7683/cplusplus-training.git
synced 2025-04-20 02:39:56 +00:00
53 lines
939 B
C++
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;
|
|
}
|
|
|