Professional Documents
Culture Documents
Weather
Weather
h>
class weather { private: int dayofmonth; int temph; int templ; int rain ; int snow;
void display();
friend void average(weather *,int n); friend int del(weather *,int n,int n1); friend void displayp(weather *,int n,int n3) ; friend int same(weather *,int n,int a); friend void modify(weather *,int n,int n4 );
};
weather ::weather(int a,int th,int tl,int r,int s) { dayofmonth=a; temph=th; templ=tl; rain =r; snow=s; count++;
} int del(weather *w,int n,int n1) { int i; for(i=0;i<n;i++) { if(n1==w[i].dayofmonth) { w[i]=w[i+1]; w[i].count--; return 1; }
} return 0; }
cout<<"\naverage high temp :\t"<<(float)th/n; cout<<"\naverage low temp:\t"<<(float)tl/n; cout<<"\naverage rain:\t"<<(float)r/n; cout<<"\naverage snow:\t"<<(float)s/n; } void displayp(weather *w,int n,int n3) { int i; for(i=0;i<n;i++) { if(n3==w[i].dayofmonth) {
cout<<"\nentered data of the day\t"; cout<<"\nday \ttemph\tlowl\train\tsnow"; cout<<"\n"<<w[i].dayofmonth; cout<<"\t"<<w[i].temph; cout<<"\t"<<w[i].templ; cout<<"\t"<<w[i].rain; cout<<"\t"<<w[i].snow; break; } } if(i==n) cout<<"\ndata not found\t"; }
return(0); }
return(1);
} void modify(weather *w,int n,int n4) { char e; int i,da,th,tl,ra,sn,k=1; for(i=0;i<n;i++) { if(n4==w[i].dayofmonth) { da=w[i].dayofmonth ; th=w[i].temph ; tl=w[i].templ ; ra=w[i].rain ; sn=w[i].snow ; break; } } cout<<"\nenter the field you want to modify\t"; cout<< "\nd for day\nh for high temp\nl for low temp\nr for rain \ns for snow\t" ; cin>>e; if(e=='d') { cout<<"\nenter the new field\t"; cin>>da;
// }
w[i]=weather(da,th,tl,ra,sn) ;
cin>>ra; w[i]=weather(da,th,tl,ra,sn) ;
do {
cout<<"\n\t\t\tenter your choice\t"; cout<<"\n\t\t\t1:enter the data\t"; cout<<"\n\t\t\t2:to print data\t"; cout<<"\n\t\t\t3:to delete data\t"; cout<<"\n\t\t\t4:to modify data\t"; cout<<"\n\t\t\t5:to find data of a particular day:\t"; cin>>ch; switch(ch) { case 1: { int k; cout<<"\nenter the no of data you want to create\t"; cin>>n; for(i=0;i<n;i++) { cout<<"\nday of month\t"; cin>>a; k= same(&w[0],n,a); if(k==0) { cout<<"\ndays cannot be same\t"; break; } else
{ cout<<"\nhigh temp\t"; cin>>th; cout<<"\nlow temp\t"; cin>>tl; cout<<"\nrain\t"; cin>>r; cout<<"\nsnow\t"; cin>>s; w[i]=weather(a,th,tl,r,s) ; } } //if(k==0) // cout<<"\ndays cannot be same\t"; } break; case 2: {
if(n!=0) { cout<<"\n\n\nno. of days whose data is entered:\t"<<n; cout<<"\nentered data of the days\t"; cout<<"\nday \ttemph\tlowl\train\tsnow"; for(i=0;i<n;i++)
{ w[i].display(); } average(&w[0],n); } else cout<<"\nno data to display\t"; } break; case 3: { int p; cout<<"\nenter the day you want to delete\t"; cin>>n1;
p=del(&w[0],n,n1);
if(p==1) { n--; }
break; case 4: {
else cout<<"\n\t\tnothing to modify\t"; } break; case 5: { cout<<"\nenter the day:\t"; cin>>n3; displayp(&w[0],n,n3); } break; default: cout<<"\n\t\t\twrong choice"; break;
return 0; }