Weather report program in c++ using constructor
Create a class named weather report that holds a daily weather report with data members dayofmonth,high temp , low temp ,amount rain and amount snow.The constructor initializes the fields with default values. Weather report program in c++ using constructor Includes a function that prompts the user and sets values for each field so that you can override the default values.
Write a program Weather report program in c++ using constructor that creates a monthly report.
Weather report program in c++ using constructor Code
1 |
#include <br/> #include <br/> #include <br/> class ping <br/> { <br/> int day,snowfall,rainfall,lowtemp,hightemp; <br/> public: <br/> static int count ; <br/> ping(); <br/> ping(int,int,int,int,int); <br/> ping::ping(ping &z) <br/> { <br/> day=z.day; <br/> hightemp=z.hightemp; <br/> lowtemp=z.lowtemp; <br/> snowfall=z.snowfall; <br/> rainfall=z.rainfall; <br/> } <br/> int dayno(); <br/> void daily(); <br/> void copy(int,int,int,int,int) ; <br/> void change(int ); <br/> }; <br/> int ping::count ; <br/> ping::ping() <br/> { <br/> day=99; <br/> hightemp=999; <br/> lowtemp=-999; <br/> snowfall=0; <br/> rainfall=0; <br/> cout<< "\t\t\tRecord created\n"; <br/> } <br/> void ping::change(int dom) <br/> { <br/> day=dom; <br/> } <br/> ping::ping(int dom,int ht,int lt,int s,int r) <br/> { <br/> day= dom; <br/> hightemp=ht; <br/> lowtemp=lt; <br/> snowfall=s; <br/> rainfall=r; <br/> } <br/> void ping::daily() <br/> { <br/> cout << "\t "; <br/> cout << hightemp << "\t\t "; <br/> cout << lowtemp << "\t "; <br/> cout << snowfall << "\t "; <br/> cout << rainfall << "\t "; <br/> } <br/> int ping::dayno() <br/> { <br/> return day; <br/> } <br/> void main() <br/> { <br/> int ch,i=0,j,flag=0; <br/> int k,temp; <br/> ping *array[31]; <br/> do <br/> { <br/> clrscr(); <br/> cout << "\t\t\t\t***Main Menu***\n"; <br/> cout << "\t\t\t\t1.Create Daily Report\n"; <br/> cout << "\t\t\t\t2.Display Daily Report\n"; <br/> cout << "\t\t\t\t3.Display Monthly Report\n"; <br/> cout << "\t\t\t\t4.Delete a record\n"; <br/> cout << "\t\t\t\t5.Exit\n"; <br/> cout << "\t\t\t\tEnter your choice:\n"; <br/> cin >> ch; <br/> switch(ch) <br/> { <br/> case 1: <br/> do <br/> { <br/> int dom; <br/> temp=0 ; <br/> cout<<"\n\t\tEnter date of month: "; <br/> cin>>dom; <br/> array[i]->count++; <br/> if(array[i]->count>1) <br/> { <br/> cout <<"\nDO U WANT TO COPY DATA FROM PREVIOUS DAY (y/n)"; <br/> if(getche()=='y'||getche()=='Y') <br/> { <br/> array[i]=new ping; <br/> *array[i]=*array[i-1]; <br/> array[i]->change(dom); <br/> i=i+1; <br/> temp=1; <br/> } <br/> } <br/> if(temp==0) <br/> { <br/> int ht ; <br/> cout << "\tEnter maximum temperature: "; <br/> cin >> ht; <br/> int lt; <br/> cout << "\tEnter the minimum temperature: "; <br/> cin >> lt; <br/> int s; <br/> cout << "\tEnter amount of snowfall: "; <br/> cin >> s; <br/> int r; <br/> cout << "\tEnter amount of rainfall: "; <br/> cin >> r ; <br/> array[i++]=new ping(dom,ht,lt,r,s); <br/> } <br/> cout<<"\n\t\tDO U WANT TO ENTER MORE:"; <br/> }while(getche()=='y'||getche()=='Y'); <br/> break; <br/> case 2: <br/> cout << "\t\t\tDisplay Daily Report\n"; <br/> cout << "\tEnter the day to be viewed: "; <br/> cin>>k; <br/> for(j=0;j<i;j++) <br=""> if(array[j]->dayno()==k) <br/> { <br/> cout<<"\n\n Day Temperature AmtRain AmtSnow"; <br/> cout<<"\n"<<" "; <br/> array[j]->daily(); <br/> getch(); <br/> break; <br/> } <br/> if(j==i) <br/> { <br/> cout<<"\nRecord not found "; <br/> cout<<"\nNOT AVAILABLE"; <br/> getch(); <br/> } <br/> break; <br/> case 3: <br/> clrscr(); <br/> cout<<"\n\t\tWEATHER REPORT"; <br/> if(i==0) <br/> { <br/> cout<<"\n\nRecord not found..."; <br/> break; <br/> } <br/> else <br/> cout<<"\n\n Day Temperature AmtRain AmtSnow"; <br/> cout<<"\n"<<" "; <br/> for(j=0;j<i;j++) <br=""> { <br/> cout<<"\n"<<" "; <br/> array[j]->daily(); <br/> } <br/> getch(); <br/> break; <br/> break; <br/> case 4: <br/> cout<<"\nENTER THE DATE WHICH U WANT TO DELETE:"; <br/> int dom; <br/> cin>>dom; <br/> for(j=0;j<i;j++) <br=""> { <br/> if(array[j]->dayno()==dom) <br/> { <br/> delete array[j]; <br/> while(j<i) <br=""> { <br/> array[j]=array[j+1]; <br/> j++; <br/> } <br/> j--; <br/> break; <br/> } <br/> } <br/> if(j==i) <br/> cout<<"\nDATE IS NOT FOUND"; <br/> else <br/> { <br/> array[i]->count--; <br/> i--; <br/> } <br/> break; <br/> case 5 : <br/> break ; <br/> default: <br/> cout<< " \t\tWrong choice...Enter again\n "; <br/> } <br/> }while(ch!=5); <br/> } |
Source projectgeek.com