#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class weather_report
{
int *dd;
int *hightemp,*lowtemp,*amount_rain,*amount_snow;
staticint count;
public:
weather_report()
{
dd=newint(99);
hightemp=newint(999),
lowtemp=newint (-999);
amount_rain=newint (0);
amount_snow=newint (0);
}
weather_report(weather_report &R)
{
dd=R.dd;
hightemp=R.hightemp;
lowtemp=R.lowtemp;
amount_rain=R.amount_rain;
amount_snow=R.amount_snow;
count++;
}
void getdata()
{
cout<<"\n\t\t Enter day of month ";
cin>>*dd;
cout<<"\n\t\t Enter hightemp";
cin>>*hightemp;
cout<<"\n\t\t Enter lowtemp";
cin>>*lowtemp;
cout<<"\n\t\t Enter amount rain";
cin>>*amount_rain;
cout<<"\n\t\t Enter amount snow";
cin>>*amount_snow;
count++;
}
void putdata()
{
cout<<"\n"<<*dd<<"\t\t"<<*hightemp<<"\t\t"<<*lowtemp;
cout<<"\t\t"<<*amount_rain<<"\t\t"<<*amount_snow<<"\n";
}
staticvoid dis()
{
cout<<count;
}
};
int weather_report:: count=0;
void main()
{
int ch,day;
int menu();
char c;
clrscr();
int i=1;
weather_report WR1[30];
do
{
// clrscr();
switch(menu())
{
case 1:
weather_report wr;
WR1[i]=wr;
cout<<"\n\t\t default data set";
i++;
break;
case 2:
WR1[i].getdata();
cout<<"\n\t\t Manually data set";
i++;
break;
case 3: clrscr();
cout<<"\n\n\t\t The Information of ";
weather_report::dis();
cout<<"days\n\n";
cout<<"\n Day Of month\thightemp\tlowtemp\t amount rain\tamount rain\n";
for(int j=1;j<i;j++)
{
WR1[j].putdata();
}
break;
case 4: exit(0);
break;
}
getch();
clrscr();
}while(ch!=4);
getch();
}
int menu()
{
cout<<"\n\t\t====================================\n";
// cout<<"\n\t\t____________________________________";
cout<<"\n\t\t 1. Set Default values\n";
cout<<"\n\t\t 2. Enter manually\n";
cout<<"\n\t\t 3. Create Weather Report\n";
cout<<"\n\t\t\t 4. Exit";
cout<<"\n\t\t====================================\n";
cout<<"\n\t\t Enter choice";
int ch;
cin>>ch;
return(ch);
}
Any idea why this is not working? It says main has to have return int. cout not declared in this scope. I'm a complete noob so I dont know what this means. And I think it is not loading the header files properly. Please help!
Hey guys thanks a lot for the help! I made the changes you guys pointed out. But I'm getting the following error: stdlib: no such file or directory. How do I install it? I'm using codeblocks 10.05. Should I get a new IDE?
Still getting the following errors:
1. error conio: no such file or directory
2. ::main must return int
3. Bunch of errors that say getch was not declared in this scope/clrscr was not declared in this scope. What does this mean?
1. I actually dont recall such header. Is it non standard? Remove that #include line
2. You didnt fix main function. It must be of return type int and return integral value (usually return 0;)
3. I dont think there exists function called clrscr. You can use system("cls") on windows or system("clear") on linux for this. However, it is considered bad habbit. (there is article about clearing screen)
Also I do not see need for getch() in this example. Remove it?
Still getting the following errors:
1. error conio: no such file or directory
2. ::main must return int
3. Bunch of errors that say getch was not declared in this scope/clrscr was not declared in this scope. What does this mean?
I would say that there is a incompatibility between your learning material and your compiler. It looks like you are using an old source for information and a new compiler.
I have one more doubt. In this program why is everything passed by reference? Can't I do the same thing without pointers? And what is the second constructor that has been used here?