#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <ctime>
#include <cassert>
#include <conio.h>
using namespace std;
class rebook
{
public:
rebook();
void new_book();
void alter_book();
void delet_book();
void scan_book();
private:
string signs;
string data;
string where;
string things;
string what;
};
class whatdata
{
public:
whatdata();
int IsLeapYear(int Year);
long YearDays(int Year);
long TotalDays(int Year, int Month, int Day);
int GetLunar(int Y1, int M1, int D1, int &Y2, int &M2, int &D2);
char inter_face();
void search_data();
void book_manage();
void select_day();
void select_month();
private:
rebook abook;
string week;
string month;
string day;
string year;
};
#define BEGINYEAR 1900
#define YEARCOUNT 150
struct LUNARINDEX
{
long Days;
short Mon13;
short Leap;
}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}, {733433, 0X1A93, 5}, {733817, 0X0A95, 15},
{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 month2[12]={"一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"};
string weeks[7] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
string months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
"Oct", "Nov", "Dec"};
rebook::rebook()
{
where = "xxx";
things = "xxx";
what = "xxx";
signs = "xxx";
data = "xxx";
}
void rebook::new_book()
{
system("cls");
cout <<endl <<"记事(以'#'表示结束)" <<endl;
time_t timer;
time(&timer);
cout <<endl <<"时间 : "<<asctime(localtime(&timer)) <<endl;
cout <<"标题 : ";
cin >>signs;
ofstream tempFile("record\\temp.txt");
time(&timer);
tempFile <<"时间 : "<<asctime(localtime(&timer)) <<endl
<<"标题 : " <<signs <<endl <<endl
<<"内容 : ";
cout <<endl <<"内容 : " << endl;
tempFile << endl << 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();
ofstream reFile1("record\\title.txt", ios::app);
reFile1 <<signs <<endl <<asctime(localtime(&timer)) <<endl;
reFile1.close();
string fname = "record\\"+signs+".txt";
ofstream reFile(fname.c_str());
ifstream tempFile1("record\\temp.txt");
assert(tempFile1);
reFile <<tempFile1.rdbuf();
tempFile1.close();
reFile.close();
cout <<endl <<endl <<"记录已经保存!!!" <<endl <<endl;
system("pause");
}
void rebook::alter_book()
{
while (1)
{
system("cls");
cout <<endl <<"请选择你想修改的标题 : " <<endl <<endl;
int i = 1;
ifstream reFile("record\\title.txt");
if (!reFile)
{
ofstream reFile1("record\\title.txt");
reFile1.close();
ifstream reFile("record\\title.txt");
}
while (reFile >>signs)
{
reFile.get();
getline(reFile, data);
cout <<i <<".\t" <<setiosflags(ios::left) <<setw(30) <<signs <<" "
<<data <<endl <<endl;
i++;
}
reFile.close();
cout <<endl <<i <<".\t返回" <<endl <<endl;
cout <<"选择 : ";
int select;
cin >>select;
if (select == i)
return;
ifstream reFile2("record\\title.txt");
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();
ofstream tempFile("record\\temp.txt");
cout <<endl <<endl <<"请在下面输入新的内容 (以'#'结束): " <<endl <<endl;
tempFile <<"标题 : " <<signs <<endl <<endl;
tempFile <<"内容 : ";
cout <<"内容 : ";
string str;
while (1)
{
cin >>str;
if (str[str.length()-1] == '#')
{
str[str.length()-1] = ' ';
tempFile <<str <<endl;
break;
}
tempFile <<str <<endl;
}
tempFile.close();
ifstream tempFile1("record\\temp.txt");
assert(tempFile1);
ofstream reFile4(fname.c_str());
reFile4 <<tempFile1.rdbuf();
tempFile1.close();
reFile4.close();
cout <<endl <<endl <<"内容更新完成!!!!" <<endl <<endl;
system("pause");
break;
}
i++;
}
reFile2.close();
}
}
void rebook::delet_book()
{
while (1)
{
system("cls");
cout <<endl <<"请选择一个你想删除的标题 : " <<endl <<endl;
ifstream reFile("record\\title.txt");
if (!reFile)
{
ofstream reFile1("record\\title.txt");
reFile1.close();
ifstream reFile("record\\title.txt");
}
int i = 1;
while (reFile >>signs)
{
reFile.get();
getline(reFile, data);
cout <<i <<".\t" <<setiosflags(ios::left) <<setw(30) <<signs <<" "
<<data <<endl <<endl;
i++;
}
reFile.close();
cout <<endl <<i <<".\t返回" <<endl <<endl;
int select;
cout <<"选择 : ";
cin >>select;
if (select == i)
return;
ifstream reFile2("record\\title.txt");
assert(reFile2);
ofstream tempFile("record\\temp.txt");
i = 1;
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();
}
getline(reFile2, data);
i++;
}
reFile2.close();
tempFile.close();
ifstream tempFile1("record\\temp.txt");
assert(tempFile1);
ofstream reFile4("record\\title.txt");
reFile4 <<tempFile1.rdbuf();
tempFile1.close();
reFile4.close();
cout <<endl <<endl <<"该条备忘录已经删除!!!" <<endl <<endl;
system("pause");
}
}
void rebook::scan_book()
{
while (1)
{
system("cls");
cout <<endl <<"记事本查询" <<endl <<endl;
ifstream reFile("record\\title.txt");
if (!reFile)
{
ofstream reFile1("record\\title.txt");
reFile1.close();
ifstream reFile("record\\title.txt");
}
int i = 1;
cout <<"序号\t" <<setiosflags(ios::left) <<setw(30) <<"标题 " <<"\t日期" <<endl <<endl;
while (reFile >>signs)
{
reFile.get();
getline(reFile, data);
cout <<i <<".\t" <<setiosflags(ios::left) <<setw(30) <<signs <<" "
<<data <<endl <<endl;
i++;
}
reFile.close();
cout <<i <<".\t返回";
int select;
cout <<endl <<endl <<"选择 : ";
cin >>select;
if (select == i)
return;
i = 1;
ifstream reFile2("record\\title.txt");
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();
}
}
whatdata::whatdata():abook()
{
week = "xxx";
month = "xxx";
day = "xxx";
year = "xxx";
}
char whatdata::inter_face()
{
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
<<"\t ※ 4. 日历查询 ※" <<endl
<<"\t ※ ※" <<endl
<<"\t ※ 5. 关闭记事本 ※" <<endl
<<"\t ※ ※" <<endl
<<"\t ※※※※※※※※※※※※※※※※※※※※※※※※※※※※※" <<endl <<endl <<"\t\t";
choose = getch();
return choose;
}
void whatdata::search_data()
{
while (1)
{
system("cls");
cout << endl << "\t\t万年历查询" << endl << endl ;
cout << "\t●\t1. 日历查询 " << endl << endl
<< "\t●\t2. 月历查询" << endl << endl
<< "\t●\t3. 返回" << endl << endl;
char select = getch();
switch (select)
{
case '1':
select_day();
break;
case '2':
select_month();
break;
case '4':
return;
default:
break;
}
}
}
void whatdata::book_manage()
{
char choose;
while (1)
{
system("cls");
cout <<endl <<"\t管理你的备忘录!!!!!" <<endl <<endl;
cout <<endl <<"\t●\t\t 1. 修改备忘录" <<endl
<<endl <<"\t●\t\t 2. 删除备忘录" <<endl
<<endl <<"\t●\t\t 3. 返回首页" <<endl <<endl <<"\t\t\t";
choose = getch();
switch (choose)
{
case '1':
abook.alter_book();
break;
case '2':
abook.delet_book();
break;
case '3':
return;
break;
default:
break;
}
}
}
void whatdata::select_day()
{
system("cls");
cout << endl << "\t万年历之日历查询" << endl << endl;
cout << "\t请输入年月日 (例如 : 2007 8 15) : ";
cin >> year >> month >>day;
int days = 0;
for (int 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 - 1] << endl << endl ;
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;
for (int 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;
for (int 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");
}
int whatdata::IsLeapYear(int Year)
{
if ((Year%4==0 && Year%100!=0) || Year%400==0)
return 1;
else
return 0;
}
long whatdata::YearDays(int Year)
{
Year--;
return(Year*365+Year/4-Year/100+Year/400+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;
}
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)
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;
rebook abook;
char select;
while (select = object.inter_face())
{
switch (select)
{
case '1':
abook.new_book();
break;
case '2':
abook.scan_book();
break;
case '3':
object.book_manage();
break;
case '4':
object.search_data();
break;
case '5':
cout << endl << "\t谢谢使用!!!!" << endl << endl << "\t";
exit(0);
break;
default:
break;
}
}
return 0;
}
C++程序设计
最新推荐文章于 2022-02-09 13:52:11 发布