⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 year.txt

📁 软件工程实验报告的一部分源码。 关于万年历的。
💻 TXT
字号:
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>

#define firstdayof1 1
	/* define the first day of first year. 星期日=7 */
#define gap "    "
	/* set gap between numbers of dates */
#define dent "                    "
	/* set right margin. */

struct info {
		int month;
		int firstdayofmonth;
		int daysofmonth;
		int leap;
	    }monthinfo;
	    
int checkinput(void);
int inputyear(void);
int isleap(int y);
void output(struct info);
void printhead(struct info );
void printmonth(struct info);
struct info setinit(int);
struct info setmonthinfo(struct info );


void main(void)
{
     int year;
     year=checkinput();
     printf("\n\n%s%s%s%s%s%d年年历\n\n",dent,gap,gap,gap,gap,year);
     monthinfo=setinit(year);
     output(monthinfo);
}

/* This fuction is to accept year, if it is leap year, it return 1, otherwise 
   return 0  							             */
 
int isleap(int y)
{
   return ((y%4==0 && y%100!=0)  || y%400==0);
}

/* This module is to accept inputyear() and check if it is correct. if it is
   correct it return int year, otherwise ask user reenter                */
   
int checkinput(void)
{
     int y;
     do{
	     y=inputyear();
	     if(y<1 || y >3000)
		{
			printf("\n输入错误!。\n\n");
			y=0;
		}
      }while(y<1);
     return y;
     }

/* This function is to accept the input year, if it is the integer, it returns
 it, otherwise it return -1                                                  */

int inputyear(void)
{
     char s[80]; 
     int i, y;
     y=-1;
     printf("请输入年份(1-3000):");
     for(i=0;i<80;++i) 
     {
	s[i]=getchar();
	if(s[i]==27)
		exit(0);
	if(s[i]==10)
		break;
     }
     for(i=0;i<80;++i)
     {
	if(s[i]==10) break;
	else if(!isdigit(s[i]))
	     return y;
     }
     y=atoi(s);
     return y;
}

/*This module is to accept monthinfo, and print the whole year calender.   */

void output(struct info monthinfo)
{
	char ch;
     do{
	 printhead(monthinfo);
	 printmonth(monthinfo);
	 printf("按任意键显视下一月, 按Esc键退出. \n");	
	 ch=getch();
	 if(ch==27)
	 exit(0);
	 monthinfo=setmonthinfo(monthinfo);
     }while(monthinfo.month<13);
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -