万年历系统源代码
JAVA课程设计 万年历 源代码
测试用例设计:根据 需求文档和功能描述, 设计出能够覆盖所有 功能的测试用例
测试工具:使用JUnit 等测试框架进行单元 测试,使用Selenium 等工具进行UI测试
测试结果分析:根 据测试结果,分析 代码存在的问题, 并进行修改和优化
集成测试:验证各个模块之间的接口是否正确,数据传输是否正常 性能测试:测试系统的响应时间、吞吐量、资源利用率等性能指标
提醒功能:用户可以设置提醒功能,在节日或假期到来之前,系统会自动提醒用户。
删除事件:用户可以删除不 再需要的事件
编辑事件:用户可以对已添加 的事件进行编辑,如修改事件 名称、时间等
添加事件:用户可以在万年历 中添加新的事件,如生日、纪 念日等
查询事件:用户可以查询特定 日期或时间段内的事件,如查
界面显示:万年历界面将显示年、 月、日、星期等信息,用户可以通 过点击相应的按钮来切换日期。
添加标题
添加标题
添加标题
添加标题
系统响应:当用户输入日期后,系统 将根据输入的日期显示相应的万年历 信息,包括年、月、日、星期等信息。
用户操作:用户可以通过点击相应 的按钮来切换日期,系统将根据用 户的操作显示相应的万年历信息。
添加标题
界面设计:简洁明了,易于阅读
添加标题
添加标题
交互性:用户可以选择查看不同日 期的日历信息
功能描述:在万年历中,用户可以选择标注节日和假期,以便于查看和提醒。
节日标注:用户可以在万年历中设置自己喜欢的节日,如春节、中秋节等,系统会自动 标注这些节日。
假期标注:用户可以在万年历中设置自己的假期,如年假、病假等,系统会自动标注这 些假期。
,a click to unlimited possibilities
C 万年历及公历农历转换源代码1
scanf("%d.%d.%d",&gyear,&gmonth,&gday); if(gyear%4==0 && gyear%100!=0 || gyear%400==0) months[2]=29; else months[2]=28; /*以下是计算在该公历年的第几天*/
whatday=gPastday[gmonth]+gday; if((gyear%4==0 && gyear%100!=0 || gyear%400==0) && (gmonth>2)) whatday++; /*上如果是闰年和月份大于二则在该公历年的第几天数+1*/ /*计算该年春节在公历年的第几天*/
clrscr();
}
}
getch();
}
/*公历每月前面的天数*/ const int gPastday[13]={0,0,31,59,90,120,151,181,212,243,273,304,334};
months[13]={0,31,0,31,30,31,30,31,31,30,31,30,31};
{case 1:printf("
* 1 * "); break;
case 3:printf("
* 3 * "); break;
case 5:printf("
* 5 * "); break;
case 7:printf("
* 7 * "); break;
case 9:printf("
* 9 * ");break;
{
java万年历源代码
java万年历源代码第一个类:chaxun.javapackage wannianli;import java.util.*;public class chaxun {public static void main(String[] args) {Scanner input =new Scanner(System.in);String answer="y";for(;answer.equals("y");){week cn=new week();cn.weekDay();//调用方法System.out.print("\是否继续?");answer=input.next();}}}第二个类:tianshu.javapackage wannianli;import java.util.*;public class tianshu {int totalDay;//总共的天数int yueTian;//每月的天数public void jsts(){int days=0;//输入月份到当年的天数System.out.println("*************************************欢迎使用万年历*************************************");Scanner input=new Scanner(System.in);System.out.print("请输入年份:");//从键盘输入年份int year=input.nextInt();System.out.print("请输入月份:");//从键盘输入月份int yue=input.nextInt();/**判断每月的天数*/for(int index=1;index<=yue;index++){if(yue==1||yue==3||yue==5||yue==7||yue==8||yue==10||yue==1 2){//满足闰年的条件yueTian=31;}elseif(yue==2&&((year%4==0)&&(!(year%100==0))||(year%400== 0))){yueTian=29;}elseif(yue==2&&(!((year%4==0)&&(!(year%100==0))||(year%400= =0)))){yueTian=28;}else if(yue==4||yue==6||yue==9||yue==11){yueTian=30;}else{System.out.print("输入的月份不正确");}if(index<=yue){days=days+yueTian;}}/**判断是否是闰年*/for(int i=100;i<year;i++){< bdsfid="116" p=""></year;i++){<>if ((year%4==0)&&(!(year%100==0))||(year%400==0)){//满足闰年的条件totalDay=totalDay+366;}else{totalDay=totalDay+365;}}totalDay=totalDay+days;//System.out.println(totalDay+"天");//return totalDay+yueTian;}}第三个类:week.jvapackage wannianli;public class week {public void weekDay() {int monDay;//星期几tianshu cn=new tianshu();cn.jsts();int week=1+cn.totalDay%7;//System.out.println(""+week);if (week==7){// 求当月第一天monDay=0;// 周日}else{monDay=week;}/* 输出日历*/System.out.println("星期日\星期一\星期二\星期三\星期四\星期五\星期六");for(int nullNo=0;nullNo<monday;nullno++){< bdsfid="145"p=""></monday;nullno++){<>System.out.print("\");// 输出空格}for(int i=1;i<=cn.yueTian;i++){System.out.print(i+"\");//输出每月的号数if((cn.totalDay + i - 1) % 7 == 5){// 如果当天为周六,输出换行System.out.println();}}} }。
万年历的c语言实现源程序
万年历的C语言编程实现源程序:#include<stdio.h>#include<stdlib.h>int Isleapyear(int y)/*判断是否是闰年*/{if((y%4==0&&y%100!=0)||(y%400==0))return 1;elsereturn 0;}int Getdaysofmonth(int y,int m)/*确定某个月的天数*/{int months[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};if(Isleapyear(y))/*如果是闰年则2月份的天数改变为29*/ months[2]=29;return months[m];}int Gettotaldays(int y,int m)/*计算从1901年1月开始到给定年月的天数*/{intmonths[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};int days=0;int i,j;if((Isleapyear(y)))months[2]=29;for(i=1901;i<y;i++)/*从1901年1月开始计算,累加y年之前的天数*/{if(Isleapyear(i))days+=366;elsedays+=365;}for(j=1;j<m;j++)/*累加m月之后的天数*/days+=months[j];return days;}int Getfirstdayintable(int y,int m)/*计算给定年月的第一天在日历表中的位置*/{int d;d=Gettotaldays(y,m);d=d+3;/*1901年1月1日是星期二,在日历中星期二是第三个位置*/d=d%7;return d;}void Showdate(int y,int m)/*显示日历*/{int first;int d;int i,k;first=Getfirstdayintable(y,m);/*得到第一天在日历中的第一个位置*/d=Getdaysofmonth(y,m);/*得到这个月的天数*/k=0;printf("-------------------------------------\n");printf(" SUN MON TUE WEN THU FRI STA\n");for(i=1;i<first;i++)/*打印第一天之前的空格*/{printf(" ");k++;/*k用于确定日历中是否回车*/}for(i=1;i<=d;i++){printf("%5d",i);/*每个具体的日期占5个字符的宽度*/k++;if(k==7)/*每行打印7个日期数字后回车*/{printf("\n");k=0;}}printf("\n-------------------------------------\n"); }int main(){int y,m;printf("Input year:");scanf("%d",&y);printf("Input month:");scanf("%d",&m);Showdate(y,m);return 0;}欢迎您的下载,资料仅供参考!致力为企业和个人提供合同协议,策划案计划书,学习资料等等打造全网一站式需求。
万年历源代码
};break;
case 2:
{
for(i=0;i<week;i++) printf(" ");
for(k=i;i<week+28;i++) a[i]=i-week+1;
m=i;
for(i=k;i<m;i++)
{if(i%7==0) {printf("\n");printline();}
printf("%-8d",a[i]);
}
printf("\n");
printline();
printf("\n");
};break;
}
}
else
{
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
printf("\n");
};break;
}
}
}
void printline()
{
printf("------------------------------------------------------\n");
}
case 10:
case 12:
{
for(i=0;i<week;i++) printf(" ");
for(k=i;i<week+31;i++) a[i]=i-week+1;
C语言实训--万年历源代码
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);
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("输入年份:");
scanf("%d",&year);
printf("the calendar of the year%d\n",year);
printf("\n");
printf("=============================\n");
for(i=1;i<13;i++)
case 10:day+=273+flag;break;
case 11:day+=304+flag;break;
case 12:day+=334+flag;break;
printf("星期%d",number);
万年历程序源代码
#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;}。
万年历源代码
//初始化 LCD************************************************************
void LCD_Initial()
{
LcdEn=0; LCD_Write(LCD_COMMAND,0x38);
#define LCD_SHOW
0x04 //显示开
#define LCD_HIDE
0x00 //显示关
#define LCD_CURSOR #define LCD_NO_CURSOR
#define LCD_FLASH #define LCD_NO_FLASH
0x02 0x00
//显示光标 //无光标
{
Time->DateString[0] = '2';
Time->DateString[1] = '0';
Time->DateString[2] = Time->Year/10 + '0';
#include <REG52.H> #include <intrins.h> //#include "LCD1602.h" //#include "DS1302.h"
#define uint unsigned int #define uchar unsigned char sbit DS1302_CLK = P1^7; sbit DS1302_IO = P1^6; sbit DS1302_RST = P1^5;
0x01 0x00
//光标闪动 //光标不闪动
java万年历源代码(可运行)
private JScrollPane sp = new JScrollPane(table);
private JButton bLastYear = new JButton("上一年");
p3.add(jsp, BorderLayout.CENTER);
p3.add(p2, BorderLayout.SOUTH);
p3.add(ld, BorderLayout.NORTH);
private JTextArea jta = new JTextArea(); //jta--JTextArea
private JScrollPane jsp = new JScrollPane(jta);
private JLabel l = new JLabel("年份文本框中可直接键入要查找的年份,以提高查询效率");
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
//import java.sql.Date;
cld.set(Integer.parseInt(strDate[0]), Integer.parseInt(strDate[1])-1, 0);
showCalendar(Integer.parseInt(strDate[0]), Integer.parseInt(strDate[1]), cld);
C++实现万年历源代码
C++实现万年历源代码本⽂实例为⼤家分享了C++实现万年历的具体代码,供⼤家参考,具体内容如下#include<iostream>#include<string>#include<fstream>#include<iomanip>using namespace std;#include<time.h>ofstream fout("⽇历.txt");void Printtitle(int n);int OrEndl(int n);string Choose(); //选择功能int Calculate(int mon,int day);void Printday(int a);void FirstDay(int wday);void SomeYear(int p);void ThisMonth(); //打印当⽉⽇历的主函数void PrintFirstNum(int mon);void Printyear(int year);void ThisYear(int p); //打印当年⽇历的主函数void Month(int n);void Printnum(int q,int mon);int Firstwday[12]; //储存每个⽉1号的星期数struct tm *local;string ch;int a[12]={31,28,31,30,31,30,31,31,30,31,30,31}; //储存每⽉的天数int main(void){long t;time(&t);local=localtime(&t);local->tm_year=local->tm_year+1900;local->tm_mon++;cout<<"今天是:"<<local->tm_year<<"年"<<local->tm_mon<<"⽉"<<local->tm_mday<<"⽇,";fout<<"今天是:"<<local->tm_year<<"年"<<local->tm_mon<<"⽉"<<local->tm_mday<<"⽇,";Month(local->tm_wday);cout<<endl;fout<<endl;cout<<"当前时间是:"<<local->tm_hour<<"时"<<local->tm_min<<"分"<<local->tm_sec<<"秒"<<local->tm_wday<<endl;fout<<"当前时间是:"<<local->tm_hour<<"时"<<local->tm_min<<"分"<<local->tm_sec<<"秒"<<local->tm_wday<<endl;string flag;int sum;if(((local->tm_year%4==0)&&(local->tm_year%100!=0))||(local->tm_year%400==0))a[1]=29;sum=Calculate(local->tm_mon,local->tm_mday);int p=sum-(local->tm_wday+1)-(sum/7)*7;do{flag=Choose();if(flag=="1") //根据选择的数字确定调⽤哪个函数ThisMonth();else if(flag=="2")ThisYear(p);else if(flag=="3")SomeYear(p);else if(flag=="4")break;else{cout<<"输⼊错误"<<endl;fout<<"输⼊错误"<<endl;continue;}}while(1);cout<<"请选择"<<"1、当⽉⽇历"<<endl<<" 2、当年⽇历"<<endl <<" 3、万年历"<<endl<<" 4、退出"<<endl;fout<<"请选择"<<"1、当⽉⽇历"<<endl<<" 2、当年⽇历"<<endl <<" 3、万年历"<<endl<<" 4、退出"<<endl;cin>>ch;fout<<ch;cout<<endl;fout<<endl;return ch;}void ThisMonth(){int m=local->tm_mon%12;Printtitle(m);int p=local->tm_mday-(local->tm_wday+1)-(local->tm_mday/7)*7; Printnum(p,local->tm_mon);}void ThisYear(int p){FirstDay(p);Printyear(local->tm_year);for(int a=1;a<12;a=a+2){Printtitle(a);PrintFirstNum(a);}}void SomeYear(int p) //打印万年历的主函数{int m;cout<<"Please enter a year number"<<endl;fout<<"Please enter a year number"<<endl;while(1){scanf("%d",&m);if( m<0 ){printf("\nInput error,Please enter a year number again:\n");fflush(stdin); //没加这句话会死循环,加了就ok}else break;}fout<<m;cout<<endl;fout<<endl;Printyear(m);int n=m;if(n<local->tm_year) //计算所输年份的1⽉1⽇星期⼏{for(;n<local->tm_year;n++){if(((n%4==0)&&(n%100!=0))||(n%400==0))p=p+2;elsep++;if(p>=7)p=p-7;}}else{for(;n>local->tm_year;n--){if(((n%4==0)&&(n%100!=0))||(n%400==0))p=p-2;elsep--;if(p<0)for(int h=1;h<12;h=h+2){Printtitle(h);if(((m%4==0)&&(m%100!=0))||(m%400==0))a[1]=29;elsea[1]=28;PrintFirstNum(h);}}void Printtitle(int n) //打印标题{do{cout<<" ";fout<<" ";char str[12][10]={"January","February","March","April","May","June","July","August","September","October","November","December"}; for(int h=0;h<10;h++){cout<<str[n-1][h];fout<<str[n-1][h];}cout<<" ";fout<<" ";if(OrEndl(n))break;n++;}while(!(n%2));do{cout<<"____________________________";fout<<"____________________________";if(OrEndl(n))break;n++;}while(!(n%2));do{cout<<" Sun Mon Tue Wed Thu Fri Sat ";fout<<" Sun Mon Tue Wed Thu Fri Sat ";if(OrEndl(n))break;n++;}while(!(n%2));}int Calculate(int mon,int day) //计算当天到当年1⽉1⽇的天数{int sum=day;for(mon--;mon!=0;mon--)sum=sum+a[mon-1];return sum;}void FirstDay(int wday) //推算每个⽉1号的星期数{if(wday<=0)wday=wday+7;Firstwday[0]=7-wday;for(int n=0;n<11;n++){Firstwday[n+1]= Firstwday[n]+a[n]%7;if(Firstwday[n+1]>6)Firstwday[n+1]=Firstwday[n+1]-7;}}int OrEndl(int n){if(ch=="1") //如果是打出当⽉⽇历就直接跳出循环{cout<<endl;fout<<endl;return 1;fout<<" ";}else{cout<<endl;fout<<endl;}return 0;}void Printyear(int year) //打印年份{int m=year/1000;int n=(year/100)%10;int p=(year/10)%10;int q=year%10;int num[4]={m,n,p,q};char str[5][10][7]={"***** "," * ","***** ","***** ","* * ","***** ","***** ","***** ","***** ","***** ", "* * "," * "," * "," * ","* * ","* ","* "," * ","* * ","* * ","* * "," * ","***** ","***** ","***** ","***** ","***** "," * ","***** ","***** ","* * "," * ","* "," * "," * "," * ","* * "," * ","* * "," * ","***** "," * ","***** ","***** "," * ","***** ","***** "," * ","***** ","***** ",};for(int g=0;g<5;g++){cout<<" ";fout<<" ";for(int i=0;i<4;i++)for(int h=0;h<7;h++){cout<<str[g][num[i]][h];fout<<str[g][num[i]][h];}cout<<endl;fout<<endl;}}void PrintFirstNum(int mon) //打印每两个⽉的⽇历{int mday[2]; //储存每两个⽉当前打印的⽇期do{int k=0;for(;k<Firstwday[mon-1];k++){ cout<<" ";fout<<" ";}k++;for(int d=1;k<8;d++,k++) //输⼊每个⽉的第⼀⾏{cout<<" "<<d<<" ";fout<<" "<<d<<" ";}if(mon%2) //判断单⽉输空格,双⽉回车{cout<<" ";fout<<" ";mday[mon%2-1]=d;}else{cout<<endl;fout<<endl;mday[mon%2+1]=d-1;}mon++;}while(!(mon%2));mon=mon-2;int i=0,k=1,m=mon-1;for(;mday[i]<a[m]+1;mday[i]++,k++){if(mday[i]<10){{cout<<" "<<mday[i]<<" ";fout<<" "<<mday[i]<<" ";}if(k==7){if(!i){cout<<" ";fout<<" ";i=1;m++;}else{cout<<endl;fout<<endl;i=0;m--;}k=0;}}m=mon-1;if(mday[0]==a[m]+1&&mday[1]<a[m+1]+1) //当双⽉未结束,单⽉输⼊结束跳出时最后⼀⾏的输出情况 {for(;k<8;k++){cout<<" ";fout<<" ";}cout<<" ";fout<<" ";k=1;for(mday[1]++;mday[1]<a[m+1]+1;mday[1]++,k++){cout<<" "<<mday[1]<<" ";fout<<" "<<mday[1]<<" ";if(k==7){cout<<endl;fout<<endl;cout<<" ";fout<<" ";}}cout<<endl;fout<<endl;}if(mday[0]<a[m]+1&&mday[1]==a[m+1]+1) //当单⽉未结束,双⽉输⼊结束跳出时最后⼀⾏的输出情况 {cout<<endl;fout<<endl;k=1;for(mday[0]++;mday[0]<a[m]+1;mday[0]++,k++){cout<<" "<<mday[0]<<" ";fout<<" "<<mday[0]<<" ";if(k==7){cout<<endl;fout<<endl;cout<<" ";fout<<" ";}}cout<<endl;fout<<endl;}}void Month(int n)cout<<str[n][h];fout<<str[n][h];}}void Printnum(int q,int mon) //打印当⽉⽇历{if(q<0)q=q+7;int k=0;if(q!=7&&q){for(;k<7-q;k++){cout<<" ";fout<<" ";}}k++;for(int d=1;d<a[mon-1]+1;d++,k++){cout<<setw(4)<<d;if(k==7){cout<<endl;fout<<endl;k=0;}}cout<<endl;fout<<endl;}以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
数字万年历简易C语言程序源代码
数字万年历简易C语言程序源代码#include"reg52.h"#define uchar unsigned char#define uint unsigned intsbit rs=P2^0; // lcd 控制端sbit en=P2^2; // lcd 控制端sbit all=P2^1; // lcd 控制端sbit s0=P1^5; //时间调节sbit s1=P1^6;sbit s2=P1^7;sbit voice=P2^7;int nt;sbit DQ=P2^6;sbit DS1302_CLK = P2^3; //实时时钟时钟线引脚sbit DS1302_IO = P2^4; //实时时钟数据线引脚sbit DS1302_RST = P2^5; //实时时钟复位线引脚sbit ACC0 = ACC^0;sbit ACC7 = ACC^7;unsigned char time;#define ads_y 0#define ads_mo 3#define ads_d 6#define ads_w 9#define ads_h 65#define ads_m 68#define ads_s 71#define DS1302_SECOND 0x80 //写入ds地址宏定义#define DS1302_MINUTE 0x82#define DS1302_HOUR 0x84#define DS1302_WEEK 0x8A#define DS1302_DAY0x86#define DS1302_MONTH 0x88#define DS1302_YEAR 0x8Cvoid delay1(unsigned int i) //ds 延时函数放在前边是为了让EP 两次存储之间延时可以调用{while(i--);}void init_ds() //ds 初始化函数{unsigned char x=0;DQ=1; //DQ复位delay1(8); //稍做延时DQ=0; //单片机将DQ拉低delay1(80); //精确延时大于480usDQ=1; //拉高总线delay1(10);x=DQ; //稍做延时后如果x=0则初始化成功x=1则初始化失败delay1(5);}unsigned char read_ds() ///ds 读一个字节{unsigned char i=0;unsigned char dat=0;for(i=8;i>0;i--){DQ=0; // 给脉冲信号dat>>=1;DQ=1; // 给脉冲信号if(DQ)dat|=0x80;delay1(5);}return(dat);}void write_ds(unsigned char dat) ///写一个字节{unsigned char i=0;for(i=8;i>0;i--){DQ=0;DQ=dat&0x01;delay1(5);DQ=1;dat>>=1;}delay1(5);}void get_nt() //获取温度{unsigned char a=0;unsigned char b=0;init_ds();write_ds(0xCC); // 跳过读序号列号的操作write_ds(0x44); // 启动温度转换delay1(10);init_ds();write_ds(0xCC); //跳过读序号列号的操作write_ds(0xBE); //读取温度寄存器等(共可读9个寄存器)前两个就是温度a=read_ds();b=read_ds();nt=0;nt=nt+b;nt=nt<<8;nt=nt+a;nt=nt*0.625; //此ds18b20 最低位为0.5 扩大十倍}void delay_1302(uint n) //按键长延时{while(n--);}void delay(uchar n) //lcd 延时子程序{uchar i,j;for(i=0;i<n;i++)< bdsfid="161" p=""></n;i++)<>for(j=0;j<10;j++);}void write_com(char com) //lcd comond in LCD控制字写入函数{en=0;P3=com;rs=0;delay(1);en=1;delay(2);en=0;delay(2);}void write_byte(char byte) //lcd data in LCD数据写入函数{en=0;P3=byte;rs=1;delay(1);en=1;delay(2);en=0;delay(2);}void init_lcd_com() //lcd init LCD初始化{all=0;write_com(0x38);write_com(0x0c);write_com(0x06);}void DS1302InputByte(unsigned char d) //实时时钟写入一字节(内部函数){unsigned char i;ACC = d;for(i=8; i>0; i--){DS1302_IO = ACC0; //相当于汇编中的RRCDS1302_CLK = 1;DS1302_CLK = 0;ACC = ACC >> 1;}}unsigned char DS1302OutputByte(void) //实时时钟读取一字节(内部函数){unsigned char i;for(i=8; i>0; i--){ACC = ACC >>1; //相当于汇编中的RRCACC7 = DS1302_IO;DS1302_CLK = 1;DS1302_CLK = 0;}return(ACC);}void Write1302(unsigned char ucAddr, unsigned char ucDa) //ucAddr: DS1302地址, ucData: 要写的数据DS1302_RST = 0;DS1302_CLK = 0;DS1302_RST = 1;DS1302InputByte(ucAddr); // 地址,命令DS1302InputByte(ucDa); // 写1Byte数据DS1302_CLK = 1;DS1302_RST = 0;}unsigned char Read1302(unsigned char ucAddr) //读取DS1302某地址的数据{unsigned char ucData;DS1302_RST = 0;DS1302_CLK = 0;DS1302_RST = 1;DS1302InputByte(ucAddr|0x01); // 地址,命令ucData = DS1302OutputByte(); // 读1Byte数据DS1302_CLK = 1;DS1302_RST = 0;return(ucData);}void DS1302_SetProtect(bit flag) //是否写保护{if(flag)Write1302(0x8E,0x10);elseWrite1302(0x8E,0x00);}void DS1302_SetTime(unsigned char Address, unsigned char V alue) // 关键函数向内写入时间{DS1302_SetProtect(0);Write1302(Address, ((V alue/10)<<4 | (V alue%10)));}void DS1302_GetTime(unsigned char xy) //关键函数向外读出时间{unsigned char ReadV alue;ReadV alue = Read1302(xy);time=((ReadV alue&0x70)>>4)*10+(ReadV alue&0x0F);}void display_nt(char ads,uchar t) //将读出时间显示char ge,shi;write_com(0x80+ads);shi=t%100/10;ge=t%10;write_byte(shi+'0');write_byte(ge+'0');}void display_nt2(char ads,uchar t) //将读出星期显示{ write_com(0x80+ads);write_byte(t+'0');}void get_dis() //获得时间并显示{DS1302_GetTime(DS1302_YEAR);display_nt(ads_y,time);DS1302_GetTime(DS1302_MONTH);display_nt(ads_mo,time);DS1302_GetTime(DS1302_DAY);display_nt(ads_d,time);DS1302_GetTime(DS1302_WEEK);display_nt2(ads_w,time);DS1302_GetTime(DS1302_HOUR);display_nt(ads_h,time);DS1302_GetTime(DS1302_MINUTE);display_nt(ads_m,time);DS1302_GetTime(DS1302_SECOND);display_nt(ads_s,time);}void set_time() //三按键设置时间{if(s0==0){write_com(0x0f); //开闪烁write_com(0x80+ads_m+1);while(s0==0);delay_1302(30000);while(s0==1){if(s1==0){DS1302_GetTime(DS1302_MINUTE); time++;DS1302_SetTime(DS1302_MINUTE,time); display_nt(ads_m,time);write_com(0x80+ads_m+1);delay_1302(30000);}if(s2==0){DS1302_GetTime(DS1302_MINUTE); time--;DS1302_SetTime(DS1302_MINUTE,time); display_nt(ads_m,time);write_com(0x80+ads_m+1);delay_1302(30000);}}write_com(0x80+ads_h+1);while(s0==0);delay_1302(30000);while(s0==1){if(s1==0){DS1302_GetTime(DS1302_HOUR); time++;DS1302_SetTime(DS1302_HOUR,time); display_nt(ads_h,time);write_com(0x80+ads_h+1);delay_1302(30000);}if(s2==0){DS1302_GetTime(DS1302_HOUR); time--;DS1302_SetTime(DS1302_HOUR,time); display_nt(ads_h,time);write_com(0x80+ads_h+1);delay_1302(30000);}}write_com(0x80+ads_w);while(s0==0);delay_1302(30000);while(s0==1){if(s1==0){DS1302_GetTime(DS1302_WEEK); time++;DS1302_SetTime(DS1302_WEEK,time); display_nt2(ads_w,time);write_com(0x80+ads_w);delay_1302(30000);}if(s2==0){DS1302_GetTime(DS1302_WEEK); time--;DS1302_SetTime(DS1302_WEEK,time); display_nt2(ads_w,time);write_com(0x80+ads_w);delay_1302(30000);}}write_com(0x80+ads_d+1);while(s0==0);delay_1302(30000);while(s0==1){if(s1==0){DS1302_GetTime(DS1302_DAY);time++;DS1302_SetTime(DS1302_DAY,time); display_nt(ads_d,time);write_com(0x80+ads_d+1);delay_1302(30000);}if(s2==0){DS1302_GetTime(DS1302_DAY);time--;DS1302_SetTime(DS1302_DAY,time);display_nt(ads_d,time);write_com(0x80+ads_d+1);delay_1302(30000);}}write_com(0x80+ads_mo+1);while(s0==0);delay_1302(30000);while(s0==1){if(s1==0){DS1302_GetTime(DS1302_MONTH); time++;DS1302_SetTime(DS1302_MONTH,time); display_nt(ads_mo,time);write_com(0x80+ads_mo+1);delay_1302(30000);}if(s2==0){DS1302_GetTime(DS1302_MONTH); time--;DS1302_SetTime(DS1302_MONTH,time); display_nt(ads_mo,time);write_com(0x80+ads_mo+1);delay_1302(30000);}}write_com(0x80+ads_y+1);while(s0==0);delay_1302(30000);while(s0==1){if(s1==0){DS1302_GetTime(DS1302_YEAR); time++;DS1302_SetTime(DS1302_YEAR,time); display_nt(ads_y,time);write_com(0x80+ads_y+1);delay_1302(30000);}if(s2==0){DS1302_GetTime(DS1302_YEAR); time--;DS1302_SetTime(DS1302_YEAR,time); display_nt(ads_y,time);write_com(0x80+ads_y+1);delay_1302(30000);}}write_com(0x0c);while(s0==0);delay_1302(30000);}}void init_lcd_dis() //显示初始化{write_com(0x80+2);write_byte('*');write_com(0x80+5);write_byte('*');write_com(0x80+8);write_byte('-');write_com(0x80+67);write_byte(':');write_com(0x80+70);write_byte(':');}void my() //右下角显示函数{char *pp;char i;code char p[]=" hou fei see a girl and say I LOVE YOU replay I LOVE YOU too ";pp=p;if(time<=60){write_com(0x80+74);for(i=0;i<=5;i++){write_byte(*(pp+time));pp++;}}}void display_nntt(int t) //当前温度显示{char ge,shi,bai;if(t<0){write_com(0x80+11);write_byte('-');t=-t;}else{write_com(0x80+11);write_byte('+');}bai=t/100;shi=t%100/10;ge=t%10;write_byte(bai+'0');write_byte(shi+'0');write_byte('.');write_byte(ge+'0');}void main(){init_lcd_com();init_lcd_dis();DS1302_SetTime(DS1302_SECOND,00); while(1){get_dis();set_time();get_nt();display_nntt(nt); my();}}。
万年历源代码
{
case 1:
while(1)
{
printf("\nqing shu ru nian,yue and tian(XXXX,XX,XX):");
printf("\n2 cha xun shi fou wei run nian");
printf("\n3 shu chu quan nian ri li");
printf("\n4 tui chu\n");
scanf("%d",&nOption);
printf("\n%d Shi run nian,shi fou ji xu?(Y/N)",nNian);
}
else
{
printf("\n%d Bu shi run nian,shi fou ji xu?(Y/N)?",nNian);
fflush(stdin); /*清理输出缓冲区*/
scanf("%c",&cCh);
if (cCh == 'N' || cCh == 'n')
printf("\nqing shu ru xu cha xun nian fen?(XXXX)");
scanf("%d",&nNian);
if (Runnian(nNian))
{
}
int Shuchunian(int nNian,int nYue)/*定义一个输出全年日历的函数*/
{
int i;
万年历源代码
if(sum<=213&&sum>182)
printf("七月%d号\n",sum-182);
if(sum<=244&&sum>213)
printf("八月%d号\n",sum-213);
printf("请输入日期 (year-month-day) n:\n");printf("例如:2011-06-20 6\n");
scanf("%d-%d-%d%d",&yr,&mn,&day,&n);
if((0==yr%4 && 0!=yr%100)||0==yr%400)
switch(option)
{
case 1:
while(1)
{
int flag=1;
char time[128];
_strtime(time);
printf( "当前系统时间:%s\n",time);
printf("\ndo you want to continue?(Y/N)");
scanf("%d",&year);
if(IsLeapYear(year))
printf("\n%d是闰年,do you want to continue?(Y/N)",year);
else
printf("\n%d 不是闰年,do you want to continue(Y/N)?",year);
万年历课程设计C语言源代码
#include<reg52.h>#include<intrins.h>#include<absacc.h>#include<math.h>#define uchar unsigned char#define uint unsigned int#define rst573 XBYTE[0X1000]#define y4 XBYTE[0X8000]#define y5 XBYTE[0Xa000]#define y6 XBYTE[0Xc000]#define y7 XBYTE[0Xe000]sbit scl1302=P1^7;sbit IO=P2^3;sbit rst1302=P1^3;sbit lcden=P1^2;sbit lcdwr=P2^1;sbit lcdrs=P2^0;sbit s5=P3^2;sbit s4=P3^3;sbit s6=P3^1;sbit s7=P3^0;uint t;sbit DQ=P1^4;float tt;uchar *riqi="20 - - "; uchar *xingqi="week "; uchar *shijian=" - - "; uchar *wedu="28.7C";uchar time[8],num;int nian,yue,ri,xq=1,shi,fen,miao; char count;void delay(uint z){uint x,y;for(x=z;x>0;x--)for(y=120;y>0;y--); }void delayus(uint t){for(;t>0;t--);}void init(){rst573;y4;rst573;P0=0x00;y6;rst573;P0=0xa0;y7;rst573;}/**************************1602***********************/void write_com(uchar com){lcdrs=0;lcdwr=0;P0=com;delay(5);lcden=1;delay(5);lcden=0;}void initlcd(){lcdwr=0;write_com(0x38);write_com(0x0c);write_com(0x06);write_com(0x01);}void write_data(uchar date){lcdrs=1;lcdwr=0;P0=date;delay(5);lcden=1;delay(5);lcden=0;}/***********************************************1302**************/ void writebyte(uchar add,date){uchar i;IO=0;rst1302=1;for(i=0;i<8;i++){scl1302=0;IO=add&0x01;scl1302=1;add>>=1;}for(i=0;i<8;i++){scl1302=0;IO=date&0x01;scl1302=1;date>>=1;}rst1302=0;}uchar readbyte(uchar add){uchar i,temp;scl1302=0;IO=0;rst1302=1;for(i=0;i<8;i++){scl1302=0;IO=add&0x01;scl1302=1;add>>=1;}for(i=0;i<8;i++){scl1302=1;temp>>=1;scl1302=0;if(IO)temp|=0x80;}return temp;}void set_1302(){writebyte(0x8e,0x00);writebyte(0x8c,nian);writebyte(0x8a,xq);writebyte(0x88,yue);writebyte(0x86,ri);writebyte(0x84,shi);writebyte(0x82,fen);writebyte(0x80,0x00);writebyte(0x8e,0x80);}void read_1302(uchar *p){p[0]=readbyte(0x81);writebyte(0x00,0x00);p[1]=readbyte(0x83);writebyte(0x00,0x00);p[2]=readbyte(0x85);writebyte(0x00,0x00);p[3]=readbyte(0x87);writebyte(0x00,0x00);p[4]=readbyte(0x89);writebyte(0x00,0x00);p[5]=readbyte(0x8b);writebyte(0x00,0x00);p[6]=readbyte(0x8d);writebyte(0x00,0x00);fen=p[1];shi=p[2];ri=p[3];yue=p[4];xq=p[5];nian=p[6];}/*************************************18b20******************/ void init_ds18b20() //18B20初始化{char presence=1;WR=0;while(presence){while(presence){DQ=1;_nop_();_nop_();DQ=0;delayus(50);DQ=1;delayus(6);presence=DQ;delayus(45); //延时500 uspresence=~DQ;}DQ=1; //拉高电平}/****************************************************************************** **/void writeonechar(unsigned char dat) //写一个字节{uchar i=0;for(i=8;i>0;i--){DQ=1;_nop_();_nop_();DQ=0;DQ=dat&0x01;delayus(6);DQ=1;dat>>=1;}DQ=1;}/****************************************************************************** ***/uchar readonechar(void) //读一个字节{uchar i=0;uchar dat=0;for(i=8;i>0;i--){DQ=1;_nop_();_nop_();dat>>=1;DQ=0;_nop_();_nop_();_nop_();_nop_();DQ=1;_nop_();_nop_();_nop_();_nop_();if(DQ)dat|=0x80;delayus(6);}return(dat);}/****************************************************************************** */uchar display_zh() //把子节转化为十进制{init_ds18b20();writeonechar(0xcc);writeonechar(0x44);init_ds18b20();_nop_();_nop_(); _nop_();_nop_();writeonechar(0xcc);writeonechar(0xbe);a=readonechar();b=readonechar();t=b;t<<=8;t=t|a;tt=t*0.0625;t=tt*10+0.5;return t;}void display1(){uchar i;write_com(0x80); //2011-11-11 23-14-59 week 1 28.7℃for(i=0;i<2;i++){write_data(riqi[i]);}write_com(0x84); //2011-11-11 23-14-59 week 1 28.7℃write_data(riqi[4]);write_com(0x87); //2011-11-11 23-14-59 week 1 28.7℃write_data(riqi[7]);write_com(0x8d);write_data('.');write_com(0x8f);write_data('C');write_com(0xc2);write_data(shijian[2]);write_com(0xc5);write_data(shijian[5]);write_com(0xc9);for(i=0;i<4;i++){write_data(xingqi[i]);}writebyte(0x80,0x00);write_com(0x82);write_data(nian/16+'0');write_data(nian%16+'0');write_com(0x85);write_data(yue/16+'0');write_data(yue%16+'0');write_com(0x88);write_data(ri/16+'0');write_data(ri%16+'0');display_zh();write_com(0x8b);write_data(t%1000/100+'0');write_data(t%100/10+'0');write_com(0x8e);write_data(t%10+'0');/********************************/write_com(0xc0);write_data(shi/16+'0');write_data(shi%16+'0');write_com(0xc3);write_data(fen/16+'0');write_data(fen%16+'0');write_com(0xc6);write_data(time[0]/16+'0');write_data(time[0]%16+'0');write_com(0xce);write_data(xq+'0');}void jian(){if(s4==0){writebyte(0x8e,0x00); writebyte(0x80,0x00);num=0;set_1302();}if(s7==0){while(!s7);num++;}switch(num){case 1:writebyte(0x8e,0x00);if(s6==0){while(!s6);fen++; writebyte(0x80,0x80);}if(fen==10)//10fen=16;if(fen==26)//20fen=32;if(fen==42)//30fen=48;if(fen==58)//40fen=64;if(fen==74)//50fen=80;if(fen==90)//60fen=0;if(s5==0){while(!s5);fen--;writebyte(0x80,0x80);}if(fen==-1)//10fen=89;if(fen==79)//20fen=73;if(fen==63)//30fen=57;if(fen==47)//40fen=41;if(fen==31)//50fen=25;if(fen==15)//50fen=9;writebyte(0x82,fen);write_com(0xc3);display1();break;case 2:writebyte(0x8e,0x00);if(s6==0){while(!s6); shi++;writebyte(0x80,0x80);} if(shi==10)//10shi=16;if(shi==26)//20shi=32;if(shi==36)//30shi=0;if(s5==0){while(!s5);shi--;writebyte(0x80,0x80);}if(shi==-1)//30shi=35;if(shi==31)//40shi=25;if(shi==15)//50shi=9;write_com(0xc0);writebyte(0x84,shi);display1();break;case 3:writebyte(0x8e,0x00);if(s6==0){while(!s6);ri++;writebyte(0x80,0x80);}if(ri==10)//10ri=16;if(ri==26)//20ri=32;if(ri==42)//30ri=48;if(ri==50)//60ri=0;if(s5==0){while(!s5);ri--;writebyte(0x80,0x80);}if(ri==-1)//10ri=49;if(ri==47)//40ri=41;if(ri==31)//50ri=25;if(ri==15)//50ri=9;write_com(0x88);writebyte(0x86,ri);display1();;break;case 4:writebyte(0x8e,0x00);if(s6==0){while(!s6);yue++;writebyte(0x80,0x80);}if(yue==10)//10yue=16;if(yue==19)//20yue=0;if(s5==0){while(!s5);yue--;writebyte(0x80,0x80);}if(yue==-1)//10yue=18;if(yue==16)//10yue=10;write_com(0x85);writebyte(0x88,yue);display1();;break;case 5:writebyte(0x8e,0x00);if(s6==0){while(!s6);nian++;writebyte(0x80,0x80);}if(nian==10)//10nian=16;if(nian==26)//20nian=32;if(nian==42)//30nian=48;if(nian==58)//40nian=64;if(nian==74)//50nian=80;if(nian==90)//60nian=96;if(nian==106)//70nian=112;if(nian==122)//80nian=128;if(nian==138)//90nian=144;if(nian==154)//60nian=0;if(s5==0){while(!s5);nian--;writebyte(0x80,0x80);}if(nian==-1)//10nian=153;if(nian==143)//90nian=137;if(nian==127)//80nian=121;if(nian==111)//70nian=105;if(nian==95)//60nian=89;if(nian==79)//50nian=73;if(nian==63)//40nian=57;if(nian==47)//30nian=41;if(nian==31)//20nian=25;if(nian==-15)//10nian=9;write_com(0x82);writebyte(0x8c,nian);display1();break;case 6:writebyte(0x8e,0x00);if(s6==0){while(!s6);xq++;writebyte(0x80,0x80);}if(xq==8)xq=1;if(xq==0)xq=7;if(s5==0){while(!s5); xq--;writebyte(0x80,0x80);}if(xq==-1)xq=7;write_com(0xce);writebyte(0x8a,xq);display1();break;case 7: writebyte(0x8e,0x00);writebyte(0x80,0x00);num=0;set_1302();break;}}void main(){init();initlcd();set_1302();while(1){ display1();jian();read_1302(time);}}。
java万年历程序代码
package pack;import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Calendar;import java.util.Date;public class rili extends JFrame implements ActionListener { JButton b_today, b_query;JLabel lb_Year, lb_Month;JButton b_week[] = new JButton[7];JButton b_day[][] = new JButton[6][7];Container thisContainer;JPanel pUp;JPanel pCenter;JPanel pCenter_week, pCenter_day;JComboBox year, month;public void init() {b_today = new JButton("Today");b_query = new JButton("Query");setTitle("日历");lb_Year = new JLabel("Year");lb_Month = new JLabel("Month");year = new JComboBox();month = new JComboBox();setDate();pUp = new JPanel();pUp.add(lb_Year);pUp.add(year);pUp.add(lb_Month);pUp.add(month);pUp.add(b_today);pUp.add(b_query);b_today.addActionListener(this);b_query.addActionListener(this);pCenter = new JPanel();pCenter_week = new JPanel();b_week[0] = new JButton("星期日");b_week[1] = new JButton("星期一");b_week[2] = new JButton("星期二");b_week[3] = new JButton("星期三");b_week[4] = new JButton("星期四");b_week[5] = new JButton("星期五");b_week[6] = new JButton("星期六");b_week[0].setSize(400, 200);b_week[1].setSize(400, 200);b_week[2].setSize(400, 200);b_week[3].setSize(400, 200);b_week[4].setSize(400, 200);b_week[5].setSize(400, 200);b_week[6].setSize(400, 200);for (int i = 0; i < 7; i++) {b_week[i].setEnabled(false);pCenter_week.add(b_week[i]);}pCenter_day = new JPanel();for (int cols = 0; cols < 6; cols++) {for (int rows = 0; rows < 7; rows++) {b_day[cols][rows] = new JButton("");b_day[cols][rows].setSize(400, 200);this.pCenter_day.add(b_day[cols][rows]);}}pCenter_day.setLayout(new GridLayout(6, 7));setDay(Integer.parseInt(this.year.getSelectedItem().toString()),Integer.parseInt(this.month.getSelectedItem().toString()));// setDay(2011,2);pCenter.setLayout(new BorderLayout());pCenter.add(pCenter_week, "North");pCenter.add(pCenter_day, "Center");thisContainer = this.getContentPane();thisContainer.setLayout(new BorderLayout());thisContainer.add(pUp, "North");thisContainer.add(pCenter, "Center");this.setVisible(true);this.setResizable(false);this.pack();}public void setDate() {int year, month, day, week;Calendar cal = Calendar.getInstance();year = cal.get(Calendar.YEAR);month = cal.get(Calendar.MONTH);day = cal.get(Calendar.DA TE);week = cal.get(Calendar.WEEK_OF_YEAR);int year_temp = year - 4;for (int i = 0; i < 10; i++) {this.year.addItem(year_temp);year_temp += 1;}this.year.setSelectedIndex(4);for (int n = 0; n < 12; n++) {this.month.addItem(n + 1);}this.month.setSelectedIndex(month);}public void setDay(int Year, int Month) {int count;Calendar c = Calendar.getInstance();c.clear();c.set(Year, Month-1, 1);count = c.getActualMaximum(Calendar.DAY_OF_MONTH); // 总天数System.out.print(count);int day = c.get(Calendar.DAY_OF_WEEK) - 1; // 0为星期天,6为星期六System.out.print(day);int i = 1 - day;for (int cols = 0; cols < 6; cols++) {for (int rows = 0; rows < 7; rows++) {String st = String.valueOf(i);b_day[cols][rows].setText(st);b_day[cols][rows].setEnabled(false);if (i > 0 && i <= count)b_day[cols][rows].setVisible(true);elseb_day[cols][rows].setVisible(false);i++;}}}public void actionPerformed(ActionEvent e) {if (e.getSource() == b_query) {this.setDay(Integer.parseInt(this.year.getSelectedItem().toString()), Integer.parseInt(this.month.getSelectedItem().toString()));}if (e.getSource() == b_today) {int year, month;Calendar cal = Calendar.getInstance();year = cal.get(Calendar.YEAR);month = cal.get(Calendar.MONTH)+1;this.setDay(year,month);}}public static void main(String[] args) {rili rl = new rili();rl.init();}}。
java_(Java)万年历源代码参考
this.getContentPane().setLayout(new BorderLayout(10, 0));
jta.setLineWrap(true); table.setGridColor(Color.GRAY); //星期之间的网格线是灰 色的
private JPanel p2 = new JPanel(); private JPanel p3 = new JPanel(new BorderLayout()); private JPanel p4 = new JPanel(new GridLayout(2,1)); private JPanel p5 = new JPanel(new BorderLayout()); private JButton bAdd = new JButton("保存日志"); private JButton bDel = new JButton("删除日志"); private JTextArea jta = new JTextArea(); //jta--JTextArea private JScrollPane jsp = new JScrollPane(jta); private JLabel l = new JLabel("您可以向年份文本框中键入 您要查找的年份,以提高查询效率"); private JLabel lt = new JLabel(); private JLabel ld = new JLabel(); private int lastTime; public MyCalendar() { super("MyCalendar"); //框架命名
万年历代码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、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include<stdio.h>#include<time.h>#include<math.h>#include<windows.h>#include<conio.h>#define KEYNUMUp 0x48#define KEYNUMDown 0x50#define KEYNUMLeft 0x4b#define KEYNUMRight 0x4d#define KEYNUMPageUp 0x49#define KEYNUMPageDown 0x51int year,month,day; //全局变量记录时间intdaysOfMonth[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 runYear(int year) //判断是否是闰年{int flag=0;if(year%400==0||(year%4==0&&year%100!=0))flag=1;return flag;}struct tm* getDay()//从系统取得当前时间{time_t timer;struct tm* gmt;time(&timer);gmt=localtime(&timer);return gmt;}int dayExame(int year,int month,int day)//检查日期是否正确{if(year<0||month<1||month>12||day<1||day>31)return 0;switch(month){case 1:case 3:case 5:case 7:case 8:case 10:case 12:if(day>31)return 0;break;case 4:case 6:case 9:case 11:if(day>30)return 0;break;default:if(runYear(year)&&day>29)return 0;else if(runYear(year)==0&&day>28)return 0;}return 1;}int getwDay(int year,int month,int day)//取得星期{int nday=0,nDay,i,w;for(i=0;i<month-1;i++)nday+=daysOfMonth[runYear(year)][i];nday+=day;nDay=year-1+(year-1)/4-(year-1)/100+(year-1)/400+nday;w=nDay%7;return w;}void printCalender(int year,int month,int day);void setDay(int &year,int &month,int &day)//调节日期{printf("%c:上一年 %c:下一年\n",24,25);printf("%c:上个月 %c:下个月\n",27,26);printf("PageUp:昨天 PageDown:明天\n");printf("其他:返回主菜单\n");char k;getch();k=getch();switch(k) //通过方向键和PageUp、PageDown键来调整日期{case KEYNUMUp: year--;if(dayExame(year,month,day)==0){year++; printf("%c",7);} //检查日期的合法性,//若错误,保持日期不变,并警告system("cls");printCalender(year,month,day);setDay(year,month,day);break;case KEYNUMDown: year++;if(dayExame(year,month,day)==0){year--;printf("%c",7);}system("cls");printCalender(year,month,day);setDay(year,month,day);break;case KEYNUMLeft: month--;if(dayExame(year,month,day)==0){month++;printf("%c",7);}system("cls");printCalender(year,month,day);setDay(year,month,day);break;case KEYNUMRight: month++;if(dayExame(year,month,day)==0){month--;printf("%c",7);}system("cls");printCalender(year,month,day);setDay(year,month,day);break;case KEYNUMPageUp: day--;if(dayExame(year,month,day)==0){day++;printf("%c",7);}system("cls");printCalender(year,month,day);setDay(year,month,day);break;case KEYNUMPageDown: day++;if(dayExame(year,month,day)==0){day--;printf("%c",7);}system("cls");printCalender(year,month,day);setDay(year,month,day);break;default: ;}}void printCalender(int year,int month,int day)//打印月历{int i;char wday[7][4]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};printf(" %d年%d月%d日\n",year,month,day);printf("***********************************\n");for(i=0;i<7;i++)printf("%5s",wday[i]);printf("\n");int w;int nowDay=1;w=getwDay(year,month,nowDay);//找到第一天的星期int n;n=daysOfMonth[runYear(year)][month-1];switch(w) //放置第一天{case 0:printf("%5d",nowDay);break;case 1:printf("%10d",nowDay);break;case 2:printf("%15d",nowDay);break;case 3:printf("%20d",nowDay);break;case 4:printf("%25d",nowDay);break;case 5:printf("%30d",nowDay);break;default:printf("%35d\n",nowDay);}nowDay++;for(i=1;i<n;i++){w=getwDay(year,month,nowDay);printf("%5d",nowDay);if(w==6) //如果是星期六则换行打印puts("\n");nowDay++;}printf("\n***********************************\n\n");}void checkCalender()//查询日历{system("cls");int year,month,day;printf("请输入你要查询的日期(格式为年月日,如2011 12 22):");scanf("%d%d%d",&year,&month,&day);while(!dayExame(year,month,day)) //如果日期输入不正确,则重新输入{printf("%c你输入的日期错误,请重新输入:",7);scanf("%d%d%d",&year,&month,&day);}system("cls");if(runYear(year))printf("\n 闰年\n\n");else printf("\n 平年\n\n");printCalender(year,month,day);}void inline backMenu(){printf("请按任意字符键返回主菜单:");getch();system("cls");}void mainMenu(int &year,int &month,int &day)//主菜单{printf(" ************主菜单************\n");printf(" * 1、日历显示 *\n");printf(" * 2、日历查询 *\n");printf(" * 3、修改日期 *\n");printf(" * 4、帮助 *\n");printf(" * 5、退出 *\n");printf(" ******************************\n");char menu[100];int flag=0;do{int f=0;do{f=0;printf("\n 请输入相应数字:");scanf("%s",menu);if(strlen(menu)>2)f=1;}while(f==1);switch(*menu){case '1':system("cls"); //清屏printCalender(year,month,day);backMenu(); //实现任意键返回主菜单mainMenu(year,month,day);break;case '2':system("cls");checkCalender();backMenu();mainMenu(year,month,day);break;case '3':system("cls");printCalender(year,month,day);setDay(year,month,day);printf("请按任意字符键返回主菜单:");getch();system("cls");mainMenu(year,month,day);break;case '4':system("cls");printf("在主菜单中输入相应的数字就可以完成以下功能:\n\n");printf("* 1、显示今天所在月的月份\n\n");printf("* 2、输入日期,判断该年是否是闰年,并显示所在月份的月历\n\n");printf("* 3、用%c %c %c %c PageUp PageDown 进行日期的调整\n\n",24,25,27,26);printf("* 4、显示功能及操作方法\n\n");printf("* 5、退出程序\n\n");backMenu();mainMenu(year,month,day);break;case '5':system("cls");printf("程序已退出!\n");exit(0);default:printf("%c 输入错误!\n",7);flag=1;}}while(flag);}void main(){struct tm *gmt=getDay();year=gmt->tm_year+1900;month=gmt->tm_mon+1;day=gmt->tm_mday;printCalender(year,month,day);//用系统时间进行初始化,打印当前月历backMenu();mainMenu(year,month,day);}。