Code should be done in C++ and compile/run in Visual Studio 2012 or later. DO NO
ID: 670416 • Letter: C
Question
Code should be done in C++ and compile/run in Visual Studio 2012 or later. DO NOT ANSWER UNLESS YOU CAN COMPLETE ALL PARTS OF THE PROBLEM! Thank you in advance for your help!
Create a class named WeatherReport that holds a daily weather report with data members such as dayOfMonth, highTemp, lowTemp, amountRain, and amountSnow. The constructor initializes the fields with default values: 99 for dayOfMonth, -9999 for highTemp, 9999 for lowTemp, and 0 for amountRain and amountSnow. Include a function that prompts the user and sets values for each field so that you can override
the default values. Instantiate 30 WeatherReport objects and, in a loop, prompt the user for a month’s data.
At the end of the month, a month-end WeatherReport object is created. Initialize the object with default values; then use a friend function to store the high temperature, low temperature, and rain and snow totals for the month in the object. The friend function takes two WeatherReport objects—the summary object and one day’s object—and it returns an updated summary object. If the day’s high temperature is higher than the summary object’s high, then replace the summary high. If the day’s low temperature is lower than the summary object’s low, then replace the summary low. Accumulate rain and snow in the summary object. Write a main()function that creates a month-end weather report from the 30 daily reports. Save the file as WeatherReport.cpp.
Explanation / Answer
#include
#include
#include
class ping
{
int day,snowfall,rainfall,lowtemp,hightemp;
public:
static int count ;
ping();
ping(int,int,int,int,int);
ping::ping(ping &z)
{
day=z.day;
hightemp=z.hightemp;
lowtemp=z.lowtemp;
snowfall=z.snowfall;
rainfall=z.rainfall;
}
int dayno();
void daily();
void copy(int,int,int,int,int) ;
void change(int );
};
int ping::count ;
ping::ping()
{
day=99;
hightemp=999;
lowtemp=-999;
snowfall=0;
rainfall=0;
cout<< " Record created ";
}
void ping::change(int dom)
{
day=dom;
}
ping::ping(int dom,int ht,int lt,int s,int r)
{
day= dom;
hightemp=ht;
lowtemp=lt;
snowfall=s;
rainfall=r;
}
void ping::daily()
{
cout << " ";
cout << hightemp << " ";
cout << lowtemp << " ";
cout << snowfall << " ";
cout << rainfall << " ";
}
int ping::dayno()
{
return day;
}
void main()
{
int ch,i=0,j,flag=0;
int k,temp;
ping *array[31];
do
{
clrscr();
cout << " ***Main Menu*** ";
cout << " 1.Create Daily Report ";
cout << " 2.Display Daily Report ";
cout << " 3.Display Monthly Report ";
cout << " 4.Delete a record ";
cout << " 5.Exit ";
cout << " Enter your choice: ";
cin >> ch;
switch(ch)
{
case 1:
do
{
int dom;
temp=0 ;
cout<<" Enter date of month: ";
cin>>dom;
array[i]->count++;
if(array[i]->count>1)
{
cout <<" DO U WANT TO COPY DATA FROM PREVIOUS DAY (y/n)";
if(getche()=='y'||getche()=='Y')
{
array[i]=new ping;
*array[i]=*array[i-1];
array[i]->change(dom);
i=i+1;
temp=1;
}
}
if(temp==0)
{
int ht ;
cout << " Enter maximum temperature: ";
cin >> ht;
int lt;
cout << " Enter the minimum temperature: ";
cin >> lt;
int s;
cout << " Enter amount of snowfall: ";
cin >> s;
int r;
cout << " Enter amount of rainfall: ";
cin >> r ;
array[i++]=new ping(dom,ht,lt,r,s);
}
cout<<" DO U WANT TO ENTER MORE:";
}while(getche()=='y'||getche()=='Y');
break;
case 2:
cout << " Display Daily Report ";
cout << " Enter the day to be viewed: ";
cin>>k;
for(j=0;j<i;j++) <br=""> if(array[j]->dayno()==k)
{
cout<<" Day Temperature AmtRain AmtSnow";
cout<<" "<<" ";
array[j]->daily();
getch();
break;
}
if(j==i)
{
cout<<" Record not found ";
cout<<" NOT AVAILABLE";
getch();
}
break;
case 3:
clrscr();
cout<<" WEATHER REPORT";
if(i==0)
{
cout<<" Record not found...";
break;
}
else
cout<<" Day Temperature AmtRain AmtSnow";
cout<<" "<<" ";
for(j=0;j<i;j++) <br=""> {
cout<<" "<<" ";
array[j]->daily();
}
getch();
break;
break;
case 4:
cout<<" ENTER THE DATE WHICH U WANT TO DELETE:";
int dom;
cin>>dom;
for(j=0;j<i;j++) <br=""> {
if(array[j]->dayno()==dom)
{
delete array[j];
while(j<i) <br=""> {
array[j]=array[j+1];
j++;
}
j--;
break;
}
}
if(j==i)
cout<<" DATE IS NOT FOUND";
else
{
array[i]->count--;
i--;
}
break;
case 5 :
break ;
default:
cout<< " Wrong choice...Enter again ";
}
}while(ch!=5);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.