Question: discribe this code to be #include #include using namespace std; void sortRainfall ( double a [ ] , string b [ ] , int c

discribe this code to be
#include
#include
using namespace std;
void sortRainfall(double a[], string b[], int c);
void getRainfall();
string months[12]{"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
double rainfall[12]{}, rainfall_total =0;
int main()
{
cout << "Please enter the inches of rainfall for the following months:
";
getRainfall();
cout <<"
The total rainfall for the year was "<< rainfall_total <<" inches.
";
cout << "The average monthly rainfall is "<< rainfall_total/12<<" inches.
";
sortRainfall(rainfall,months,12);
cout << "The highest rainfall occurred in "<< months[11]<<" at "<< rainfall[11]<<" inches.
";
cout << "The lowest rainfall occurred in "<< months[0]<<" at "<< rainfall[0]<<" inches.
";
cout << "The rainfall from highest to lowest is:
";
for (int i =11; i >=0; i--)
cout << months[i]<<": "<< rainfall[i]<<" inches
";
}
void getRainfall()
{
//fill in rainfall array in this method. Display below if the user tries to enter negative numbers.
for(int i=0;i<12;i++){
cout << months[i]<<": ";
cin>>rainfall[i];
if(rainfall[i]<0){
cout << "You cannot enter negative numbers.
";
i--;
}
}
}
void sortRainfall(double rainfall[], string months[], int length){
int i, j;
double temp;
string s;
// outer loop to travel through the all elements
for (i =0; i < length -1; i++){
// inner loop to compare the outer loop elements
for (j =0; j < length - i -1; j++)
// if element at j< than j+1 than swap both
if (rainfall[j]> rainfall[j +1]){
// swap logic
temp = rainfall[j];
rainfall[j]= rainfall[j+1];
rainfall[j+1]= temp;
s = months[j];
months[j]= months[j+1];
months[j+1]= s;
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!