主题:本人刚刚学c++,求高手们给我改一下这个程序的错误
#include<iostream>
#include<ctime>
using namespace std;
class Date
{
public:
Date(int y,int m,int d);
void setDate(int y,int m,int d);
void setYear(int y);
void setMonth(int m);
void setDay(int d);
int getYear();
int getMonth();
int getDay();
void print();
private:
int Year;
int Month;
int Day;
};
void Date::Date(int y,int m,int d)
{
Date(y,m,d);
}
void Date::setDate(int y,int m,int d)
{
setDay(d);
setYear(y);
setMonth(m);
}
void Date::setMonth(int m)
{
Month=(m>0&&m<12?m:1);
}
void Date::setYear(int y)
{
Year=(y>0?y:1);
}
void Date::setDay(int d)
{
Day=(d>0&&d<=31?d:1);
}
int Date::getYear()
{
return Year;
}
int Date::getMonth()
{
return Month;
}
int Date::getDay()
{
return Day;
}
void Date::print()
{
cout<<Year <<'/'<< Month<<'/'<< Day;
}
int main()
{
int y,m,d;
cout<<"input year month day";
cin>>y>>m>>d;
Date now(y,m,d);
cout<<"the seted time:";
now.print();
return 0;
}
#include<ctime>
using namespace std;
class Date
{
public:
Date(int y,int m,int d);
void setDate(int y,int m,int d);
void setYear(int y);
void setMonth(int m);
void setDay(int d);
int getYear();
int getMonth();
int getDay();
void print();
private:
int Year;
int Month;
int Day;
};
void Date::Date(int y,int m,int d)
{
Date(y,m,d);
}
void Date::setDate(int y,int m,int d)
{
setDay(d);
setYear(y);
setMonth(m);
}
void Date::setMonth(int m)
{
Month=(m>0&&m<12?m:1);
}
void Date::setYear(int y)
{
Year=(y>0?y:1);
}
void Date::setDay(int d)
{
Day=(d>0&&d<=31?d:1);
}
int Date::getYear()
{
return Year;
}
int Date::getMonth()
{
return Month;
}
int Date::getDay()
{
return Day;
}
void Date::print()
{
cout<<Year <<'/'<< Month<<'/'<< Day;
}
int main()
{
int y,m,d;
cout<<"input year month day";
cin>>y>>m>>d;
Date now(y,m,d);
cout<<"the seted time:";
now.print();
return 0;
}