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

C++11 Write a program that takes its input from a file of numbers of type double

ID: 3666167 • Letter: C

Question

C++11

Write a program that takes its input from a file of numbers of type double. The program outputs to the screen the standard deviation of the numbers in the file. The file contains nothing but numbers of type double separated by blanks and/or line breaks. The standard deviation of a list of numbers x1, x2, x3, and so forth is defined as the square root of:

((x1 – a)2 + (x2 – a)2 + (x3 – a)2 + ...) / (n - 1)

Where the number a is the average of the numbers x1, x2, x3, and so forth and the number n is the count of how many numbers there are.

Your program should take file name as input from the user.

A session should look like the following example (including whitespace and formatting), with a possibly number in the output:

The string printed by the program should include a newline at the end, but no other trailing whitespace (whitespace at the end of the line).

The standard deviation must be displayed to exactly three digits after the decimal point.

Explanation / Answer

#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string>
#include <iomanip>
#include <math.h>

using namespace std;
int Countrecords=0;

int main()
{


double variance =0,standdeviation=0;
// In order to read strings from a file//
string myfilenameone, str;
myfilenameone = "myfile.txt";// This is the file name
ifstream inFile;
inFile.open(myfilenameone.c_str());
if (!inFile)
{
cout <<"Error opening file " << endl;
system("pause");
return -1;
}



// Countrecords =inFile.end;

// In order to read the file from beginning to end and find the number of lines

int elementAdditions=0,element=0,elementPrevious=0;
cout<<"Enter numbers In The File As Following"<<endl;
while (!inFile.eof()) {

getline(inFile,str);
cout<<str<<endl;
element =atoi(str.c_str());
if(Countrecords>0)
{
elementAdditions+= (element-elementPrevious)*(element-elementPrevious);
}
elementPrevious=element;

Countrecordst++;


}
variance=( double) elementAdditions/Countrecords;
standdeviation=sqrt(variance);

cout<<"Variance Is "<<variance<<endl;
cout<<"standard deviation Is " <<standdeviation<<endl;
getchar();
}


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