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

An amateur meteorologist wants to keep track of weather conditions during the pa

ID: 3660902 • Letter: A

Question

An amateur meteorologist wants to keep track of weather conditions during the past year's three month winter season and has designated each day as either rainy ('R'), cloudy ('C'), or sunny ('S'). Write a program that stores this information in a 3 x 30 array of characters where the row indicates the month. (0 = October, 1 = November, 2 = December) and the column indicates the day of the month. Note that data is not being collected for the 31st of any month. The program should begin by reading the weather data in from a file. Then it should create a report that displays for each month and for the whole three-month period, how days were rainy, how many were cloudy, and how many were sunny. It should also report which of the three months had the largest number of rainy days. For use with your program, create a file called RainOrShine.dat and copy/paste the following data... RRCSSSCSCRRRCSSSCSSRSCCRCRRCSS //(next line in .dat file starts here) SSSCCSSSCCSSSCCSSSCRCRCSSSSSS //(next line in .dat file starts here) SSSSCSSSCSSSCRRCCCSSSSSCSSSSCS

Explanation / Answer

#include<iostream>
#include<fstream>
#include<string>

using namespace std;

int main ()
{
    ifstream myfile;
    myfile.open("RainOrShine.dat");
    char data[3][30];
    int month = 0;
    int day = 0;

    while (myfile.good())
    {
        char temp;
        myfile.get(temp);
        if (temp == ' ')
        {
            ++month;
            day = 0;
        }
        else
        {
            data[month][day] = temp;
            ++day;
        }
    }

    myfile.close();

    string month_names[] = {"October", "November", "December"};
    int rainy_cloudy_sunny[3][3] = {{0,0,0},{0,0,0},{0,0,0}};
    for (int m = 0; m < 3; ++m)
    {
        cout << month_names[m] << endl;
        for (int d = 0; d < 31; ++d)
        {
            switch (data[m][d])
            {
              case 'R':
                  ++rainy_cloudy_sunny[m][0];
                  break;

              case 'C':
                  ++rainy_cloudy_sunny[m][1];
                  break;

              case 'S':
                  ++rainy_cloudy_sunny[m][2];
                  break;

              default:
                  break;
            }
        }
        cout << "Rainy: " << rainy_cloudy_sunny[m][0] << endl;
        cout << "Cloudy: " << rainy_cloudy_sunny[m][1] << endl;
        cout << "Sunny: " << rainy_cloudy_sunny[m][2] << endl << endl;
    }

    int most_rainy = 0;
    int max = rainy_cloudy_sunny[0][0];
    for (int m = 1; m < 3; ++m)
    {
        if (rainy_cloudy_sunny[m][0] > max)
        {
            most_rainy = m;
        }
    }

    cout << "Most rainy days: " << month_names[most_rainy] << endl;
    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote