#include <iostream> |
#include<ctype.h> //字符处理函数: 本类别函数用于对单个字符进行处理,包括字符的类别测试和字符的大小写转换。 |
#include<math.h> //数学函数: 本分类给出了各种数学计算函数。 |
#include<signal.h>//信号处理: 该分类函数用于处理那些在程序执行过程中发生例外的情况。 |
#include<stdarg.h> //可变参数处理: 本类函数用于实现诸如printf,scanf等参数数量可变底函数。 |
#include<stdio.h> //输入输出函数:该分类用于处理包括文件、控制台等各种输入输出设备,各种函数以“流”的方式实现。 |
#include<string.h> //字符串处理: 本分类的函数用于对字符串进行合并、比较等操作。 |
#include<time.h> //日期和时间函数: 本类别给出时间和日期处理函数。 |
#include<stdlib.h> //实用工具函数: 本分类给出了一些函数无法按以上分类,但又是编程所必须要的。 |
#include<windows.h>//延迟函数。 |
#define P printf//标准输出 |
#define S scanf//标准输入 |
#define C char//字符型 |
#define F float//单精度型 |
#define D double//双精度型 |
#define L long//长整型 |
/* run this program using the console pauser or add your own getch, system("pause") or input loop */ |
int main( int argc, char ** argv) |
{ |
//各类自定义的函数 。 |
int qiuxingqi( int nianfen, int yuefen, int rizi); //求星期几函数。 |
int qiurunnian( int nianfen); //求是否为闰年函数。 |
int yanchi( int yanchi); //延遲函數。 |
void qiuyuerili( int nianfen, int yuefen); //打印某个月份的日历。 |
void qiunianrili( int nianfen); //打印某年的日历。 |
//各类自定义的变量。 |
int xq,sj,nian,yue,ri,run; |
int zcxxh=1; //主程序循環。 |
int zxh=0; //子程序循環。 |
int cxgn; //功能選擇變量。 |
int zpd; //子程序判斷。 |
//系統日期顯示 |
struct tm *ptr; |
time_t it; |
it= time (NULL); |
ptr= localtime (&it); |
//程序欢迎界面 |
system ( "color 5" ); |
P( "\n" ); |
P( "\n" ); |
P( "\n" ); |
P( "\n" ); |
P( " * * * \n" ); |
P( " ***** * * ** **** ** \n" ); |
P( " * ***** * * * ** \n" ); |
P( " * ** * * * * ** \n" ); |
P( " * ** * ** * * * ** \n" ); |
P( " * * * * * * * ** \n" ); |
P( " * * * * * * * \n" ); |
P( " * * * ** * * \n" ); |
P( " * * * * * * * ** ** \n" ); |
P( " * * * * * * ** \n" ); |
P( " * * * * * \n" ); |
P( " * * * ********* \n" ); |
yanchi(21111); |
system ( "cls" ); |
system ( "color 4" ); |
P( "\n" ); |
P( "\n" ); |
P( "\n" ); |
P( "\n" ); |
P( " * \n" ); |
P( " *********** * **********\n" ); |
P( " * ********* * * \n" ); |
P( " * * * * * \n" ); |
P( " * * * * ******* \n" ); |
P( " ******* ******** * * * \n" ); |
P( " * * * * * * * \n" ); |
P( " * * * * * * * \n" ); |
P( " * * *********** * * * \n" ); |
P( " * * * * * * \n" ); |
P( " * * * * * * \n" ); |
P( " * *** * * * *** \n" ); |
yanchi(31111); |
system ( "cls" ); |
//主程序界面。 |
while (zcxxh) |
{ |
system ( "color a2" ); |
P( "\n" ); |
P( "\n" ); |
P( "\n" ); |
P( "\n" ); |
P( "\n" ); |
P( " --------------------------------------------------------------\n" ); |
P( " | |\n" ); |
P( " | 現在是:%4d年%02d月%02d日 |\n" ,ptr->tm_year+1900,ptr->tm_mon+1,ptr->tm_mday,ptr->tm_hour,ptr->tm_min,ptr->tm_sec); |
P( " | |\n" ); |
P( " | 1、輸入年份,程序判斷是否為閏年。 |\n" ); |
P( " | |\n" ); |
P( " | 2、輸入年月日,程序判斷這天為星期幾。 |\n" ); |
P( " | |\n" ); |
P( " | 3、輸入月份,打印出該月的日歷。 |\n" ); |
P( " | |\n" ); |
P( " | 4、輸入年份,打印出該年的日歷。 |\n" ); |
P( " | |\n" ); |
P( " | |\n" ); |
P( " --------------------------------------------------------------\n" ); |
P( "\n" ); |
P( "\n" ); |
P( "請輸入您要選擇的功能!" ); |
S( "%d" ,&cxgn); |
zxh=1; |
if (cxgn==1) //功能1、判断闰年 |
{ |
while (zxh) |
{ |
system ( "cls" ); |
P( "請輸入您想要判斷的年份:" ); |
S( "%d" ,&nian); |
if (nian<=10000) |
{ |
run=qiurunnian(nian); |
if (run==1) |
P( "您輸入的該年份為:閏年\n" ); |
else if (run==0) |
P( "您輸入的該年份為:平年\n" ); |
} |
else |
{ |
system ( "cls" ); |
P( "您輸入的格式有誤,請重新輸入......" ); |
yanchi(21111); |
system ( "cls" ); |
zxh=1; |
continue ; |
} |
yanchi(21111); |
P( "\n" ); |
P( "\n" ); |
P( "您需要的是繼續判斷還是返回主窗口?\n" ); |
P( "輸入0為主窗口,1為繼續判斷!\n" ); |
S( "%d" ,&zpd); |
if (zpd==1) |
zxh=1; |
else |
{ |
system ( "cls" ); |
break ; |
} |
} |
} |
else if (cxgn==2) //功能2、判断星期 |
{ |
while (zxh) |
{ |
system ( "cls" ); |
P( "請輸入您想要判斷日期,格式為:年-月-日\n" ); |
S( "%d-%d-%d" ,&nian,&yue,&ri); |
if (yue>12||ri>31) |
{ |
P( "您輸入的日期有誤!請您重新輸入\n" ); |
system ( "cls" ); |
zxh=1; |
continue ; |
} |
else if (yue==2&&ri>29) |
{ |
system ( "cls" ); |
P( "您輸入的日期有誤!請您重新輸入\n" ); |
yanchi(21111); |
system ( "cls" ); |
zxh=1; |
continue ; |
} |
else |
{ |
xq=qiuxingqi(nian,yue,ri); |
P( "您查詢的這一天是:" ); |
switch (xq) |
{ |
case 0:P( "星期日!\n" ); break ; |
case 1:P( "星期一!\n" ); break ; |
case 2:P( "星期二!\n" ); break ; |
case 3:P( "星期三!\n" ); break ; |
case 4:P( "星期四!\n" ); break ; |
case 5:P( "星期五!\n" ); break ; |
case 6:P( "星期六!\n" ); break ; |
} |
} |
yanchi(21111); |
P( "\n" ); |
P( "\n" ); |
P( "您需要的是繼續查询還是返回主窗口?\n" ); |
P( "輸入0為主窗口,1為繼續查询!\n" ); |
S( "%d" ,&zpd); |
if (zpd==1) |
zxh=1; |
else |
{ |
system ( "cls" ); |
break ; |
} |
} |
} |
else if (cxgn==3) //功能3、打印某月日历 |
{ |
while (zxh) |
{ |
system ( "cls" ); |
P( "請輸入您想要打印的月份,格式為:年-月\n" ); |
S( "%d-%d" ,&nian,&yue); |
if ((nian<10000)||(yue<13||yue>0)) |
{ |
P( " %d年%d月\n" ); |
qiuyuerili(nian,yue); //打印某个月份的日历 |
} |
else |
{ |
system ( "cls" ); |
P( "您輸入的日期有誤!請您重新輸入\n" ); |
yanchi(21111); |
system ( "cls" ); |
zxh=1; |
continue ; |
} |
yanchi(21111); |
P( "\n" ); |
P( "\n" ); |
P( "您需要的是繼續打印還是返回主窗口?\n" ); |
P( "輸入0為主窗口,1為繼續打印!\n" ); |
S( "%d" ,&zpd); |
if (zpd==1) |
zxh=1; |
else |
{ |
system ( "cls" ); |
break ; |
} |
} |
} |
else if (cxgn==4) //功能4、打印某年日历 |
{ |
while (zxh) |
{ |
system ( "cls" ); |
P( "請輸入您想要打印的年份,格式為:年\n" ); |
S( "%d" ,&nian); |
if (nian<10000) |
qiunianrili(nian); |
else |
{ |
system ( "cls" ); |
P( "您輸入的日期有誤!請您重新輸入\n" ); |
yanchi(21111); |
system ( "cls" ); |
zxh=1; |
continue ; |
} |
yanchi(21111); |
P( "\n" ); |
P( "\n" ); |
P( "您需要的是繼續打印還是返回主窗口?\n" ); |
P( "輸入0為主窗口,1為繼續打印!\n" ); |
S( "%d" ,&zpd); |
if (zpd==1) |
zxh=1; |
else |
{ |
system ( "cls" ); |
break ; |
} |
} |
} |
} |
return 0; |
} |
//求星期几函数 |
int qiuxingqi( int nianfen, int yuefen, int rizi) //求某一天是星期几函数。 |
{ |
if (yuefen==1) //蔡勒公式指出:如果是1,2月 要按照上一年的13,14月来计算。 |
{nianfen-=1; |
yuefen=13; |
} |
if (yuefen==2) |
{nianfen-=1; |
yuefen=14; |
} |
int shiji=nianfen/100; |
nianfen=nianfen-shiji*100; //年数的后两位数。 |
int xingqi; |
xingqi=(nianfen+nianfen/4+shiji/4-2*shiji+26*(yuefen+1)/10+rizi-1)%7; //蔡勒公式。 |
if (xingqi<0) //负数的时候要往前加星期而不是直接得出的星期. |
xingqi+=7; |
return xingqi; //返回值为星期几。 |
} |
//求闰年函数 |
int qiurunnian( int nianfen) //求某一年是否为闰年。 |
{ |
int shifourunnian; //闰年该值为1否为0. |
if ((nianfen%4==0&&nianfen%100!=0)||(nianfen%400==0)) //计算是否为闰年。 |
shifourunnian=1; |
else |
shifourunnian=0; |
return shifourunnian; |
} |
//延迟函数 |
int yanchi( int yanchi) //延遲函數,延遲時間與自己cpu有關。 |
{ |
int yccs1,yccs2; |
for (yccs1=0;yccs1<=yanchi;yccs1++) |
for (yccs2=0;yccs2<=yanchi;yccs2++); |
} |
//打印某一个月份的日历 |
void qiuyuerili( int nianfen, int yuefen) //打印某个月份的日历 |
{ |
int qiurunnian( int nianfen); |
int qiuxingqi( int nianfen, int yuefen, int rizi); |
int runnian,xingqiji,tianshu,rn2yts; |
int kgs=0,jcxh; |
runnian=qiurunnian(nianfen); //判断该年的2月是多少天。 |
if (runnian==1) |
rn2yts=29; |
else if (runnian==0) |
rn2yts=28; |
xingqiji=qiuxingqi(nianfen,yuefen,1); |
switch (yuefen) //判断该月总共多少天。 |
{ |
case 1:tianshu=31; break ; |
case 2:tianshu=rn2yts; break ; |
case 3:tianshu=31; break ; |
case 4:tianshu=30; break ; |
case 5:tianshu=31; break ; |
case 6:tianshu=30; break ; |
case 7:tianshu=31; break ; |
case 8:tianshu=31; break ; |
case 9:tianshu=30; break ; |
case 10:tianshu=31; break ; |
case 11:tianshu=30; break ; |
case 12:tianshu=31; break ; |
} |
kgs=xingqiji-1; |
P( "该月有%d天\n" ,tianshu); |
P( "日 一 二 三 四 五 六\n" ); |
for (jcxh=0;jcxh<=kgs;jcxh++) //输出每月的第一天前面的空格 |
P( " " ); |
for (jcxh=1;jcxh<=tianshu;jcxh++) //输出该月的每一天。 |
{ |
P( "%-4d" ,jcxh); |
if ((kgs+jcxh+1)%7==0) |
P( "\n" ); |
} |
P( "\n" ); |
} |
//打印某一年的日历 |
void qiunianrili( int nianfen) //打印某年的日历。 |
{ |
void qiuyuerili( int nianfen, int yuefen); //打印每月的日历计算。 |
int yuefen; |
for (yuefen=1;yuefen<=12;yuefen++) //循环每月 |
{ |
P( " %d年%d月\n" ,nianfen,yuefen); |
qiuyuerili(nianfen,yuefen); |
P( "\n" ); |
P( "\n" ); |
} |
} |
初级程序员
by: 云代码会员 发表于:2018-05-12 10:41:04 顶(0) | 踩(0) 回复
挺有意思的
回复评论