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

Here\'s the code given to go off of: /*analysis.cpp*/ #include <iostream> #inclu

ID: 3588130 • Letter: H

Question

Here's the code given to go off of:

/*analysis.cpp*/

#include <iostream>
#include <string>

using namespace std;

//
// InputYearOfDataAndReturnAverage()
//
// Inputs 12 rainfall values --- one per month --- and returns the average.
//
double InputYearOfDataAndReturnAverage()
{
//
// TODO:
//
return -1.0;
}

Summary: analyze years of rainfall data from Chicago Midway airport, outputting the year and average rainfall for that year. Write a complete C++ program that inputs rainfall data collected at Chicago Midway airport, and outputs the average rainfall for each year. The format of the input data is as follows. There are N>0 lines, each containing 13 values: a year followed by 12 real numbers denoting the amount of rainfall for the 12 months of January, February,March, December. The last line of the input consists of a single value -1. Here's one possible input sequence: 2011 0.71 3.46 2.32 5.73 5.32 7.41 5.44 3.94 3.89 2.24 3.65 2.51 2012 2.16 1.39 2.17 2.63 4.32 1.07 3.78 6.06 1.61 3.21 1.04 2.09 2013 3.18 2.57 2.22 7.95 6.47 3.12 2.19 2.52 1.93 5.69 2.94 1.54 For this input, your program should produce the following output, which is the average rainfall for each year: 2011: 3.885 2012: 2.6275 2013: 3.52667

Explanation / Answer

The below prpgram results the same as reuired. the main program is calling function InputYearOfDataAndReturnAverage and passing 12 months data into it and the function returns the avergae of data. the programs terminates when we pass -1 to it.

/*analysis.cpp*/
#include <iostream>
#include <string>
using namespace std;
//
// InputYearOfDataAndReturnAverage()
//
// Inputs 12 rainfall values --- one per month --- and returns the average.
//
double InputYearOfDataAndReturnAverage(double monthData[13]){
int i;
double avg = 0.0;
for(i=0;i<12;i++){
avg += monthData[i];
}
avg = avg/12.0;
return avg;
}

int main(){
int year,i;
double monthData[13],avg;
while(1){
cin>>year;
if(year == -1) break;
for(i=0;i<12;i++){
cin>>monthData[i];
}
avg = InputYearOfDataAndReturnAverage(monthData);
cout<<year<<": "<<avg<<" ";
}
return 0;
}