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

Wave steepness is the ratio of wave height (WH) to wave length(WL) and is an ind

ID: 3555066 • Letter: W

Question

Wave steepness is the ratio of wave height (WH) to wave length(WL) and is an indicator of wave stability. When wave steepness exceeds a 1/7 ratio; the wave becomes unstable and begins to break. Assume a data file exits with the following header:

##YY   MM   DD   HH   MM   WH(m) WL(m)

Each subsequent line in the data file contains time and wave height measurements, in the following format:

year(int) month (int) day (int) hour (int) minute (int) wave height (double) wave length (double)

Write a program to calculate the average steepness given an input file in the above format. The program should also determine and print what percentage of the time the steepness exceeded the average. The input file can be of any length.

Here is what i have so far from a similar question but this is finding the height and not the steepness. filename is "filename.c_str".. i also chose 20 lines in the file

#include
#include
#include
#include
#include

using namespace std;
double average(double[], int);
int main()
{
const int SAMPLE_SIZE = 20;
double waveHeights [SAMPLE_SIZE], WVHT, newVal;
int year, month, day, hour, minute;
string filename, header;
ifstream fin;
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);
}
getline(fin,header);
int i = 0;
fin >> year >> month >> day >> hour >> minute >> waveHeights [i];
cout << header << endl;
cout << "Starting time: " < int pos;
for(i=1; i {
fin >> year >> month >> day >> hour >> minute >> newVal;
pos = 0;
while(pos < i && newVal < waveHeights[pos])
{
++pos;
}
if(pos == i)
{
waveHeights[i] = newVal;
}
else
{
for (int k=i; k>pos; --k)
{
waveHeights[k] = waveHeights [k-1];
}
waveHeights[pos] = newVal;
}
}
int top3rd = SAMPLE_SIZE/3;
WVHT = average (waveHeights, top3rd);
cout << "ending time: " << endl << year
<< setw(3) << month << setw(3) << day
<< setw(3) << hour << setw(3) << minute << endl;
cout << "WVHT is " << WVHT << endl;
fin. close();
return 0;
}
double average(double array[], int size)
{
double sum = 0.0;
for(int i=0; i {
sum += array[i];
}
sum = sum/size;
return sum;
}

Explanation / Answer

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cstdlib>
using namespace std;
double average(double[], int);
int main()
{
const int SAMPLE_SIZE = 20;
double waveHeights [SAMPLE_SIZE],wavelength[SAMPLE_SIZE],steepness[SAMPLE_SIZE],steep_average;
int year, month, day, hour, minute,i=0;
string filename, header;
ifstream fin;
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);
}
while(!fin.eof())
{
getline(fin,header);
cout << header << endl;
fin>>year>>month>>day>>hour>>minute>>waveHeights[i]>>wavelength[i];
i++;
}
for(int j=0;j<i;j++)
{
steepness[i]=waveHeights[i]/wavelength[i];
}
steep_average=average(steepness,i);
cout<<" steep average=: "<<steep_average;
return 0;
}
double average(double arr[], int s)
{
double sum = 0.0;
for(int i=0; i<s; ++i)
{
sum += arr[i];
}
sum = sum/s;
return sum;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote