Question: #include #include / / Define the number of months and days const int MONTHS = 3 ; const int DAYS = 3 0 ; /
#include
#include
Define the number of months and days
const int MONTHS ;
const int DAYS ;
Function prototypes
void readWeatherDatachar dataDAYS const char filename;
void calculateAndPrintReportconst char dataDAYS;
int countWeatherconst char data char type;
void findMonthWithMostRainconst char dataDAYS;
int main
Initialize a xD array of characters to store weather data
char weatherDataMONTHSDAYS;
Read weather data from the file
readWeatherDataweatherData "RainOrShine.txt;
Generate and print the weather report
calculateAndPrintReportweatherData;
Identify which month had the most rainy days
findMonthWithMostRainweatherData;
return ;
Function to read weather data from a file
void readWeatherDatachar dataDAYS const char filename
std::ifstream inFilefilename;
if inFile.isopen
std::cerr "Error opening file.";
exit;
for int month ; month MONTHS; month
for int day ; day DAYS; day
inFile data month day;
inFile.close;
Function to count the number of specific weather type days
int countWeatherconst char data char type
int count ;
for int day ; day DAYS; day
if data day type
count;
return count;
Function to calculate and print the weather report
void calculateAndPrintReportconst char dataDAYS
const char monthsMONTHSJune "July", "August";
int totalSunny totalCloudy totalRainy ;
for int month ; month MONTHS; month
int sunnyDays countWeatherdata monthS;
int cloudyDays countWeatherdata monthC;
int rainyDays countWeatherdata monthR;
std::cout monthsmonth Sunny Days: sunnyDays
Cloudy Days: cloudyDays Rainy Days: rainyDays std::endl;
totalSunny sunnyDays;
totalCloudy cloudyDays;
totalRainy rainyDays;
std::cout "Total Sunny Days: totalSunny Cloudy Days: totalCloudy
Rainy Days: totalRainy std::endl;
Function to find the month with the most rainy days
void findMonthWithMostRainconst char dataDAYS
const char monthsMONTHSJune "July", "August";
int maxRainyDays ;
int maxRainyMonth ;
for int month ; month MONTHS; month
int rainyDays countWeatherdata monthR;
if rainyDays maxRainyDays
maxRainyDays rainyDays;
maxRainyMonth month;
std::cout "The month with the most rainy days is monthsmaxRainyMonth std::endl;
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
