private:
static int no_record;
int day_of_month;
int hightemp;
int lowtemp;
int amt_rain;
int amt_snow;
static int total_ht;
static int total_lt;
static int total_r;
static int total_s;
float avg_ht;
float avg_lt;
float avg_r;
float avg_s;
public:
weather_report();
weather_report(int ,int ,int ,int ,int );
~weather_report();
int tellday();
int tellrecord();
void viewreport();
void telltemp();
void modify();
};
int weather_report::no_record=0;
int weather_report::total_ht=0;
int weather_report::total_lt=0;
int weather_report::total_r=0;
int weather_report::total_s=0;
weather_report::weather_report()
{
day_of_month=99;
hightemp=999;
lowtemp=-999;
amt_rain=0;
amt_snow=0;
}
weather_report::weather_report(int dom,int ht,int lt,int amtr,int amts)
{
day_of_month=dom;
hightemp=ht;
lowtemp=lt;
amt_rain=amtr;
amt_snow=amts;
total_ht+=ht;
total_lt+=lt;
total_r+=amtr;
total_s+=amts;
no_record++;
cout<<"\nRecord Created !!";
}
weather_report::~weather_report()
{
no_record--;
total_ht-=hightemp;
total_lt-=lowtemp;
total_r-=amt_rain;
total_s-=amt_snow;
cout<<"\nRecord Deleted !!";
}
void weather_report::modify()
{
int temp,k;
cout<<"\n\n\t\tSUBMENU:\n\t1> Modify high temp\n\t2> Modify low temp";
cout<<"\n\t3> Modify amt of rain\n\t4> Modify amt of snow";
cout<<"\n\t5> Back to main menu\n\tChoose one: ";
k=getche()-48;
total_ht-=hightemp;
total_lt-=lowtemp;
total_r-=amt_rain;
total_s-=amt_snow;
switch(k)
{
case 1:
cout<<"\n\tEnter new value : ";
cin>>temp;
hightemp=temp;
break;
case 2:
cout<<"\n\tEnter new value : ";
cin>>temp;
lowtemp=temp;
break;
case 3:
cout<<"\n\tEnter new value : ";
cin>>temp;
amt_rain=temp;
break;
case 4:
cout<<"\n\tEnter new value : ";
cin>>temp;
amt_snow=temp;
break;
case 5:
break;
}
total_ht+=hightemp;
total_lt+=lowtemp;
total_r+=amt_rain;
total_s+=amt_snow;
cout<<"\n\n..Record modified..";
}
void weather_report::viewreport()
{
cout<<day_of_month<<" "<<hightemp<<" "<<lowtemp<<" ";
cout<<amt_rain<<" "<<amt_snow;
}
void weather_report::telltemp()
{
avg_ht=(float)total_ht/no_record;
avg_lt=(float)total_lt/no_record;
avg_r=(float)total_r/no_record;
avg_s=(float)total_s/no_record;
cout<<"\n\nAverage High Temp: "<<avg_ht;
cout<<"\nAverage Low Temp: "<<avg_lt;
cout<<"\nAverage amount of rain: "<<avg_r;
cout<<"\nAverage amount of snow: "<<avg_s;
}
int weather_report::tellday()
{
return day_of_month;
}
int weather_report::tellrecord()
{
return no_record;
}
int main()
{
weather_report *w[31];
int i=0,k,j,temp;
do
{
clrscr();
cout<<"\n\t\tWEATHER REPORT";
cout<<"\n\t\tMENU:\n\t1> Create a record\n\t2> Delete a record";
cout<<"\n\t3> Modify a record\n\t4> View DAILY report\n\t";
cout<<"5> View MONTHLY report\n\t6> Exit\n\tChoose one: ";
k=getche()-48;
switch(k)
{
case 1:
int dom;
cout<<"\n\n\tReading records...\n\tEnter day of month: ";
cin>>dom;
if(dom>31&&dom<1)
{
cout<<"\n\nERR: ....Invalid day....";
break;
}
for(j=0;j<i;j++)
{
if(w[j]->tellday()==dom)
{
cout<<"\nERR: Cannot duplicate days....";
getch();
break;
}
}
if(j!=i)
break;
int ht;
cout<<"\tEnter high temp: ";
cin>>ht;
int lt;
cout<<"\tEnter low temp: ";
cin>>lt;
int amtr;
cout<<"\tEnter amount of rain: ";
cin>>amtr;
int amts;
cout<<"\tEnter amount of snow: ";
cin>>amts;
w[i++]=new weather_report(dom,ht,lt,amtr,amts);
break;
case 2:
cout<<"\nEnter the day to be deleted: ";
cin>>k;
int flag=0;
for(j=0;j<i;j++)
if(w[j]->tellday()==k)
{
flag=1;
delete w[j];
for(k=j;k<i-1;k++)
w[k]=w[k+1];
i--;
break;
}
if(flag==0)
cout<<"\nNo record found...";
break;
case 3:
cout<<"\nEnter the day to be Modify: ";
cin>>k;
flag=0;
for(j=0;j<i;j++)
if(w[j]->tellday()==k)
{
flag=1;
clrscr();
cout<<"\n\t\tWEATHER REPORT";
cout<<"\n\nRecordNo Day HighTemp LowTemp AmtRain AmtSnow";
cout<<"\n"<<j+1<<" ";
w[j]->viewreport();
w[j]->modify();
}
if(flag==0)
cout<<"\nNo record found...";
break;
case 4:
cout<<"\nEnter the day to be viewed: ";
cin>>k;
for(j=0;j<i;j++)
if(w[j]->tellday()==k)
{
cout<<"\n\nRecordNo Day HighTemp LowTemp AmtRain AmtSnow";
cout<<"\n"<<j+1<<" ";
w[j]->viewreport();
break;
}
if(j==i)
cout<<"\nRecord not found....";
break;
case 5:
clrscr();
cout<<"\n\t\tWEATHER REPORT";
cout<< endl;
cout<<"Total no of records: ";
cout<<w[i-1]->tellrecord();
if(i==0)
{
cout<<"\n\nRecord not found...";
break;
}
else
cout<<"\n\nRecordNo Day HighTemp LowTemp AmtRain AmtSnow";
for(j=0;j<i;j++)
{
cout<<"\n"<<j+1<<" ";
w[j]->viewreport();
}
w[j-1]->telltemp();
break;
case 6:
exit(0);
break;
default:
cout<<"\n\tWrong choice....";
}
cout<<"\n\n\n\t...Press 'Enter' to continue...";
}while(getch()==13);
return 0;
}
No comments:
Post a Comment