//OrinTill Qimid CS1A Chapter 4, P. 294, 4
//
/**************************************************************
* Tic Tac Toe
*
* ____________________________________________________________
*
* ____________________________________________________________
* INPUT
*
* OUTPUT
*
**************************************************************/
#include <iostream>
#include <vector>
#include <limits>
#include <fstream>
using namespace std;
int main() {
const int MONTHS = 3;
const int DAYS = 30;
// Initialize a 2D vector to store weather data for each month and each day
vector<vector<char>> weatherData(MONTHS, vector<char>(DAYS));
// Input weather data from file
string filename = "RainOrShine.dat";
ifstream inputFile(filename);
if (!inputFile) {
cerr << "Error opening file: " << filename << endl;
return 1;
}
for (int month = 0; month < weatherData.size(); ++month) {
for (int day = 0; day < weatherData[month].size(); ++day) {
inputFile >> weatherData[month][day];
}
}
inputFile.close();
// Display weather report
const string monthNames[3] = {"June", "July", "August"};
int totalRainy = 0, totalCloudy = 0, totalSunny = 0;
int maxRainyDays = 0;
string rainiestMonth;
for (int month = 0; month < MONTHS; ++month) {
int rainyDays = 0, cloudyDays = 0, sunnyDays = 0;
for (char day : weatherData[month]) {
if (day == 'R') {
rainyDays++;
} else if (day == 'C') {
cloudyDays++;
} else if (day == 'S') {
sunnyDays++;
}
}
totalRainy += rainyDays;
totalCloudy += cloudyDays;
totalSunny += sunnyDays;
cout << "\nWeather Report for " << monthNames[month] << ":" << endl;
cout << "Rainy Days: " << rainyDays << endl;
cout << "Cloudy Days: " << cloudyDays << endl;
cout << "Sunny Days: " << sunnyDays << endl;
if (rainyDays > maxRainyDays) {
maxRainyDays = rainyDays;
rainiestMonth = monthNames[month];
}
}
cout << "\nThree-Month Weather Summary:" << endl;
cout << "Total Rainy Days: " << totalRainy << endl;
cout << "Total Cloudy Days: " << totalCloudy << endl;
cout << "Total Sunny Days: " << totalSunny << endl;
cout << "Month with the Most Rainy Days: " << rainiestMonth << " with " << maxRainyDays << " rainy days." << endl;
return 0;
}