Question
C++ and Analysis.cpp
6.22 P06-02 Rainfall Analysis with Functions 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-O 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 -1 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 Like the previous exercise, the provided code is actually spread across 2 0++ source files: "main.cpp and 'analysis.opp. Start by reviewing the code for main.cpp' which is visible in the editor pane--note that this code is read-only (you cannot modify it). In particular, focus on the code within the while loop. Once the year is input, you'l see that the InputYearofDataAndReturnAverage0 function is called to input the remaining 12 values on that line, then compute and return the average The average is stored, output, and then the next year is input and
Explanation / Answer
save this file as analysis.cpp, compile and run.
use your main.cpp as instructed. A sample main function is added in this file for your reference
/*
* analysis.cpp
*
* Created on: 08-Oct-2017
* Author:
*/
#include <iostream>
#include <string>
using namespace std;
double InputYearOfDataAndReturnAverage();
// call this function from main.cpp after year is entered
double InputYearOfDataAndReturnAverage()
{
double data;
double sum=0;
cout<<"Enter the Month wise data";
for(int i=0;i<12;i++)
{
cin>>data;
sum=sum+data;
}
return (sum/12.0);
}
//put this code in main.cpp
int main()
{
int year;
double avg;
while(1)
{
cout<<"Enter year";
cin>>year;
avg=InputYearOfDataAndReturnAverage();
cout<<"Average rainfall is"<<avg<<endl;
}
return 0;
}