设计一个日期类,Date,要求:包含年(year)月(month)日(day)私有数据成员。
还有,包含构造函数,重载输出运算符“<<”与冲在输入运算符“>>”。计科系的,都想找答案是不?没戏的,还是自己做吧。...
还有,包含构造函数,重载输出运算符“<<”与冲在输入运算符“>>”。
计科系的,都想找答案是不?
没戏的,还是自己做吧。 展开
计科系的,都想找答案是不?
没戏的,还是自己做吧。 展开
2个回答
展开全部
//给你写了一个,你看看吧
class Date{
private:
int year;
int month;
int day;
public:
Date():year(1990),month(1),day(1){};
friend ostream & operator <<(ostream &os,Date &date);
friend istream & operator >>(istream &is,Date &date);
};
ostream &operator <<(ostream &os,Date &date)
{
os<<date.year<<"-"<<date.month<<"-"<<date.day;
return os;
}
istream &operator>>(istream &is,Date &date)
{
is>>date.year>>date.month>>date.day;
if(date.year>9999||date.year<0||date.month>12||date.month<1||date.day>31||date.day<0)
cout<<"error"<<endl;
return is;
}
class Date{
private:
int year;
int month;
int day;
public:
Date():year(1990),month(1),day(1){};
friend ostream & operator <<(ostream &os,Date &date);
friend istream & operator >>(istream &is,Date &date);
};
ostream &operator <<(ostream &os,Date &date)
{
os<<date.year<<"-"<<date.month<<"-"<<date.day;
return os;
}
istream &operator>>(istream &is,Date &date)
{
is>>date.year>>date.month>>date.day;
if(date.year>9999||date.year<0||date.month>12||date.month<1||date.day>31||date.day<0)
cout<<"error"<<endl;
return is;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2010-04-28
展开全部
class Date
{
public:
Date(UINT y,UINT m,UINT d);
~Date();
void operator<<(Date);
protected:
UINT year;
UINT month;
UINT day;
}
Date::Date()
{
year=y;
month=m;
day=d;
}
void Date::operator<<(Date date)
{
cout<< date.year<<date.month<<date.day<<endl;
}
{
public:
Date(UINT y,UINT m,UINT d);
~Date();
void operator<<(Date);
protected:
UINT year;
UINT month;
UINT day;
}
Date::Date()
{
year=y;
month=m;
day=d;
}
void Date::operator<<(Date date)
{
cout<< date.year<<date.month<<date.day<<endl;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询