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

This should be solved in the meanabs. cpp file. Write a program that takes its i

ID: 3696901 • Letter: T

Question

This should be solved in the meanabs. cpp file. Write a program that takes its input from a file of numbers of type double. The program outputs to the screen the mean of the absolute values of numbers in the file. The file contains nothing but numbers of type double separated by blanks and/or line breaks. The mean value of the absolute values of a list of numbers x1, x2, X3, and so forth is defined as following:(|x1| + |x2| + |x3| + ... + |x_n|)/n Where the number a is the average of the absolute values 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. Suppose that in a session, the file "nums.txt" contains the following content. 1 2 7 5 20 3 The execution of the program should look like the following (including whitespace and formatting), with a possibly different number in the output: Enter filename: nums.txt The mean of absolute values of numbers is 6.333 The string printed by the program should include a newline at the end, but no other trailing whitespace. The mean of absolute values of numbers must be displayed to exactly three digits after the decimal point.

Explanation / Answer

#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
double abs(double a)
{
if(a<0)return -1*a;
return a;
}
int main()
{
cout<<"Enter the name of the file:";
string name;
cin>>name;
ifstream in;
in.open(name);
double temp,sum=0;
int cnt=0;
while(in>>temp)
{
sum+=abs(temp);
cnt++;
}
cout<<"The mean is "<<setprecision(4)<<sum/cnt<<endl;
return 0;
}

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