万年历软件可以实现日历显示,日历查询,日历修改,日期备忘录,信息帮助这些功能:
#include<stdio.h>
#include"CalendarTable.h"
#include<stdlib.h>
int main()
{
CalendarTable();
system("pause");
return 0;
}
/****************************************************************************************/
#pragma once
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include"time.h"
#include<assert.h>
#include<stdlib.h>
#include<string.h>
void CalendarTable();
void CalculateDay();
void ShowEveryMonth();
int JudgeLeapYear();
int JudgeMonth();
void AlterCalendarTable();
/**************************************************************************/
void ShowEveryMonth(int year)
{
int month=1;
while (month <= 12)
{
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))//是闰年
{
//printf("是闰年\n");
printf("************************\n");
//printf("本月日历\n");
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)//1 3 5 7 8 10 12月的日历
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
printf("29 30 31\n");
}
else if (month == 4 || month == 6 || month == 9 || month == 11)//4 6 9 11月的日历
{
//printf("其他月份\n");
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
printf("29 30\n");
}
else//2月的日历
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
printf("29\n");
}
}
else
{
//printf("不是闰年\n");
printf("************************\n");
//printf("本月日历\n");
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)//1 3 5 7 8 10 12月的日历
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
printf("29 30 31\n");
}
else if (month == 4 || month == 6 || month == 9 || month == 11)//4 6 9 11月的日历
{
//printf("其他月份\n");
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
printf("29 30\n");
}
else//2月的日历
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
}
}
month++;
}
}
void CalculateDay(int year,int month,int day)//计算天数
{
//int year;
//int month;
//int day;
//printf("请输入要查询的日期\n");
//scanf("%d/%d/%d", &year, &month, &day);
time_t t;
struct tm *local;
time(&t);
local = localtime(&t);
int ThisYear = 1900 + local->tm_year;
int ThisDay = local->tm_mday;
int ThisWeek = local->tm_wday;
int Next1ThisYear = ThisYear - 1;//现实时间大
int Next2ThisYear = ThisYear + 1;//现实时间小
int ThisMonth = 1 + local->tm_mon;
int Next1ThisMonth = ThisMonth - 1;
int Next2ThisMonth = ThisMonth + 1;
int Next1Month = month + 1;
int Next2Month = month - 1;
int TotalGapDay = 0;
int TotalGapLeapYear = 0;
int TotalGapYear = 0;
int BigMonth = 0;
int LittleMonth = 0;
int SecondMonth = 0;
int WeekResult = 0;
int RetMonth = 0;
int InputDay = 0;
int InputThisDay = 0;
int LeapSecondMonth = 0;
int NotLeapSecondMonth = 0;
if (Next1ThisYear >= year)
{
while (Next1ThisYear > year)
{
int ret;
ret = JudgeLeapYear(Next1ThisYear);
if (ret == 1)
{
TotalGapLeapYear++;
}
else
{
TotalGapYear++;
}
Next1ThisYear--;
}
}
else
{
while (Next2ThisYear < year)
{
int ret;
ret = JudgeLeapYear(Next2ThisYear);
if (ret == 1)
{
TotalGapLeapYear++;
}
else
{
TotalGapYear++;
}
Next2ThisYear++;
}
}
while (Next1ThisMonth >= 1 && year<ThisYear)
{
while (year < ThisYear&&Next1Month <= 12)//输入不是本年的月份情况
{
if (Next1Month == 1 || Next1Month == 3 || Next1Month == 5 || Next1Month == 7
|| Next1Month == 8 || Next1Month == 10 || Next1Month == 12)
{
BigMonth++;
}
else if (Next1Month == 4 || Next1Month == 6 || Next1Month == 9 || Next1Month == 11)
{
LittleMonth++;
}
else
{
int ret = 0;
ret = JudgeLeapYear(year);
if (ret == 1)
{
LeapSecondMonth++;
}
else
{
NotLeapSecondMonth++;
}
}
Next1Month++;
}
if (Next1ThisMonth == 1 || Next1ThisMonth == 3 || Next1ThisMonth == 5 || Next1ThisMonth == 7
|| Next1ThisMonth == 8 || Next1ThisMonth == 10 || Next1ThisMonth == 12)
{
BigMonth++;
}
else if (Next1ThisMonth == 4 || Next1ThisMonth == 6 || Next1ThisMonth == 9 || Next1ThisMonth == 11)
{
LittleMonth++;
}
else
{
int ret = 0;
ret = JudgeLeapYear(ThisYear);
if (ret == 1)
{
LeapSecondMonth++;
}
else
{
NotLeapSecondMonth++;
}
}
Next1ThisMonth--;
}
while (Next2Month >= 1 && year > ThisYear)
{
while (year >ThisYear&&Next2ThisMonth <= 12)//不是本年输入年份的月份情况
{
if (Next2ThisMonth == 1 || Next2ThisMonth == 3 || Next2ThisMonth == 5 || Next2ThisMonth == 7
|| Next2ThisMonth == 8 || Next2ThisMonth == 10 || Next2ThisMonth == 12)
{
BigMonth++;
}
else if (Next2ThisMonth == 4 || Next2ThisMonth == 6 || Next2ThisMonth == 9
|| Next2ThisMonth == 11)
{
LittleMonth++;
}
else
{
int ret = 0;
ret = JudgeLeapYear(ThisYear);
if (ret == 1)
{
LeapSecondMonth++;
}
else
{
NotLeapSecondMonth++;
}
}
Next2ThisMonth++;
}
if (Next2Month == 1 || Next2Month == 3 || Next2Month == 5 || Next2Month == 7
|| Next2Month == 8 || Next2Month == 10 || Next2Month == 12)
{
BigMonth++;
}
else if (Next2Month == 4 || Next2Month == 6 || Next2Month == 9 || Next2Month == 11)
{
LittleMonth++;
}
else
{
int ret = 0;
ret = JudgeLeapYear(year);
if (ret == 1)
{
LeapSecondMonth++;
}
else
{
NotLeapSecondMonth++;
}
}
Next2Month--;
}
if (year == ThisYear)
{
if (month > ThisMonth)
{
while (Next2Month > ThisMonth)
{
if (Next2Month == 1 || Next2Month == 3 || Next2Month == 5 || Next2Month == 7
|| Next2Month == 8 || Next2Month == 10 || Next2Month == 12)
{
BigMonth++;
}
else if (Next2Month == 4 || Next2Month == 6 || Next2Month == 9 || Next2Month == 11)
{
LittleMonth++;
}
else if (Next2Month == 2)
{
int ret = 0;
ret = JudgeLeapYear(year);
if (ret == 1)
{
LeapSecondMonth++;
}
else
{
NotLeapSecondMonth++;
}
}
Next2Month--;
}
}
else if (month < ThisMonth)
{
while (Next1Month < ThisMonth)
{
if (Next1Month == 1 || Next1Month == 3 || Next1Month == 5 || Next1Month == 7
|| Next1Month == 8 || Next1Month == 10 || Next1Month == 12)
{
BigMonth++;
}
else if (Next1Month == 4 || Next1Month == 6 || Next1Month == 9 || Next1Month == 11)
{
LittleMonth++;
}
else if (Next1Month == 2)
{
int ret = 0;
ret = JudgeLeapYear(year);
if (ret == 1)
{
LeapSecondMonth++;
}
else
{
NotLeapSecondMonth++;
}
}
Next1Month++;
}
}
else
{
if (day >= ThisDay)
{
printf("同年同一个月,相差%d天\n", day - ThisDay);
TotalGapDay = day - ThisDay;
if (TotalGapDay % 7 == 0)
{
WeekResult = ThisWeek;
}
else
{
if ((TotalGapDay % 7 + ThisWeek) <= 7)
{
WeekResult = TotalGapDay % 7 + ThisWeek;
}
else
{
WeekResult = TotalGapDay % 7 + ThisWeek - 7;
}
}
printf("今天是星期%d\n", WeekResult);
return;
}
else
{
printf("同年同一个月,相差%d天\n", ThisDay - day);
TotalGapDay = ThisDay - day;
if (TotalGapDay % 7 == 0)
{
WeekResult = ThisWeek;
}
else
{
if ((ThisWeek - TotalGapDay % 7) >= 0)
{
WeekResult = ThisWeek - TotalGapDay % 7;
}
else
{
WeekResult = 7 - TotalGapDay % 7 + ThisWeek;
}
}
printf("今天是星期%d\n", WeekResult);
return;
}
}
}
if (year < ThisYear)
{
InputThisDay = ThisDay;
RetMonth = JudgeMonth(month);
if (RetMonth == 1)
{
InputDay = 31 - day;
}
else if (RetMonth == 0)
{
InputDay = 30 - day;
}
else
{
int ret = JudgeLeapYear(year);
if (ret == 1)
{
InputDay = 29 - day;
}
else
{
InputDay = 28 - day;
}
}
}
else if (year > ThisYear)
{
InputDay = day;
RetMonth = JudgeMonth(ThisMonth);
if (RetMonth == 1)
{
InputThisDay = 31 - ThisDay;
}
else if (RetMonth == 0)
{
InputThisDay = 30 - ThisDay;
}
else
{
int ret = JudgeLeapYear(ThisYear);
if (ret == 1)
{
InputThisDay = 29 - ThisDay;
}
else
{
InputThisDay = 28 - ThisDay;
}
}
}
else
{
if (month < ThisMonth)
{
InputThisDay = ThisDay;
RetMonth = JudgeMonth(month);
if (RetMonth == 1)
{
InputDay = 31 - day;
}
else if (RetMonth == 0)
{
InputDay = 30 - day;
}
else
{
int ret = JudgeLeapYear(year);
if (ret == 1)
{
InputDay = 29 - day;
}
else
{
InputDay = 28 - day;
}
}
}
else if (month > ThisMonth)
{
InputDay = day;
RetMonth = JudgeMonth(ThisMonth);
if (RetMonth == 1)
{
InputThisDay = 31 - ThisDay;
}
else if (RetMonth == 0)
{
InputThisDay = 30 - ThisDay;
}
else
{
int ret = JudgeLeapYear(year);
if (ret == 1)
{
InputThisDay = 29 - ThisDay;
}
else
{
InputThisDay = 28 - ThisDay;
}
}
}
}
TotalGapDay = TotalGapYear * 365 + TotalGapLeapYear * 366 + BigMonth * 31 + LittleMonth * 30 + LeapSecondMonth * 29 + NotLeapSecondMonth * 28 + InputThisDay + InputDay;
printf("相差%d天\n", TotalGapDay);
}
int JudgeMonth(int month)//判断月份
{
int ret = 0;
if (month == 1 ||month == 3 ||month == 5 || month == 7
|| month == 8 || month == 10 || month == 12)
{
ret = 1;
return ret;
}
else if (month == 4 || month == 6 || month == 9 || month == 11)
{
return ret;
}
else
{
ret = -1;
return ret;
}
}
int JudgeLeapYear(int year)//判断是否为闰年
{
int ret=0;
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
{
ret = 1;
return ret;
}
else
{
return ret;
}
}
void ReturnMenu()//回主菜单
{
CalendarTable();
}
void ShowData()//显示当前日期
{
struct tm *local;
time_t t;
t = time(NULL);
local = localtime(&t);
printf("%d", 1900 + local->tm_year);
printf("/");
printf("%d", 1 + local->tm_mon);
printf("/");
printf("%d\n", local->tm_mday);
}
void ShowTime()//显示当前时间
{
struct tm *local;
time_t t;
t = time(NULL);
local = localtime(&t);//local->tm_hour, local->tm_min, local->tm_sec
printf("%d:", local->tm_hour);
printf("%d:", local->tm_min);
printf("%d\n", local->tm_sec);
}
void ShowDataTime()//显示日期时间
{
struct tm *local;
time_t t;
t = time(NULL);
local = localtime(&t);
printf("%d:", local->tm_hour);
printf("%d:", local->tm_min);
printf("%d\n", local->tm_sec);
printf("%d", 1900 + local->tm_year);
printf("/");
printf("%d", 1 + local->tm_mon);
printf("/");
printf("%d\n", local->tm_mday);
}
void ShowDynamicTime()//动态显示时间
{
while (1)
{
time_t t;
struct tm *local;
time(&t);
local = localtime(&t);
printf("%d/%d/%d %d:%d:%d\n", 1900 + local->tm_year, 1 + local->tm_mon,
local->tm_mday, local->tm_hour, local->tm_min, local->tm_sec);
Sleep(1000);
}
}
void ShowMonth()//显示本月日历表
{
time_t t;
struct tm *local;
time(&t);
local = localtime(&t);
int ThisYear = 1900+local->tm_year;
printf("%d\n", ThisYear);
int ThisMonth = 1 + local->tm_mon;
if ((ThisYear %4 == 0 && ThisYear %100 != 0)||(ThisYear % 400 == 0))//是闰年
{
printf("是闰年\n");
printf("************************\n");
printf("本月日历\n");
if (ThisMonth == 1 || ThisMonth == 3 || ThisMonth == 5 || ThisMonth == 7 || ThisMonth == 8 || ThisMonth == 10 || ThisMonth == 12)//1 3 5 7 8 10 12月的日历
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
printf("29 30 31\n");
}
else if (ThisMonth == 4 || ThisMonth == 6 || ThisMonth == 9 || ThisMonth == 11)//4 6 9 11月的日历
{
printf("其他月份\n");
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
printf("29 30\n");
}
else//2月的日历
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
printf("29\n");
}
}
else
{
printf("不是闰年\n");
printf("************************\n");
printf("本月日历\n");
if (ThisMonth == 1 || ThisMonth == 3 || ThisMonth == 5 || ThisMonth == 7 || ThisMonth == 8 || ThisMonth == 10 || ThisMonth == 12)//1 3 5 7 8 10 12月的日历
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
printf("29 30 31\n");
}
else if (ThisMonth == 4 || ThisMonth == 6 || ThisMonth == 9 || ThisMonth == 11)//4 6 9 11月的日历
{
printf("其他月份\n");
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
printf("29 30\n");
}
else//2月的日历
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
}
}
}
/**************************/
void CheckWeek()//查询***是星期几
{
int year;
int month;
int day;
printf("请输入要查询的日期\n");
scanf("%d/%d/%d", &year, &month, &day);
time_t t;
struct tm *local;
time(&t);
local = localtime(&t);
int ThisYear = 1900 + local->tm_year;
int ThisDay = local->tm_mday;
int ThisWeek = local->tm_wday;
int Next1ThisYear = ThisYear - 1;//现实时间大
int Next2ThisYear = ThisYear + 1;//现实时间小
int ThisMonth = 1 + local->tm_mon;
int Next1ThisMonth = ThisMonth - 1;
int Next2ThisMonth = ThisMonth+1;
int Next1Month = month + 1;
int Next2Month = month - 1;
int TotalGapDay = 0;
int TotalGapLeapYear = 0;
int TotalGapYear = 0;
int BigMonth = 0;
int LittleMonth = 0;
int SecondMonth = 0;
int WeekResult = 0;
int RetMonth = 0;
int InputDay = 0;
int InputThisDay = 0;
int LeapSecondMonth = 0;
int NotLeapSecondMonth = 0;
if (Next1ThisYear >= year)
{
while (Next1ThisYear > year)
{
int ret;
ret = JudgeLeapYear(Next1ThisYear);
if (ret == 1)
{
TotalGapLeapYear++;
}
else
{
TotalGapYear++;
}
Next1ThisYear--;
}
}
else
{
while (Next2ThisYear < year)
{
int ret;
ret = JudgeLeapYear(Next2ThisYear);
if (ret == 1)
{
TotalGapLeapYear++;
}
else
{
TotalGapYear++;
}
Next2ThisYear++;
}
}
while (Next1ThisMonth >= 1&&year<ThisYear)
{
while (year < ThisYear&&Next1Month <= 12)//输入不是本年的月份情况
{
if (Next1Month == 1 || Next1Month == 3 || Next1Month == 5 || Next1Month == 7
|| Next1Month == 8 || Next1Month == 10 || Next1Month == 12)
{
BigMonth++;
}
else if (Next1Month == 4 || Next1Month == 6 || Next1Month == 9 || Next1Month == 11)
{
LittleMonth++;
}
else
{
int ret = 0;
ret = JudgeLeapYear(year);
if (ret == 1)
{
LeapSecondMonth++;
}
else
{
NotLeapSecondMonth++;
}
}
Next1Month++;
}
if (Next1ThisMonth == 1 || Next1ThisMonth == 3 || Next1ThisMonth == 5 || Next1ThisMonth == 7
|| Next1ThisMonth == 8 || Next1ThisMonth == 10 || Next1ThisMonth == 12)
{
BigMonth++;
}
else if (Next1ThisMonth == 4 || Next1ThisMonth == 6 || Next1ThisMonth == 9 || Next1ThisMonth == 11)
{
LittleMonth++;
}
else
{
int ret = 0;
ret = JudgeLeapYear(ThisYear);
if (ret == 1)
{
LeapSecondMonth++;
}
else
{
NotLeapSecondMonth++;
}
}
Next1ThisMonth--;
}
while (Next2Month >= 1 && year > ThisYear)
{
while (year >ThisYear&&Next2ThisMonth <=12)//不是本年输入年份的月份情况
{
if (Next2ThisMonth == 1 || Next2ThisMonth == 3 || Next2ThisMonth == 5 || Next2ThisMonth == 7
|| Next2ThisMonth == 8 || Next2ThisMonth == 10 || Next2ThisMonth == 12)
{
BigMonth++;
}
else if (Next2ThisMonth == 4 || Next2ThisMonth == 6 || Next2ThisMonth == 9
|| Next2ThisMonth == 11)
{
LittleMonth++;
}
else
{
int ret=0;
ret=JudgeLeapYear(ThisYear);
if (ret == 1)
{
LeapSecondMonth++;
}
else
{
NotLeapSecondMonth++;
}
}
Next2ThisMonth++;
}
if (Next2Month == 1 || Next2Month == 3 || Next2Month == 5 || Next2Month == 7
|| Next2Month == 8 || Next2Month == 10 || Next2Month == 12)
{
BigMonth++;
}
else if (Next2Month == 4 || Next2Month == 6 || Next2Month == 9 || Next2Month == 11)
{
LittleMonth++;
}
else
{
int ret = 0;
ret = JudgeLeapYear(year);
if (ret == 1)
{
LeapSecondMonth++;
}
else
{
NotLeapSecondMonth++;
}
}
Next2Month--;
}
if (year == ThisYear)
{
if (month > ThisMonth)
{
while (Next2Month > ThisMonth)
{
if (Next2Month == 1 || Next2Month == 3 || Next2Month == 5 || Next2Month == 7
|| Next2Month == 8 || Next2Month == 10 || Next2Month == 12)
{
BigMonth++;
}
else if (Next2Month == 4 || Next2Month == 6 || Next2Month == 9 || Next2Month == 11)
{
LittleMonth++;
}
else if (Next2Month==2)
{
int ret = 0;
ret = JudgeLeapYear(year);
if (ret == 1)
{
LeapSecondMonth++;
}
else
{
NotLeapSecondMonth++;
}
}
Next2Month--;
}
}
else if (month < ThisMonth)
{
while (Next1Month < ThisMonth)
{
if (Next1Month == 1 || Next1Month == 3 || Next1Month == 5 || Next1Month == 7
|| Next1Month == 8 || Next1Month == 10 || Next1Month == 12)
{
BigMonth++;
}
else if (Next1Month == 4 || Next1Month == 6 || Next1Month == 9 || Next1Month == 11)
{
LittleMonth++;
}
else if (Next1Month == 2)
{
int ret = 0;
ret = JudgeLeapYear(year);
if (ret == 1)
{
LeapSecondMonth++;
}
else
{
NotLeapSecondMonth++;
}
}
Next1Month++;
}
}
else
{
if (day >= ThisDay)
{
printf("同年同一个月,相差%d天\n", day - ThisDay);
TotalGapDay = day - ThisDay;
if (TotalGapDay % 7 == 0)
{
WeekResult = ThisWeek;
}
else
{
if ((TotalGapDay % 7 + ThisWeek) <= 7)
{
WeekResult = TotalGapDay % 7 + ThisWeek;
}
else
{
WeekResult = TotalGapDay % 7 + ThisWeek - 7;
}
}
printf("今天是星期%d\n", WeekResult);
return;
}
else
{
printf("同年同一个月,相差%d天\n", ThisDay - day);
TotalGapDay = ThisDay - day;
if (TotalGapDay % 7 == 0)
{
WeekResult = ThisWeek;
}
else
{
if ((ThisWeek - TotalGapDay % 7) >= 0)
{
WeekResult = ThisWeek - TotalGapDay % 7;
}
else
{
WeekResult = 7 - TotalGapDay % 7 + ThisWeek;
}
}
printf("今天是星期%d\n", WeekResult);
return;
}
}
}
if (year < ThisYear)
{
InputThisDay = ThisDay;
RetMonth = JudgeMonth(month);
if (RetMonth == 1)
{
InputDay = 31 - day;
}
else if (RetMonth == 0)
{
InputDay = 30 - day;
}
else
{
int ret = JudgeLeapYear(year);
if (ret == 1)
{
InputDay = 29 - day;
}
else
{
InputDay = 28 - day;
}
}
}
else if (year > ThisYear)
{
InputDay = day;
RetMonth = JudgeMonth(ThisMonth);
if (RetMonth == 1)
{
InputThisDay = 31 - ThisDay;
}
else if (RetMonth == 0)
{
InputThisDay = 30 -ThisDay;
}
else
{
int ret = JudgeLeapYear(ThisYear);
if (ret == 1)
{
InputThisDay = 29 - ThisDay;
}
else
{
InputThisDay = 28 - ThisDay;
}
}
}
else
{
if (month < ThisMonth)
{
InputThisDay = ThisDay;
RetMonth = JudgeMonth(month);
if (RetMonth == 1)
{
InputDay = 31 - day;
}
else if (RetMonth == 0)
{
InputDay = 30 - day;
}
else
{
int ret = JudgeLeapYear(year);
if (ret == 1)
{
InputDay = 29 - day;
}
else
{
InputDay = 28 - day;
}
}
}
else if (month > ThisMonth)
{
InputDay = day;
RetMonth = JudgeMonth(ThisMonth);
if (RetMonth == 1)
{
InputThisDay = 31 - ThisDay;
}
else if (RetMonth == 0)
{
InputThisDay = 30 - ThisDay;
}
else
{
int ret = JudgeLeapYear(year);
if (ret == 1)
{
InputThisDay = 29 - ThisDay;
}
else
{
InputThisDay = 28 - ThisDay;
}
}
}
}
TotalGapDay = TotalGapYear * 365 + TotalGapLeapYear * 366 + BigMonth * 31 + LittleMonth * 30 + LeapSecondMonth * 29+NotLeapSecondMonth*28 + InputThisDay + InputDay;
printf("相差%d天\n", TotalGapDay);
if (year < ThisYear)
{
if (TotalGapDay % 7 == 0)
{
WeekResult = ThisWeek;
}
else
{
if ((ThisWeek - TotalGapDay % 7) >= 0)
{
WeekResult = ThisWeek - TotalGapDay % 7;
}
else
{
WeekResult = 7 - TotalGapDay % 7 + ThisWeek;
}
}
printf("今天是星期%d\n", WeekResult);
}
else
{
if (TotalGapDay % 7 == 0)
{
WeekResult = ThisWeek;
}
else
{
if ((TotalGapDay % 7 + ThisWeek) <= 7)
{
WeekResult = TotalGapDay % 7 + ThisWeek;
}
else
{
WeekResult = TotalGapDay % 7 + ThisWeek - 7;
}
}
printf("今天是星期%d\n", WeekResult);
}
}
void CheckWeekLater()//查询***几天之后是星期几
{
time_t t;
struct tm *local;
time(&t);
local = localtime(&t);
int ThisWeek = local->tm_wday;
int LaterTotalGapDay = 0;
int WeekResult = 0;
printf("输入今天后的天数\n");
scanf("%d", &LaterTotalGapDay);
if (LaterTotalGapDay % 7 == 0)
{
WeekResult = ThisWeek;
}
else
{
if ((LaterTotalGapDay % 7 + ThisWeek) <= 7)
{
WeekResult = LaterTotalGapDay % 7 + ThisWeek;
}
else
{
WeekResult = LaterTotalGapDay % 7 + ThisWeek - 7;
}
}
printf("今天是星期%d\n", WeekResult);
}
void CheckWeekBefore()//查询***几天之前是星期几
{
time_t t;
struct tm *local;
time(&t);
local = localtime(&t);
int ThisWeek = local->tm_wday;
int BeforeTotalGapDay = 0;
int WeekResult = 0;
printf("输入今天前的天数:\n");
scanf("%d", &BeforeTotalGapDay);
if (BeforeTotalGapDay % 7 == 0)
{
WeekResult = ThisWeek;
}
else
{
if ((ThisWeek - BeforeTotalGapDay % 7) >= 0)
{
WeekResult = ThisWeek - BeforeTotalGapDay % 7;
}
else
{
WeekResult = 7 - BeforeTotalGapDay % 7 + ThisWeek;
}
}
printf("今天是星期%d\n", WeekResult);
}
void CheckMonth()//查询***月的日历表
{
int year;
int month;
int ReturnYear;
int ReturnMonth;
printf("输入某年份的某月:");
scanf("%d%d",&year,&month);
ReturnMonth = JudgeMonth(month);
if (ReturnMonth == 1)
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
printf("29 30 31\n");
}
else if (ReturnMonth == 0)
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
printf("29 30\n");
}
else
{
ReturnYear = JudgeLeapYear(year);
if (ReturnYear == 1)
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
printf("29\n");
}
else
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
}
}
}
void CheckYear()//查询***年的日历表
{
int year;
printf("输入要显示的年份:\n");
scanf("%d",&year);
ShowEveryMonth(year);
}
void CheckDays()//查询***距离现在多少天
{
int year;
int month;
int day;
printf("请输入要查询的日期\n");
scanf("%d/%d/%d", &year, &month, &day);
CalculateDay(year, month, day);
}
/****************************/
void LastMonth()//上一个月
{
time_t t;
struct tm *local;
time(&t);
local = localtime(&t);
int ThisMonth = 1+local->tm_mon;
int ThisYear = 1900+local->tm_year;
if (ThisMonth > 1)
{
int NextMonth = ThisMonth - 1;
int ReturnMonth = JudgeMonth(NextMonth);
if (ReturnMonth == 1)
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
printf("29 30 31\n");
}
else if (ReturnMonth == 0)
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
printf("29 30\n");
}
else
{
int ReturnYear = JudgeLeapYear(ThisYear);
if (ReturnYear == 1)
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
printf("29\n");
}
else
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
}
}
}
else if (ThisMonth == 1)
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
printf("29 30 31\n");
}
}
void NextMonth()//下一个月
{
time_t t;
struct tm *local;
time(&t);
local = localtime(&t);
int ThisMonth = 1+local->tm_mon;
int ThisYear = 1900+local->tm_year;
if (ThisMonth <12)
{
int NextMonth = ThisMonth+1;
int ReturnMonth = JudgeMonth(NextMonth);
if (ReturnMonth == 1)
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
printf("29 30 31\n");
}
else if (ReturnMonth == 0)
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
printf("29 30\n");
}
else
{
int ReturnYear = JudgeLeapYear(ThisYear);
if (ReturnYear == 1)
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
printf("29\n");
}
else
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
}
}
}
else if (ThisMonth == 12)
{
printf("1 2 3 4 5 6 7\n");
printf("8 9 10 11 12 13 14\n");
printf("15 16 17 18 19 20 21\n");
printf("22 23 24 25 26 27 28\n");
printf("29 30 31\n");
}
}
void LastYear()//上一年
{
time_t t;
struct tm *local;
time(&t);
local = localtime(&t);
int ThisYear = 1900 + local->tm_year;
int NextYear = ThisYear - 1;
ShowEveryMonth(NextYear);
}
void NextYear()//下一年
{
time_t t;
struct tm *local;
time(&t);
local = localtime(&t);
int ThisYear = 1900 + local->tm_year;
int NextYear = ThisYear + 1;
ShowEveryMonth(NextMonth);
}
void SaveCalendar()//保存当前日历
{
time_t t;
struct tm *local;
time(&t);
local = localtime(&t);
int ThisYear = 1900 + local->tm_year;
int ThisMonth = 1 + local->tm_mon;
int ThisDay = local->tm_mday;
FILE *fOut;
char strYear[15] = {‘a‘};
char strMonth[3]={‘a‘};
char strDay[3] = {‘a‘};
int i = 0;
int n = 0;
_itoa(ThisYear, strYear, 10);
_itoa(ThisMonth, strMonth, 10);
_itoa(ThisDay, strDay, 10);
strcat(strYear, strMonth);
strcat(strYear, strDay);
n = strlen(strYear);
if ((fOut = fopen("rili.txt", "w")) != NULL)
{
for (i = 0; i < n;i++)
{
fputc(strYear[i], fOut);
}
fputc(‘\0‘, fOut);
printf("日期保存成功\n");
}
else
{
printf("打开文件失败\n");
}
fclose(fOut);
}
/********************************/
void AddMemorandum()//添加备忘录信息
{
int count = 0;
char message[30];
char data[10];
int i = 0;
int k = 0;
FILE *fOut=fopen("beiwang.txt","wb");
printf("是否要添加\n");
while (1)
{
scanf("%d", &i);
if (i == 1)
{
printf("请输入添加备忘录的信息:\n");
scanf("%s", data);
scanf("%s", message);
int LenData = strlen(data)+1;
int LenMessage = strlen(message)+1;
int j = 0;
if (fOut!= NULL)
{
for (j = 0; j < LenData; j++)
{
fputc(data[j], fOut);
}
fputc(‘\n‘,fOut);
for (j = 0; j < LenMessage; j++)
{
fputc(message[j], fOut);
}
fputc(‘\n‘, fOut);
}
else
{
printf("打开文件失败\n");
}
count++;
printf("成功添加一个备忘录\n");
}
else
{
fclose(fOut);
printf("不再添加\n");
break;
}
}
}
void DelateMemorandum()//删除备忘录信息
{
FILE *fIn = fopen("beiwang.txt", "wb");
if (fIn != NULL)
{
remove("beiwang.txt");
}
else
{
printf("打开文件失败\n");
}
fclose(fIn);
}
void ChangeMemorandum()//更改备忘录信息
{
FILE *fOut = fopen("output.txt", "wb");
FILE *fIn = fopen("beiwang.txt", "rb");
char str[10];
printf("输入要修改备忘录的日期:\n");
scanf("%s",str);
if (fOut == NULL || fIn == NULL)
{
printf("打开文件失败\n");
}
else
{
char message[100];
while (fgets(message,100,fIn))
{
int ret = 1;
ret = strcmp(str, message);
if (ret == 0)
{
int i = 0;
printf("修改本天的备忘信息:\n");
char NewStr[100];
scanf("%s", NewStr);
fputs(message, fOut);
fgets(message, 100, fIn);
while (NewStr[i] != ‘\0‘)
{
fputc(NewStr[i],fOut);
i++;
}
fputc(‘\0‘, fOut);
}
else
{
fputs(message, fOut);
fgets(message, 100, fIn);
fputs(message, fOut);
}
}
}
fclose(fIn);
fclose(fOut);
}
void CheckMemorandum()//查询备忘录信息
{
FILE *fIn = fopen("beiwang.txt", "rb");
char str[100];
char CheckStr[10];
scanf("%s", CheckStr);
if (fIn != NULL)
{
while (1)
{
int ret = 1;
fgets(str, 100, fIn);
ret = strcmp(CheckStr, str);
if (ret == 0)
{
fgets(str, 100, fIn);
printf("本天应该做的:");
printf("%s\n", str);
break;
}
else
{
if (fgets(str, 100, fIn) == NULL)
{
printf("本天没有备忘信息\n");
break;
}
else
{
}
}
}
}
else
{
printf("打开文件失败\n");
}
}
void ShowMemorandum()//展示备忘录信息
{
FILE *fIn = fopen("beiwang.txt", "rb");
char str[50];
while ((fgets(str, 50, fIn))!=NULL)
{
printf("%s\n", str);
}
}
/**************************************************************************/
void Memorandum()//日期备忘录
{
int k;
scanf_s("%d", &k);
switch (k)
{
case 1:
printf("添加备忘录信息\n");
AddMemorandum();
break;
case 2:
printf("删除备忘录信息\n");
DelateMemorandum();
break;
case 3:
printf("更改备忘录信息\n");
ChangeMemorandum();
break;
case 4:
printf("查询备忘录信息\n");
CheckMemorandum();
break;
case 5:
printf("备忘录信息展示\n");
ShowMemorandum();
break;
case 0:
printf("退出备忘录\n");
ReturnMenu();
break;
}
}
/******************************/
void AlterCalendarTable()//修改日历
{
int key1=0;
int key2 = 0;
key1 = getch();
key2 = getch();
switch (key2)
{
case 72:
printf("上一个月:\n");
LastMonth();
break;
case 80:
printf("下一个月:\n");
NextMonth();
break;
case 75:
printf("上一年:\n");
LastYear();
break;
case 77:
printf("下一年:\n");
NextYear();
break;
case 71:
printf("保存当前日历\n");
SaveCalendar();
break;
case 79:
printf("返回主菜单\n");
ReturnMenu();
break;
}
}
/****************************/
void CheckCalendarTable()//日历查询
{
int j;
scanf_s("%d",&j);
switch (j)
{
case 1:
printf("查询***是星期几\n");
CheckWeek();
break;
case 2:
printf("查询***几天之后是星期几\n");
CheckWeekLater();
break;
case 3:
printf("查询***几天之前是星期几\n");
CheckWeekBefore();
break;
case 4:
printf("查询***月的日历表\n");
CheckMonth();
break;
case 5:
printf("查询***年的日历表\n");
CheckYear();
break;
case 6:
printf("查询***距离现在多少天\n");
CheckDays();
break;
case 0:
printf("返回主菜单\n");
ReturnMenu();
break;
}
}
/***************************/
void ShowCalendarTable()//日历显示
{
int m;
scanf_s("%d", &m);
switch (m)
{
case 1:
printf("显示当前日期\n");
ShowData();
break;
case 2:
printf("显示当前时间\n");
ShowTime();
break;
case 3:
printf("显示日期时间\n");
ShowDataTime();
break;
case 4:
printf("动态显示时间\n");
ShowDynamicTime();
break;
case 5:
printf("显示本月日历表\n");
ShowMonth();
break;
case 0:
printf("返回主菜单\n");
ReturnMenu();
break;
}
}
/*********************************/
void HelpMessage()//信息帮助
{
char str1[] = "1的功能是显示相应的日历表,里面的不同键又可以实现更详细的功能";
char str2[] = "2的功能是查询相应的日历表,里面的不同键又可以实现更详细的功能";
char str3[] = "3的功能是修改相应的日历表,里面的不同键又可以实现更详细的功能";
char str4[] = "4的功能是日历表的备忘录,里面的不同键又可以实现更详细的功能";
char str5[] = "5的功能是信息帮助";
char str0[] = "0的功能是直接退出日历表";
FILE *fOut = fopen("HelpMessage.txt", "wb");
if (fOut == NULL)
{
printf("打开文件失败\n");
}
else
{
int i = 0;
while (str1[i] != ‘\0‘)
{
fputc(str1[i], fOut);
i++;
}
fputc(‘\n‘, fOut);
i = 0;
while (str2[i] != ‘\0‘)
{
fputc(str2[i], fOut);
i++;
}
fputc(‘\n‘, fOut);
i = 0;
while (str3[i] != ‘\0‘)
{
fputc(str3[i], fOut);
i++;
}
fputc(‘\n‘, fOut);
i = 0;
while (str4[i] != ‘\0‘)
{
fputc(str4[i], fOut);
i++;
}
fputc(‘\n‘, fOut);
i = 0;
while (str5[i] != ‘\0‘)
{
fputc(str5[i], fOut);
i++;
}
fputc(‘\n‘, fOut);
i = 0;
while (str0[i] != ‘\0‘)
{
fputc(str0[i], fOut);
i++;
}
fputc(‘\n‘, fOut);
fclose(fOut);
}
}
/**************************************************************************/
void CalendarTable()
{
int n;
scanf_s("%d", &n);
switch (n)
{
case 1:
printf("日历显示\n");
ShowCalendarTable();
break;
case 2:
printf("日历查询\n");
CheckCalendarTable();
break;
case 3:
printf("修改日历\n");
AlterCalendarTable();
break;
case 4:
printf("日历备忘录\n");
Memorandum();
break;
case 5:
printf("信息帮助\n");
HelpMessage();
break;
case 0:
printf("退出系统\n");
exit(0);
break;
}
}
只是实现了软解的各接口功能,要想有更好的用户体验还有改进的地方。
本文出自 “anser” 博客,请务必保留此出处http://674353165.blog.51cto.com/10786549/1744628
原文地址:http://674353165.blog.51cto.com/10786549/1744628