Question
#include #include #include #include #include using namespace std; //Function prototypes double average(double[], int); int main() { //Declare and initialize objectss const int SAMPLE_SIZE = 20;
#include
//Function prototypes double average(double[], int);
int main() { //Declare and initialize objectss const int SAMPLE_SIZE = 20; double waveHeights[SAMPLE_SIZE], WVHT, newVal; int year, month, day, hour, minute; string filename, header; ifstream fin; //Get filename and open file cout << "Enter name of input file: "; cin >> filename; fin.open(filename.c_str()); if(fin.fail()) { cerr << "Could not open the file " << filename << " Goodbye." << endl; exit(1); } //Read header from input file //getline(fin.header); //Read first line of input data int i = 0; fin >> year >> month >> day >> hour >> minute >> waveHeights[i]; //Echo header cout << header << endl; //Print starting date and time. cout << "Starting time: " << endl << year << setw(3) << month << setw(3) << day << setw(3) << hour << setw(3) << minute << endl; //Read remaining lines of input //Order waveHeight in descending order int pos; for (i=1; i
double average(double array[], int size) { double sum = 0.0; for(int i=0; i /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ Modify the program so that it reads all of the wave-height data and stores it in an array, unordered, then calls the function: (This function needs to sort the data before calculating the WVHT.) /*----------------------------------------------*/ /* This function sorts an array with n elements */ /* into ascending order. */ void sort(double x[], int n) { //Declare objects int m; double hold; //implement selection sort algorithm. for (int k=0; k<=n-2; ++k) { //Find position of smallest value in array //beginning at k m = k; for (int j=k+1; j<=n-1; ++j) { if (x[j] < x[m]) m=j; } //Exchange smallest value with value at k hold = x[m]; x[m] = x[k]; x[k] = hold; } //Void return return; } /*----------------------------------------------*/
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started