The program should have an array of 12 structures to hold weather data for an entire year. When the program runs, it should ask the user to enter data for each month. The program then should display month-wise min., max. and average temperatures and rainfalls in a table-like format. In addition, it should display average min., average max. and average mean temperature of the entire year. Similarly, it should display average min., average max. and average mean rainfall of the entire year. The following checks should be implemented for valid input. • Temperature range: -70 to +60 C • Rainfall range: 1mm to 25mm • Min. value <= Average value <= Max value
#include<conio.h>
#include <iostream>
# include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include <cmath>
#include<dos.h>
#include <bits/stdc++.h>
using namespace std;
#define MIN -60
#define MAX 70
#define MIN_RF 0
#define MAX_RF 100
struct Weather
{
int MinTemp;
int MaxTemp;
float AvgTemp;
int MinRainFall;
int MaxRainFall;
float AvgRainFall;
};
int main()
{
struct Weather W[12];
int n;
float MeanMinT=0,MeanMaxT=0,MeanAvgT=0;
float MeanMinRF=0,MeanMaxRF=0,MeanAvgRF=0;
string Month[12] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
for(n==0;n<12;n++)
{
W[n].MinTemp = 0;
W[n].MaxTemp = 0;
W[n].AvgTemp = 0;
W[n].MinRainFall = 0;
W[n].MaxRainFall = 0;
W[n].AvgRainFall = 0;
}
for(n=0;n<12;n++)
{
cout<<"\nMonth: "<<Month[n];
W[n].MinTemp = MAX+1;
while(W[n].MinTemp<MIN || W[n].MinTemp>MAX) {cout<<"\nEnter Minimum Temp. ("<<MIN<<" to "<<MAX<<" deg C) = "; cin>>W[n].MinTemp;}
W[n].MaxTemp = MAX+1;
while(W[n].MaxTemp<MIN || W[n].MaxTemp>MAX) {cout<<"\nEnter Maximum Temp. ("<<MIN<<" to "<<MAX<<" deg C) = "; cin>>W[n].MaxTemp;}
W[n].AvgTemp = MAX+1;
while(W[n].AvgTemp<MIN || W[n].AvgTemp>MAX) {cout<<"\nEnter Average Temp. ("<<MIN<<" to "<<MAX<<" deg C) = "; cin>>W[n].AvgTemp;}
W[n].MinRainFall = MAX_RF+1;
while(W[n].MinRainFall<MIN_RF || W[n].MinRainFall>MAX_RF) {cout<<"\nEnter Minimum RainFall ("<<MIN_RF<<" to "<<MAX_RF<<") = "; cin>>W[n].MinRainFall;}
W[n].MaxRainFall = MAX_RF+1;
while(W[n].MaxRainFall<MIN_RF || W[n].MaxRainFall>MAX_RF) {cout<<"\nEnter Maximum RainFall ("<<MIN_RF<<" to "<<MAX_RF<<") = "; cin>>W[n].MaxRainFall;}
W[n].AvgRainFall = MAX_RF+1;
while(W[n].AvgRainFall<MIN_RF || W[n].AvgRainFall>MAX_RF) {cout<<"\nEnter Average RainFall ("<<MIN_RF<<" to "<<MAX_RF<<") = "; cin>>W[n].AvgRainFall;}
}
for(n=0;n<12;n++)
{
MeanMinT = MeanMinT + W[n].MinTemp;
MeanMaxT = MeanMaxT + W[n].MaxTemp;
MeanAvgT = MeanAvgT + W[n].AvgTemp;
MeanMinRF = MeanMinRF + W[n].MinRainFall;
MeanMaxRF = MeanMaxRF + W[n].MaxRainFall;
MeanAvgRF = MeanAvgRF + W[n].AvgRainFall;
}
MeanMinT = MeanMinT/12;
MeanMaxT = MeanMaxT/12;
MeanAvgT = MeanAvgT/12;
MeanMinRF = MeanMinRF/12;
MeanMaxRF = MeanMaxRF/12;
MeanAvgRF = MeanAvgRF/12;
cout<<"\nMonth\tMin. Temp.\tMax. Temp.\tAvg. Temp.\tMin. Rain Fall\tMax. Rain Fall\tAvg. Rain Fall";
for(n=0;n<12;n++)
{
cout<<"\n"<<Month[n]<<"\t"<<setprecision(5)<<W[n].MinTemp<<"\t\t"<<W[n].MaxTemp<<"\t\t"<<W[n].AvgTemp<<"\t\t"<<W[n].MinRainFall<<"\t\t"<<W[n].MaxRainFall<<"\t\t"<<W[n].AvgRainFall;
}
cout<<"\n\nAvg. Min. Temp. = "<<MeanMinT;
cout<<"\nAvg. Max. Temp. = "<<MeanMaxT;
cout<<"\nAvg. Avg. Temp. = "<<MeanAvgT;
cout<<"\nAvg. Min. Rain Fall = "<<MeanMinRF;
cout<<"\nAvg. Max. Rain Fall = "<<MeanMaxRF;
cout<<"\nAvg. Avg. Rain Fall = "<<MeanAvgRF;
return(0);
}
Comments
Leave a comment