save mid chapter 7

This commit is contained in:
Jean Jacques Avril 2021-10-20 11:18:09 +02:00
parent d76e6b7ffc
commit c572dac718
5 changed files with 136 additions and 1 deletions

View File

@ -1,6 +1,8 @@
{
"files.associations": {
"iterator": "cpp",
"iostream": "cpp"
"iostream": "cpp",
"tuple": "cpp",
"xutility": "cpp"
}
}

View File

@ -0,0 +1,65 @@
#include <iostream>
#include <cstdlib>
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 *ein_tier;
ein_tier = Daten_abfragen(); // Methodenaufrufe
Einnahme_berechnen(ein_tier);
cout << endl
<< endl;
delete ein_tier;
system("PAUSE");
return 0;
}

Binary file not shown.

View File

@ -0,0 +1,68 @@
#include <iostream>
#include <cstdlib>
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;
}

Binary file not shown.