Write a C++ program that defines a structure, Mweather. The structure stores the
ID: 3642631 • Letter: W
Question
Write a C++ program that defines a structure, Mweather. The structure stores the following data about the monthly weather. All the member variables are double.total rainfall
high temperature
low temperature
average temperature
In the program, declare an array of 12 structures to hold weather data for an entire year.
When the programs runs, it should ask the user to enter data for each month, that is, the total rainfall, the highest temperature and the lowest temperature. The data must be entered in that order for testing purposes.
Once the data is entered for all the months, the program should calculate the average temperature for each month. Pass the array of structures to a function to calculate the average temperature for each month and store the result in the appropriate member variable.
The program should then calculate and display:
the average rainfall for the year
the total rainfall for the year
the highest and lowest temperatures for the year
the average of all the monthly average temperatures
You should write a function to calculate the averages and write the output.
Explanation / Answer
#include #include using namespace std; struct Mweather{ double total_rainfall; double high_temp; double low_temp; double average_temp; }; void avr_temp(struct Mweather *tmp); void avr_rain(struct Mweather *tmp); void high_temp(struct Mweather *tmp); void low_temp(struct Mweather *tmp); void main(){ struct Mweather M[12]; int i=0; while(iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.