OOMP : Practical 1 : Weather Report

#include <iostream>

using namespace std;

int count=0;
int d[31];

class WeatherReport
{
public:
int hightemp;
int lowtemp;
int amountofrain;
int amountofsnow;

public:
int dayofmonth;
WeatherReport()
{
dayofmonth=99;
hightemp=999;
lowtemp=-999;
amountofrain=0;
amountofsnow=0;
}
void displaydata()
{
cout<<"\nDay of Month\t"<<"||"<<"High Temperature\t"<<"||"<<"Low Temperature\t"<<"||"<<"Amount of Rain\t"<<"||"<<"Amount of Snow\t"<<endl;
cout<<dayofmonth<<"\t\t"<<hightemp<<"\t\t\t"<<lowtemp<<"\t\t\t"<<amountofrain<<"\t\t\t"<<amountofsnow<<endl;
}

void datacalculation();
void getdata(int );
void average();

}a[31],b;


void WeatherReport::average()
{ int *p;
p=d;
int dayt=0,ht=0,lt=0,raint=0,snowt=0;
for (int k=0;k<31;k++,p++)
{

if (a[k].dayofmonth!=99)
{
dayt+=a[k].dayofmonth;
ht+=a[k].hightemp;
lt+=a[k].lowtemp;
raint+=a[k].amountofrain;
snowt+=a[k].amountofsnow;
}
}
dayt/=count;
ht/=count;
lt/=count;
raint/=count;
snowt/=count;
cout<<"\nHigh Temperature\t"<<ht<<"\n";
cout<<"Low Temperature\t"<<lt<<"\n";
cout<<"Amount Of Rain\t"<<raint<<"\n"<"Amount of Snow\t";
cout<<"Amount of snow"<<"\t"<<snowt<<endl;




}
void WeatherReport:: getdata(int i)
{
dayofmonth=i;
cout<<"\nEnter high temperature\t";
cin>>hightemp;
cout<<"\nEnter low temperature\t";
cin>>lowtemp;
cout<<"\nEnter amount of rain\t";
cin>>amountofrain;
cout<<"\nEnter amount of snow\t";
cin>>amountofsnow;
count++;


}


int main()
{
  int *r;
int ch,t;
  r=d;
do
{

cout<<"\n\n-------------Weather Report----------------";
cout<<"\n1. Enter data";
cout<<"\n2. Average of data";
cout<<"\n3. Display data";
cout<<"\n Enter Your Choice";

cin>>ch;
switch (ch)
{
case 1: cout<<"Enter the Day You Want To Change Data For : \n";
cin>>t;
*r=t;
r++;
a[t].getdata(t);
break;

case 2: cout<<"Average is as follows: ";
b.average();
break;

case 3: for (int i=1;i<=31;i++)
{
a[i].displaydata();
}
break;
}
}while(ch);
return 0;
}

SHARE
    Blogger Comment
    Facebook Comment