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

Project#08: Rainfall Analysis Complete By: Assignment: Policy Wednesday, March 1

ID: 3729065 • Letter: P

Question

Project#08: Rainfall Analysis Complete By: Assignment: Policy Wednesday, March 14th @ 11:59pm Solve the following exercise, save as rainfall.cpp Individual work only, late work *is* accepted (see "Policy" section on last page for more details) submit rainfall.cpp via zybook section 6.26 Post a comment to start a disc @Mention someone to notify s Submission: Rainfall analysis The goal is to write a complete C+ program to analyze monthly rainfall data. The data we'll use is from Chicago's Midway airport, but the data could be from any location. The file format consists of an information row, followed by N >0 rows of data. For example, here's the contents of the input file midway-1.txt Chicago _Midway Airport 20152017 2015 1.23 0.24 0.48 2.94 4.13 4.37 2.25 3.46 4.97 1.59 4.14 5.40 2016 0.65 0.21 3.05 2.50 5.56 1.56 4.95 6.42 1.19 4.22 1.66 1.25 2017 2.65 2.40 4.18 6.27 3.77 2.60 423 1.90 0.56 5.98 2.33 0.17 Each data row starts with an integer year, followed by 12 real numbers denoting the inches of rainfall for each month (Jan, Feb, icage Mlay Airport as Dec). The program analyzes this data and outputs the following: 1. The average rainfall for each year 2. The trend (,,+, ++) as 2016: 2.76833 ed to the previous year27: 3.867)

Explanation / Answer

CODE

#include<iostream>

#include<fstream>

using namespace std;

void readInput(ifstream &input, double rainfall[][13], int& rows)

{

while(!input.eof())

{

for(int i=0; i<13; i++)

input>>rainfall[rows][i];

rows++;

}

}

void printAverageByYear(double rainfall[][13], int rows)

{

cout<<"Average by year (in inches): "<<endl;

for(int i=0; i<rows; i++)

{

double sum=0;

for(int j=1; j<=12; j++)

{

sum+=rainfall[i][j];

}

double avg=sum/12;

cout<<(int)rainfall[i][0]<<": "<<avg<<endl;

}

cout<<endl<<endl;

}

string getMonthName(int month)

{

switch(month){

case 1: return "January";

case 2: return "February";

case 3: return "March";

case 4: return "April";

case 5: return "May";

case 6: return "June";

case 7: return "July";

case 8: return "August";

case 9: return "September";

case 10: return "October";

case 11: return "November";

case 12: return "December";

}

return NULL;

}

void averageByMonth(double rainfall[][13], int &rows)

{

cout<<"Average by month (in inches): "<<endl;

for(int i=1; i<=12; i++)

{

double sum=0;

for(int j=0; j<rows; j++)

{

sum+=rainfall[j][i];

}

double avg=sum/rows;

cout<<getMonthName(i)<<": "<<avg<<endl;

}

cout<<endl<<endl;

}

void getMaximumRainfall(double rainfall[][13], int rows)

{

double max=-1;

int year=-1;

int month=-1;

for(int i=0; i<rows; i++)

{

for(int j=1; j<=12; j++)

{

if(rainfall[i][j]>max)

{

max=rainfall[i][j];

year=(int)rainfall[i][0];

month=j;

}

}

}

cout<<"Maximum Rainfall: "<<max<<" inches on "<<getMonthName(month)<<" "<<year<<endl<<endl;

}

void getMinimumRainfall(double rainfall[][13], int rows)

{

double min=100000;

int year=-1;

int month=-1;

for(int i=0; i<rows; i++)

{

for(int j=1; j<=12; j++)

{

if(rainfall[i][j]<min)

{

min=rainfall[i][j];

year=(int)rainfall[i][0];

month=j;

}

}

}

cout<<"Minimum Rainfall: "<<min<<" inches on "<<getMonthName(month)<<" "<<year<<endl<<endl;

}

int main()

{

ifstream input;

input.open("rainfall.txt");

double rainfall[200][13];

int rows=0;

readInput(input, rainfall, rows);

printAverageByYear(rainfall, rows);

averageByMonth(rainfall, rows);

getMaximumRainfall(rainfall, rows);

getMinimumRainfall(rainfall, rows);

cin.get();

return 0;

}

If any queries please get back to me

Thank You