From 56e7e711b70eab993e2764be59159a6930e98f81 Mon Sep 17 00:00:00 2001 From: "lisa.pizzo" Date: Wed, 29 Oct 2025 18:18:58 +0100 Subject: [PATCH] Delete mainEx2.cpp --- mainEx2.cpp | 50 -------------------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 mainEx2.cpp diff --git a/mainEx2.cpp b/mainEx2.cpp deleted file mode 100644 index 9d6191a..0000000 --- a/mainEx2.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -#include -#include -#include -using namespace std; - -int main() { - vector data; - double x; - - ifstream infile("data_1.txt"); - while (infile >> x) { //>> takes things from an input and saves as x - data.push_back(x); //saves each x in data - } - infile.close(); - - int n = data.size(); - - double minVal = *min_element(data.begin(), data.end()); - double maxVal = *max_element(data.begin(), data.end()); - - double sum = 0.0, logSum = 0.0, recipSum = 0.0; - for (int i = 0; i < n; ++i) { //for (initialization; condition; update) - sum += data[i]; - logSum += log(data[i]); - recipSum += 1.0 / data[i]; - } - double arith = sum / n; - double geom = exp(logSum / n); - double harm = n / recipSum; - - // standard deviation - double variance = 0.0; - for (int i = 0; i < n; ++i) { - variance += (data[i] - arith) * (data[i] - arith); - } - double stdev = sqrt(variance / n); - - ofstream outfile("out_1.txt"); - outfile << "Minimum: " << minVal << endl; - outfile << "Maximum: " << maxVal << endl; - outfile << "Arithmetic mean: " << arith << endl; - outfile << "Geometric mean: " << geom << endl; - outfile << "Harmonic mean: " << harm << endl; - outfile << "Standard deviation: " << stdev << endl; - outfile.close(); - - return 0; -}