mirror of https://github.com/Askill/AP-SCE.git
Converted 1.1.3 to OO
This commit is contained in:
parent
5de4060d4b
commit
da8168f2cf
|
|
@ -0,0 +1 @@
|
|||
#include "2d.h"
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
class Shape
|
||||
{
|
||||
public:
|
||||
virtual long double compute_area(long double) { return 0; };
|
||||
Shape(){};
|
||||
virtual ~Shape() {};
|
||||
};
|
||||
|
||||
|
||||
class Circle : public Shape
|
||||
{
|
||||
public:
|
||||
Circle() {}
|
||||
~Circle() {}
|
||||
long double compute_area(long double d) override
|
||||
{
|
||||
return (d / 2)*(d / 2) * 3.14159265359;
|
||||
}
|
||||
};
|
||||
107
SCE/SCE/3d.h
107
SCE/SCE/3d.h
|
|
@ -1,21 +1,18 @@
|
|||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "2d.h"
|
||||
using namespace std;
|
||||
|
||||
class Body
|
||||
{
|
||||
private:
|
||||
public:
|
||||
long double volume;
|
||||
long double mass;
|
||||
long double electric_resistance;
|
||||
vector<long double> heights;
|
||||
vector<long double> densities;
|
||||
vector<long double> resistances;
|
||||
//Virtual compute functions
|
||||
virtual long double compute_volume(){};
|
||||
virtual long double compute_mass(){};
|
||||
virtual long double compute_electric_resistamce(){};
|
||||
|
||||
public:
|
||||
//Set
|
||||
void set_volume(long double v) { volume = v; };
|
||||
void set_mass(long double m) { mass = m; };
|
||||
|
|
@ -28,17 +25,105 @@ public:
|
|||
virtual void data_entry(){};
|
||||
virtual void compute_options(){};
|
||||
|
||||
virtual long double compute_volume() { return 0; };
|
||||
virtual long double compute_mass() { return 0; };
|
||||
virtual long double compute_electric_resistamce() { return 0; };
|
||||
|
||||
Body() {};
|
||||
virtual ~Body() { heights.clear(); };
|
||||
virtual ~Body() {};
|
||||
};
|
||||
|
||||
|
||||
|
||||
class Cylinder : public Body
|
||||
{
|
||||
private:
|
||||
vector<long double> radii;
|
||||
|
||||
public:
|
||||
|
||||
vector<long double> radii;
|
||||
Cylinder() {};
|
||||
~Cylinder(){};
|
||||
|
||||
void data_entry() override
|
||||
{
|
||||
char auswahl = 'j';
|
||||
long double teil_lange;
|
||||
long double teil_durchmesser;
|
||||
long double teil_dichte;
|
||||
long double teil_widerstand;
|
||||
|
||||
//Data entry
|
||||
while (auswahl == 'j')
|
||||
{
|
||||
//Reseting the variables
|
||||
teil_lange = 0;
|
||||
teil_durchmesser = 0;
|
||||
teil_dichte = 0;
|
||||
teil_widerstand = 0;
|
||||
|
||||
|
||||
cout << "Definieren Sie die Teilabschnitte des Zylinders" << endl;
|
||||
cout << " Laenge: "; cin >> teil_lange; heights.push_back(teil_lange);
|
||||
cout << " Durchmesser in mm: "; cin >> teil_durchmesser; radii.push_back(teil_durchmesser);
|
||||
cout << " Dichte in g/mm^3: "; cin >> teil_dichte; densities.push_back(teil_dichte);
|
||||
cout << " Spezifischer Widerstand in ohm * (mm^2) / m: "; cin >> teil_widerstand; resistances.push_back(teil_widerstand);
|
||||
cout << " Gibt es weitere Teilbereiche? j/n "; cin >> auswahl;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
void compute_options() override
|
||||
{
|
||||
//Compute
|
||||
char auswahl = 'j';
|
||||
while (auswahl == 'j')
|
||||
{
|
||||
cout << "Was wollen Sie berechnen?" << endl;
|
||||
cout << " 1 Volumen" << endl;
|
||||
cout << " 2 Masse" << endl;
|
||||
cout << " 3 Elektrischer Widerstand" << endl;
|
||||
|
||||
cin >> auswahl;
|
||||
switch (auswahl)
|
||||
{
|
||||
case '1': cout << "Volumen: " << compute_volume() << " mm^3" << endl; break;
|
||||
case '2': cout << "Masse: " << compute_mass() << " g" << endl; break;
|
||||
case '3': cout << "Widerstand: " << compute_electric_resistamce() << " ohm" << endl; break;
|
||||
|
||||
default: cout << "Okay, bye" << endl; break;
|
||||
}
|
||||
cout << "Wollen Sie fortfahren? j/n "; cin >> auswahl;
|
||||
}
|
||||
}
|
||||
long double compute_volume() override
|
||||
{
|
||||
long double Volume = 0;
|
||||
Circle circle;
|
||||
for (int i = 0; heights.size() != i; i++)
|
||||
{
|
||||
Volume = Volume + heights[i] * circle.compute_area(radii[i]);
|
||||
}
|
||||
set_volume(Volume);
|
||||
return Volume;
|
||||
}
|
||||
long double compute_mass()override
|
||||
{
|
||||
long double mass = 0;
|
||||
Circle circle;
|
||||
for (int i = 0; heights.size() != i; i++)
|
||||
{
|
||||
mass = mass + heights[i] * circle.compute_area(radii[i]) * densities[i];
|
||||
}
|
||||
set_mass(mass);
|
||||
return mass;
|
||||
}
|
||||
long double compute_electric_resistamce() override
|
||||
{
|
||||
long double resistance = 0;
|
||||
Circle circle;
|
||||
for (int i = 0; heights.size() != i; i++)
|
||||
{
|
||||
resistance = resistance + heights[i] * 1000 * circle.compute_area(radii[i]) * resistances[i];
|
||||
}
|
||||
set_electric_resistance(resistance);
|
||||
return resistance;
|
||||
}
|
||||
};
|
||||
100
SCE/SCE/SCE.cpp
100
SCE/SCE/SCE.cpp
|
|
@ -1,14 +1,8 @@
|
|||
#include "stdafx.h"
|
||||
#include "3d.h"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
void Zylinder();
|
||||
long double Kreis_flacheninhalt(long double);
|
||||
long double Zylinder_volumen(vector<long double>, vector<long double>);
|
||||
long double Zylinder_masse(vector<long double>, vector<long double>, vector<long double>);
|
||||
long double Zylinder_widerstand(vector<long double>, vector<long double>, vector<long double>);
|
||||
void cylinder();
|
||||
|
||||
int main()
|
||||
{
|
||||
|
|
@ -23,98 +17,18 @@ int main()
|
|||
cin >> auswahl;
|
||||
switch(auswahl)
|
||||
{
|
||||
case '1': Zylinder(); break;
|
||||
case '1': cylinder(); break;
|
||||
|
||||
default: cout << "Okay, bye"; break;
|
||||
default: cout << "Okay, bye" << endl; break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Zylinder()
|
||||
void cylinder()
|
||||
{
|
||||
vector<long double> zylinder_lange;
|
||||
vector<long double> zylinder_durchmesser;
|
||||
vector<long double> zylinder_dichte;
|
||||
vector<long double> zylinder_widerstand;
|
||||
|
||||
char auswahl = 'j';
|
||||
long double teil_lange;
|
||||
long double teil_durchmesser;
|
||||
long double teil_dichte;
|
||||
long double teil_widerstand;
|
||||
|
||||
//Eingabe der Daten
|
||||
while (auswahl == 'j')
|
||||
{
|
||||
//Reset der Variablen für den Durchlauf
|
||||
teil_lange = 0;
|
||||
teil_durchmesser = 0;
|
||||
teil_dichte = 0;
|
||||
teil_widerstand = 0;
|
||||
|
||||
|
||||
cout << "Definieren Sie die Teilabschnitte des Zylinders" << endl;
|
||||
cout << "Laenge: "; cin >> teil_lange; zylinder_lange.push_back(teil_lange);
|
||||
cout << endl << "Durchmesser in mm: "; cin >> teil_durchmesser; zylinder_durchmesser.push_back(teil_durchmesser);
|
||||
cout << endl << "Dichte in g/mm^3: "; cin >> teil_dichte; zylinder_dichte.push_back(teil_dichte);
|
||||
cout << endl << "Spezifischer Widerstand in ohm * (mm^2) / m: "; cin >> teil_widerstand; zylinder_widerstand.push_back(teil_widerstand);
|
||||
cout << "Gibt es weitere Teilbereiche? j/n "; cin >> auswahl;
|
||||
}
|
||||
auswahl = 'j';
|
||||
//Berechungen
|
||||
while(auswahl=='j')
|
||||
{
|
||||
cout << "Was wollen Sie berechnen?" << endl;
|
||||
cout << "Volumen" << "\t" << "1" << endl;
|
||||
cout << "Masse" << "\t" << "2" << endl;
|
||||
cout << "Elektrischer Widerstand" << "\t" << "3" << endl;
|
||||
|
||||
cin >> auswahl;
|
||||
switch (auswahl)
|
||||
{
|
||||
case '1': cout << Zylinder_volumen(zylinder_lange, zylinder_durchmesser) << " mm^3" << endl; break;
|
||||
case '2': cout << Zylinder_masse(zylinder_lange, zylinder_durchmesser, zylinder_dichte) << " g" << endl; break;
|
||||
case '3': cout << Zylinder_widerstand(zylinder_lange, zylinder_durchmesser, zylinder_dichte) << " ohm" << endl; break;
|
||||
|
||||
default: cout << "Okay, bye"; break;
|
||||
}
|
||||
cout << "Wollen Sie fortfahren? j/n "; cin >> auswahl;
|
||||
}
|
||||
Cylinder cylinder;
|
||||
cylinder.data_entry();
|
||||
cylinder.compute_options();
|
||||
|
||||
}
|
||||
|
||||
long double Kreis_flacheninhalt(long double durchmesser)
|
||||
{
|
||||
return (durchmesser / 2)*(durchmesser / 2) * 3.14159265359;
|
||||
}
|
||||
|
||||
long double Zylinder_volumen(vector<long double> langen, vector<long double> durchmesser)
|
||||
{
|
||||
long double Volumen = 0;
|
||||
for(int i = 0; langen.size() != i; i++)
|
||||
{
|
||||
Volumen = Volumen + langen[i] * Kreis_flacheninhalt(durchmesser[i]);
|
||||
}
|
||||
return Volumen;
|
||||
}
|
||||
|
||||
long double Zylinder_masse(vector<long double> langen, vector<long double> durchmesser, vector<long double> dichten)
|
||||
{
|
||||
long double masse = 0;
|
||||
for (int i = 0; langen.size() != i; i++)
|
||||
{
|
||||
masse = masse + langen[i] * Kreis_flacheninhalt(durchmesser[i]) * dichten[i];
|
||||
}
|
||||
return masse;
|
||||
}
|
||||
|
||||
long double Zylinder_widerstand(vector<long double> langen, vector<long double> durchmesser, vector<long double> widerstande)
|
||||
{
|
||||
long double widerstand = 0;
|
||||
for (int i = 0; langen.size() != i; i++)
|
||||
{
|
||||
widerstand = widerstand + langen[i]* 1000 * Kreis_flacheninhalt(durchmesser[i]) * widerstande[i];
|
||||
}
|
||||
return widerstand;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue