C++课程设计
来源:互联网 发布:java拦截器例子 编辑:程序博客网 时间:2024/06/05 18:11
日历记事本
要求:带有日程提醒功能的日历。
显示信息:用户可以向前查询前一个月的日期,也可以向后查询下一个月的日期。
定时提醒:用户可以针对某一天来添加,删除和编辑这一天的日程提醒信息,当系统时间和提醒时间相吻合时,给出具有提示信息的对话框。
查询信息:用户可以查询到某个月的所有的提示信息
#include <iostream>#include <string>#include <iomanip>//格式输出如左对齐右对齐等#include <fstream>#include <ctime>#include <cassert>//cassert里面主要是定义了assert宏#include <conio.h>//包含getch()函数的头文件,conio.h是基本输入输出库,主要是文件和标准控制台的输入输出。里面有一个很常用的清屏函数clrsr()可以清屏! using namespace std;class Notes{public: Notes();//默认构造函数 void new_notes();//新建记事 void alter_notes();//修改记事 void delet_notes();//删除记事 void scan_notes();//浏览记事char choose_time();//选择记事的时间char choose_thing();//选择事件的种类private: string signs;//标题 string data;//日期 string description;//事件描述};//日期类class whatdata{public: whatdata();//默认构造函数 int IsLeapYear(int Year); //判断是否是闰年 long YearDays(int Year); //计算某一年到1900年一月一日的相距天数 long TotalDays(int Year, int Month, int Day);//计算某年某月某日到1900年一月一日的相距天数 int GetLunar(int Y1, int M1, int D1, int &Y2, int &M2, int &D2); //这要是将公历转化为阴历 void select_day();//万年历之日历查询 void select_month();//万年历之月历查询private: string week; string month; string day; string year;};class calendar_notebook:public Notes,public whatdata{public: char first_page();//首页 void notes_manage();//记事本管理 void search_data();//日历查询};#define BEGINYEAR 1900 #define YEARCOUNT 150 struct LUNARINDEX //农历大小月数据索引结构,数据时间自1900年至2050年 { long Days; // 天数,表示该农历年1月1日距公历元年元月1日的天数 short Mon13; // 该数据的0至12位分别标明农历1至13月的大小,含闰月 short Leap; // 该年的农历闰月值,15表示无闰月。 }LunarIndex[]={ {693626, 0X16D2, 8}, {694010, 0X0752, 15}, {694364, 0X0EA5, 15}, //1900 {694719, 0X164A, 5}, {695102, 0X064B, 15}, {695456, 0X0A9B, 15}, {695811, 0X1556, 4}, {696195, 0X056A, 15}, {696549, 0X0B59, 15}, {696904, 0X1752, 2}, {697288, 0X0752, 15}, {697642, 0X1B25, 6}, {698026, 0X0B25, 15}, {698380, 0X0A4B, 15}, {698734, 0X14AB, 5}, // 1914 {699118, 0X02AD, 15}, {699472, 0X056B, 15}, {699827, 0X0B69, 2}, {700211, 0X0DA9, 15}, {700566, 0X1D92, 7}, {700950, 0X0E92, 15}, {701304, 0X0D25, 15}, {701658, 0X1A4D, 5}, {702042, 0X0A56, 15}, {702396, 0X02B6, 15}, {702750, 0X15B5, 4}, {703135, 0X06D4, 15}, {703489, 0X0EA9, 15}, {703844, 0X1E92, 2}, {704228, 0X0E92, 15}, //1929 {704582, 0X0D26, 6}, {704965, 0X052B, 15}, {705319, 0X0A57, 15}, {705674, 0X12B6, 5}, {706058, 0X0B5A, 15}, {706413, 0X06D4, 15}, {706767, 0X0EC9, 3}, {707151, 0X0749, 15}, {707505, 0X1693, 7}, {707889, 0X0A93, 15}, {708243, 0X052B, 15}, {708597, 0X0A5B, 6}, {708981, 0X0AAD, 15}, {709336, 0X056A, 15}, {709690, 0X1B55, 4}, //1944 {710075, 0X0BA4, 15}, {710429, 0X0B49, 15}, {710783, 0X1A93, 2}, {711167, 0X0A95, 15}, {711521, 0X152D, 7}, {711905, 0X0536, 15}, {712259, 0X0AAD, 15}, {712614, 0X15AA, 5}, {712998, 0X05B2, 15}, {713352, 0X0DA5, 15}, {713707, 0X1D4A, 3}, {714091, 0X0D4A, 15}, {714445, 0X0A95, 8}, {714828, 0X0A97, 15}, {715183, 0X0556, 15}, //1959 {715537, 0X0AB5, 6}, {715921, 0X0AD5, 15}, {716276, 0X06D2, 15}, {716630, 0X0EA5, 4}, {717014, 0X0EA5, 15}, {717369, 0X064A, 15}, {717722, 0X0C97, 3}, {718106, 0X0A9B, 15}, {718461, 0X155A, 7}, {718845, 0X056A, 15}, {719199, 0X0B69, 15}, {719554, 0X1752, 5}, {719938, 0X0B52, 15}, {720292, 0X0B25, 15}, {720646, 0X164B, 4}, //1974 {721030, 0X0A4B, 15}, {721384, 0X14AB, 8}, {721768, 0X02AD, 15}, {722122, 0X056D, 15}, {722477, 0X0B69, 6}, {722861, 0X0DA9, 15}, {723216, 0X0D92, 15}, {723570, 0X1D25, 4}, {723954, 0X0D25, 15}, {724308, 0X1A4D, 10}, {724692, 0X0A56, 15}, {725046, 0X02B6, 15}, {725400, 0X05B5, 6}, {725784, 0X06D5, 15}, {726139, 0X0EA9, 15}, //1989 {726494, 0X1E92, 5}, {726878, 0X0E92, 15}, {727232, 0X0D26, 15}, {727586, 0X0A56, 3}, {727969, 0X0A57, 15}, {728324, 0X14D6, 8}, {728708, 0X035A, 15}, {729062, 0X06D5, 15}, {729417, 0X16C9, 5}, {729801, 0X0749, 15}, {730155, 0X0693, 15}, {730509, 0X152B, 4}, {730893, 0X052B, 15}, {731247, 0X0A5B, 15}, {731602, 0X155A, 2}, //2004 {731986, 0X056A, 15}, {732340, 0X1B55, 7}, {732725, 0X0BA4, 15}, //2007 {733079, 0X0B49, 15}, /*2009*/ {733433, 0X1A93, 5},/*2009*/{733817, 0X0A95, 15}, //2010 {734171, 0X052D, 15}, {734525, 0X0AAD, 4}, {734909, 0X0AB5, 15}, {735264, 0X15AA, 9}, {735648, 0X05D2, 15}, {736002, 0X0DA5, 15}, {736357, 0X1D4A, 6}, {736741, 0X0D4A, 15}, {737095, 0X0C95, 15}, //2019 {737449, 0X152E, 4}, {737833, 0X0556, 15}, {738187, 0X0AB5, 15}, {738542, 0X15B2, 2}, {738926, 0X06D2, 15}, {739280, 0X0EA5, 6}, {739664, 0X0725, 15}, {740018, 0X064B, 15}, {740372, 0X0C97, 5}, {740756, 0X0CAB, 15}, {741111, 0X055A, 15}, {741465, 0X0AD6, 3}, {741849, 0X0B69, 15}, {742204, 0X1752, 11}, {742588, 0X0B52, 15}, //2034 {742942, 0X0B25, 15}, {743296, 0X1A4B, 6}, {743680, 0X0A4B, 15}, {744034, 0X04AB, 15}, {744388, 0X055B, 5}, {744772, 0X05AD, 15}, {745127, 0X0B6A, 15}, {745482, 0X1B52, 2}, {745866, 0X0D92, 15}, {746220, 0X1D25, 7}, {746604, 0X0D25, 15}, {746958, 0X0A55, 15}, {747312, 0X14AD, 5}, {747696, 0X04B6, 15}, {748050, 0X05B5, 15}, //2049 {748405, 0X1DAA, 3}}; //2050 int month1[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};string week1[7]={"星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"};//string weeks[7] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};//默认构造函数Notes::Notes() { description = "xxx";//事件描述 signs = "xxx";//标题 data = "xxx";//日期}//默认构造函数whatdata::whatdata(){ week = "xxx"; month = "xxx"; day = "xxx"; year = "xxx";}//首页char calendar_notebook::first_page(){ system("cls"); char choose; cout << endl;cout<<"\t ● 日 历 记 事 本 ●" <<endl <<"\t ==========================================================" <<endl <<"\t ※ ※" <<endl <<"\t ※ 1. 记事本管理 ※" <<endl <<"\t ※ ※" <<endl <<"\t ※ 2. 日历查询 ※" <<endl<<"\t ※ ※" <<endl<<"\t ※ 3. 关闭日历记事本 ※" <<endl<<"\t ==========================================================" <<endl; choose = getch(); return choose;}//记事本管理void calendar_notebook::notes_manage(){ char choose; while (1) { system("cls");cout<<"\t ● 记 事 本 管 理 ●" <<endl <<"\t ==========================================================" <<endl <<"\t ※ ※" <<endl <<"\t ※ 1. 新建记事 ※" <<endl <<"\t ※ ※" <<endl <<"\t ※ 2. 记事本浏览 ※" <<endl<<"\t ※ ※" <<endl<<"\t ※ 3. 修改记事 ※" <<endl<<"\t ※ ※" <<endl<<"\t ※ 4. 删除查询 ※" <<endl<<"\t ※ ※" <<endl<<"\t ※ 5. 返回 ※" <<endl<<"\t ==========================================================" <<endl; choose = getch(); switch (choose) { case '1':calendar_notebook::new_notes ();//新建记事 break; case '2':calendar_notebook::scan_notes ();//浏览记事 break; case '3': calendar_notebook::alter_notes();//修改记事 break;case '4': calendar_notebook::delet_notes();//删除记事 break;case '5':return;break; default: break; } } }char Notes::choose_time()//辅助新建事件方法的完成,选择记事的种类{char choose; cout<<"\t ● 选择事件种类 ●" <<endl <<"\t ==========================================================" <<endl <<"\t ※ ※" <<endl <<"\t ※ 1. 当前事件 ※" <<endl <<"\t ※ ※" <<endl <<"\t ※ 2. 以后备忘事件 ※" <<endl<<"\t ※ ※" <<endl<<"\t ※ 3. 以往发生事件 ※" <<endl<<"\t ==========================================================" <<endl; cout<<"choose:"; cin>>choose; return(choose);}char Notes::choose_thing(){char choose; cout<<"\t ● 选择事件种类 ●" <<endl <<"\t ==========================================================" <<endl <<"\t ※ ※" <<endl <<"\t ※ 1. 已经发生事件 ※" <<endl <<"\t ※ ※" <<endl <<"\t ※ 2. 以后备忘事件 ※" <<endl<<"\t ==========================================================" <<endl; cout<<"choose:"; cin>>choose; return(choose);}/*新建记事过程:首先选择记事类型,然后输入整个记事内容,将记事存储在一个空文件中,然后将记事的标题和时间输出到专门记录时间和标题的title.txt文件中,然后再新建一个以标题为文件名文件,里面记录了这个事件的全部详细信息。*/void Notes::new_notes(){ system("cls");ofstream tempFile("record\\temp.txt",ios_base::out);//打开临时输出文件,用于输出。这里此文件起中转的作用,里面放的是最新的一个事件 time_t timer;struct tm tm1;char a;a=choose_time();if(a=='1') { time(&timer);//获得当前时间距离1970年一月一日0时0分0秒的秒数, //localtime(&timer)此函数获得的tm结构体的时间,是已经进行过时区转化为本地时间。 //asctime(localtime(&timer))转换为日历时间 cout <<endl <<"时间 : "<<asctime(localtime(&timer)) <<endl;} if (a=='2'||a=='3'){ int year,month; cout<<"请输入事件将要发生的时间(年份应该大于1970年):"<<endl; cout<<"年 "<<"月 "<<"日 "<<"小时 "<<"分钟 "<<"秒 "<<"例如: 2008 7 9 12 12 12"<<endl; cin>>year>>month>>tm1.tm_mday>>tm1.tm_hour>>tm1.tm_min>>tm1.tm_sec ; tm1.tm_year =year-1900; tm1.tm_mon =month-1; tm1.tm_isdst =0; timer = mktime(&tm1); cout <<"时间 : "<<asctime(localtime(&timer)) <<endl; } cout <<"标题 : "; cin >>signs; tempFile <<"标题 : " <<signs <<endl <<"时间:"<<asctime(localtime(&timer)) <<endl <<"内容 : "; cout <<endl <<"内容(以#号键结束) : " << endl; tempFile << endl ; string str; while (1) { cin >>str; if (str[str.length()-1] == '#') { str[str.length()-1] = ' '; tempFile <<str <<endl <<endl; break; } tempFile <<str <<endl <<endl; } tempFile.close();if(a=='1'||a=='3'){ ofstream reFile1("record\\past_things_title.txt", ios::app);//打开输出文件reFile1,并且在文件尾添加数据,reFile1存放的是所有记事的标题和时间 reFile1 <<signs <<endl<<asctime(localtime(&timer)) <<endl; reFile1.close();}if(a=='2'){ ofstream reFile1("record\\memorial_things_title.txt", ios::app); reFile1 <<signs <<endl<<asctime(localtime(&timer)) <<endl; reFile1.close();} string fname = "record\\"+signs+".txt"; ofstream reFile(fname.c_str()); //新建一个以标题为名称的txt文件,将该事件的所有信息记录在该文件里面 ifstream tempFile1("record\\temp.txt"); assert(tempFile1); reFile <<tempFile1.rdbuf();//rdbuf重定向缓冲区,把tempFile1流重新定向到reFile,也就是输出到tempFile的内容,变成输出到reFile里 tempFile1.close(); reFile.close(); cout <<endl <<endl <<"记录已经保存!!!" <<endl <<endl; system("pause"); }/*修改记事过程:首先将所有记事的标题和时间按顺序显示出来(即将文件title.txt文件里面的所有内容读出来),操作者选择要修改的事件种类和事件标题,然后找到所选事件的文件并打开,将该事件详细情况显示出来,让操作者再确认一下是否要修改,确定要修改后在进行修改*/void Notes::alter_notes(){ while (1) { system("cls");cout<<endl<<"请选择你想修改的事件种类"<<endl;char a;a=choose_thing();ifstream reFile;if(a=='1') {reFile.open("record\\past_things_title.txt",ios_base::in);}if(a=='2'){ reFile.open("record\\memorial_things_title.txt",ios_base::in);}int i = 1; if(reFile) {while (reFile >>signs)//将title.txt文件里面的内容都读到标准输出界面上来{ reFile.get(); getline(reFile, data); cout <<i <<".\t" <<setiosflags(ios::left) <<setw(30) <<signs <<" "//设置输出格式 <<data <<endl <<endl; i++;}}else{cout<<"error"<<endl;return;} reFile.close(); cout <<endl <<i <<".\t返回" <<endl <<endl; cout <<endl <<"请选择你想修改的事件: " <<endl <<endl; int select;//选择想修改的事件 cin >>select; if (select == i) return;ifstream reFile2;if(a=='1') {reFile2.open("record\\past_things_title.txt",ios_base::in);}if(a=='2'){ reFile2.open("record\\memorial_things_title.txt",ios_base::in);} assert(reFile2); i = 1;//修改事件 while (reFile2 >>signs) { reFile2.get(); getline(reFile2, data); if (i == select) { string fname = "record\\"+signs+".txt"; system("cls"); ifstream reFile3(fname.c_str()); assert(reFile3); cout <<endl <<"你想修改的内容如下 : " <<endl <<endl; cout <<reFile3.rdbuf(); reFile3.close();cout<<"确定要修改吗?确定请输入1,取消请输入2。"<<endl;int i=0;cin>>i;if(i==1){ cout <<endl <<endl <<"请在下面输入新的内容 (以'#'结束): " <<endl <<endl; cout <<"内容 : "; ofstream reFile4(fname.c_str()); reFile4<<"标题:"<<signs<<endl<<"时间:"<<data<<endl<<"内容:"<<endl; string str; while (1) { cin >>str; if (str[str.length()-1] == '#') { str[str.length()-1] = ' '; reFile4<<str <<endl; break; } reFile4 <<str <<endl; } reFile4.close(); cout <<endl <<endl <<"内容更新完成!!!!" <<endl <<endl;}if(i==2) {cout<<"未修改"<<endl;}if(i!=2&&i!=1){cout<<"输入了错误指令"<<endl;} system("pause"); return; } i++; } reFile2.close(); }}/*删除记事过程: 操作者先选择要删除事件的种类,再将该种类的所有事件显示给操作者看,然后让操作者选择,然后将该条记录删除*/void Notes::delet_notes(){ while (1) { system("cls");char a;cout <<endl <<"请选择一个你想删除的标题 : " <<endl <<endl;a=choose_thing();ifstream reFile;if(a=='1') {reFile.open ("record\\past_things_title.txt",ios_base::in);}if(a=='2'){reFile.open ("record\\memorial_things_title.txt",ios_base::in);} int i = 1;//将所有时间即(title.txt文件的内容)读入到内存并且显示在标准输出界面上if(reFile){ while (reFile >>signs) { reFile.get(); getline(reFile, data); cout <<i <<".\t" <<setiosflags(ios::left) <<setw(30) <<signs <<" " <<data <<endl <<endl; i++; }}else{cout<<"error"<<endl;} reFile.close(); cout <<endl <<i <<".\t返回" <<endl <<endl; int select;//选则要删除的事件 cout <<"选择 : "; cin >>select; if (select == i) return;ifstream reFile2;if(a=='1') {reFile2.open ("record\\past_things_title.txt",ios_base::in);}if(a=='2'){reFile2.open ("record\\memorial_things_title.txt",ios_base::in);} assert(reFile2); ofstream tempFile("record\\temp.txt"); i = 1;/*删除的过程:将未选中的时间都输出在文件temp.txt中,最后又将temp.txt中的内容输出到文件title.txt中,这样就完成了删除工作*/ int b;while (reFile2 >>signs) { reFile2.get(); getline(reFile2, data); if (i != select) tempFile <<signs <<endl <<data <<endl <<endl; else { system("cls"); cout <<endl <<endl <<"你想删除的事件内容如下 : " <<endl <<endl; string fname = "record\\"+signs+".txt"; ifstream reFile3(fname.c_str()); assert(reFile3); cout <<reFile3.rdbuf(); reFile3.close();cout<<"确定要删除吗?确定请输入1,取消请输入2。"<<endl;cin >>b;if(b==2){ tempFile <<signs <<endl <<data <<endl <<endl;}if(b!=2&&b!=1){cout<<"输入了错误指令"<<endl;tempFile <<signs <<endl <<data <<endl <<endl;} //getline(reFile2, data); }i++; } reFile2.close(); tempFile.close(); ifstream tempFile1("record\\temp.txt"); assert(tempFile1);ofstream reFile4;if(a=='1') {reFile4.open ("record\\past_things_title.txt");}if(a=='2'){reFile4.open ("record\\memorial_things_title.txt");} reFile4 <<tempFile1.rdbuf(); tempFile1.close(); reFile4.close();if(b==1) {cout <<endl <<endl <<"该条事件记录已经删除!!!" <<endl <<endl;} else{cout <<endl <<endl <<"该条事件记录未删除!!!" <<endl <<endl;} system("pause"); }}/*浏览记事本过程:操作者先选择浏览事件的种类,然后将相对应事件种类的title.txt文件打开,让操作者浏览所有记事的标题和时间,最后再选择要浏览的事件,系统将事件的整个详细情况显示出来 */void Notes::scan_notes(){ while (1) { system("cls"); cout<<endl<<"请选择你想浏览事件的种类"<<endl;char a;a=choose_thing(); cout <<endl <<"记事本查询" <<endl <<endl;ifstream reFile;if(a=='1') {reFile.open("record\\past_things_title.txt",ios_base::in);}if(a=='2'){ reFile.open("record\\memorial_things_title.txt",ios_base::in);} int i = 1; cout <<"序号\t" <<setiosflags(ios::left) <<setw(30) <<"标题 " <<"\t日期" <<endl <<endl;//将title.txt文件的内容全部读入到内存,并且显示在标准输出界面上if(reFile){ while (reFile >>signs) { reFile.get(); getline(reFile, data); cout <<i <<".\t" <<setiosflags(ios::left) <<setw(30) <<signs <<" " <<data <<endl <<endl; i++; }}else{cout<<"error!"<<endl;} reFile.close(); cout <<i <<".\t返回"<<endl; int select;//选择 cout <<endl<<"选择 : "; cin >>select; if (select == i) return; i = 1;ifstream reFile2;if(a=='1') {reFile2.open("record\\past_things_title.txt",ios_base::in);}if(a=='2'){ reFile2.open("record\\memorial_things_title.txt",ios_base::in);} assert(reFile2);//将选择的事件的整个详细内容显示出来 while (reFile2 >>signs) { reFile2.get(); getline(reFile2, data); if (i == select) { system("cls"); string fname = "record\\"+signs+".txt"; ifstream reFile3(fname.c_str()); assert(reFile3); cout <<reFile3.rdbuf(); reFile3.close(); cout <<endl <<endl; system("pause"); break; } //getline(reFile, data);此句可要可不要 i++; } reFile2.close(); }}//万年历查询界面void calendar_notebook::search_data(){ while (1) { system("cls"); cout<<"\t 万 年 历 查 询 " <<endl <<"\t *************************************************************" <<endl <<"\t *************************************************************" <<endl <<"\t * *" <<endl <<"\t * 1. 日历查询 *" <<endl <<"\t * *" <<endl <<"\t * 2. 月历查询 *" <<endl <<"\t * *" <<endl <<"\t * 3. 返回 *" <<endl <<"\t * *" <<endl<<"\t *************************************************************" <<endl <<"\t *************************************************************" <<endl; char select = getch(); switch (select) { case '1': select_day();//万年历之日历查询 break; case '2': select_month();//万年历之月历查询 break; case '3': return; default: break; } }}/*日历查询,根据所输入的日期时间推算出这一天是星期几,然后原样输出公历,星期几,最后主要的是阳历转阴历的算法,这里调用了另外的函数GetLunar(atoi(year.c_str()), atoi(month.c_str()),atoi(day.c_str()), Y2, M2, D2);来实现*/void whatdata::select_day(){ int i=0; system("cls"); cout << endl << "\t万年历之日历查询" << endl << endl; cout << "\t请输入年月日 (例如 : 2007 8 15) : "; cin >> year >> month >>day; int days = 0;//用来算是星期几 for (i = 1; i < atoi(year.c_str()); i++) { if ((i%4 == 0 && i%100 != 0) || (i%400 == 0)) days += 366; else days += 365; days = days%7; } if ((i%4 == 0 && i%100 != 0) || (i%400 == 0)) month1[1] = 29; for ( i = 0; i < atoi(month.c_str()) - 1; i++) days += month1[i]; days += atoi(day.c_str()); days = days%7; month1[1] = 28; cout <<endl << endl <<"阳历 : "; cout << year << " 年 " << month << " 月 " << day << " 日 \t" << week1[(days+6)%7] << endl << endl ;//这句的days+6是因为数组时的下标是0到6,本来也可以减1,但是考虑到days等于0的情况,所以就加6 cout << "阴历 : "; int Y2, M2, D2; GetLunar(atoi(year.c_str()), atoi(month.c_str()),atoi(day.c_str()), Y2, M2, D2); cout << Y2 << " 年 " << M2 << " 月 " << D2 << " 日 " << endl << endl; system ("pause");}//月历查询void whatdata::select_month(){ system("cls"); cout << endl << "\t万年历之月历查询" << endl << endl; cout << "\t请输入某年某月 (例如 : 2007 8) : " ; cin >> year >> month; cout << endl << endl <<year << " 年 " << month << " 月"; if ((atoi(year.c_str())%4 == 0 && atoi(year.c_str())%100 != 0) || (atoi(year.c_str())%400 == 0)) { month1[1] = 29; cout << "\t\t\t\t\t\t 闰年" << endl ; } else cout << "\t\t\t\t\t\t 平年" << endl ; cout << "==========================================================" <<endl <<endl; cout << "星期日 星期一 星期二 星期三 星期四 星期五 星期六" <<endl <<endl; int days = 0;//用来算某天是星期几int i,j; for (i = 1; i < atoi(year.c_str()); i++) { if ((i%4 == 0 && i%100 != 0) || (i%400 == 0)) days += 366; else days += 365; days = days%7; } for (i = 0; i < atoi(month.c_str()) - 1; i++) days += month1[i]; days = (days + 1)%7;//这里days是从0开始的所以要加1 for (j = 0; j < days; j++) cout << setw(10) << " "; cout << setw(3) << 1; for (j = 2; j <= month1[atoi(month.c_str()) - 1]; j++) { days++; if (days%7 == 0)//控制输出换行 cout << endl << endl << setw(3) << j; else cout << setw(10) << j ; } cout <<endl << endl <<"========================================================" <<endl <<endl; month1[1] = 28; fflush(stdin);//为了确保不影响后面的数据读取,清空输入缓冲区 system("pause");}//// 判断输入的公历年份是否为闰年,是闰年则函数返回1,否则返回0 int whatdata::IsLeapYear(int Year) { if ((Year%4==0 && Year%100!=0) || Year%400==0) return 1; else return 0; } // 计算输入公历年份的1月1日为从公元1年1月1日以来的第几天,返回天数 long whatdata::YearDays(int Year) { Year--; return(Year*365+Year/4-Year/100+Year/400+1);} // 计算输入的公历日期为从公元1年1月1日以来的第几天,返回总天数 long whatdata::TotalDays(int Year, int Month, int Day) { const int MonthDays[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; long Days=0L; int i; if(Month<=0) Month=1; if(Month>12) { //Month--; Year+=Month/12; Month%=12; //Month++; } for(i=1;i<Month;i++) Days+=MonthDays[i]; if(IsLeapYear(Year)&&Month>2) Days+=1; Days+=YearDays(Year); return Days+Day-1; } /* 输入公历年月日,返回农历年月日,函数返回1表示成功,0表示失败,如果M2返回负值,则说明是农历的闰月,月份值为其绝对值.,这里面又要用到LUNARINDEX[]数据结构数组,根据它的二进制编码来表示阴历年的信息。*/int whatdata::GetLunar(int Y1, int M1, int D1, int &Y2, int &M2, int &D2) { short MBit[13]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096}; long TDays; int Sum,Lest,i,Offset; Offset=Y1-BEGINYEAR; if(Offset<0||Offset>YEARCOUNT) return 0; TDays=TotalDays(Y1,M1,D1);//算出公历日期距离元年元月元日的总天数 Y2=Y1; //算出对应公历日期的阴历的年份 if(LunarIndex[Offset].Days>TDays) { if(Offset==0) return 0; Offset--; Y2--; } Lest=(int)(TDays-LunarIndex[Offset].Days); //算出阳历比阴历除了整年份的天数多出的天数 //一下算阴历年的月份 for(Sum=i=0;i<13;i++) { if((LunarIndex[Offset].Mon13&MBit[i])!=0) { Sum+=30; if(Sum>Lest) { Sum-=30; break; } } else { Sum+=29; if(Sum>Lest) { Sum-=29; break; } } } if(i==13)//如果i=13就说明上面再算年的时候有问题,少算了一年 return 0; i++; if(i>LunarIndex[Offset].Leap) { i--; if(i==LunarIndex[Offset].Leap){i=-i;} } M2=i; D2=Lest-Sum+1; //算出阴历年的天 return 1; }int main(){ whatdata object;//建立一个日期对象 Notes abook;//建立一个记事本对象 calendar_notebook calendar_notebook1;//建立一个日历记事本对象 char select; while (select = calendar_notebook1.first_page()) { switch (select) { case '1': calendar_notebook1.notes_manage();//记事本管理 break; case '2': calendar_notebook1.search_data();//日历查询 break; case '3': cout << endl << "\t谢谢使用!!!!" << endl << endl << "\t"; exit(0); break; default: break; } } return 0;}
0 0
- C课程设计
- C课程设计
- C课程设计
- C语言课程设计任务书
- C语言课程设计
- C语言课程设计
- C语言课程设计
- c语言课程设计
- C语言课程设计---通讯录
- c语言课程设计
- c语言课程设计
- c语言课程设计笔记
- C语言课程设计
- C语言课程设计
- c语言课程设计
- c语言课程设计
- 求助!!!C语言课程设计
- c语言课程设计2
- WIN7 数据源配置问题(32位&&64位)
- 文件上传漏洞
- 手机通讯录变成乱码如何恢复
- 设置vim 不再re-tabbing
- 比较Swift与HDFS话Ceph本质(by quqi99)
- C++课程设计
- gcc和g++的区别
- Nothing
- cocos2dx 3.X 环境配置总结
- 光纤收发器单纤和双纤区别
- POJ 3304 Segments(计算几何:直线与线段相交)
- 字节流转换字符流实例
- 开始学习C#与.net
- iOS中arc的设置与使用