Write a modular program (functions) that analyzes a year\'s worth of rainfall da
ID: 3533768 • Letter: W
Question
Write a modular program (functions) that analyzes a year's worth of rainfall data. In addtioin to main(), the program should have a getData function that reads the 12 month rain data from a data file and stores it in an array. Set up a parralel array to store the names of the months which are in a different data file.
It should also have two value-returning functions that compute and return to main the totalRainfall and averageRainfall.
This information should be used either by main or by a displayReport function called by main to print a summary rainfall report similar to the following:
2012 Rain Report for Neversnows County
Total rainfall: 23.19 inches
Average monthly Rainfall: March 1.93 inches
Explanation / Answer
#include<iostream.h>
#include<fstream.h>
int rain_data[12],i;
char name[[30];
float avgrain();
float totalrain();
void getdata();
void main()
{
float total,avg;
getdata();
total=totalrain();
avg=avgrain();
cout<<"Total rain is "<<total;
cout<<"monthly rain and its avg is "<<avg<<" of month "<<name;
}
void getdata()
{
fstream file;
file.open("data.txt",ios::in);
int dat;
for(i=0;i<12;i++)
{
dat=file.read((*ch)&dat,sizeof(dat));
rain_data[i]=dat;
}
cout<<"Enter the month ";
cin>>name;
}
float avgrain()
{
float avg;=0
int i;
for(i=0;i<12;i++)
{
avg=avg+rain_data[i];
}
avg=avg/12;
return avg;
}
float totalrain()
{
float total=0;
for(i=0;i<12;i++)
total=total+rain_data[i];
return total;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.