永发信息网

C++高手请进!!

答案:4  悬赏:80  手机版
解决时间 2021-01-06 15:33
C++高手请进!!
最佳答案
嘻嘻,刚好做过~~~~~
#include
void main()
{
while(1)
{
int month2[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int year,month,day;

printf("\nPlease write down the day,like 1988 11 30\n");
scanf("%d%d%d",&year,&month,&day);

if(month==2)
{
if((year%400==0)||((year%4==0)&&(year%100!=0)))
{
month2[1]=29;
}
}

if(day>month2[month-1]||month>13)
printf("Wrong date!");

if(day==31&&month==12)
{
year++;
month=1;
day=1;
}
else if(day {
day++;
}
else if(day==month2[month-1])
{
month++;
day=1;
}

if(day>month2[month-1]||month>13)
printf("Wrong date!");
printf("The next day is %d %d %d",year,month,day);
}
}
全部回答
闰年
闰年: 1.为了弥补人为的年份规定与地球实际绕日公转的时间差,2.而人为把时间差补上了的年份,该年即为闰年.
遵循的规律为: 四年一闰,百年不润,四百年再润.
if((year % 400 == 0)|(year % 4 == 0)&(year % 100 != 0))//闰年的计算方法
详情如下:
闰年(leap year),在公历(格里历)或夏历中有闰日的年份,以及在中国旧历农历中有闰月的年份。地球绕太阳运行周期为365天5小时48分46秒(合365.24219天)即一回归年(tropical year)。公历的平年只有365日,比回归年短约0.2422 日,所余下的时间约为四年累计一天,于第四年加于2月,使当年的历年长度为366日,这一年就为闰年。现行公历中每400年有97个闰年。夏历的平年只有354日,比12个朔望月短0.3671日,为使每月初一与月朔相合,规定每30年中有11年的年底增加1日,这一年的历年有355日,即为闰年。中国旧历农历作为阴阳历的一种,每月的天数依照月亏而定,一年的时间以12个月为基准,平年比一回归年少约11天。为了合上地球围绕太阳运行周期即回归年,每隔2到4年,增加一个月,增加的这个月为闰月。在加有闰月的那一年有13个月,历年长度为384或385日,这一年也称为闰年。
按照每四年一个闰年计算,平均每年就要多算出0.0078天,这样经过四百年就会多算出大约3天来,因此,每四百年中要减少三个闰年。所以规定,公历年份是整百数的,必须是400的倍数的才是闰年,不是400的倍数的就是平年。
也就是我们通常所说的:
四年一闰,百年不闰,四百年再闰。
西方公历的“闰年”
阳历中有闰日的年份叫闰年,相反就是平年,平年为365天,闰年为366天。在公历(格里历)纪年中,平年的二月为28天,闰年的二月为29天。闰年平月2月29日为闰日。
增加闰日的原因
现时的公历以回归年为“年”的计算基础,而一个回归年大约等于365.24220日。因为在平年公历只计算365日,结果四年后便会累积0.24220×4=0.9688日,大约等于一日,所以便逢四年增加一日闰日以抵销这0.9688日。
计算闰年的方法
公历纪年法中,能被4整除的大多是闰年,不能被100整除而能被400整除的年份是闰年,能被3200整除的也不是闰年,如1900年是平年,2000年是闰年,3200年不是闰年。
中国农历的“闰年”
中国旧历农历纪年中,有闰月的一年称为闰年。一般年份为12个月,354或355天,闰年则为13个月,383或384天
编程中公历闰年的简单计算方法:
设年份 year
if (year能被4整除 and 不能被100整除) or year能被400整除
then 该年为闰年
else 该年为平年
具体程序代码:
#主模块:
;月历打印
;主程序设置好入口参数,BX=年份,DL=月份
;调用子程序 display
;By wangrui
;2006-12-8
extrn display:far
Esccode equ 01h
Up equ 048h
Down equ 050h
Left equ 04bh
Right equ 04dh
dseg segment
Year dw 0
Month db 0
temp db 10 dup(0)
count dw ?
ErrMsg db 0dh,0ah,"The input NOT decimal! $"
dseg ends
cseg segment
assume cs:cseg,ds:dseg
start:
mov ax,dseg
mov ds,ax
call GetYearMonth
Ws:
mov bx,Year
mov dl,Month
call far ptr display
again:
mov ah,0
int 16h
cmp ah,Esccode
je Exit
cmp ah,Up
je NextY
cmp ah,Down
je PreY
cmp ah,Left
je PreM
cmp ah,Right
je NextM
jmp again
NextY:
inc Year
jmp Ws
PreY:
dec Year
jmp Ws
NextM:
inc Month
cmp Month,12
jbe skip0
mov Month,1
inc Year
skip0:
jmp Ws
PreM:
dec Month
cmp Month,1
jae skip1
mov Month,12
dec Year
skip1:
jmp Ws
Exit:
mov ah,4ch
int 21h
;**************************************************
GetYearMonth proc near
push ax
push cx
push si
push di
inputagain:
mov Year,0
mov Month,0
mov si,0
repeatY:
mov ah,1
int 21h
cmp al,0dh
je EndY
cmp al,20h
je EndY
cmp al,1bh
je ExitDos0
cmp al,30h
jb Err
cmp al,39h
ja Err
sub al,30h
mov temp[si],al
inc si
jmp repeatY
Err:
mov ah,9
lea dx,ErrMsg
int 21h
mov ah,2
mov dl,0dh
int 21h
mov dl,0ah
int 21h
jmp inputagain
EndY:
mov bx,10
mov di,si
mov si,0
NextYBit:
mov ah,0
mov al,temp[si]
mov count,di
sub count,si
dec count
mov cx,count
jcxz skipY
lopmul: mul bx
loop lopmul
skipY: add Year,ax
inc si
cmp si,di
jne NextYBit
;----------------------------------The year is put into [Year]
push dx
mov ah,2
mov dl,0dh
int 21h
mov dl,0ah
int 21h
pop dx
jmp skiplap
ExitDos0:
jmp ExitDos
skiplap:
mov si,0
repeatM:
mov ah,1
int 21h
cmp al,0dh
je EndMon
cmp al,20h
je EndMon
cmp al,1bh
je ExitDos
cmp al,30h
jb Err
cmp al,39h
ja Err
sub al,30h
mov temp[si],al
inc si
jmp repeatM
EndMon:
mov di,si
mov si,0
mov bl,10
NextMBit:
mov al,temp[si]
mov count,di
sub count,si
dec count
mov cx,count
jcxz skipM
lpmul: mul bl
loop lpmul
skipM: add Month,al
inc si
cmp si,di
jne NextMBit
;-------------------------The Month is put into [Month]
push dx
mov ah,2
mov dl,0dh
int 21h
mov dl,0ah
int 21h
pop dx
pop di
pop si
pop cx
pop ax
ret
ExitDos:
mov ah,4ch
int 21h
GetYearMonth endp
cseg ends
end start
#打印模块:
;***********************************
;入口参数:bx = Year dl=Month
;***********************************
public display
data segment
Year dw ?
Month db ?
leap db ?
weekstr db " MON TUR WEN THU FRI SAT SUN",’$’
fillblank db " $"
fillblank4 db " $"
fillblank3 db " $"
c db ?
y db ?
firstday db ?
temp db ?
MonthSize db ?
data ends
cseg segment
assume cs:cseg,ds:data
display proc far
push ds
mov ax,data
mov ds,ax
mov Year,bx
mov Month,dl
mov dx,0
xor bh,bh
mov ah,2
int 10h
mov ah,6
mov al,0
mov bh,0
好办,好办!!!我C++ 虽然不是高手,这个还是有点简单哈!!!!
上面那个用C语言编的,没的意思!!!!
#ifndef DATE_H
#define DATE_H
// class Date definition
class Date {
public:
Date( int = 1, int = 1, int = 1900 ); // default constructor
void print();
void setDate( int, int, int );
void setMonth( int );
int getMonth();
void setDay( int );
int getDay();
void setYear( int );
int getYear();
bool isLeapYear();
int monthDays();

void nextDay ();
private:
int month;
int day;
int year;
}; // end class Date
#endif // DATE_H
#include
using std::cout;
#include "date.h"
// constructor
Date::Date( int m, int d, int y )
{
setDate( m, d, y );
} // end class Date constructor
// return day
int Date::getDay()
{
return day;
} // end function getDay
// return month
int Date::getMonth()
{
return month;
} // end function getMonth
// return year
int Date::getYear()
{
return year;
} // end function getYear
// set day
void Date::setDay( int d )
{
if ( month == 2 && isLeapYear() )
day = ( d <= 29 && d >= 1 ) ? d : 1;
else
day = ( d <= monthDays() && d >= 1 ) ? d : 1;
} // end function setDay
// set month
void Date::setMonth( int m )
{
month = ( m <= 12 && m >= 1 ) ? m : 1;
} // end function setMonth
// set year
void Date::setYear( int y )
{
year = ( y <= 2010 && y >= 1900 ) ? y : 1900;
} // end function setYear
// set date
void Date::setDate( int mo, int dy, int yr )
{
setMonth( mo );
setDay( dy );
setYear( yr );
} // end function setDate
// output Date
void Date::print()
{
cout << month << '-' << day << '-' << year << '\n';
} // end function print
void Date::nextDay()
{
day += 1;
if ( day > monthDays() )
{
setDay( day );
month += 1;

if ( month > 12 )
{
setMonth( month );
year += 1;

if ( year > 2010 )
setYear( year );
}
}
}
// test whether is a leap year
bool Date::isLeapYear()
{
if ( year % 400 == 0 || ( year % 4 == 0 && year % 100 != 0 ) )
return true;
else
return false; // not a leap year
} // end function isLeapYear
// return days in month
int Date::monthDays()
{
const int days[ 12 ] = { 31, 28, 31, 30, 31, 30, 31, 31, 30,
31, 30, 31 };
return month == 2 && isLeapYear() ? 29 : days[ month - 1 ];
} // end function monthDays
#include
using std::cout;
using std::endl;
#include "date.h"
int main()
{
const int MAXDAYS = 298;
Date d( 10 , 2, 2002 );
// test print and nextDay
for ( int loop = 1; loop <= MAXDAYS; ++loop )
{
d.print();
d.nextDay();
} // end for
cout << endl;
return 0;
} // end main
咳亚,就是这样,为了看程序是可以的,我把天数改了,你就把天数改改就可以了!!!!
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
我家用中材罗定水泥倒地梁二年时间了,地梁侧
为什么说北方看不出谁穷,南方看不出谁有钱
英译汉【 Tortoises, as heavy as four grown
大两P空调是25匹吗
学生无身份证怎么住酒店
Darkmoor Manor 植物园在哪
i ask her who she is 中的her充当什么
延安公交司机一个月多少钱
你们掉头发有没有能治好的
热固性粉末涂料表面有一层粉末是怎么回事?
影视鉴赏
一幅幅精美的图画,赏心悦目,有什么之效(最合
中国的公海在哪里
一些漫画里女生腿上或者身上写的正字是什么意
为什么买顶楼的房子,就能赠送那么多面积怎么
推荐资讯
为什么我总是遇到骗子
单选题谷氨酸产生菌培养基中五大类营养物质不
为什么到了春夏天时手总是长小泡,还会
这样的狗便便是健康还是不健康
瑞亚女子生活馆地址在哪,我要去那里办事
相见不如怀念,怀念不如相见,再见不如相忘于
小腿肿吃啥好
如何看待dota2更新7.0后冰蛙被遗老喷
外地人口怎么办理当地居住证
雨花区长沙津市牛肉粉(曙光中路店)我想知道这
南阳哪有游乐场
曲阜三孔的专业导游在游客中心请还是在孔庙、
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?