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

The code at the bottom of this submission was submitted by a chegg expert, but i

ID: 3679358 • Letter: T

Question

The code at the bottom of this submission was submitted by a chegg expert, but it did not compile.

perhaps you could expand on, or rewrite it

This project should be compatible with the default compiler for codeblocks

In C++

We want to track weather conditions during the past year's three-month summer season as has designated each day as either rainy ('R'), cloudy ('C'), or sunny ('S').

Write a program that stores this information in s 3x30 array of characters, where the row indicates the month and the column indicates the day of the month. Note no data is being captured for the 31st of any month.

This program will read the data in from a file called RainOrShine.txt. which must be created beforehand and it must cointain the following information:
R C R S R S R R S R S C R C S S S S R S C S R C S S C C R S
C R R R S R S R C S R C R S S S R S C R R S C C S C S C R R
C R C C S C C R R R S S S C R C C C R C R S S S R S C R R C

From this data it you should create a report that displays , for each month and for the whole three month period, how many days were rainy, how many were cloudy, and how many were sunny. It should also report which of the months had the largest number of rainy days.

The output should look like this:

#include <fstream>        // Required for input / outputting files.
#include <string>     // Required for strings.
using namespace std;

const int MONTH = 3;
const int DAY = 30;

int main()
{
string weather[MONTH][DAY] = {"June", "July", "August"};
using namespace std;
int totalRainy,
totalSunny,
totalCloudy;

ifstream datafile;

// Name of program.
cout << " Rain or Shine ";
cout << "--------------- ";

datafile.open("RainOrShine.dat");
if (!datafile)
cout << "Error opening data file. ";
else
{
cout << "Weather Report ";

for (int months = 0; months <= MONTH; months++)
{   totalRainy = 0,
totalSunny = 0,
totalCloudy = 0;

cout << weather[months][DAY];
datafile >> weather[months][DAY];

if ('R')
totalRainy += weather[months][DAY];
if ('S')
totalSunny += weather[months][DAY];
if ('C')
totalCloudy += weather[months][DAY];

cout << endl;
cout << " Total rainy days: " << totalRainy << endl;
cout << " Total sunny days: " << totalSunny << endl;
cout << " Total cloudy days: " << totalCloudy << endl << endl;

}

datafile.close();

for (int months = 0; months <= MONTH; months++)
{   totalRainy += weather[months][DAY];
totalSunny += weather[months][DAY];
totalCloudy += weather[months][DAY];
}


int highest = 0;
for (int count = 1; count < weather[MONTH][DAY]; count++)
{
if (weather[count] > weather[highest])
highest = count;
}

// Displays the total of all 3 months.
cout << "Total rainy days for all 3 months: " << totalRainy << endl;
cout << "Total sunny days for all 3 months: " << totalSunny << endl;
cout << "Total cloudy days for all 3 months: " << totalCloudy << endl;
cout << "The month with the most rainy days is " << highest << endl;

}

// Stops the program from closing automatically.
system("pause");
return 0;


}
#include <iostream>

#define MONTH 3
#define DAY 31

using namespace std;

int main(void)
   {

#if 0
string weather[MONTH][DAY+1] = {
{ "June", "1", "2", "3" },
{ "July" },
{ "August" }
};

for (int i = 0; i < MONTH; i++) {
for (int j = 0; j < DAY+1; j++)
cout << weather[i][j]
<< " ";
cout << endl;
}
#endif

#if 1
struct {
string month;
int day[DAY];
} weather[MONTH] = {
{ "June", 1, 2, 3 },
{ "July", { 1, 2, 3, 4, 5 } },
            { "August", 1 }
        };

         for (int i = 0; i < MONTH; i++) {
             cout << weather[i].month
                 << ": ";
            for (int j = 0; j < DAY; j++)
                 cout << weather[i].day[j]
                     << " ";
            cout << endl;
}
#endif

         return 0;
    }


Thank you for your time!

une uly ugust Rainy 10 12 10 32 Cloudy 7 8 12 27 Sunny 13 10 8 31 otal The rainiest month isJuly with 12 amount of rain

Explanation / Answer

/**** C++ code to track weather conditions during the past year's three-month summer season ****/

#include <iostream> // Setup standard output.
#include <fstream> // Required for input / outputting files.
#include <iomanip> // Required for numeric formatting function.
#include <string> // Required for strings.
using namespace std;


int main()
{   
const int MONTH = 3;
const int DAY = 30;
char name[MONTH][DAY] = {"June", "July", "August"};
char rain = 'R';
char sun = 'S';
char cloud = 'C';
int day = 0;
int months = 0;
int total_rainy = 0;
int total_sunny = 0;
int total_cloudy = 0;
int max_days = 0;   
string max_month;

ifstream datafile;

datafile.open("RainOrShine.txt");

if (!datafile)
cout << "Error opening data file. ";
else
{ cout << "Weather Report ";

cout << " Rainy Cloudy Sunny ";

for (months = 0; months < MONTH; months++)
{
int rainy = 0;
int cloudy = 0;
int sunny = 0;
for (day = 0; day < DAY; day++)
{
cout << name[months][day];
datafile >> name[months][day];

if (name[months][day] == 'R')
{
rainy++;
total_rainy++;

}

else if (name[months][day] == 'S')
{
sunny++;
total_sunny++;
}


else if (name[months][day] == 'C')
{
cloudy++;
total_cloudy++;
}


}
  
if(max_days < rainy)
{
max_days = rainy;
if(months == 0) max_month = "June";
else if(months == 1) max_month = "July";
else if(months == 2) max_month = "August";
}

cout<<" ";

cout <<rainy<<" ";
cout <<cloudy<<" ";
cout <<sunny<<" ";
cout <<" ";
}
datafile.close();
cout << "Total "<<total_rainy<<" "<<total_cloudy<<" "<<total_sunny<<endl;

}
cout << "The rainiest month is: "<< max_month<<" with "<<max_days<<" amount of rain. ";

return 0;

}