Solutions
This commit is contained in:
parent
79b9099274
commit
d3aa42a3e0
64 changed files with 2726 additions and 0 deletions
48
sheet1/B/main.cpp
Normal file
48
sheet1/B/main.cpp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue