Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that will calculate statistical information on a set of integer

ID: 3675622 • Letter: W

Question

Write a program that will calculate statistical information on a set of integer numbers. Your main program must call three functions: read_data, calculate_stats, save_results. read_data will prompt the user for a file that contains the data, one number per line. Only read up to the size of the array. Parameter 1: the array to receive the values Parameter 2: the size of the array Return: the count of the numbers read calculate stats will return the real average and standard deviation via a call by reference Parameter 1: the array of the values Parameter 2: the number of elements used in the array Parameter 3: receive the real standard deviation as computed using the formula Return: the real average save_results will prompt the user for a file for the result to be saved to. The format:

Explanation / Answer

#include<iostreams.h>
#include<fstream.h>
#include<conio.h>
#include<math.h>

int read_data(int a[],int size)
{
   char f[20];
   cout<<"Enter file name to read data";
   cin>>f;

   ifstream fin(f);
   int i=0;
   while(!fin.eof() && i<size)
   {
       fin>>a[i];
       i++;
   }
   return i;
}

double calculate_stats(int a[], int size, double sd)
{
   int i,sum=0;

   for(i=0;i<size;i++)
   {
       sum=sum+a[i];
   }
   double av=sum/size;
   return av;
}

void save_result(int a[], int size, double av, double sd)
{
   char f[20];
   cout<<"Enter file name to save data";
   cin>>f;

   ofstream fout(f);
   int i=0;
   while(i<size)
   {
       fout<<(a[i]);
       i++;
   }

   fout<<"Number of inputs:";
   fout<<size;
   fout<<" ";

   fout<<"Average:";
   fout<<av;
   fout<<" ";

   fout<<"Standard deviation:";
   fout<<sd;
   fout<<" ";
}

void main()
{
   int a[250],s=250,i,total=0;
   double sumDiffSqr=0;
   int c=read_data(a,s);
   for (int num = 0; num < s; num++)
   {
       sumDiffSqr = sumDiffSqr + pow((num - (total / c)), 2);
   }

   double sd = sqrt(sumDiffSqr/c);

   double av=calculate_stats(a, s,sd);

   save_result(a,s,av,sd);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote