Rainfall Statistics Write a modular program that analyzes a year\'s worth of rai
ID: 3634915 • Letter: R
Question
Rainfall StatisticsWrite a modular program that analyzes a year's worth of rainfall data. In addition to main, the program should have a getData function that accepts the total rainfall for each of 12 months from the user, and stores it in a double array. It should also have four value-returning functions that compute and return to main the totalRainfall, averageRainfall, driestRainfall, and wettestMonth. These last two functions return the number of the month with the lowest and highest rainfall amounts, not the amount of rain that fell those months. Notice that this month number can be used to obtain the amount of rain that fell those months. This information should be used either by main or by a displayReport function called by main to print a summary rainfall report similiar to the following:
2010 Rain Report for Neversnows County
Total rainfall : 23.19 inches
Average monthly rainfall : 1.93 inches
The least rain fell in January with 0.24 inches.
The most rain fell in April with 4.29 inches.
Input validation: Do not accept rainfall amounts less than 0.
please make sure, the program includes all of the details, all functions asked for and do what is asked and a report as the one above is printed in the window and also make sure the program runs with no errors.
Explanation / Answer
please rate - thanks
# include <iostream>
#include <string>
using namespace std;
double GetTotal(double[],int);
int GetLargest(double[],int);
double GetAverage(double,int);
int GetSmallest(double[],int);
int main ()
{int i,numbers=12,n;
string month[12]={"January","February","March","April","May","June","July","August",
"September","October","November","December"};
double rain[numbers],tot;
for(i=0;i<numbers;i++)
{cout<<"Enter the rain for month "<<month[i]<<": ";
cin>>rain[i];
while(rain[i]<0)
{cout<<"must be >0 ";
cout<<"Enter the rain for "<<month[i]<<": ";
cin>>rain[i];
}
}
cout<<" 2010 Rain Report for Neversnows County ";
tot=GetTotal(rain,numbers);
cout<<"The total rainfall for the year is: "<<tot<<" inches ";
cout<<"The average monthly rainfall is: "<<GetAverage(tot,numbers)<<" inches ";
n=GetLargest(rain,numbers);
cout<<"The most rain fell in: "<<month[n]<<" with "<<rain[n]<<" inches ";
n=GetSmallest(rain,numbers);
cout<<"The least rain fell in: "<<month[n]<<" with "<<rain[n]<<" inches ";
system("pause");
return 0;
}
double GetTotal(double r[],int n)
{int i;
double val=0;
for(i=0;i<n;i++)
val+=r[i];
return val;
}
int GetLargest(double r[],int n)
{int i;
int val=0;
for(i=1;i<n;i++)
if(r[i]>r[val])
val=i;
return val;
}
double GetAverage(double t,int n)
{return t/n;
}
int GetSmallest(double r[],int n)
{int i;
int val=0;
for(i=1;i<n;i++)
if(r[i]<r[val])
val=i;
return val;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.