You are on page 1of 13

#include<iostream.h> #include<conio.

h>

class weather { private: int dayofmonth; int temph; int templ; int rain ; int snow;

static int count;

public: weather(); weather(int a,int th,int tl,int r,int s);

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 );

};

int weather ::count;

weather:: weather() { dayofmonth=99; temph=999; templ=-999; rain =0; snow=0; }

weather ::weather(int a,int th,int tl,int r,int s) { dayofmonth=a; temph=th; templ=tl; rain =r; snow=s; count++;

void weather ::display()

cout<<"\n"<<dayofmonth; cout<<"\t"<<temph; cout<<"\t"<<templ; cout<<"\t"<<rain; cout<<"\t"<<snow;

} 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; }

void average(weather *w,int n) {

int tl=0,th=0,r=0,s=0,i; for(i=0;i<n ;i++) { tl=tl+w[i].templ; th=th+w[i].temph; r=r+w[i].rain; s=s+w[i].snow;

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"; }

int same(weather *w,int n,int a) { int i; for(i=0;i<n;i++) { if(a==w[i].dayofmonth)

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) ;

k= same(&w[0],n,da); if(k!=0) { w[i]=weather(da,th,tl,ra,sn) ;

} if(e=='h') { cout<<"\nenter the new field\t"; cin>>th; w[i]=weather(da,th,tl,ra,sn) ;

} if(e=='l') { cout<<"\nenter the new field\t"; cin>>tl; w[i]=weather(da,th,tl,ra,sn) ;

} if(e=='r') { cout<<"\nenter the new field\t";

cin>>ra; w[i]=weather(da,th,tl,ra,sn) ;

} if(e=='s') { cout<<"\nenter the new field\t"; cin>>sn; w[i]=weather(da,th,tl,ra,sn) ;

// if(k==0) // cout<<"\ndays cannot be same\t"; }

int main() { weather w[40]; int n=0,ch,i,a,tl,th,r,s,n1,n2,n3; char c; clrscr();

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: {

if(n!=0) { cout<<"\nenter the day you want to modify\t"; cin>>n2; modify(&w[0],n,n2); }

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;

} cout<<"\n\t\t\tif you want to continue.........y"; cin>>c; }while(c=='y'||c=='Y');

return 0; }

You might also like