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:
@@ -0,0 +1,52 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
#include<iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class KFZ
|
||||
{
|
||||
protected:
|
||||
string marke;
|
||||
int kmstand;
|
||||
};
|
||||
|
||||
class Auto : public KFZ
|
||||
{
|
||||
private:
|
||||
int passagiere;
|
||||
public:
|
||||
Auto()
|
||||
{
|
||||
cout << "Neues Auto wird erstellt." << endl;
|
||||
cout << "Marke: ";
|
||||
cin >> marke;
|
||||
cout << "Passagiere: ";
|
||||
cin >> passagiere;
|
||||
}
|
||||
|
||||
void einsteigen(int personen)
|
||||
{
|
||||
passagiere += personen;
|
||||
}
|
||||
|
||||
void ausgabe()
|
||||
{
|
||||
cout << "Marke: " << marke << endl;
|
||||
cout << "Passagiere: " << passagiere << endl;
|
||||
}
|
||||
};
|
||||
|
||||
class LKW : public KFZ
|
||||
{
|
||||
private:
|
||||
float tonnen;
|
||||
public:
|
||||
LKW()
|
||||
{
|
||||
cout << "Neuer LKW wird erstellt." << endl;
|
||||
cout << "Marke: ";
|
||||
cin >> marke;
|
||||
cout << "Tonnen: ";
|
||||
cin >> tonnen;
|
||||
}
|
||||
|
||||
void beladen(float gewicht)
|
||||
{
|
||||
tonnen += gewicht;
|
||||
}
|
||||
|
||||
void ausgabe()
|
||||
{
|
||||
cout << "Marke: " << marke << endl;
|
||||
cout << "Tonnen: " << tonnen << endl;
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
Auto autos[3] = Auto();
|
||||
LKW lkws[2] = LKW();
|
||||
|
||||
int personen;
|
||||
float gewicht;
|
||||
|
||||
cout << endl << endl;
|
||||
|
||||
for(int i = 0; i<3; i++)
|
||||
{
|
||||
cout << "Auto Nr. " << i+1 << endl;
|
||||
cout << "Anzahl Personen die einsteigen: ";
|
||||
cin >> personen;
|
||||
autos[i].einsteigen(personen);
|
||||
}
|
||||
|
||||
for(int i = 0; i<2; i++)
|
||||
{
|
||||
cout << "LKW Nr. " << i+1 << endl;
|
||||
cout << "Beladen des LKWs. Gewicht in Tonnen angeben: ";
|
||||
cin >> gewicht;
|
||||
lkws[i].beladen(gewicht);
|
||||
}
|
||||
|
||||
cout << endl << endl;
|
||||
|
||||
for(int i = 0; i <3; i++)
|
||||
{
|
||||
cout << "Ausgabe Auto Nr. " << i+1 << endl;
|
||||
autos[i].ausgabe();
|
||||
}
|
||||
|
||||
for(int i = 0; i <2; i++)
|
||||
{
|
||||
cout << "Ausgabe LKW Nr. " << i+1 << endl;
|
||||
lkws[i].ausgabe();
|
||||
}
|
||||
|
||||
system("pause");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user