/*
Problem Statement:
Create a class named weather report that holds a daily weather report with
data members day_of_month,hightemp,lowtemp,amount_rain and
amount_snow. The constructor initializes the fields with default values: 99
for day_of_month, 999 for hightemp,-999 for low temp and 0 for
amount_rain and amount_snow. Include a function that prompts the user
and sets values for each field so that you can override the default values.
Write a program that creates a monthly report.
*/
#include
#include
class weather
{
public:
int day_of_month[50];
int high_temp[50];
int low_temp[50];
int amount_rain[50];
int amount_snow[50];
weather() //defination
{
day_of_month[0]=99;
high_temp[0]=999;
low_temp[0]=-999;
amount_rain[0]=amount_snow[0]=0;
}
void get_data(int n);
void put_data(int n);
void average(int n);
};
void weather:: average(int n)
{
int min ,max,total_rainfall,total_snowfall;
total_rainfall=0;
total_snowfall=0;
min=low_temp[0];
max=high_temp[0];
for(int i=0;i
{
total_rainfall=(total_rainfall+amount_rain[i]);
total_snowfall=(total_snowfall+amount_snow[i]);
if(low_temp[i]
{
min=low_temp[i];
}
if(high_temp[i]>max)
{
max=high_temp[i];
}
}
total_rainfall=total_rainfall/n;
total_snowfall=total_snowfall/n;
cout<<"\n\nAverage rainfall:"<
cout<<"\n\nAverage snowfall:"<
cout<<"\n\nLowest Temp:"<
cout<<"\n\nHighest Temp :"<
}
void weather::get_data(int n)
{
for(int i=0;i
{
cout<<"\nEnter day of month:";
cin>>day_of_month[i];
cout<<"\nEnter The Highest Temp Of The Day: ";
cin>>high_temp[i];
cout<<"\nEnter The Lowest Temp Of The Day: ";
cin>>low_temp[i];
cout<<"\nEnter Amount Of Rain Of The Day: ";
cin>>amount_rain[i];
cout<<"\nEnter Amount Of Snow Of The Day: ";
cin>>amount_snow[i];
}
}
void weather ::put_data(int n)
{
for(int i=0;i
{
cout<<"\nDay of month(Date): "<
cout<<"\n\n\tHigh temp of that day: "<
cout<<"\n\n\tLow temp of that day: "<
cout<<"\n\n\tAmount of rain of that day: "<
cout<<"\n\n\tAmount of snow of that day: "<
}
}
void main()
{
int i,n;
weather w1;
clrscr();
cout<<"\nEnter no of days for the report:";
cin>>n;
cout<<"\nDefault Values:";
w1.put_data(1);
w1.get_data(n);
cout<<"\n......Weather Report.....";
w1.put_data(n);
w1.average(n);
getch();
}
Problem Statement:
Create a class named weather report that holds a daily weather report with
data members day_of_month,hightemp,lowtemp,amount_rain and
amount_snow. The constructor initializes the fields with default values: 99
for day_of_month, 999 for hightemp,-999 for low temp and 0 for
amount_rain and amount_snow. Include a function that prompts the user
and sets values for each field so that you can override the default values.
Write a program that creates a monthly report.
*/
#include
#include
class weather
{
public:
int day_of_month[50];
int high_temp[50];
int low_temp[50];
int amount_rain[50];
int amount_snow[50];
weather() //defination
{
day_of_month[0]=99;
high_temp[0]=999;
low_temp[0]=-999;
amount_rain[0]=amount_snow[0]=0;
}
void get_data(int n);
void put_data(int n);
void average(int n);
};
void weather:: average(int n)
{
int min ,max,total_rainfall,total_snowfall;
total_rainfall=0;
total_snowfall=0;
min=low_temp[0];
max=high_temp[0];
for(int i=0;i
{
total_rainfall=(total_rainfall+amount_rain[i]);
total_snowfall=(total_snowfall+amount_snow[i]);
if(low_temp[i]
{
min=low_temp[i];
}
if(high_temp[i]>max)
{
max=high_temp[i];
}
}
total_rainfall=total_rainfall/n;
total_snowfall=total_snowfall/n;
cout<<"\n\nAverage rainfall:"<
cout<<"\n\nAverage snowfall:"<
cout<<"\n\nLowest Temp:"<
cout<<"\n\nHighest Temp :"<
}
void weather::get_data(int n)
{
for(int i=0;i
{
cout<<"\nEnter day of month:";
cin>>day_of_month[i];
cout<<"\nEnter The Highest Temp Of The Day: ";
cin>>high_temp[i];
cout<<"\nEnter The Lowest Temp Of The Day: ";
cin>>low_temp[i];
cout<<"\nEnter Amount Of Rain Of The Day: ";
cin>>amount_rain[i];
cout<<"\nEnter Amount Of Snow Of The Day: ";
cin>>amount_snow[i];
}
}
void weather ::put_data(int n)
{
for(int i=0;i
{
cout<<"\nDay of month(Date): "<
cout<<"\n\n\tHigh temp of that day: "<
cout<<"\n\n\tLow temp of that day: "<
cout<<"\n\n\tAmount of rain of that day: "<
cout<<"\n\n\tAmount of snow of that day: "<
}
}
void main()
{
int i,n;
weather w1;
clrscr();
cout<<"\nEnter no of days for the report:";
cin>>n;
cout<<"\nDefault Values:";
w1.put_data(1);
w1.get_data(n);
cout<<"\n......Weather Report.....";
w1.put_data(n);
w1.average(n);
getch();
}
Comments
Post a Comment