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

c++ program You are to write a program to calculate some statistics about colleg

ID: 3910931 • Letter: C

Question

c++ program

You are to write a program to calculate some statistics about college student’s heights.  Your input file is Heights inches.  Each input line contains a height and the number of students that are of that height or frequency.

For example:      56     2        where this student is 56 inches tall and there were 2

                        57     0        no students of height 57 inches

                        58     3        Three students of height 58 inches  and so on

                        59     5

                        …

You are to read in the data and compute the mean (average) , the standard deviation and skewness

The mean is  sum of Xidivided by n.

The standard deviation is   square root  of (sum of (  Xi   - mean ) 2  divided by n  )

The skewness is   3 times ( mean – median ) divided by the standard deviation  (median is the middle value of the data.)

Explanation / Answer

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <fstream>
#include <string>
#include <cmath>
using namespace std;
int main ()
{
                    //Array to save the name
string a,b;
int loop=0,sumheight=0,sumcount=0,height,count,i,heightt[10];
float average,standardDeviation = 0.0;
ifstream myfile ("studentsheight.txt");     //To read from the *.txt File
if (myfile.is_open())                   //Checking if the file can be opened
{
  while (! myfile.eof() )             //Runs while the file is NOT at the end
  {
   myfile>>a>>b;
            height=atoi(a.c_str());    //Convert to integer
            heightt[loop]=atoi(a.c_str());
            count=atoi(b.c_str());      //Convert to integer
            sumheight+=height;
            sumcount+=count;

   loop++;                         //Does an increment to the variable 'loop'
  }
  myfile.close();                     //Closes the file
}
else cout << "Unable to open file"<<endl; //Gives an error message if the file can't be opened
    average=sumheight/sumcount;
    for(i = 0; i < loop; ++i)
        standardDeviation += pow(heightt[i] - average, 2);

       cout<<" Mean = "<<average;
       cout<<" Standard Deviation = "<<standardDeviation;
}

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