Question #46739

A meteorologist wants to keep track of weather conditions during the past year’s three month summer
season and has designated each day as either rainy (‘R’), cloudy (‘C’), or sunny (‘S’). Write a C++
program that stores this information in a 3x30 array of characters, where the row indicates the month
(0 = June, 1 = July, 2 = August) 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 named “weather.txt”. Then it 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 three months had the largest number of rainy days.

Expert's answer

Source Code

#include <conio.h>
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
    char weather[3][30];
    string test;
    int days = 0;
    int mounth = 0;
    int RainyMounth = 0;
    int RainyDay = 0;
    ifstream in("weather.txt");
    for (int i = 0; i < 93; i++)
    {
        if (i != 0 && i != 31 && i != 62)
        {
            if (days > 29)
            {
                days = 0;
                mounth++;
            }
            in >> test;
            weather[mounth][days] = test[0];
            days++;
        }
        else
        {
            in >> test;
        }
    }
    int Fday = 0;
    int Fmounth = 0;
    int current = 0;
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 30; j++)
        {
            if (weather[i][j] == 'R')
            {
                Fday++;
            }
        }
        if (Fday > current)
        {
            current = Fday;
            Fmounth = i;
        }
        Fday = 0;
    }
    cout << "June\t" << "July\t" << "August\t" << endl;
    for (int count = 0; count < 30; count++)
    {
        cout << count + 1 << ".";
        cout << weather[0][count] << "\t";
        cout << weather[1][count] << "\t";
        cout << weather[2][count] << endl;
    }
    switch (Fmounth)
    {
        case 0:
            cout << "Largest number of rainy days : June" << endl;
            break;
        case 1:
            cout << "Largest number of rainy days : July" << endl;
            break;
        case 2:
            cout << "Largest number of rainy days : August" << endl;
            break;
    }
    system("pause");
    return 0;
}


weather.txt:

```

June

C

S

R

C

S

C

R

S

C

C

S

C

S

C

S

S

R

S

S

C

C

S

C

S

C

S

C

C

S

C

July

R

S

C

S

R

S

S

R

C

C

R

S

S

S

C

C

S

R

S

S

C

R

S

C

S

R

S

S

S

S

August

C

S

C

S

C

C

C

C

C

C

R

C

N

C

S

R

S

C

R

C

C

C

C

C

C

C

C

C

C

```

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS