Dateien nach „BSP_1_A“ hochladen

This commit is contained in:
Georg Thomas Mandl 2025-10-22 23:13:05 +02:00
commit 97a7a2432d
4 changed files with 166 additions and 0 deletions

51
BSP_1_A/bsp_1_a.cbp Normal file
View file

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="bsp_1_a" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/bsp_1_a" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/bsp_1_a" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="bsp_1_a.cpp" />
<Unit filename="bsp_1_a.h" />
<Unit filename="main.cpp" />
<Extensions>
<DoxyBlocks>
<comment_style block="0" line="0" />
<doxyfile_project />
<doxyfile_build extract_all="1" />
<doxyfile_warnings />
<doxyfile_output />
<doxyfile_dot />
<general />
</DoxyBlocks>
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

38
BSP_1_A/bsp_1_a.cpp Normal file
View file

@ -0,0 +1,38 @@
#include "bsp_1_a.h"
#include<cmath>
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<float> 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;
}

31
BSP_1_A/bsp_1_a.h Normal file
View file

@ -0,0 +1,31 @@
#ifndef BSP_1_A_H_INCLUDED
#define BSP_1_A_H_INCLUDED
#include<vector>
/** \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<float> x, float &a, float &g, float &h);
#endif // BSP_1_A_H_INCLUDED

46
BSP_1_A/main.cpp Normal file
View file

@ -0,0 +1,46 @@
#include <iostream>
#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<float> 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;
}