Answer to Question #328046 in C++ for User12345

Question #328046

Write C++ program using pointers in which An amateur 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 program that stores this information in a 3 × 10 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 are not being collected for the date greater than 10th f any month. The program should begin by reading the weather data from user. 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.


1
Expert's answer
2022-04-13T02:15:14-0400
#include <iostream>
#include <map>


const int MONTHS = 3;
const int DAYS = 10;


void print_month_for_report(int i, std::map<char, int> june, std::map<char, int> july, std::map<char, int> august, std::map<char, int> total)
{
	switch (i)
	{
	case 0:
		std::cout << "June:" << std::endl;
		std::cout << "Rainy days - " << june['R'] << std::endl;
		std::cout << "Cloudy days - " << june['C'] << std::endl;
		std::cout << "Sunny days - " << june['S'] << std::endl;
		break;
	case 1:
		std::cout << "July:" << std::endl;
		std::cout << "Rainy days - " << july['R'] << std::endl;
		std::cout << "Cloudy days - " << july['C'] << std::endl;
		std::cout << "Sunny days - " << july['S'] << std::endl;
		break;
	case 2:
		std::cout << "August:" << std::endl;
		std::cout << "Rainy days - " << august['R'] << std::endl;
		std::cout << "Cloudy days - " << august['C'] << std::endl;
		std::cout << "Sunny days - " << august['S'] << std::endl;
		break;
	case 3:
		std::cout << "The whole three-month period:" << std::endl;
		std::cout << "Rainy days - " << total['R'] << std::endl;
		std::cout << "Cloudy days - " << total['C'] << std::endl;
		std::cout << "Sunny days - " << total['S'] << std::endl;
	}
}


int main()
{
	std::map<char, int> total_weather_count = { {'R', 0}, {'C', 0}, {'S', 0} };
	std::map<char, int> june_weather_count = { {'R', 0}, {'C', 0}, {'S', 0} };
	std::map<char, int> july_weather_count = { {'R', 0}, {'C', 0}, {'S', 0} };
	std::map<char, int> august_weather_count = { {'R', 0}, {'C', 0}, {'S', 0} };
	char weather[MONTHS][DAYS];
	
	for (int i = 0; i < MONTHS; i++)
	{
		for (int j = 0; j < DAYS; j++)
		{
			std::cin >> *(*(weather + i) + j);


			switch (i)
			{
			case 0:
				june_weather_count[*(*(weather + i) + j)]++;
				break;
			case 1:
				july_weather_count[*(*(weather + i) + j)]++;
				break;
			case 2:
				august_weather_count[*(*(weather + i) + j)]++;
				break;
			}


			total_weather_count[*(*(weather + i) + j)]++;
		}
	}


	for (int i = 0; i < MONTHS + 1; i++)
	{
		print_month_for_report(i, june_weather_count, july_weather_count, august_weather_count, total_weather_count);
	}


	std::cout << "The most rainy month is ";
	if (june_weather_count['R'] >= july_weather_count['R'] && june_weather_count['R'] >= august_weather_count['R'])
	{
		std::cout << "June";
	}
	else if (july_weather_count['R'] >= june_weather_count['R'] && july_weather_count['R'] >= august_weather_count['R'])
	{
		std::cout << "July";
	}
	else
	{
		std::cout << "August";
	}
}

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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS