diff --git a/SCE/SCE/2d.cpp b/SCE/SCE/2d.cpp index 3712970..3d8027b 100644 --- a/SCE/SCE/2d.cpp +++ b/SCE/SCE/2d.cpp @@ -1 +1,6 @@ -#include "2d.h" \ No newline at end of file +#include "2d.h" + +long double Circle::compute_area(long double d) +{ + return (d / 2)*(d / 2) * 3.14159265359; +} \ No newline at end of file diff --git a/SCE/SCE/3d.cpp b/SCE/SCE/3d.cpp index 783b49e..14b49fe 100644 --- a/SCE/SCE/3d.cpp +++ b/SCE/SCE/3d.cpp @@ -23,7 +23,7 @@ void Cylinder::data_entry() cout << "Definieren Sie die Teilabschnitte des Zylinders" << endl; cout << " Laenge in mm: "; 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 << " Dichte in g/cm^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; } diff --git a/SCE/SCE/SCE.cpp b/SCE/SCE/SCE.cpp index 1ef7e10..4e90a61 100644 --- a/SCE/SCE/SCE.cpp +++ b/SCE/SCE/SCE.cpp @@ -1,8 +1,10 @@ #include "3d.h" #include +#include "lgs.h" using namespace std; void cylinder(); +void lgs(); int main() { @@ -11,6 +13,7 @@ int main() { cout << "Was wollen Sie tun ?" << endl; cout << "1 Berechungen an einem Zylinder" << endl; + cout << "2 LGS lösen" << endl; cout << "e Beenden" << endl; @@ -18,6 +21,7 @@ int main() switch(auswahl) { case '1': cylinder(); break; + case '2': lgs(); break; default: cout << "Okay, bye" << endl; break; } @@ -32,3 +36,8 @@ void cylinder() cylinder.compute_options(); } +void lgs() +{ + LGS lgs; + lgs.data_entry(); +} diff --git a/SCE/SCE/lgs.cpp b/SCE/SCE/lgs.cpp new file mode 100644 index 0000000..57c8cd3 --- /dev/null +++ b/SCE/SCE/lgs.cpp @@ -0,0 +1,89 @@ +#include "lgs.h" +#include "time.h" +#include +using namespace std; + +void LGS::data_entry() +{ + char auswahl = 'n'; + //Data entry + while (auswahl == 'n') + { + cout << "Anzahl der Unbekannten: "; cin >> variables; + creat_array(); + cout << "Geben Sie die Gleichungen nach folgendem Schema an:" << endl; + cout << "[A1 *x][B1 *y][C1 *z]=[D1]" << endl; + cout << "[A2 *x][B2 *y][C2 *z]=[D2]" << endl; + cout << "[A3 *x][B3 *y][C3 *z]=[D3]" << endl; + + for (int i = 0; i < variables; ++i) + { + for (int n = 0; n < variables+1; ++n) + { + cout << " "; + int var = n + 65; + cout << (char)var << i + 1 << ": "; + cin >> GA[i][n]; + + } + print_ln(i); + cout << endl; + } + print(); + cout << "Sind die angaben Korrekt? j/n"; cin >> auswahl; + + } + cout << endl; + +} + +void LGS::creat_array() +{ + GA = new long double*[variables]; + for (int i = 0; i < variables; ++i) + GA[i] = new long double[variables+1]; +} + +void LGS::print() +{ + for (int i = 0; i < variables; ++i) + { + for (int n = 0; n < variables + 1; ++n) + { + cout << GA[i][n] << " "; + if (n == variables-1) + cout << "= "; + } + cout << endl; + } +} + +void LGS::print_ln(int ln) +{ + for (int n = 0; n < variables + 1; ++n) + { + int var = 123 - variables + n; + cout << " +" << GA[ln][n] << (var!=123 ? (char)var : ' '); + if (n == variables - 1) + cout << "= "; + } + cout << endl; +} + +float LGS::cramer() +{ + double t1 = clock(); + + return (float)((clock() - t1) / CLOCKS_PER_SEC); +} + +float LGS::gauss() +{ + double t1 = clock(); + + return (float)((clock() - t1) / CLOCKS_PER_SEC); +} + + + + diff --git a/SCE/SCE/lgs.h b/SCE/SCE/lgs.h new file mode 100644 index 0000000..e165b96 --- /dev/null +++ b/SCE/SCE/lgs.h @@ -0,0 +1,22 @@ +#pragma once +class LGS{ +public: + long double** GA; + int variables = 0; + + + LGS(){}; + ~LGS() + { + for (int i = 0; i < variables; ++i) + delete[] GA[i]; + delete[] GA; + }; + + float gauss(); + float cramer(); + void data_entry(); + void creat_array(); + void print(); + void print_ln(int); +}; \ No newline at end of file