mirror of
https://inf-git.fh-rosenheim.de/studavrije7683/cplusplus-training.git
synced 2025-04-10 22:29:55 +00:00
save mid chapter 7
This commit is contained in:
parent
d76e6b7ffc
commit
c572dac718
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@ -1,6 +1,8 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"iterator": "cpp",
|
||||
"iostream": "cpp"
|
||||
"iostream": "cpp",
|
||||
"tuple": "cpp",
|
||||
"xutility": "cpp"
|
||||
}
|
||||
}
|
65
Teil_1/7. Das Klassenkonzept/Uebung 1 - Bauernhof.cpp
Normal file
65
Teil_1/7. Das Klassenkonzept/Uebung 1 - Bauernhof.cpp
Normal 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;
|
||||
}
|
BIN
Teil_1/7. Das Klassenkonzept/Uebung 1 - Bauernhof.exe
Normal file
BIN
Teil_1/7. Das Klassenkonzept/Uebung 1 - Bauernhof.exe
Normal file
Binary file not shown.
68
Teil_1/7. Das Klassenkonzept/Uebung 2 - Tiere.cpp
Normal file
68
Teil_1/7. Das Klassenkonzept/Uebung 2 - Tiere.cpp
Normal 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;
|
||||
}
|
BIN
Teil_1/7. Das Klassenkonzept/Uebung 2 - Tiere.exe
Normal file
BIN
Teil_1/7. Das Klassenkonzept/Uebung 2 - Tiere.exe
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user