1个回答
展开全部
#include <iostream>
class TDate
{
public:
TDate();
TDate(int y, int m, int d);
TDate(TDate &date);
friend void Print(TDate &date);
void SetDay(int day);
private:
int Day, Month, Year;
};
TDate::TDate() :Day(0), Month(0), Year(0) {}
TDate::TDate(int day, int month, int year) : Day(day), Month(month), Year(year) {}
TDate::TDate(TDate &date): Day(date.Day), Month(date.Month), Year(date.Year) {}
void Print(TDate &date)
{
std::cout << date.Year << "年" << date.Month << "月" << date.Day << "日" << std::endl;
}
void TDate::SetDay(int day)
{
Day = day;
}
int main()
{
TDate d1;
TDate d2(11, 9, 2001);
TDate d3(d2);
Print(d1);
Print(d2);
Print(d3);
d3.SetDay(12);
Print(d3);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询