mirror of
https://inf-git.fh-rosenheim.de/studavrije7683/cplusplus-training.git
synced 2026-06-29 01:23:21 +00:00
save mid chapter 7
This commit is contained in:
Vendored
+3
-1
@@ -1,6 +1,8 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"iterator": "cpp",
|
||||
"iostream": "cpp"
|
||||
"iostream": "cpp",
|
||||
"tuple": "cpp",
|
||||
"xutility": "cpp"
|
||||
}
|
||||
}
|
||||
@@ -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.
@@ -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.
Reference in New Issue
Block a user