subject

The provided code reads in data from a file and stores it in a vector named signal. Three functions prototypes are declared at the top named mean, stdev, and median.
Define these functions to calculate the mean, standard deviation, and median of the values in the signal vector.

#include
using namespace std;
// Function prototypes. You must define these functions after main().
double mean( vector &sig );
double stdev( vector &sig );
double median( vector &sig );

int main(){
// create object to read in data
ifstream inFile;
double mean( vector &sig ){
// Fill in function definition
// The vector sig is in scope here, so you can use it
// Return the mean value
}

double stdev( vector &sig ){
// Fill in function definition
// The vector sig is in scope here, so you can use it
// Return the stdev
}

double median( vector &sig ){
// Fill in function definition
// The vector sig is in scope here, so you can use it
// Return the median value
}
// read in filename
string fname;
cout << "Provide an input file name: " << endl;
cin >> fname;

// open file and confirm that it is open
inFile. open(fname);
if (!inFile. is_open()){
cout << "Could not open file " << fname << "." << endl;
return -1;
}

// read in numbers from file and store in a vector
vector signal(0);
while( !inFile. eof() ){
double tmp;
inFile >> tmp;
signal. push_back( tmp );
}
signal. pop_back();

printf(" Average: %lf\n", mean( signal ));
printf("Standard deviation: %lf\n", stdev( signal ));
printf(" Median: %lf\n", median( signal ));

// close file
inFile. close();

return 0;
}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 09:50
17. implement the jvm dload instruction for the mic-2. it has a 1-byte index and pushes the local variable at this position onto the stack. then it pushes the next higher word onto the stack as well
Answers: 2
question
Computers and Technology, 22.06.2019 17:40
Consider the simple 3-station assembly line illustrated below, where the 2 machines at station 1 are parallel, i.e., the product only needs to go through one of the 2 machines before proceeding to station 2.what is the throughput time of this process?
Answers: 2
question
Computers and Technology, 22.06.2019 18:00
Which of the following physical laws can make the flow of water seem more realistic? a. motion b. gravity c. fluid dynamics d. thermodynamics
Answers: 2
question
Computers and Technology, 23.06.2019 12:30
What is the difference between the internet and the world wide web?
Answers: 1
You know the right answer?
The provided code reads in data from a file and stores it in a vector named signal. Three functions...
Questions
question
Mathematics, 05.01.2021 06:30
question
Mathematics, 05.01.2021 06:30
question
Mathematics, 05.01.2021 06:30
question
Mathematics, 05.01.2021 06:30
Questions on the website: 13722367