Question: Modify the code below so that the program now reads a location followed by 1 2 numbers that represent amount of rainfall for each month
Modify the code below so that the program now reads a location followed by numbers that represent
amount of rainfall for each month in that location. program reads a data file that is named READRAINFALL.TXT
reads a data file
void readRainfallForLocation ifstream &fin, float rainfall;
two overloaded functions:
output the contents of the parallel arrays of months and rainfall
void outputArrays ofstream &fout, string months float rainfall;l
output the statistics to a file
oid outputStatistics ofstream &fout, string months float rainfall
float total, float average, int locGreatest;
Please update this code I built adding the things above.
#include
using namespace std;
function to print the rainfall of each month
void rainfallStatisticsstring month double rainfall
double sum ; variable to store the total sum of rainfall
string maxMonth month; variable to return month with maximum rainfall
double maxRainfall INTMIN; variable to store the maximum rainfall
running the loop till the last month
forint i; i; i
printing the month and rainfall
cout monthi fixed setprecision rainfalli inches" endl;
storing the sum
sum sum rainfalli;
checking the month with highest rainfall
ifrainfalli maxRainfall
maxRainfall rainfalli;
maxMonth monthi;
calculating the average of the rainfall
double average sum double;
cout endl;
cout "Total for the year sum inches" endl;
cout "Average rainfall per month average inches" endl;
cout "Month with the greatest rainfall was maxMonth with rainfall of maxRainfall inches" endl;
driver program
int main
array to store the nonth name
string monthJan "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec";
array to store the rainfall
double rainfall;
double rainfall;
cout "Hayward Statistics" endl;
cout endl;
cout "Month" "Rainfall" endl;
calling the function for Hayward
rainfallStatisticsmonth rainfall;
cout endl;
cout endl;
cout "Seattle Statistics" endl;
cout endl;
cout "Month" "Rainfall" endl;
calling the function for Houston
rainfallStatisticsmonth rainfall;
return ;
This is a shell for final code.
#include
#include
#include
#include
using namespace std;
Prototypes
void readRainfallForLocation ifstream &fin, float rainfall;
void findTotalandAveragefloat monthlyRain float &total, float &average;
int findGreatestRainLocfloat ;
void outputArrays string months float rainfall;
void outputArrays ofstream &fout, string months float rainfall;
void outputStatistics string months float rainfall float total, float average, int locGreatest;
void outputStatistics ofstream &fout, string months float rainfall float total, float average, int locGreatest;
int main
declare and initialize an array of strings containing month abbreviations
string monthsJan "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ;
float monthlyRainfall; Stores monthly rainfall for an entire year for one location
string location;
float total, average;
int locGreatest; array index of greatest rainfall
ifstream fin;
ofstream fout;
fin.openREADRAINFALLTXT;
fixme Open both input and output files and check that they opened successfully
Master loop
getlinefin location; priming input gets first location
while fin.eof
readRainfallForLocation fin monthlyRainfall; input the twelve monthly rain amounts
fixme Call the other functions as done in the zyLab
add two overloaded output to file functions as shown in protoypes
fin.ignore; skip over the line feed left in the buffer after last number was read
getlinefin location; get the next location until End of File
return ;
All functions are omitted for now.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
