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

We want to track weather conditions during the past year\'s three-month summer s

ID: 3673431 • Letter: W

Question

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. 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. Remember that good correct functions are required too, you must pass the 2d array to a fuction!! Finish your program, zip the main.cpp AND the RainorShine.txt file together, then load it to Mimir!! The test case uses the linked sample file.

Explanation / Answer

#include <bits/stdc++.h>
#include <time.h>
using namespace std;

void printStats(char weatherData[][30]) {
   int perMonthCount[3][3] = {0};

   for (int i = 0; i < 3; ++i) {
       for (int j = 0; j < 30; ++j) {
           switch(weatherData[i][j]) {
               case 'R':
                   perMonthCount[i][0] += 1;
               case 'C':
                   perMonthCount[i][1] += 1;
               case 'S':
                   perMonthCount[i][2] += 1;
           }
       }
   }

   int totalCount[3] = {0};
   for (int i = 0; i < 3; ++i) {
       for (int j = 0; j < 3; ++j) {
           totalCount[i] += perMonthCount[j][i];
       }
   }

   for (int i = 0; i < 3; ++i) {
       printf("For %d(th) month: ", i + 1);
       printf("Rainy: %d ", perMonthCount[i][0]);
       printf("Cloudy: %d ", perMonthCount[i][1]);
       printf("Shiny: %d ", perMonthCount[i][2]);
   }

   printf(" All months stats: ");
   printf("Rainy: %d ", totalCount[0]);
   printf("Cloudy: %d ", totalCount[1]);
   printf("Shiny: %d ", totalCount[2]);

   int maxRainIndex = 0;
   for (int i = 1; i < 3; ++i) {
       if (perMonthCount[maxRainIndex][0] > perMonthCount[i][0]) {
           maxRainIndex = i;
       }
   }
  
   printf("Maximum rain happened in %d(th) month of value %d ", maxRainIndex + 1, perMonthCount[maxRainIndex][0]);
}

int main() {
   freopen("RainOrShine.txt", "r", stdin);
   char weatherData[3][30];
   for (int i = 0; i < 3; ++i) {
       for (int j = 0; j < 30; ++j) {
           cin >> weatherData[i][j];
       }
   }
   printStats(weatherData);
   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