diff --git a/BSP_1_A/bsp_1_a.cbp b/BSP_1_A/bsp_1_a.cbp new file mode 100644 index 0000000..4c4f076 --- /dev/null +++ b/BSP_1_A/bsp_1_a.cbp @@ -0,0 +1,51 @@ + + + + + + diff --git a/BSP_1_A/bsp_1_a.cpp b/BSP_1_A/bsp_1_a.cpp new file mode 100644 index 0000000..4109f2c --- /dev/null +++ b/BSP_1_A/bsp_1_a.cpp @@ -0,0 +1,38 @@ +#include "bsp_1_a.h" +#include + +using namespace std; + +void mean(long long int x, long long int y, long long int z, float &a, float &g, float &h) +{ + a = x/3.0 + y/3.0 + z/3.0; // arithmetisches Mittel + g = pow(x,1/3.0)*pow(y,1/3.0)*pow(z,1/3.0); // geometrisches Mittel + h = 3/((1.0/x)+(1.0/y)+(1.0/z)); // harmonisches Mittel + return; +} + + +void meanvec(std::vector x, float &a, float &g, float &h) +{ + a = 0; + for(size_t k=1; k<=x.size(); k=k+1) + { + a = a+x.at(k-1); + } + a = a/x.size(); + + g = 1; + for(size_t k=1; k<=x.size(); k=k+1) + { + g = g*pow(x.at(k-1),1.0/x.size()); + } + + h = 0; + for(size_t k=1; k<=x.size(); k=k+1) + { + h = h + 1.0/x.at(k-1); + } + h = x.size()/h; + + return; +} diff --git a/BSP_1_A/bsp_1_a.h b/BSP_1_A/bsp_1_a.h new file mode 100644 index 0000000..c8f5c1d --- /dev/null +++ b/BSP_1_A/bsp_1_a.h @@ -0,0 +1,31 @@ +#ifndef BSP_1_A_H_INCLUDED +#define BSP_1_A_H_INCLUDED + +#include + +/** \brief Funktion zur Berechnung des arithmetischen, geometrischen und harmonischen Mittels aus 3 Zahlen + * + * \param[in,out] x erste Zahl + * \param[in,out] y zweite Zahl + * \param[in,out] z dritte Zahl + * \param[in,out] a arithmetisches Mittel + * \param[in,out] g geometrisches Mittel + * \param[in,out] h harmonisches Mittel + * \return + * + */ +void mean(long long int x, long long int y, long long int z, float &a, float &g, float &h); + + +/** \brief Funktion zur Berechnung des arithmetischen, geometrischen und harmonischen Mittels aus den Eintraegen eines gegebenen Vektors + * + * \param[in,out] x Vektor mit Eintraegen + * \param[in,out] a arithmetisches Mittel + * \param[in,out] g geometrisches Mittel + * \param[in,out] h harmonisches Mittel + * \return + * + */ +void meanvec(std::vector x, float &a, float &g, float &h); + +#endif // BSP_1_A_H_INCLUDED diff --git a/BSP_1_A/main.cpp b/BSP_1_A/main.cpp new file mode 100644 index 0000000..9e9eb98 --- /dev/null +++ b/BSP_1_A/main.cpp @@ -0,0 +1,46 @@ +#include +#include "bsp_1_a.h" +using namespace std; +// BSP 1_A + +int main() +{ + float a, g, h; + + // Berechnung der Mittelwerte für verschiedene Testdaten + mean(1,4,16, a, g, h); + + cout << "Eingabedaten = (1,4,16)" << endl; + cout << "arithmetisches Mittel = " << a << endl; + cout << "geometrisches Mittel = " << g << endl; + cout << "harmonisches Mittel = " << h << endl; + + cout << "##########" << endl; + + mean(2,3,5, a, g, h); + + cout << "Eingabedaten = (2,3,5)" << endl; + cout << "arithmetisches Mittel = " << a << endl; + cout << "geometrisches Mittel = " << g << endl; + cout << "harmonisches Mittel = " << h << endl; + + cout << "##########" << endl; + + mean(1000,4000,16000, a, g, h); + + cout << "Eingabedaten = (1000,4000,16000)" << endl; + cout << "arithmetisches Mittel = " << a << endl; + cout << "geometrisches Mittel = " << g << endl; + cout << "harmonisches Mittel = " << h << endl; + + cout << "##########" << endl << "Berechnung via Vektor" << endl; + + // für Vektoren + vector x{2,3,5,2,3,5,2,3,5,2,3,5}; + meanvec(x, a, g, h); + cout << "Eingabedaten = (2,3,5,2,3,5,2,3,5,2,3,5)" << endl; + cout << "arithmetisches Mittel = " << a << endl; + cout << "geometrisches Mittel = " << g << endl; + cout << "harmonisches Mittel = " << h << endl; + return 0; +}