c++ 求大神帮忙补充中间虚线的 定义一个处理日期的类TDate,它有3个私有数据成员:Day, Month, Year,
并实现如下要求:构造函数重载,缺省的年月日置0;TDate()TDate(intday)TDate(intday,intmonth)TDate(intday,intmon...
并实现如下要求:
构造函数重载,缺省的年月日置0;
TDate()
TDate(int day)
TDate(int day, int month)
TDate(int day, int month, int year)
#include <iostream>
using namespace std;
class TDate {
int Day, Month, Year;
/**********Program**********/
/********** End **********/
void display() {
if(Day+Month+Year==0) cout<<"日期无效"<<endl;
else {
cout<<"今天是";
if(Year!=0) cout<<Year<<"年";
if(Month!=0) cout<<Month<<"月";
if(Day!=0) cout<<Day<<"日"<<endl;
}
}
};//end class TDate
void main(void)
{
TDate d1,d2(24),d3(24,3),d4(24,3,2012);
d1.display ();
d2.display ();
d3.display ();
d4.display ();
} 展开
构造函数重载,缺省的年月日置0;
TDate()
TDate(int day)
TDate(int day, int month)
TDate(int day, int month, int year)
#include <iostream>
using namespace std;
class TDate {
int Day, Month, Year;
/**********Program**********/
/********** End **********/
void display() {
if(Day+Month+Year==0) cout<<"日期无效"<<endl;
else {
cout<<"今天是";
if(Year!=0) cout<<Year<<"年";
if(Month!=0) cout<<Month<<"月";
if(Day!=0) cout<<Day<<"日"<<endl;
}
}
};//end class TDate
void main(void)
{
TDate d1,d2(24),d3(24,3),d4(24,3,2012);
d1.display ();
d2.display ();
d3.display ();
d4.display ();
} 展开
1个回答
展开全部
#include <iostream>
using namespace std;
class TDate {
int Day, Month, Year;
/**********Program**********/
public:
TDate()
{
Day = 0;
Month = 0;
Year = 0;
}
TDate(int day)
{
Day = day;
Month = 0;
Year = 0;
}
TDate(int day, int month)
{
Day = day;
Month = month;
Year = 0;
}
TDate(int day, int month, int year)
{
Day = day;
Month = month;
Year = year;
}
/********** End **********/
void display() {
if(Day+Month+Year==0)
cout<<"日期无效"<<endl;
else {
cout<<"今天是";
if(Year!=0) cout<<Year<<"年";
if(Month!=0) cout<<Month<<"月";
if(Day!=0) cout<<Day<<"日"<<endl;
}
}
};//end class TDate
void main(void)
{
TDate d1,d2(24),d3(24,3),d4(24,3,2012);
d1.display ();
d2.display ();
d3.display ();
d4.display ();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询