WELCOME

Welcome to KoDes4U

Pages

Friday, March 4, 2011

Constructor and Destructor(C++ Program)

/*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: 99for day of month,
999 for hightemp, -999 for lowtemp,00 for amount_rain and amount_snow.
Include a function that prompts the user and sets the values for each field
so that you can override the default values. Write a program that creates a
monthly report.
Coded for KoDes4U.blogspot.com*/

#include

#include

class weather_report
{
public:
//char month[25];
int date,days,amount_rain,amount_snow;
float hightemp,lowtemp ;
weather_report() //constructor defining
{
days=99;
hightemp=999;
lowtemp=-999;
amount_rain=0;
amount_snow=0;
}
~weather_report() //destructor defining
{
}
void set_data();
void display_report();
};

void weather_report::set_data()
{
cout<<"\nEnter the day of month :"; cin>>date;
cout<<"\nEnter the high temp:"; cin>>hightemp;
cout<<"\nEnter the low temp:"; cin>>lowtemp;
cout<<"\nEnter the amount of rainfall:"; cin>>amount_rain;
cout<<"\nEnter the amount of snowfall:"; cin>>amount_snow;
}

void weather_report::display_report()
{
cout<<"\t"<
>month;
cout<<"\nEnter the number of days you want:"; cin>>days;
for(cnt=0;cnt
{
weather[cnt].set_data();
}
cout<<"\n\n**********WEATHER REPORT**********\n\n"; cout<<"MONTH\tDATE\tHIGHTEMP\tLOWTEMP\tRAIN\tSNOW\n"; cout<<"\n------------------------------------------------"; cout<<"\n\n"; for(cnt=0;cnt
{
cout<<"\n"<
weather[cnt].display_report();
}
getch();
}

No comments:

Post a Comment