Hello i got an assignment to do on classes, basically i got 90% of the program working except for some minor issues which i cant seem to figure out.
Here is the code:
#include <iostream.h>
#include <assert.h>
#include <cstring>
class weather
{
private:
int day;
int month;
int year;
int temp;
int humid;
char *condition;
void leapyear(int);
public:
weather(int =1,int =99,int =54,int =100,int =33,char*= "Elie"); //Problem
~weather();
void setall(int,int,int,int,int,char*);
int get_day();
int get_month();
int get_year();
int get_temp(int);
int get_humid();
void print();
void get_condition();
};
weather::weather(int x,int y,int z,int t,int h,char *k)
{
setall(x,y,z,t,h,k)
};
weather::~weather()
{ delete condition;}
void weather::setall(int a,int b,int c,int d,int e,char *f)
{
{if (a<1 ||a>31)//day
day=1;
else
day=a;}
{if (b<1 || b>12)//month
month=1;
else
month=b;}
{if(c<1900||c>2005)//year
year=2000;
else
year=c;}
{if (d<60||d>60)//temp
temp=20;
else
temp=d;}
{if (e<0||e>100)//humid
humid=55;
else
humid=e;}
condition=new char[strlen(f)+1];
assert (condition!=0);
strcpy(condition,f);
}
int weather::get_day()
{return day;}
int weather::get_month()
{return month;}
int weather::get_year()
{return year;}
int weather::get_temp(int t)
{ t=0;
t=((9/5)*temp)+32;
return t;
}
int weather::get_humid()
{return humid;}
void weather::leapyear(int a)
{
a=year;
if (a%4==0 && a%100!=0)
cout<<"This is a leap year"<<endl;
else
cout<<"This is not a leap year"<<endl;
}
void weather::print()
{
cout<<"On the: "<<day<<"/"<<month<<"/"<<year<<endl;
cout<<"-------------------------------------------------------"<<endl;
cout<<"Temperature is: "<<temp<<endl;
cout<<"Humidity (in %) is: "<<humid<<endl;
cout<<"Condition is "<<condition<<endl;
}
void weather::get_condition()
{ cout<<condition;}
void main()
{
weather a;
a.print();
}
Can anyone please compile it and tell me where my mistakes are.
I would like to thank anyone that helps .