Develop a C program that prompt and read the name of an inpu

Develop a C++ program that prompt and read the name of an input data file (input stream). Then, it will read data from the file and calculate the following statistical metrics:

1. Mean (average) objects per minute (?)

2. Standard deviation

The standard deviation for a set of values is:

Where, n = number of samples

?x = sum of values

?x^2 = sum of squares of x values

After the program has calculated and displayed the two metrics, it must close the input file (input stream), and it will offer the user to calculate Poisson probabilities, as in the first increment, keeping the calculated ? for whenever the user want to use it. If the user proceeds with Poisson simulations, the program will create or append to an output file (output stream), which is a log of different combinations of ?, k and t, along with the corresponding Poison probability. If the user declines proceeding with calculations, no new entries in the log should be created. The output file will look like:

The calculated value of lambda must be displayed with 1 decimal figure and the standard deviation value,with 4 decimals.  Finally, all files (streams) must be appropriately opened and closed.

Solution

#include <iostream>
#include <string>
#include <cmath>
#include <fstream>
using namespace std;

int main(){
   int numbers[100];
   int size = 0;
   int sum = 0;
   int sumSquares = 0;
   // reading file
   std::ifstream infile(\"input.txt\");
  
   int number;
   while (std::getline(infile, number))
   {
       // storing into array
       numbers[size] = number;
       sum = sum + number;
       sumSquares = sumSquares + (number*number);
       size++;
   }
   infile.close();
   // calculating mean
   double mean = sum/size;
   double standard_deviation = sqrt((sumSquares) - ((mean*mean)/size(size-1)));
   //outputting results
   cout<<\"Mean: \"<<mean;
   cout<<\"Standard deviation: \"<<standard_deviation;
  
   // outputting to file
   ofstream outputFile;
   outputFile.open (\"output.txt\");
   outputFile<<\"Mean: \"<<mean;
   outputFile<<\"Standard deviation: \"<<standard_deviation;
   outputFile.close();
return 0;
}

Develop a C++ program that prompt and read the name of an input data file (input stream). Then, it will read data from the file and calculate the following stat
Develop a C++ program that prompt and read the name of an input data file (input stream). Then, it will read data from the file and calculate the following stat

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site