Exercises_MarkusSchmidt/sheet1/B/main.cpp
Markus Schmidt d3aa42a3e0 Solutions
2025-10-21 19:36:38 +02:00

48 lines
1.2 KiB
C++

#include "file_io.h"
#include "means.h"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
cout << "File einlesen." << endl;
const string name("data_1.txt"); // name of input file
const string name2("out_1.txt"); // name of output file
vector<short> a; //-2^15 to 2^15-1 fits the values from the file
double min, max, ar, ge, ha, std;
read_vector_from_file(name, a);
const unsigned size = a.size();
min = *min_element(a.begin(), a.end());
max = *max_element(a.begin(), a.end());
means_vector(a, ar, ge, ha);
std = 0;
for(unsigned int i = 0; i < size; i++)
{
std += pow(a.at(i)-ar,2);
}
std = sqrt(std/size);
cout << "min: " << min << ", max: " << max << endl;
cout << "Arithmetic mean: " << ar
<< ", geometric mean: " << ge
<< ", harmonic mean: " << ha << endl;
cout << "std: " << std << endl;
vector<double> results = {min, max, ar, ge, ha, std};
write_vector_to_file(name2, results);
return 0;
}