用C语言编写的万年历

合集下载

万年历c语言源程序

万年历c语言源程序

万年历c语言源程序#include stdio.h #include windows.h #include wincon.h #includestring.h #includestdlib.h #includeconio.h #includetime.h #includemath.h #define NULL 0*****_SCREEN_BUFFER_INFO csbiInfo; extern *****API HWND WINAPI GetConsoleWindow(); time_t T;struct tm * now; int min,sec;int hour,nowyear,nowmonth,nowday; void ti2() { time ( T ); now = localtime ( T ); hour=now-tm_hour%12; min=now-tm_min-15; sec=now-tm_sec-15; }void ti(){ time ( T ); now = localtime ( T ); hour=now-tm_hour; min=now-tm_min; sec=now-tm_sec; nowyear=now-tm_year+1900; nowmonth=now-tm_mon+1; nowday=now-tm_mday; }int yearbak=0; void clock_sz(); int pd( int year);void huizs(int line_head_month); void hzdy(int year,int nowmonth_hz); void menu(); void clear();int main(int argc, char* argv[]) { int x=0; ti();clock_sz(); hzdy(nowyear,nowmonth); menu(); return 0; }void clear() { int i; HWND hwnd; HANDLE hOut; HDC hdc;HBRUSH hbr; COORD pos={1,4}; hwnd=GetConsoleWindow(); hdc = GetDC(hwnd); hOut = GetStdHandle(STD_OUTPUT_HANDLE); hbr= CreateSolidBrush(RGB(0,0,0)); SelectObject(hdc,hbr); Rectangle(hdc,0,65,670,470); SetConsoleCursorPosition(hOut, pos); for(i=0;i i++) printf(“ \n "); SetConsoleCursorPosition(hOut, pos); Rectangle(hdc,0,65,670,470); ReleaseDC(hwnd, hdc); } void menu() { int year=0,xyear=0,x, xy=0,i ; struct re { int top; int left; int right; int bottom; }rt; HWND hwnd; HDC hdc,dc; HBRUSH hbr; COORD pos3_1 = {1, 4},pos3_2= {1, 1},pos = {1, 4},pos2_3 = {1, 6},pos2_4 = {1, 7}; INPUT_RECORD mouseRec; DWORD state = 0, res=0; POINT pt; HPEN pn;HANDLE hOut, hIn;hwnd=GetConsoleWindow();//得到控制台窗口句柄hdc = GetDC(hwnd); //得到画图设备句柄dc = GetDC(hwnd);//画刷hbr= CreateSolidBrush(RGB(255,0,0)); SelectObject(dc,hbr);for(rt.left=20,i=2;ii++) rt[i].left=rt[i-1].left+50;for(rt.right=50,i=2;ii++) rt[i].right=rt[i-1].right+50; //定位按钮for(i=0;ii++) rt[i].top=40; for(i=0;ii++) rt[i].bottom=60;hOut = GetStdHandle(STD_OUTPUT_HANDLE); hIn=GetStdHandle(STD_INPUT_HANDLE);pn=CreatePen(PS_SOLID,1,RGB(255,0,255)); GetClientRect(hwnd, rt); SelectObject(hdc, pn);SetBkMode(hdc,*****RENT); MoveToEx(hdc,1,35,NULL); LineTo(hdc,620,35); LineTo(hdc,620,62); LineTo(hdc,1,62); LineTo(hdc,1,35);pn=CreatePen(PS_SOLID,2,RGB(255,255,0));SelectObject(hdc, pn);MoveToEx(hdc,5,75,NULL); LineTo(hdc,45,75);hbr= CreateSolidBrush(RGB(0,0,190)); SelectObject(dc,hbr); for(i=1;ii++) Rectangle(dc,rt[i].left,rt[i].top,rt[i].right,rt[i].bottom);SetTextColor(hdc,RGB(0,255,255));TextOut(hdc,280,10,TEXT("万年历"),6);//输出文本SetTextColor(hdc,RGB(255,255,0));////设颜色TextOut(hdc,rt.left,rt.top,TEXT(" 1"),3);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT(" 2"),3);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT(" 3"),3);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT(" 4"),3);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT(" 5"),3);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT(" 6"),3);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT(" 7"),3);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT(" 8"),3);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT(" 9"),3);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT(" 0"),3);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT("确定"),4);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT("清除"),4);//输出文本TextOut(hdc,40,350,TEXT("提示:双击窗口退出"),18);//输出文本SetConsoleCursorPosition(hOut, pos3_1); ShowWindow(hwnd,SW_SHOW); SetConsoleTextAttribute(hOut, 10); for(;;) { SetConsoleTextAttribute(hOut, 10); ReadConsoleInput(hIn, mouseRec, 1, res); Sleep(100); if (mouseRec.EventType == MOUSE_EVENT) { if (mouseRec.Event.MouseEvent.dwEventFlags == DOUBLE_CLICK) break; if (mouseRec.Event.MouseEvent.dwButtonState == FROM_LEFT_1ST_BUTTON_*****) { GetCursorPos(pt); ScreenToClient(hwnd,pt); if(pt.x20 pt.x50 pt.yrt.top pt.yrt.bottom) { if(xyear4) printf("1"); xyear++; if(xyear==1) year=1*1000; if(xyear==2) year=year+1*100; if(xyear==3) year=year+1*10; if(xyear==4) { year=year+1; printf("\n你选择的年为%d",year); } continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.top pt.yrt.bottom) { if(xyear4) printf("2"); xyear++; if(xyear==1) year=2*1000; if(xyear==2) year=year+2*100;if(xyear==3) year=year+2*10; if(xyear==4){ year=year+2;printf("\n你选择的年为%d",year); } continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.bottom) { if(xyear4) printf("3"); xyear++; if(xyear==1) year=3*1000; if(xyear==2) year=year+3*100; if(xyear==3) year=year+3*10; if(xyear==4){ year=year+3; printf("\n你选择的年为%d",year); } continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.bottom){ if(xyear4) printf("4"); xyear++; if(xyear==1) year=4*1000; if(xyear==2) year=year+4*100; if(xyear==3) year=year+4*10; if(xyear==4){ year=year+4; printf("\n你选择的年为%d",year); } continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.bottom){ if(xyear4) printf("5"); xyear++; if(xyear==1) year=5*1000; if(xyear==2) year=year+5*100; if(xyear==3) year=year+5*10; if(xyear==4){ year=year+5;pt.yrt.top pt.yrt.top pt.yrt.topprintf("\n你选择的年为%d",year); } continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.bottom){ if(xyear4) printf("6"); xyear++; if(xyear==1) year=6*1000; if(xyear==2) year=year+6*100; if(xyear==3) year=year+6*10; if(xyear==4){ year=year+6; printf("\n你选择的年为%d",year); } continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.bottom){ if(xyear4) printf("7"); xyear++; if(xyear==1) year=7*1000; if(xyear==2) year=year+7*100; if(xyear==3) year=year+7*10;if(xyear==4){ year=year+7; printf("\n你选择的年为%d",year); } continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.bottom){ if(xyear4) printf("8"); xyear++; if(xyear==1) year=8*1000; if(xyear==2) year=year+8*100; if(xyear==3) year=year+8*10; if(xyear==4){ year=year+8; printf("\n你选择的年为%d",year);pt.yrt.top pt.yrt.top pt.yrt.top} continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.bottom){ if(xyear4) printf("9"); xyear++; if(xyear==1) year=9*1000; if(xyear==2) year=year+9*100; if(xyear==3) year=year+9*10; if(xyear==4){ year=year+9; printf("\n你选择的年为%d",year); } continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.bottom){ if(xyear4) printf("0"); xyear++; if(xyear==1) year=0*1000; if(xyear==2) year=year+0*100; if(xyear==3) year=year+0*10; if(xyear==4){ year=year+0; printf("\n你选择的年为%d",year); } continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.bottom){ if(xyear=1year!=0) { clear(); yearbak=year; SetConsoleCursorPosition(hOut, pos3_2); printf("公元%d年",yearbak); SetConsoleCursorPosition(hOut, pos3_1); for(i=1;ii+=3) huizs(i);pt.yrt.top pt.yrt.top pt.yrt.topx=MessageBox(NULL,"是否显示后六个月?", "提示",MB_YESNO); if(x==6) { SetConsoleTextAttribute(hOut, 14); clear(); for(i=7;ii+=3) huizs(i); } } else printf("输入不合法,请点击清除重新输入"); continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.top pt.yrt.bottom){ xyear=0; year=0; clear(); clock_sz(); hzdy(nowyear,nowmonth);pn=CreatePen(PS_SOLID,2,RGB(255,255,0)); SelectObject(hdc, pn);//选画笔MoveToEx(hdc,5,75,NULL); LineTo(hdc,45,75); SetConsoleCursorPosition(hOut, pos); continue; } }; } } ReleaseDC(hwnd,hdc); }int pd( int year) { int pr=0; if((year%100==0)(year%400==0)) pr=1; else if(year%4==0year%100!=0) pr=1; else pr=0; return pr; } void huizs(int line_head_month) { int i=0,j=0,k=0,month=0,n=0,daysum=0,jlw=0;int monthhead={0},mlt={1,1,1}; int endline=0,test=0; int year=0; year=yearbak; for(i=1;iyear;i++) { if(pd(i)) daysum+=366; else daysum+=365; } j=daysum%7; monthhead=j; for(month=1;monthmonth++) { if(pd(year)month==2) n=29; else if(pd(year)==0month==2) n=28; else if(month==4||month==6||month==9||month==11) n=30; else n=31; monthhead[month]=(monthhead[month-1]+n)%7; } while(test=5){ for(month=line_head_month;month=(line_head_month+2);mo nth++) { if(month%3==1endline==0) { printf("\t%d月\t\t\t%d月\n",month,month+1,month+2); printf("一二三四五六日一二三四五六日三四五六日\n"); } if(endline==0) { for(k=0;kmonthhead[month-1];k++) printf(" "); j=monthhead[month-1]; } if(endline==0) i=1; else i=mlt[month-1]; for(;ji++,j++) { if(pd(year)month==2) n=29; else if(pd(year)==0month==2) n=28;%d月一二else if(month==4||month==6||month==9||month==11) n=30; else n=31; if(in) { for(k=0;kk++) printf(" "); break; } printf("%-3.0d",i); } printf(" "); mlt[month-1]=i; if(month%3==0) { printf("\n"); endline=1; } j=0; } test++; } }void hzdy(int year,int nowmonth_hz) { int i=0,j=0,k=0,month=0,n=0,daysum=0,jlw=0; int monthhead={0},mlt={1,1,1}; int endline=0,test=0; for(i=1;iyear;i++) { if(pd(i)) daysum+=366; else daysum+=365; } j=daysum%7; monthhead=j; for(month=1;monthmonth++) { if(pd(year)month==2) n=29; else if(pd(year)==0month==2) n=28;//平年else if(month==4||month==6||month==9||month==11) n=30; elsen=31; monthhead[month]=(monthhead[month-1]+n)%7; } if(pd(year)nowmonth_hz==2) n=29;//闰年else if(pd(year)==0nowmonth_hz==2) n=28;//平年else if(nowmonth_hz==4||nowmonth_hz==6||nowmonth_hz==9||no wmonth_hz==11) n=30;//4,6,9,11月else n=31; printf("\n\n\n\n\n\n\n\n 当前时间:%d年%d月%d日%d时%d分\n\n",nowyear,nowmonth,nowday,hour,min); printf("\t一二三四五六日\n\t"); for(k=0;kmonthhead[nowmonth_hz-1];k++) printf(" "); j=monthhead[nowmonth_hz-1]; for(i=1;ii++,j++) { if(j==7) { printf("\n\t"); j=0; } printf("%-3.0d",i); } printf("\n"); } void clock_sz() { float a,b,c; float x=0,y=0,ex=100,ey=160,radian=0,oldx,oldy,radius=90; float mx=0,my=0,oldmx,oldmy,mradius=40; float hx=0,hy=0,oldhx,oldhy,hradius=20; intkd_r1,kd_r2,kd_radius=170,kd_radius1,old_kd_x,old_kd_y,kd_radi an=0,k=0,q=0,oldk,oldq; HWND hwnd; HANDLE hOut; HDC hdc; *****F C1=RGB(0,0,0),C2=RGB(0,0,0); HBRUSH hbr,hbr1,hbr2; HPENhpn,gpn,rpn,ppn2,ypn,bpn,kdpn,rkdpn,dotpn,blue,black,blkdpn, pkdpn,hpn2; hwnd=GetConsoleWindow(); hdc = GetDC(hwnd);hOut = GetStdHandle(STD_OUTPUT_HANDLE); hbr= CreateSolidBrush(RGB(0,100,0)); hbr1= CreateSolidBrush(C1); hbr2= CreateSolidBrush(RGB(0,0,150)); hpn2=CreatePen(PS_SOLID,1,RGB(255,0,0));rpn=CreatePen(PS_SOLID,1,RGB(255,0,0));hpn=CreatePen(PS_SOLID,1,RGB(0,255,255));blue=CreatePen(PS_SOLID,3,RGB(0,0,255));bpn=CreatePen(PS_SOLID,1,RGB(255,255,255));gpn=CreatePen(PS_SOLID,2,RGB(0,255,0));pkdpn=CreatePen(PS_SOLID,3,RGB(0,255,255));kdpn=CreatePen(PS_SOLID,1,RGB(255,255,0));rkdpn=CreatePen(PS_SOLID,4,RGB(255,0,0));blkdpn=CreatePen(PS_SOLID,6,RGB(0,0,0));black=CreatePen(PS_SOLID,4,C1); ex=400;//时钟圆心位置ey=230;while(kd_radian=360){ if(kd_radian%5==0) { if(kd_radian%90==0){ kd_radius=130; SelectObject(hdc,rkdpn); } else{ kd_radius=125; SelectObject(hdc,pkdpn); } } else { kd_radius=130; SelectObject(hdc, kdpn); kd_radius1=120; } y=kd_radius*sin(kd_radian/180.0*3.14);x=kd_radius*cos(kd_radian/180.0*3.14);MoveToEx(hdc,ex,ey,NULL); LineTo(hdc,ex+x,ey+y); y=kd_radius1*sin(kd_radian/180.0*3.14);x=kd_radius1*cos(kd_radian/180.0*3.14); old_kd_x=x; old_kd_y=y; SelectObject(hdc,blkdpn); MoveToEx(hdc,ex,ey,NULL); LineTo(hdc,ex+old_kd_x,ey+old_kd_y); kd_radian+=6; };SetTextColor(hdc,RGB(0,255,0));}TextOut(hdc,ex+kd_radius+8,ey-7,TEXT("3"),1);TextOut(hdc,ex-4,ey+kd_radius+3,TEXT("6"),1); TextOut(hdc,ex-kd_radius-15,ey-5,TEXT("9"),1); TextOut(hdc,ex-7,ey-kd_radius-18,TEXT("12"),2); radius=110;mradius=90;//分针半径hradius=70;//时针半径x=0,y=0; radian=0;SetTextColor(hdc,RGB(0,255,225));////设颜色SetBkColor(hdc,RGB(0,0,0));////设颜色ti2();a=sec*6/180.0*3.14; b=min*6/180.0*3.14;c=(hour*30.0-90.0+(min+15)/2.0)/180.0*3.14; SetTextColor(hdc,RGB(0,255,255)); my=mradius*sin(b); mx=mradius*cos(b); SelectObject(hdc, gpn);MoveToEx(hdc,ex,ey,NULL); LineTo(hdc,ex+mx,ey+my); LineTo(hdc,ex+mx,ey+my); hy=hradius*sin(c); hx=hradius*cos(c);SelectObject(hdc, blue);MoveToEx(hdc,ex,ey,NULL); LineTo(hdc,ex+hx,ey+hy); ReleaseDC(hwnd, hdc);。

单片机万年历C语言程序完整

单片机万年历C语言程序完整
sbit out = P2^3; //立刻跳出调整模式按钮
sbit DQ = P3^0;
char done,count,temp,flag,up_flag,down_flag,t_value;
uchar TempBuffer[5],week_value[2];
void show_time(); //液晶显示程序
unsigned char Day;
unsigned char Month;
unsigned char Year;
unsigned char DateString[11];
unsigned char TimeString[9];
}SYSTEMTIME;//定义的时间类型
#define AM(X)X
#define PM(X)(X+12)//转成24小时制
{
unsigned char ucData;
DS1302_RST = 0;
DS1302_CLK = 0;
DS1302_RST = 1;
DS1302InputByte(ucAddr|0x01); //地址,命令
ucData = DS1302OutputByte(); //读1Byte数据
DS1302_CLK = 1;
#define DS1302_SECOND0x80 //时钟芯片的寄存器位置,存放时间
#define DS1302_MINUTE0x82
#define DS1302_HOUR0x84
#define DS1302_WEEK0x8A
#define DS1302_DAY0x86
#define DS1302_MONTH0x88
#define uchar unsigned char

C#实现农历日历的方法

C#实现农历日历的方法

C#实现农历⽇历的⽅法本⽂实例讲述了C#实现农历⽇历的⽅法。

分享给⼤家供⼤家参考。

具体实现⽅法如下:复制代码代码如下://天⼲private static string []TianGan = {"甲","⼄","丙","丁","戊","⼰","庚","⾟","壬","癸"};//地⽀private static string []DiZhi = {"⼦","丑","寅","卯","⾠","巳","午","未","申","⾣","戌","亥"};//⼗⼆⽣肖private static string []ShengXiao = {"⿏","⽜","虎","兔","龙","蛇","马","⽺","猴","鸡","狗","猪"};//农历⽇期private static string []DayName = {"*","初⼀","初⼆","初三","初四","初五","初六","初七","初⼋","初九","初⼗", "⼗⼀","⼗⼆","⼗三","⼗四","⼗五", "⼗六","⼗七","⼗⼋","⼗九","⼆⼗", "廿⼀","廿⼆","廿三","廿四","廿五", "廿六","廿七","廿⼋","廿九","三⼗"};//农历⽉份private static string []MonthName = {"*","正","⼆","三","四","五","六","七","⼋","九","⼗","⼗⼀","腊"};//公历⽉计数天private static int []MonthAdd = {0,31,59,90,120,151,181,212,243,273,304,334};//农历数据private static int []LunarData = {2635,333387,1701,1748,267701,694,2391,133423,1175,396438,3402,3749,331177,1453,694,201326,2350,465197,3221,3402,400202,2901,1386,267611,605,2349,137515,2709,464533,1738,2901,330421,1242,2651,199255,1323,529706,3733,1706,398762,2741,1206,267438,2647,1318,204070,3477,461653,1386,2413,330077,1197,2637,268877,3365,531109,2900,2922,398042,2395,1179,267415,2635,661067,1701,1748,398772,2742,2391,330031,1175,1611,200010,3749,527717,1452,2742,332397,2350,3222,268949,3402,3493,133973,1386,464219,605,2349,334123,2709,2890,267946,2773,592565,1210,2651,395863,1323,2707,265877};/// <summary>/// 获取对应⽇期的农历////// </summary>/// <param name="dtDay">公历⽇期</param>//////<returns></returns>public string GetLunarCalendar(DateTime dtDay){string sYear = dtDay.Year.ToString(); string sMonth = dtDay.Month.ToString();string sDay = dtDay.Day.ToString();int year;int month;int day;try {year = int.Parse(sYear);month = int.Parse(sMonth);day = int.Parse(sDay);}catch {year = DateTime.Now.Year;month = DateTime.Now.Month;day = DateTime.Now.Day;}int nTheDate;int nIsEnd;int k, m, n, nBit, i;string calendar = string.Empty;//计算到初始时间1921年2⽉8⽇的天数:1921-2-8(正⽉初⼀)nTheDate = (year - 1921) * 365 + (year - 1921) / 4 + day + MonthAdd[month - 1] - 38; if ((year % 4 == 0) && (month > 2)) nTheDate += 1;//计算天⼲,地⽀,⽉,⽇nIsEnd = 0; m = 0; k = 0; n = 0;while (nIsEnd != 1){if (LunarData[m] < 4095) k = 11; else k = 12; n = k; while (n >= 0){ //获取LunarData[m]的第n个⼆进制位的值nBit = LunarData[m];for (i = 1; i < n + 1; i++) nBit = nBit / 2;nBit = nBit % 2;if (nTheDate <= (29 + nBit)) { nIsEnd = 1; break; }nTheDate = nTheDate - 29 - nBit; n = n - 1;}if (nIsEnd == 1) break; m = m + 1;}year = 1921 + m; month = k - n + 1; day = nTheDate;#region 格式化⽇期显⽰为三⽉廿四if (k == 12){if (month == LunarData[m] / 65536 + 1)month = 1 - month;else if (month > LunarData[m] / 65536 + 1)month = month - 1;}//⽣肖//calendar = ShengXiao[(year - 4) % 60 % 12].ToString() + "年 ";// // //天⼲// //calendar += TianGan[(year - 4) % 60 % 10].ToString();// // //地⽀// //calendar += DiZhi[(year - 4) % 60 % 12].ToString() + " ";//// //农历⽉//if (month < 1)//calendar += "闰" + MonthName[-1 * month].ToString() + "⽉";elsecalendar += MonthName[month].ToString() + "⽉";//// //农历⽇//calendar += DayName[day].ToString() + "⽇";////return calendar;////#endregion}希望本⽂所述对⼤家的C#程序设计有所帮助。

C语言实训--万年历源代码

C语言实训--万年历源代码

C语言实训--万年历源代码# include#include#include#include#include# define YEAR 365int numday[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31}, {31,29,31,30,31,30,31,31,30,31,30,31}};int leap(int year);int calday(int y,int m);int counterdays(int year,int month,int day);int week(int year,int month,int day);int eachyeartotal(int year,int month,int day);int maxDay(int y,int month);void print(int y,int m,int w);void festival (int year,int month,int day);int IsLeap(int y);int guanli(int i);void rili(int year,int month);int rili1();void rili2();void rili3();void rili4();void rili5();void fan();void show(int year,int month,int date,int sec,int mini,int hour);int main(){int i;printf("***************************************\n"); printf("1.查询日历,输入年份:\n");printf("2.查询该月日历及对应星期,输入年份和月份:\n"); printf("3.查询星期几及节日,输入年月日:\n");printf("4.距您输入日期还有多少天,输入日期:\n"); printf("5.通过键盘上下控制不同年月日:\n");scanf("%d",&i);guanli(i);return 0;}int guanli(int i){switch(i){case 1:rili1();return main();case 2:rili2();return main();case 3:rili3();return main();case 4:rili4();return main();case 5:rili5();return main();}return 0;}int rili1(){int year;int n,i;printf("输入年份:");scanf("%d",&year);printf("the calendar of the year%d\n",year);printf("\n");printf("=============================\n"); for(i=1;i<13;i++){printf(" %d月份\n",i);rili(year,i);}n = leap(year);return 0;}void rili2(){int year,month,w;printf("输入年月:");scanf("%d%d",&year,&month);w=calday(year,month);print(year,month,w);}void rili3(){int year,month,day,number;printf("输入年月日:");scanf("%d%d%d",&year,&month,&day);festival(year,month,day);number= week(year,month,day);printf("星期%d",number);}void rili4(){int year,month,day;printf("输入年月日:");scanf("%d%d%d",&year,&month,&day); eachyeartotal( year,month,day);counterdays(year,month,day);}void rili5(){int year,month,date,sec,mini,hour;fan();show(year,month,date,sec,mini,hour);}int leap(int year){int n=(year%4==0 && year%100!=0 || year%100!=0); return n;}void rili(int year,int month){int i,day,first_day,flag,year1,year2;int temp = 6;flag =leap(year);year1=year/100;year2=year%100;if(year>2000){year1=year1-20;day = year1/4;day+=(YEAR+24)*year1+YEAR*year2+(year2-1)/4;if(year>2000)day++;switch(month){case 1:day; break;case 2:day+=31;break;case 3:day+=59+flag;break;case 4:day+=90+flag;break;case 5:day+=120+flag;break;case 6:day+=151+flag;break;case 7:day+=181+flag;break;case 8:day+=212+flag;break;case 9:day+=243+flag;break;case 10:day+=273+flag;break;case 11:day+=304+flag;break;case 12:day+=334+flag;break;}day+=temp;first_day=day%7;}else{year1 = 20-1-year;year2=100-year2-1;day+=(YEAR+24)*year1+YEAR*year2+year2/4; switch(month){case 12:day+=31;break;case 11:day+=61;break;case 10:day+=92;break;case 9:day+=122;break;case 8:day+=153;break;case 7:day+=184;break; case 6:day+=214;break; case 5:day+=245;break; case 4:day+=275;break; case 3:day+=306;break; case 2:day+=334+flag;break; case 1:day+=365+flag;break; }day-=temp;day = day%7;first_day=(7-day)%7;}switch(month){case 1:case 2:month=28+flag;break; case 3:case 4:case 5:case 6:case 7:case 8:case 9:case 10:case 11:month=30;break; case 12:month =31;break;}for(i=1;i<4*first_day;i++) printf(" ");for(i=0;i<month;i++)< p="">{printf("%4d",i+1);if((first_day+i)%7==6)printf("\n");}printf("\n");printf("===============================\n");}///////////////////////////////////////////////////////////int counterdays(int year,int month,int day){int year1,days0,days1,month1,days,day1;time_t timep;struct tm*p;time(&timep);p=gmtime(&timep);year1=(1900+p->tm_year);month1=(1+p->tm_mon);day1=(p->tm_mday);days0=(year-1)*365 + (year-1)/4 - (year-1)/100 + (year-1)/400 +eachyeartotal (year,month,day);days1=(year1 - 1)*365+(year1-1)/4-(year1-1)/100 + (year1 - 1)/400 +eachyeartotal (year1,month1,day1);days=days0-days1;printf("\n今天距%d年%d月%d日还有%d天\n\n",year,month,day,days);return days;}int eachyeartotal(int year,int month,int day){int i,sum=0;for(i=1;i<month;i++)< p="">{sum+=maxDay(year,i);}sum+=day;return sum;}int IsLeap(int y){if(y%4==0 && y%100!=0 || y%400==0) return 1; else return 0;}int maxDay(int y,int month){int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};if(IsLeap(y))a[1]=29;return a[month-1];}///////////////////////////////////////void festival (int year,int month,int day){if (month==1 && day==1) printf (",这天是元旦");if (month==2 && day==14) printf (",这天是情人节"); if (month == 3)switch(day){case 8:printf (",这天是妇女节"); break;case 12:printf (",这天是植树节");}if (month==1 && day==1) printf (",这天是愚人节");if(month == 5)switch (day){case 1:printf(",这天是劳动节");break;case 4:printf(",这天是青年节");}if (month==6 && day==1) printf (",这天是儿童节");if (month==7 && day==1) printf (",这天是建党节");if (month==8 && day==1) printf (",这天是建军节");if (month==9 && day==10) printf (",这天是教师节");if (month==10 && day==1) printf (",这天是国庆节");printf("\n");}int week(int year,int month,int day){int number = (year-1)+(year-1)/4 - (year-1)/100+(year-1)/400+eachyeartotal(year,month,day);number = number%7;return number;}/////////////////////////////////////////////void print(int y,int m,int w){int i,l;printf("Calendar %d-%02d\n",y,m);printf("---------------------\n");printf("Su Mo Tu We Th Fr Sa \n");printf("---------------------\n");for (i=0;i<w;i++)< p=""> printf(" ");if (IsLeap(y))l=1;elsel=0;for (i=1;i<=numday[l][m-1];i++) {printf("%-3d",i);w++;if (w%7==0)printf("\n");}if (w%7) printf("\n");printf("---------------------\n"); }int calday(int y,int m){int d=0,w;while (y>1910){if (IsLeap(y)) d+=366;else d+=365;y--;}while (m>1){ --m;d+=numday[0][m-1];}w=(d+1)%7;return w;}//////////////////////////////////////////void show(int year,int month,int date,int sec,int mini,int hour) {const char month_str[][4]={"","Jan","Feb","Mar","Apl", "May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};const int month_day[]={0,31,28,31,30,31,30,31,31,30,31,30,31};int i,j,wdays,mdays,days;for(i=1,days=0;i<year;i++)< p="">{if(leap(i))days += 366;}else{days += 365;}}for(i=1;i<month;i++)< p="">{if(i==2 && leap(year)){days+=29;}else{days+=month_day[i];}}printf(" %s.%d.%d %d:%d:%d \n",month_str[month],date,year,hour,mini,sec);printf(" 一二三四五六日\n");wdays = days % 7;for( j = 0; j < wdays; j++){printf(" ");}if(month == 2 && leap(year)){mdays=29;}else{mdays= month_day[month];}for(i=1;i<=mdays;i++){if( i > 1 && days % 7 == 0 ){printf("\n");}printf("%4d",i);days=days+1; }printf("\n---------------------------\n\n\n");}{time_t rawtime;struct tm *info;int year,month,date,sec,mini,hour; char ch;time ( &rawtime );info = localtime ( &rawtime );year =info->tm_year + 1900; month =info->tm_mon + 1;date =info->tm_mday;hour =info->tm_hour;mini =info->tm_min;sec =info->tm_sec;while(1){show(year,month,date,sec,mini,hour); printf("↑......上一年\n\n");printf("↓......下一年\n\n");printf("←....前一个月\n\n");pr intf("→....后一个月\n\n");printf("Esc.......退出\n\n");ch=getch();switch(ch){case 27://Ecs exit(0);case -32://Navigatorch=getch();if(ch==77){//Rightyear+=(month==12)?1:0;month=month%12+1;}else if(ch==75){year-=(month==1)?1:0; month=(month-2+12)%12+1; }else if(ch==72)year--;else if(ch==80)year++;system("cls");}}</month;i++)<></year;i++)<></w;i++)<></month;i++)<></month;i++)<>。

CC++程序设计——万年历(完整代码+实验报告)

CC++程序设计——万年历(完整代码+实验报告)

2、主要函数流程图: (1)类的构造函数:用于给类的对象赋值。提示用户输入数据,并具有较强的错误输 入数据检查功能。(参见图 3-1) (2)闰年判断函数:判断哪些年份为闰年。 (图 3-2)
正文 第 2 页(共 18 页)
开 始
开 始
year%4==0

输入待查询的 年份


year%100==0
* ","***** ","***** ","***** ","***** ","***** "," * ","***** ","***** "," * ","***** ","***** ","
"***** ","
=====================公元"<<year<<"年日历====================="<<endl; =====================公元"<<year<<"年日历====================="<<endl;
/*实现 3 维数组图案的输出*/ for(int g=0;g<5;g++) { cout<<" fout<<" for(int i=0;i<4;i++) for(int h=0;h<7;h++) { cout<<ss[g][num[i]][h]; fout<<ss[g][num[i]][h]; } cout<<endl; fout<<endl; } }

C语言课程设计万年历 完整版

C语言课程设计万年历  完整版

目录一引言 (2)二系统功能和数据说明 (3)一)功能简介 (3)二)程序中的数据说明 (3)三程序总体设计及流程图 (4)一)应用到的c语言 (4)二)程序的总框架 (5)四功能模块设计及调试 (5)一)算法说明 (5)1.总天数的算法 (5)2.计算输入日期是星期几 (6)3.对输入信息的汇总 (8)4..界面的控制 (10)二)调试结果 (11)五程序清单 (12)六结束语 (17)一引言通过大一上学期对C语言的学习,了解到了很多C语言的相关知识。

学习的过程有很多困惑但是当自己能够独立的看懂,能过独立的完成一个简单的程序时,心中就会收获无限的喜悦和成就感。

我可以里哟哦那个它看懂一些简单的程序,编写一些简单的计算程序,更多的是学会了一种思想——编程,它让我在去思考很多日常生活中的事物是怎么样通过一个个小小的函数实现功能的,激发我对探究的兴趣。

C语言是近年在国内外得到迅速推广应用的一种语言。

C语言功能丰富,表达能力强,使用灵活方便,应用面广,目标程序效率高,可移植性好,既具有高级语言的优点,又具有低级语言的许多特点。

因此,C语言特别适合于编写各种软件。

在这次的课程设计中我将把日常生活中最经常接触的——日期的查询利用C语言的程序编成一个简单的日历。

通过这个小小的日历可以实现很多功能。

在程序中你能看到很多熟悉的C语言关键字,同时也加入了很多自己课外了解到的一些关键字。

在不断的调试中最终才获得最为完整的程序。

接下来就是我的C 语言课程设计的具体内容来了二系统功能和数据说明(一)功能简介在我们的日常生活中能接触到很多不同类型的日历,在日历上我们通常希望它能简介明了的给我们最想要的日期信息。

在我的万年历当中,就是将日历,月历做的简单明了,很方便我们的使用。

下面是它要实现的一些基本功能:用C语言编写万年历1、输入年份,判断是否为闰年2、输入年月日,判断改日为星期几3、输入年份,打出12个月历,输入月份,打出该月的日历4、要求用多个函数实现[名称]万年历[修改]1、对输入的日期进行容错处理2、增加和修改为英文的月份和星期显示3、采用指针形式的weeks和month数组(二)程序中的数据说明①int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};这是定义的关于每个月天数的数组,根据大小月以及二月分的特殊情况将每个月的天数最为数组中的元素存入数组当中。

C++程序设计(万年历——说明书)

C++程序设计(万年历——说明书)

C++程序设计说明书题目:万年历班级学号:学生姓名:目录一.应用程序的名称二.应用程序的主题、设计目的三.应用程序简介1.程序的基本结构及内容2。

程序的运行环境四.主要运行界面的介绍五.程序亮点六.课程设计中存在的问题及解决方法一.课程设计名称万年历二.应用程序要求、目的主题:万年历目的:实现对年月的查询三.应用程序简介(1)基本结构:整个程序有cls_screen(清屏)、judgement(判断是否为闰年)、show_week(记录周几)、print_year(查询某年)、print_year_month(查询某年某月)等自定义函数,程序中涉及到switch语句、for语句、if语句等和多次函数调用语句,开头定义了day_of_month[]数组,主要目的是将12个月每个月有多少天依次排出,在后面又用if语句判断二月的天数是28还是29。

在主函数中运用while 语言与switch语句的嵌套,是程序拥有了循环的功能.用fflush(stdin);语句清除输入缓存,使程序在使用过程中不会太过眼花缭乱。

万年历的编程,需要两个方面的讨论和研究,一是要在用户输入年份的时候,判断该年是否为闰年,而对于闰年的判断,能被4整除但不能被100整除,或者能被400整除的年份为闰年,否则为平年。

所以会改变day_of_month[]数组中的二月份的数值。

二是在用户输入年月份的时候,判断该年该月的第一天是周几,从来好排列。

而对于判断周几,需要运用公式:w=(y+[y/4]+[c/4]—2c+[26(m+1)/10]+d-1)%7并用if语句使用判断。

通过这两个方面的讨论和实现,才能合理的编程出万年历的基本程序代码.(2)源程序代码:#include〈stdio.h>#include 〈string。

h〉#include 〈time.h>#include <math。

h〉#include 〈windows。

C语言农历表算法

C语言农历表算法

#include<stdio.h>void DateTrans(char *chDate,int *nYear,int *nMonth,int *nDay);// 1int IsLeapYear(int nYear);// 2int GetWeekOfFirstday(int nYear);// 3int GetWeek(int nYear,int nMonth,int nDay,int nWeekOfFirstday);// 4void PrintCalendar(int nWeek,int nDay,int nMonthDays,char *chDate);// 5void DateTrans(char *chDate,int *nYear,int *nMonth,int *nDay)// 1{*nYear=(chDate[0]-'0')*1000+(chDate[1]-'0')*100+(chDate[2]-'0')*10+chDate[3] -'0';*nMonth=(chDate[5]-'0')*10+chDate[6]-'0';*nDay=(chDate[8]-'0')*10+chDate[9]-'0';}int IsLeapYear(int nYear)// 2{if(nYear%4==0)return 1;elsereturn 0;}int GetWeekOfFirstday(int nYear)// 3{if(nYear>2000)return ((nYear-2001)*365+(nYear-2001)/4+1)%7;else if(nYear<2000)return 6-((2000-nYear)*365+(2000-nYear)/4)%7;elsereturn 6;}int GetWeek(int nYear,int nMonth,int nDay,int nWeekOfFirstday)// 4{int nDaysYear[]={31,28,31,30,31,30,31,31,30,31,30,31};int nDaysLeapYear[]={31,29,31,30,31,30,31,31,30,31,30,31};int i,sum=0;if(nYear%4==0){for(i=0;i<(nMonth-1);i++){sum+=nDaysLeapYear[i];}return (sum+nDay+nWeekOfFirstday-1)%7;}else{for(i=0;i<(nMonth-1);i++){sum+=nDaysYear[i];}return (sum+nDay+nWeekOfFirstday-1)%7;}}void PrintCalendar(int nWeek,int nDay,int nMonthDays,char *chDate) // 5{int i,j;printf("the calender of this month as following:\n");printf("*********************************\n");printf(" SUN MON TUE WEN THU FRI STA\n");for(i=1,j=1;j<=nMonthDays;i++){if(i<=nWeek+1)printf(" ");else{printf("%4d",j);j++;}if(i%7==0)printf("\n");}printf("\n********************************\n");printf("OK!\n");}main(){char chDate[11],i=0,j,isleapyear;int nYear,nMonth,nDay;int nWeekOfFirstday;int nMonthDays;int nWeek;char *Week;int nDaysYear[]={31,28,31,30,31,30,31,31,30,31,30,31};int nDaysLeapYear[]={31,29,31,30,31,30,31,31,30,31,30,31};printf("请输入你要查找的日期,如(2001\\01\\01或2001.01.01:\n或者是你想要日历的月份:如(2000\\01或2000.01):\n");do{scanf("%c",&chDate[i]);i++;}while(chDate[i-1]!='\n');if(i==11)chDate[i-1]='\0';elsefor(j=8;j<11;j++)chDate[j]='0';DateTrans(chDate,&nYear,&nMonth,&nDay);// 1while(nYear<=0||nMonth<1||nMonth>12){printf("查询年月chDate非法\n");return 0;}nWeekOfFirstday = GetWeekOfFirstday(nYear);// 3nWeek=GetWeek(nYear,nMonth,nDay,nWeekOfFirstday);// 4isleapyear=IsLeapYear(nYear);// 2if(isleapyear==1)nMonthDays=nDaysLeapYear[nMonth-1];else if(isleapyear==0)nMonthDays=nDaysYear[nMonth-1];if(i==11){while(nDay<1||nDay>nMonthDays){printf("查询日期chDate非法\n");return 0;}switch(nWeek){case 0:Week="SUNDAY";break;case 1:Week="MONDAY";break;case 2:Week="TUESDAY";break;case 3:Week="WEDNESDAY";break;case 4:Week="THUESDAY";break;case 5:Week="FRIDAY";break;case 6:Week="SATERDAY";break;}printf("This day (%s) is %s\n",chDate,Week);printf("OK!\n");}elsePrintCalendar(nWeek,nDay,nMonthDays,chDate); //5 }。

c++万年历及公历农历转换源代码2

c++万年历及公历农历转换源代码2

#include <stdio.h>#include <stdlib.h>#include <conio.h>#define X " Sun Mon Tue Wed Thu Fri Sat"#define P printf#define B break#define FP fprintfstruct date /*日期*/{int year;int month;int date;};struct taglunarcal /**/{int basedays;int intercalation;int monthdays[13];}dalist[]={{31,8,0,1,0,0,1,0,1,1,0,1,1,0,1},{50,0,0,1,0,0,1,0,1,0,1,1,1,0,0},{39,0,1,0,1,0,0,1,0,1,0,1 ,1,1,0},{29,5,0,1,0,1,0,0,1,0,0,1,1,0,1},{47,0,1,1,0,1,0,0,1,0,0,1,1,0,0},{35,0,1,1,0,1,1,0,0,1,0,1,0,1,0},{25,4,0,1,1,0,1,0,1,0,1,0,1,0,1},{4 4,0,0,1,0,1,0,1,1,0,1,0,1,0,0},{33,0,1,0,0,1,1,0,1,0,1,1,0,1,0},{22,2,0,1,0,0,1,0,1,0,1,1,1,0,1},{41,0,0,1,0,0,1,0,1,0,1,1,1,0,0},{3 0,6,1,0,1,0,0,1,0,0,1,1,0,1,1},{49,0,1,0,1,0,0,1,0,0,1,1,0,1,0},{37,0,1,1,0,1,0,0,1,0,0,1,0,1,0},{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0,0,1,1,1},{4 8,0,0,1,1,0,1,0,1,0,1,0,1,0,0},{37,0,1,0,1,0,1,1,0,1,0,1,0,1,0},{26,5,0,1,0,0,1,0,1,1,0,1,0,1,1},{45,0,0,1,0,0,1,0,1,1,0,1,1,0,0},{3 4,0,1,0,1,0,0,1,0,1,0,1,1,1,0},{24,4,0,1,0,1,0,1,0,0,1,1,1,0,1},{41,0,1,1,0,1,0,0,1,0,0,1,1,0,0},{30,8,1,1,1,0,1,0,0,1,0,1,1,0,1},{4 9,0,1,1,0,1,0,1,0,1,0,0,1,0,0},{38,0,1,1,0,1,1,0,1,0,1,0,1,0,0},{27,6,0,1,1,0,1,0,1,0,1,0,1,0,0},{46,0,0,1,0,1,0,1,1,0,1,1,0,1,0},{3 6,0,0,1,0,0,1,0,1,0,1,1,1,0,0},{25,4,1,0,1,0,1,0,0,1,1,1,0,1,0},{43,0,1,0,1,0,0,1,0,0,1,1,0,1,0},{32,0,1,0,1,0,0,0,0,1,0,1,0,1,0},{2 1,2,1,1,1,1,0,0,1,0,0,1,0,1,1},{40,0,1,1,0,1,0,1,0,1,0,0,1,0,0}};getleap( int year ) /*1代表闰年*/{if ( year % 400 == 0 )return 1;else if ( year % 100 == 0 )return 0;else if ( year % 4 == 0 )return 1;elsereturn 0;}print(int n){int i;for(i=0;i<n;i++) printf(" ");}int day(int year){long a,b;if(year<=2000){a=2000-year;b=6-(a+a/4-a/100+a/400)%7; return b;}else{a=year-2000; b=(a+1+(a-1)/4-(a-1)/100+(a-1)/400)%7+6; return b%7; }}solardate(struct date * input) /*公历年第几天*/{int i,number=0,solarcal[12]={31,28,31,30,31,30,31,31,30,31,30,31}; number=getleap(input->year);for(i=0;i<input->month-1;i++){number+=solarcal[i];}return number+input->date;}lunardate(struct date *input)/*农历年第几天*/{int i,leap=0,number=0;if(dalist[input->year-1900].intercalation==0)leap=0;else if(input->month==dalist[input->year-1900].intercalation){printf(" 0 not leap month\n 1 leap month");scanf("%d",&leap);}else if(input->month>dalist[input->year-1900].intercalation) leap=1;for(i=0;i<input->month+leap-1;i++)number+=dalist[input->year-1900].monthdays[i]+29;return number+input->date;}lunarmonth(int year,int *mon){int i,j;mon[0]=dalist[year].monthdays[0]+29;for(i=1,j=1;i<12;i++,j++){if(i==dalist[year].intercalation){mon[i-1]+=dalist[year].monthdays[j]+29;j++;}mon[i]=mon[i-1]+dalist[year].monthdays[j]+29;}}main(){int i,j,k,m,n,f1,f2,year,d,y,ly,cord,greday,lunday,diff,add,leap,tlylm[12],lastylm[12],a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31},SolarDays[2][12] = {{31,59,90,120,151,181,212,243,273,304,334,365},{31,60,91,121,152,182,213,244,274,305,335, 366}};char fname[12]={"0"}; FILE *fw;struct date input;do{printf("\n--------------------------------------------\n");printf(" 请选择");printf("\n--------------------------------------------\n");printf(" 1 公历转换成农历");printf("\n--------------------------------------------\n");printf(" 2 农历转换成公历");printf("\n--------------------------------------------\n");printf(" 3 万年历");printf("\n--------------------------------------------\n");printf(" 4 退出");printf("\n--------------------------------------------\n");printf("\n 请选择: 1,2,3,4\n");scanf("%d",&cord);clrscr();switch(cord){case 1:{printf("\n(公历) 请输入年.月.日(yyyy.mm.dd) \n");scanf("%d.%d.%d",&input.year,&input.month,&input.date);/*输入年月日*/y=input.year;greday=solardate(&input);/*公历年第几天*/diff=greday-dalist[y-1900].basedays;if(diff>0)lunarmonth(y-1900,tlylm);else{y-=1;lunarmonth(y-1900,tlylm);diff+=tlylm[11];}for(i=0;tlylm[i]<diff;i++);if(i!=0)diff-=tlylm[i-1];printf("(农历) %d.%d.%d",y,i+1,diff);break;}clrscr();case 2:{printf("\n(农历) 请输入年.月.日(yyyy.mm.dd) \n");scanf("%d.%d.%d",&input.year,&input.month,&input.date);y=input.year;ly=getleap(y);lunday=lunardate(&input);/*农历年第几天*/add=lunday+dalist[y-1900].basedays;if(add-365+ly>0){add-=365+ly;y+=1;}for(i=0;SolarDays[ly][i]<add;i++);if(i!=0)add-=SolarDays[ly][i-1];printf("(公历) %d.%d.%d",y,i+1,add);break;}case 3:{system("cls");P(" 请输入你所要查看的年份:");scanf("%d",&year);fw=fopen(fname,"w+");if(fw==NULL){P(" can not open file."); return;}P(" The calendar of the year %d.\n",year);FP(fw,"The calendar of the year %d.\n",year);d=day(year);if(year%4==0&&year%100||year%400==0) a[2]++;for(i=1;i<=12;i+=2){m=0; n=0; f1=0; f2=0;switch(i){case 1:P(" Januray 1 "); FP(fw," Januray 1 "); B; case 3:P(" March 3 "); FP(fw," March 3 "); B; case 5:P(" May 5 "); FP(fw," May 5 "); B; case 7:P(" July 7 "); FP(fw," July 7 "); B; case 9:P(" September 9 "); FP(fw," September 9 "); B; case 11:P(" Nevember 11 "); FP(fw," Nevember 11 "); B; }print(21);for(k=0;k<21;k++) fprintf(fw," ");switch(i+1){case 2:P(" February 2 "); FP(fw," February 2 ");B; case 4:P(" April 4 "); FP(fw," April 4 ");B;case 6:P(" June 6 "); FP(fw," June 6 ");B; case 8:P(" August 8 "); FP(fw," August 8 "); B; case 10:P(" October 10 "); FP(fw," October 10 ");B; case 12:P(" December 12"); FP(fw," December 12");B;}P("\n");fprintf(fw,"\n");P(X); fprintf(fw,X); print(6);fprintf(fw," "); P(X); fprintf(fw,X);fprintf(fw,"\n"); P("\n");for(j=0;j<6;j++){if(j==0){print(d*4); for(k=0;k<d*4;k++) fprintf(fw," ");for(k=0;k<7-d;k++){P("%4d",++m); fprintf(fw,"%4d",m);}print(6); fprintf(fw," ");d+=a[i]%7; d%=7;print(d*4); for(k=0;k<d*4;k++) fprintf(fw," ");for(k=0;k<7-d;k++){P("%4d",++n); fprintf(fw,"%4d",n);}P("\n"); fprintf(fw,"\n");}else{for(k=0;k<7;k++){if(m<a[i]){P("%4d",++m); fprintf(fw,"%4d",m);}else{print(4); fprintf(fw,"");}if(m==a[i]) f1=1;}print(6); fprintf(fw," ");for(k=0;k<7;k++){if(n<a[i+1]){P("%4d",++n);fprintf(fw,"%4d",n);}else{print(4); fprintf(fw,"");}if(n==a[i+1]) f2=1;}P("\n"); fprintf(fw,"\n");if(f1&&f2) B;}}d+=a[i+1]%7; d%=7; P(" "); fprintf(fw," "); if(i==5){getch();system("cls");}}fclose(fw);getch();break;}case 4:{exit(0);}}}while(cord<=4);}。

C语言万年历代码

C语言万年历代码

else if(ch=='n'||ch=='N')
{ month+=1;
if(month>12) {month=1;year+=1;}
}
printf("\t\t********e退出 p上一月 n下一月********");
}
void first_set(int *year,int *month)
{ do{
printf ("please input the year(1~9999):");
if (choose=='y'||choose=='Y') main();
}
days_of_month(int x,int y)
{
int z;
switch (y)
{case 1:
case 3:
case 5:
case 7:
case 8:
printf ("please input the month(1~12):");
scanf ("%d",month);
if(*month<1||*month>12) printf ("WANNING:ERROR,please input again!\n");
printf ("\n\n********************************************************************************\n\n");
自己做的日历(C语言)
本帖最后由 kekeyu 于 2010-8-15 16:59 编辑

万年历程序源代码

万年历程序源代码

#include<iostream>#include<iomanip>#include <ctime>using namespace std;int dayofmonth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int dd[12]={ 31,28,31,30,31,30,31,31,30,31,30,31 };class datee{private:int d,m,y;public:int isLeap( int y );int getDayPerMonth( int y , int m );int getNumDay( datee D );bool legalDate( datee D );void count();};/*ÅжÏÊÇ·ñÊÇÈòÄê*/int datee::isLeap( int y ){if( !(y%4)&&y%100 || !(y%400) )return 1;return 0;}/*¼ÆË㲻ͬÇé¿ö¶þÔ·ݵÄÌìÊý*/int datee::getDayPerMonth( int y , int m ){if( m==2 )return dd[1]+isLeap( y );return dd[m-1];}/*¼ÆËãʱ¼ä²î*/int datee::getNumDay( datee D ){int ret=0;int i;for( i=1 ; i<=D.y ; i++ )ret+=365+isLeap( D.y );for( i=1 ; i<D.m ; i++ )ret+=getDayPerMonth( D.y , i );ret+=D.d;return ret;}/*ÔËÓò¼¶ûÐͺ¯ÊýÅжÏÊäÈëÊý¾ÝµÄÕýÎó*/bool datee::legalDate( datee D ){if( D.y<0||D.y>9999 )return false;if( D.m<1||D.m>12 )return false;if( D.d<1||D.d>getDayPerMonth( D.y , D.m ) )return false;return true;}void datee::count(){long day;datee sysDate,date;cout<<"please input what date you want to compared:"<<endl; cout<<"year month day"<<endl;cout<<"the one:";cin>>date.y>>date.m>>date.d;while( !legalDate(date) ){cout<<"illegal date,input again: "<<endl;cin>>date.y>>date.m>>date.d;}cout<<"the tow:";cin>>sysDate.y>>sysDate.m>>sysDate.d;while( !legalDate(sysDate) ){cout<<"illegal system date,input again: "<<endl;cin>>sysDate.y>>sysDate.m>>sysDate.d;}day=getNumDay(date)-getNumDay(sysDate);if(day<0)day=-day;cout<<"the time difference is :"<<endl<<day<<endl;}class Date{private:int year;int month;int day;public:void SetDate();int IsLeap(int year);void ShowDate();int getdays(int year,int month,int day);void showweek();void printmonth();void printyear();void input(){cin>>year>>month;while(month<1||month>12){cout<<"illegal month,please input again:"<<endl;cin>>year>>month;panduan();}}void panduan(){if(month<1||month>12){cout<<"illegal month,please input again:"<<endl;cin>>year>>month;}}};void Date::SetDate(){int yy,mm,dd;cout<<"please input the date:"<<endl<<"year month date"<<endl;cin>>yy>>mm>>dd;if(yy<=0){ cout<<"Year value error!"<<endl;}if(mm<=0&&mm>12){cout<<"Month value error!"<<endl;exit(1);}year=yy;month=mm;switch(month){case 4:case 6:case 9:case 11:{if(dd>=1&&dd<=30)day=dd;else{cout<<"Day value error!"<<endl;cout<<"please input again:"<<endl;cout<<"year month date"<<endl;cin>>yy>>mm>>dd;day=dd;}} break;case 2:{if(IsLeap(year)){if(dd>=1&&dd<=29)day=dd;else{cout<<"Day value error!"<<endl;cout<<"please input again:"<<endl;cout<<"year month date"<<endl;cin>>yy>>mm>>dd;day=dd;}}else{if(dd>=1&&dd<=28)day=dd;else{cout<<"Day value error!"<<endl;cout<<"please input again:"<<endl;cout<<"year month date"<<endl;cin>>yy>>mm>>dd;day=dd;}}}break;default:{if(dd>=1&&dd<=31)day=dd;else{cout<<"Day value error!"<<endl;cout<<"please input again:"<<endl;cout<<"year month date"<<endl;cin>>yy>>mm>>dd;day=dd;}}}}int Date::IsLeap(int year){if(year%400==0||(year%100!=0&&year%4==0))return 1;elsereturn 0;}void Date::ShowDate(){cout<<year<<"-"<<month<<"-"<<day<<" ";}int Date::getdays(int year,int month,int day){int i,sum=0;for(i=1;i<year;i++){if(IsLeap(i))sum+=366;elsesum+=365;}if(IsLeap(year))dayofmonth[2]=29;for(i=1;i<month;i++)sum+=dayofmonth[i];sum+=day;return sum;}void Date::showweek(){int s;s=getdays(year,month,day)%7;switch(s){case 0:cout<<"Sunday"<<endl;break;case 1:cout<<"Monday"<<endl;break;case 2:cout<<"Tuesday"<<endl;break;case 3:cout<<"Wednesday"<<endl;break;case 4:cout<<"Thursday"<<endl;break;case 5:cout<<"Friday"<<endl;break;case 6:cout<<"Saturday"<<endl;break;}}void Date::printmonth(){if(year%4==0)cout<<" "<<year<<" "<<month<<" "<<"(ÈòÄê)"<<endl;elsecout<<" "<<year<<" "<<month<<" ¡¡"<<"(·ÇÈòÄê)"<<endl; cout<<"ÈÕ "<<"Ò» "<<"¶þ "<<"Èý"<<" ËÄ "<<"Îå "<<"Áù "<<endl;cout<<"Su "<<"Mo "<<"Tu "<<"We "<<"Th "<<"Fr "<<"Sa "<<endl;int s=getdays(year,month,1);s=s%7;for(int m=0;m<s;m++)cout<<" ";cout<<setw(2)<<setfill(' ')<<"1"<<" ";if(IsLeap(year)) dayofmonth[2]=29;int yue=dayofmonth[month];for(int i=2;i<8-s;i++)cout<<setw(2)<<setfill(' ')<<i<<' ';cout<<endl;int j;for(i=8-s,j=1;i<=yue;i++,j++){cout<<setw(2)<<setfill(' ')<<i<<' ';if(j%7==0)cout<<endl;}cout<<endl;}void Date::printyear(){int y,m;cin>>y;year=y;if(year%4==0)cout<<"------the year is "<<year<<"£¨ÈòÄ꣩"<<"----------"<<endl;elsecout<<"------the year is "<<year<<"£¨·ÇÈòÄ꣩"<<"---------"<<endl;for( m=1;m<13;m++) //×ܹ²12¸öÔ·Ý{cout<<" ***********************"<<endl;cout<<endl<<setw(5)<<m<<""<<year<<"Äê"<<setw(5)<<m<<"Ô·Ý"<<endl;cout<<" "<<"ÈÕ "<<"Ò» "<<"¶þ "<<"Èý"<<" ËÄ "<<"Îå "<<"Áù "<<endl;cout<<" "<<"Su "<<"Mo "<<"Tu "<<"We "<<"Th "<<"Fr "<<"Sa "<<endl;month=m;int s=getdays(year,month,1);s=s%7;for(int m=0;m<s;m++)cout<<" ";cout<<" "<<setw(2)<<setfill(' ')<<"1"<<" ";if(IsLeap(year)) dayofmonth[2]=29;int yue=dayofmonth[month];for(int i=2;i<8-s;i++)cout<<setw(2)<<setfill(' ')<<i<<' ';cout<<endl<<" ";int j;for(i=8-s,j=1;i<=yue;i++,j++){cout<<setw(2)<<setfill(' ')<<i<<' ';if(j%7==0)cout<<endl<<" ";}cout<<endl<<" ***********************"<<endl;}}class m{private:int a,b,number;public:void months(){if (b==1||b==3||b==5||b==7||b==8||b==10||b==12){number=31;}elseif(b==4||b==6||b==9||b==11){number=30;}elseif(b==2){if(a%4==0){number=29;}else{number=28;}}cout<<number<<endl;}void month(){cin>>a>>b;if(b>0&&b<13)months();else{cout<<"error!"<<endl;cout<<"please input again:"<<endl;cin>>a>>b;months();}}};int main(){int choose;char ch;Date mydate;system("title »¶Ó-ʹÓÃÍòÄêÀú!");while(choose!=0){cout<<"************************************************************"<<endl;cout<<" »¶Ó-ʹÓÃÍòÄêÀú! Ô¸ÄúʹÓõÄ˳ÐÄ£¬¿ªÐÄ!"<<endl;/*»ñȡϵͳʱ¼ä*/time_t timen;time(&timen);tm* t_tm = localtime(&timen);cout<<" ϵͳµ±Ç°Ê±¼äΪ: "<<t_tm->tm_year+1900<<"Äê"<<t_tm->tm_mon+1<<"ÔÂ"<<t_tm->tm_mday<<"ÈÕ"<<endl;cout<<"ÇëÑ¡Ôñ¡°0¡«5¡±"<<endl;cout<<"1£º¼ÆËãʱ¼ä²î 2£º²éѯijÔÂÌìÊý"<<endl;cout<<"3£º²éѯijÈÕÐÇÆÚ 4£ºÏÔʾijÄêÈÕÀú"<<endl;cout<<"5£º²éѯijÄêijÔÂÔÂÀú"<<endl;cout<<"0£ºÍ˳ö"<<endl;cout<<"******************************************************** ****"<<endl;cin>>choose;switch(choose) //¹¦ÄÜÑ¡Ôñ{case 1:datee myday;myday.count();/*ÅжÏÊÇ·ñÇåÆÁ²¢ÏÔʾÖ÷²Ëµ¥*/cout<<"please choose whether or not return the menu 'y'or other keys"<<endl;cin>>ch;if(ch=='y'){system("cls");//ÇåÆÁ£¬²¢·µ»ØÖ÷²Ëµ¥system("COLOR a1");break;}elsebreak; //ÏÔʾÖ÷²Ëµ¥case 2:cout<<"please input what you wangt to know the year,month:";m a;a.month();cout<<"please choose whether or not return the menu 'y'or other keys"<<endl;cin>>ch;if(ch=='y'){system("cls");system("COLOR 1b");break;}elsebreak;case 3:mydate.SetDate();mydate.ShowDate();mydate.showweek();mydate.printmonth();cout<<"please choose whether or not return the menu 'y'or other keys"<<endl;cin>>ch;if(ch=='y'){system("cls");system("COLOR 6e");break;}elsebreak;case 4:cout<<"please input what years you want to know£º";cout<<endl;mydate.printyear();cout<<"please choose whether or not return the menu 'y'or other keys"<<endl;cin>>ch;if(ch=='y'){system("cls");system("COLOR 3d");break;}elsebreak;case 5:cout<<"please input the year,month what you want to know."<<endl;mydate.input();mydate.printmonth();cout<<"please choose whether or not return the menu 'y' or other keys"<<endl;cin>>ch;if(ch=='y'){system("cls");system("COLOR 55");break;}elsebreak;case 0:cout<<"ллʹÓÃÍòÄêÀúϵͳ£¬Çë¹Ø±Õ!!!!!"<<endl;exit(0);break;default:cout<<"ÄúÊäÈëÓÐÎó£¬ÇëÖØÐÂÊäÈë"<<endl;}}return 0;}。

C语言程序设计 输出任意年份的日历

C语言程序设计  输出任意年份的日历
for(q=i1;q<7;q++)/*格式对齐的控制使第二列的日历每行的第一个书从同一位置开始*/
printf("");
printf("");
i2=0;flag2=0;
for(day2=p-(W+t[month-1])%7;day2<=t[month]&&flag2==0;day2++)
{i2++;printf("%4d",day2);
{
if(month<3)
{c=((int)(year-1)/100);
Y=(year-1)-((int)((year-1)/100))*100;
w=((int)(c/4))-2*c+Y+((int)(Y/4))+((int)(13*(month+13)/5));
W=(w+70)%7;
}
else if(month>=3)
if(i2%7==0) flag2=1;}
printf("\n");
}
}
}
{c=((int)(year/100));
Y=year-((int)(year/100))*100;
w=((int)(c/4))-2*c+Y+((int)(Y/4))+((int)(13*(month+1)/5));
W=(w+70)%7;
}
printf("\n\n%d%d\n",month,month+1);printf("日一二三四五六日一二三四五六\n");i1=W;/*一行一行的输出*/

万年历c语言代码讲解

万年历c语言代码讲解

万年历c语言代码讲解摘要:一、万年历C语言代码讲解简介1.万年历的概念及用途2.C语言代码讲解的重要性二、C语言代码基础1.C语言简介2.C语言基本语法3.C语言的数据类型与变量三、万年历C语言代码实现1.计算闰年2.计算月份的天数3.计算日期的星期4.输出万年历四、万年历C语言代码的优化与拓展1.代码性能优化2.功能的拓展与实现五、总结1.万年历C语言代码讲解的意义2.对编程能力的提升正文:一、万年历C语言代码讲解简介万年历是一种记录了公历日期的工具,它可以帮助我们快速查询公历日期对应的农历、节日、提醒等信息。

C语言是一种广泛应用于计算机领域的编程语言,掌握C语言编程对于学习其他编程语言有很大的帮助。

本文将详细讲解万年历C语言代码的实现过程,帮助读者更好地理解C语言编程。

二、C语言代码基础1.C语言简介C语言是一种高级编程语言,由丹尼斯·里奇(Dennis Ritchie)于20世纪70年代在贝尔实验室开发。

C语言具有良好的性能和可移植性,被广泛应用于操作系统、嵌入式系统、硬件驱动等领域。

2.C语言基本语法C语言的基本语法包括变量声明、数据类型、运算符、控制结构、函数等。

了解这些基本语法对于编写C语言代码至关重要。

3.C语言的数据类型与变量C语言的数据类型包括整型、浮点型、字符型等。

变量是存储数据的容器,通过变量名来表示。

声明变量时需要指定变量的数据类型和存储空间。

三、万年历C语言代码实现1.计算闰年闰年是指公历年份可以被4整除但不能被100整除的年份,或者是可以被400整除的年份。

通过编写一个函数,我们可以判断一个年份是否为闰年。

2.计算月份的天数根据公历规定,每个月的天数不同。

通过编写一个函数,我们可以计算指定月份的天数。

3.计算日期的星期通过编写一个函数,我们可以根据公历日期计算对应的星期。

4.输出万年历根据用户输入的日期范围,输出对应的万年历信息。

四、万年历C语言代码的优化与拓展1.代码性能优化在实现万年历C语言代码的过程中,可以通过优化算法、使用更高效的函数等方式提高代码性能。

万年历的程序代码

万年历的程序代码

万年历的程序代码一年没碰Pascal了,写起来还有点吃力,希望对99级的同学有点帮助. : 程序已编译通过;附2000年年历;: 不足之处请大家批评指出.: 只限参考,不可抄袭.: Program wnl(input,output);: label: again;: var: a:char;: i:integer;: ran,year,all_days,all_years:integer;: days_month,first_month:array[1..12]of integer;: procedure display;: var: i,j,k,l,m,n,c,d,mm,nn:integer;: begin: for j:=0 to 5 do: begin: mm:=1;: nn:=1;: k:=j*2+1;: l:=j*2+2;: m:=first_month[k];: n:=first_month[l];: if m=0 then m:=7;: if n=0 then n:=7;: for i:=1 to 21 do write( );: write(No.,k:2);: for i:=1 to 32 do write( );: writeln(No.,l:2);: for i:=1 to 8 do write( );: writeln(||mon|tur|wed|thr|fri|sat|sun|| ||mon|tur|wed|thr|: fri|sat|sun||);: write( ||);: for c:=1 to 7 do if c$#@60;m then write( |) else: begin: write(mm:3,|);: mm:=mm+1;: end;: write(| ||);: for c:=1 to 7 do if c$#@60;n then write( |) else: begin: write(nn:3,|);: nn:=nn+1;: end;: writeln(|);{the first line.}: for d:=1 to 5 do: begin: write( ||);: for c:=1 to 7 do if mm>days_month[k] then write( |) else: begin: write(mm:3,|);: mm:=mm+1;: end;: write(| ||);: for c:=1 to 7 do if nn>days_month[l] then write( |) else: begin: write(nn:3,|);: nn:=nn+1;: end;: writeln(|);: end;: readln;: end;: end;: begin{main}: days_month[1]:=31;: days_month[2]:=28;: days_month[3]:=31;: days_month[4]:=30;: days_month[5]:=31;: days_month[6]:=30;: days_month[7]:=31;: days_month[8 31;: days_month[9]:=30;: days_month[10]:=31;: days_month[11]:=30;: days_month[12]:=31;: writeln(This program may help you to make a calender of the year yo: u input.);: again: year:=0;: ran:=0;: for i:=1 to 12 do first_month[i]:=0;: writeln(Please input the year number:);: readln(year);: if (year mod 400 =0) or ((year mod 100 $#@60;>0) and (year mod 4=0)) then: ran:=1;: days_month[2]:=days_month[2]+ran;: all_years:=year-1;: all_days:=all_years+(all_years div 4)-(all_years div 100)+(all_years : div 400);: first_month[1]:=(all_days+1) mod 7;: for i:=2 to 12 do first_month[i]:=(first_month[i-1]+days_month[i-1]) : mod 7;: display;: writeln(Press enter to continute,Ctrl+C to quit.);: readln;: goto again;: end.{main}: 2000年年历:: This program may help you to make a calender of the year you input. : Please input the year number:2000: No. 1 No. 2: ||mon|tur|wed|thr|fri|sat|sun|| ||mon|tur|wed|thr|fri|sat|sun||: || | | | | | 1| 2|| || | 1| 2| 3| 4| 5| 6||: || 3| 4| 5| 6| 7| 8| 9|| || 7| 8| 9| 10| 11| 12| 13||: || 10| 11| 12| 13| 14| 15| 16|| || 14| 15| 16| 17| 18| 19| 20||: || 17| 18| 19| 20| 21| 22| 23|| || 21| 22| 23| 24| 25| 26| 27||: || 24| 25| 26| 27| 28| 29| 30|| || 28| 29| | | | | ||: || 31| | | | | | || || | | | | | | ||: No. 3 No. 4: ||mon|tur|wed|thr|fri|sat|sun|| ||mon|tur|wed|thr|fri|sat|sun||: || | | 1| 2| 3| 4| 5|| || | | | | | 1| 2||: || 6| 7| 8| 9| 10| 11| 12|| || 3| 4| 5| 6| 7| 8| 9||: || 13| 14| 15| 16| 17| 18| 19|| || 10| 11| 12| 13| 14| 15| 16||: || 20| 21| 22| 23| 24| 25| 26|| || 17| 18| 19| 20| 21| 22| 23||: || 27| 28| 29| 30| 31| | || || 24| 25| 26| 27| 28| 29| 30||: || | | | | | | || || | | | | | | ||: No. 5 No. 6: ||mon|tur|wed|thr|fri|sat|sun|| ||mon|tur|wed|thr|fri|sat|sun||: || 1| 2| 3| 4| 5| 6| 7|| || | | | 1| 2| 3| 4||: || 8| 9| 10| 11| 12| 13| 14|| || 5| 6| 7| 8| 9| 10| 11||: || 15| 16| 17| 18| 19| 20| 21|| || 12| 13| 14| 15| 16| 17| 18||: || 22| 23| 24| 25| 26| 27| 28|| || 19| 20| 21| 22| 23| 24| 25||: || 29| 30| 31| | | | || || 26| 27| 28| 29| 30| | ||: || | | | | | | || || | | | | | | ||: No. 7 No. 8: ||mon|tur|wed|thr|fri|sat|sun|| ||mon|tur|wed|thr|fri|sat|sun||: || | | | | | 1| 2|| || | 1| 2| 3| 4| 5| 6||: || 3| 4| 5| 6| 7| 8| 9|| || 7| 8| 9| 10| 11| 12| 13||: || 10| 11| 12| 13| 14| 15| 16|| || 14| 15| 16| 17| 18| 19| 20|| : || 17| 18| 19| 20| 21| 22| 23|| || 21| 22| 23| 24| 25| 26| 27|| : || 24| 25| 26| 27| 28| 29| 30|| || 28| 29| 30| 31| | | ||: || 31| | | | | | || || | | | | | | ||: No. 9 No.10: ||mon|tur|wed|thr|fri|sat|sun|| ||mon|tur|wed|thr|fri|sat|sun|| : || | | | | 1| 2| 3|| || | | | | | | 1||: || 4| 5| 6| 7| 8| 9| 10|| || 2| 3| 4| 5| 6| 7| 8||: || 11| 12| 13| 14| 15| 16| 17|| || 9| 10| 11| 12| 13| 14| 15||: || 18| 19| 20| 21| 22| 23| 24|| || 16| 17| 18| 19| 20| 21| 22|| : || 25| 26| 27| 28| 29| 30| || || 23| 24| 25| 26| 27| 28| 29||: || | | | | | | || || 30| 31| | | | | ||: No.11 No.12: ||mon|tur|wed|thr|fri|sat|sun|| ||mon|tur|wed|thr|fri|sat|sun|| : || | | 1| 2| 3| 4| 5|| || | | | | 1| 2| 3||: || 6| 7| 8| 9| 10| 11| 12|| || 4| 5| 6| 7| 8| 9| 10||: || 13| 14| 15| 16| 17| 18| 19|| || 11| 12| 13| 14| 15| 16| 17|| : || 20| 21| 22| 23| 24| 25| 26|| || 18| 19| 20| 21| 22| 23| 24|| : || 27| 28| 29| 30| | | || || 25| 26| 27| 28| 29| 30| 31||: || | | | | | | || || | | | | | | ||: Press enter to continute,Ctrl+C to quit.--。

C++实现万年历(原创)

C++实现万年历(原创)

C++实现万年历(原创)任务要求功能要求:(1)提供菜单⽅式选择,假定输⼊的年份在1940-2040年之间。

(2)输⼊⼀个年份,输出是在屏幕上显⽰该年的⽇历。

(3)输⼊年⽉,输出该⽉的⽇历,如图2-1所⽰: 图2- 1 ⽉⽇历(4)输⼊年份、⽉份、⽇期,计算得到的是这⼀天据今天有多少天,星期⼏。

(5)输⼊公历的年⽉⽇,输出农历年⽉⽇。

(6)输⼊农历节⽓,输出当年农历的年⽉⽇及公历年⽉⽇。

可以假定只涉及年份是1940年到2040年。

总体设计将⽂件三部分 Date.h、main.cpp、Date.cpp1) Date.h:包括函数的声明。

2) main.cpp:包含调⽤与模拟交互界⾯的函数代码3) Date.cpp://输⼊输⼊⼀个年份,输出是在屏幕上显⽰该年的⽇历。

void print_annual_calendar(int year)//输⼊年⽉,输出该⽉的⽇历。

void print_monthly_calendar(int year,int month)//输⼊年份、⽉份、⽇期,计算得到的是这⼀天据今天有多少天,星期⼏。

void print_number_week(int year,int month ,int day)//输⼊公历,显⽰农历。

void gregorian_to_lunar (int year,int month,int day)//输⼊农历节⽓,输出当年农历的年⽉⽇和公历年⽉⽇。

void solar_term(char *str)详细设计说明(1) 查询距今多少天,星期⼏?①计算某⼀⽇期到1939年1⽉1⽇的天数:getDaysTo1939(int year, int month, int day)1. 判断是否是闰年(平年365天,闰年366天),函数如表4-1所⽰:表4- 1 isLeapYear函数定义函数bool isLeapYear(int year)返回值若year年是闰年返回true,否则返回false参数说明year参数是要判断的年份1. 判断某年某⽉有多少天?函数如表4-2所⽰:表4- 2 getDaysOfMonth函数定义函数int getDaysOfMonth(int year,int month)返回值返回year年month⽉的天数参数说明year、month参数分别是要查询的年、⽉例如:计算2020年8⽉14⽇到1939年1⽉1⽇的天数。

十五位数码管电子钟万年历设计 c编写

十五位数码管电子钟万年历设计    c编写

十五位数码管电子钟万年历设计c编写后带原理设计图供参考(本人已验证可正常工作)我们以一个实际的时钟电路来说明定时器的软件编程方法,时钟就是我们最为常见的显示时、分、秒为单位的计时工具,它是典型的应用代表。

时钟的最小计时单位是秒,但使用单片机定时器来进行计时,若使用 6.0MHz的晶振,即使按工作方式1工作,最大的计时时间也只能到131ms,所以我们可把每个定时时间取125ms,这样定时器溢出8次(125ms╳8=1000ms)就得到最小的计时单位秒。

而要实现8次计数用软件方法实现是轻而易举的。

我们使用定时器1,以工作方式1工作,定时器进行125ms定时。

采用中断方法进行溢出次数的累计,当计满8次即得到1秒的计时。

一个时钟的计时累加,要实现分、时的进位,要用到多种进制,秒、分、时中的进位是十进制,秒向分进位和分想时进位却是六十进制,而每天又有十二小时制或二十四小时制,它们分别又是十二进制和二十四进制。

从秒到分和从分到小时可以通过软件累加和数值比较方法实现。

在单片机的内部RAM中,需要设置显示缓冲区,显示的时、分、秒值是从显示缓冲区中取出的,在RAM中设置四个单元作为显示缓冲区,分别是7AH、7BH、7CH。

为使电路和原理叙述方便,我们这里不显示秒值,秒的进位我们通过闪烁分值实现。

这样我们一共有四位LED分别显示时和分值。

同时时钟都需要校准的。

在程序中还需设置显示码表,要显示的数值通过查表指令将显示用的真正码值送到LED上。

我们用单片机AT89C2051的PP3.4和P3.5两个I/O口外接微动开关来实现时和分的校正,每按一次小时或分值加1,连续按下数值累计下去,实现时钟的校准。

在电路中我们还设置了一个蜂鸣器,用作简单报时用,如可设早上7:30分起床,中午1点30分再有起床报时,每次响时1分钟,响1秒,停2秒的方式,而不是连续响铃。

这个程序我们采用12小时制,为此,要在程序中设置相应的标志,以利于主程序识别。

单片机万年历程序代码

单片机万年历程序代码

单片机万年历程序代码以下是一个示例单片机万年历的程序代码:```c#include <reg51.h>typedef unsigned char uchar;typedef unsigned int uint;sbit K1 = P2^0; // 显示年份sbit K2 = P2^1; // 显示月份sbit K3 = P2^2; // 显示日期uchar code year_tab[] = {31,28,31,30,31,30,31,31,30,31,30,31}; uchar code week_tab[] = {0x06,0x07,0x01,0x02,0x03,0x04,0x05}; uchar year, month, day, week;void delay(uint ms){uint i, j;for(i=ms;i>0;i--)for(j=110;j>0;j--);}uchar getKey(){if(K1==0) {delay(5);if(K1==0)return 1;while(!K1);}if(K2==0) {delay(5);if(K2==0)return 2;while(!K2);}if(K3==0) {delay(5);if(K3==0)return 3;while(!K3);}return 0;}void display(uchar num) {P0 = num;delay(1);P0 = 0x00;}void init(){TMOD=0x01;TH0=0xFC;TL0=0x67;EA=1;ET0=1;TR0=1;}void main(){init();while(1) {uchar key = getKey();if(key == 1) {year++;if(year == 100)year = 0;}else if(key == 2) {month++;if(month == 13)month = 1;}else if(key == 3) {day++;if(day > year_tab[month-1]) { day = 1;}}display(year / 10);display(year % 10);display(month / 10);display(month % 10);display(day / 10);display(day % 10);display(week);}}void timer0() interrupt 1{TH0=0xFC;TL0=0x67;week++;if(week == 7)week = 0;}```该代码的主要思路是通过外部三个按键模拟年、月和日的调节,通过一个定时器不断更新星期的计数,然后将年、月、日和星期分别在数码管上显示出来。

万年历

万年历

编写一个万年历程序,能显示日历,查询任意日期。

日历初始化和显示。

能根据系统日期进行初始化,并显示当前月份的月历,并突出显示当前日期。

日期查询,可以输入一个日期,然后查询并正确显示日期所在月份的月历,并突出显示查询日期,如果输入日期不正确给出提示。

#include<stdio.h>#include<time.h>#include<iostream.h>#include"万年历.h"int main(){int y,m,d,h,min,sec;//系统时间参数int cho;//用户选项int yt,mt,dt;//拥护输入的时间参数while(1){cout<<"≡≡≡≡≡≡万年历菜单选项≡≡≡≡≡";cout<<"请按编号选择功能";cout<<" ⑴查询当前时间";cout<<" ⑵显示本月月历";cout<<" ⑶查找给定日期对应的月历";cout<<" ⑷退出万年历";cin>>cho;Initdate(y,m,d,h,min,sec);switch(cho){case 1: cout<<"当前时间为<<y<<"."<<m<<"."<<d<<"."<<" "<<h<<":"<<min<<":"<<sec<<" ";week(y,m,d);break;case 2: printmonth(y,m,d);break;case 3: cout<<"请输入所要查找的日期,格式如2000 7 5";cin>>yt<<mt<<dt;search(yt,mt,dt);break;case 4: exit(1);break;default :cout<<"输入错误,请重新输入";}}return;}void week(y,m,d)//日期对于的星期{int c,w;c=y/100+1;if(m<=2) {m=m+12;y=y-1;}w=(y+y/4+c/4-2*c+26*(m+1)/10+d-1)%7;if(w=0) cout("Sun");else if (w==1)cout<<"Mon";else if (w==2)cout<<"Tue";else if (w==3)cout<<"wed";else if (w==4)cout<<"Thu";else if (w=5)cout<<"Fri";else cout<<"Sta"; }void Initdate(&y,&m,&d,&h,&min,&sec)//根据系统时间初始化万年历{time_t t;time(&t);struct tm * local_time = localtime(&t);sec=local_time->tm_sec;min=local_time->tm_min ;h=local_time->tm_hour ;d=local_time->tm_mday ;m=local_time->tm_mon+1;y=local_time->tm_year+1900;}void printmonth(y,m,d)//打印出给定时间对于月历{int ym[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};int leap,i;leap=(y%4==0&&y%100!=0||y%400==0)for(i=1;i<d;i++)cout<<i<<" "<<week(y,m,i)<<endl;cout<<"★" ;for(i=d;i<=ym[leap][m];i++)cout<<i<<" "<<week(y,m,i)<<endl;}int judge(y,m,d)//判断给定时间是否存在{int ym[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};int leap,i;if(y<=0||m<1||m>12)return 0;leap=(y%4==0&&y%100!=0||y%400==0);if(d<1||d>ym[leap][m])return 0;else return 1;}int search(y,m,d)//查找打印给定时间对应阅历{if(judge(y,m,d)==0)cout<<"error date";else printmonth(y,m,d);}2011-8-9 16:29最佳答案// abc4.cpp : 定义控制台应用程序的入口点。

万年历代码c语言

万年历代码c语言

万年历代码c语言万年历是一种实用的日历工具,它可以根据年、月、日来显示当天的日期信息,并可以切换到其他日期来查询对应的日期信息。

在编写万年历的代码时,我们需要考虑输入的年份是否为闰年、每个月的天数、以及每个月第一天是星期几等等。

以下是一份使用C语言编写万年历的参考代码:```c#include <stdio.h>// 判断是否为闰年int isLeapYear(int year) {return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); }// 获取某年某月的天数int getMonthDays(int year, int month) {int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};if (month == 2 && isLeapYear(year)) {return 29;}return days[month - 1];}// 获取某年某月第一天是星期几int getFirstDayOfWeek(int year, int month) {int day = 1;for (int i = 1800; i < year; i++) {if (isLeapYear(i)) {day = (day + 366) % 7;} else {day = (day + 365) % 7;}}for (int i = 1; i < month; i++) {day = (day + getMonthDays(year, i)) % 7;}return day;}int main() {int year, month;printf("请输入年份:");scanf("%d", &year);printf("请输入月份:");scanf("%d", &month);// 判断输入是否合法if (year < 1800 || month < 1 || month > 12) {printf("输入的年份或月份不合法!\n");return 0;}// 获取某年某月的天数和第一天是星期几int days = getMonthDays(year, month);int firstDayOfWeek = getFirstDayOfWeek(year, month); // 打印万年历printf("日一二三四五六\n");for (int i = 0; i < firstDayOfWeek; i++) {printf(" ");}for (int i = 1; i <= days; i++) {printf("%2d ", i);if ((firstDayOfWeek + i) % 7 == 0) {printf("\n");}}printf("\n");return 0;}```以上代码实现了一个简单的万年历功能,在控制台输出给定年份和月份的月历。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

// VC++6.0 编译通过
# include <stdio.h>
# include <windows.h>
int year; //定义年份为全局变量
int check_year (int year) //判断输入的年份是否为闰年
{
if(year%4 == 0 && year%100 !=0 || year%400 == 0)
return 1;
else
return 0;
}
int check_month (int month) //判断每月的天数
{
switch (month)
{
case 0: return 0; break;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: return 31; break;
case 4:
case 6:
case 9:
case 11: return 30; break;
case 2: //闰年二月和平年二月的天数
{
if (check_year(year) == 1)
return 29;
else
return 28;
} break;
}
}
int firstday (int year,int month) //判断某年某月的第一天为星期几{
static int w=0;
w += check_month(month-1);
return ((year-1)+((year-1)/4)-((year-1)/100)+((year-1)/400)+1+w)%7;
}
main ()
{
int month=1,day,i,flag;
printf ("请输入要打印的年份: ");
scanf ("%d",&year);
printf ("\n");
printf (" %d年\n\n",year);
for (month=1;month<=12;month++)
{
printf (" %d月\n",month);
printf (" ---------------------------\n");
printf (" SUN MON TUE WED THU FRI SET\n");
printf (" ---------------------------\n");
flag = firstday(year,month);
for (i=0;i<flag;i++) //每月第一天所在星期几之前的位置用空格输出printf (" ");
for (day=1;day<=check_month(month);day++) //按格式输出日历
{
printf ("%4d",day);
if ((day+flag)%7 == 0)
printf ("\n");
}
printf("\n\n");
system("pause");
printf("\n");
}
}。

相关文档
最新文档