定义一个关于日期时间的类,并在类中定义构造函数、析构函数,然后声明对象,判断该日期是否为闰年并输出
答案:2 悬赏:20
解决时间 2021-11-09 07:02
- 提问者网友:若相守£卟弃
- 2021-11-08 22:17
定义一个关于日期时间的类,并在类中定义构造函数、析构函数,然后声明对象,判断该日期是否为闰年并输出
最佳答案
- 二级知识专家网友:何必打扰
- 2021-11-08 23:33
class Date//默认一个月是30天
{
public:
Date(int x=2011,int y=1,int z=8):year(x),month(y),day(z)//构造函数
{
cout<<"初始化日期是:"<
}
~Date(){}//析构函数
void NextDate()
{
day++;
if (day>30)
{
day=day-30;
month++;
}
if (month>12)
{
month=month-12;
year++;
}
cout<<"the next date is "<
}
public String Leapyear(){
if((year%4==0)&&(year%100!=0)||(year%400==0))
return 1;
}
private:
int year;
int month;
int day;
};
int main()
{
Date date1;
Date date2(2011,12,30);
date1.NextDate();
date2.NextDate();
if(data1.Leapyear() == 1)
cout<<"the next date is "<
else
return;
if(data1.Leapyear() == 1)
cout<<"the next date is "<
else
return;
}
{
public:
Date(int x=2011,int y=1,int z=8):year(x),month(y),day(z)//构造函数
{
cout<<"初始化日期是:"<
~Date(){}//析构函数
void NextDate()
{
day++;
if (day>30)
{
day=day-30;
month++;
}
if (month>12)
{
month=month-12;
year++;
}
cout<<"the next date is "<
public String Leapyear(){
if((year%4==0)&&(year%100!=0)||(year%400==0))
return 1;
}
private:
int year;
int month;
int day;
};
int main()
{
Date date1;
Date date2(2011,12,30);
date1.NextDate();
date2.NextDate();
if(data1.Leapyear() == 1)
cout<<"the next date is "<
return;
if(data1.Leapyear() == 1)
cout<<"the next date is "<
return;
}
全部回答
- 1楼网友:一池湖水
- 2021-11-08 23:52
function leapyear(x,y:integer):array of integer;
var
i,j:integer;
a:array[1..1000] of integer;
begin
j:=0;;
for i=x to y do
begin
inc(j);
if (i mod 4) or (i mod 400)=0 then
a[j]:=i;
end;
leapyear:=a;
end;
其实用子程序简单多了。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯