日历记事本

#include<iostream.h>
#include<string>
#include<iomanip.h>
#include<fstream.h>
#include<time.h>
#include<stdlib.h>
class Calendar{
public:
Calendar();
int Date(int a, int b);
int Show(int i, int t);
int Show1(int y, int m);
private:
int fate1[12], fate2[12];
};
class  notepad{
public:
void Mome();
void record();
void recordlook();
void allrecord();
void Delete();
void Modify_the();
};
class System{
public:
void Interface();
void Input();
void Time();
void query();
private:
int year, month;
Calendar Cal;
notepad note;
};
class Heavy{
public:
friend ostream&operator<<(ostream &out, Heavy &s);
friend istream&operator>>(istream &in, Heavy &s);
int year,month,day;
char sth[50];
};
ostream & operator<<(ostream&out, Heavy &s)
{
out << s.year <<"年"<<s.month<<"月"<<s.day<<"日"<< s.sth << endl;
return out;
}
istream & operator>>(istream &in, Heavy&s)
{
in >> s.year>>s.month>>s.day>> s.sth;
return in;
}
Calendar::Calendar()
{
fate1[0] = 0; fate1[1] = 31; fate1[2] = 28; fate1[3] = 31; fate1[4] = 30; fate1[5] = 31; fate1[6] = 30; fate1[7] = 31;
fate1[8] = 31; fate1[9] = 30; fate1[10] = 31; fate1[11] = 30;
fate2[0] = 0; fate2[1] = 31; fate2[2] = 29; fate2[3] = 31; fate1[4] = 30; fate2[5] = 31; fate2[6] = 30; fate2[7] = 31;
fate2[8] = 31; fate2[9] = 30; fate2[10] = 31; fate2[11] = 30;
}
int Calendar::Date(int a, int b)
{
int d = 0, n, t, i, e, m;
e = a; m = b;
for (i = 0; i<e; i++)
{
if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0)
d++;
}
t = (e - 1) * 365 + d;
if (e % 4 == 0 && e % 100 != 0 || e % 400 == 0)
{
for (i = 0; i < m; i++)
{
t = t + fate2[i];
}
n = t % 7 ;
if (m == 4 || m == 6 || m == 9 || m == 11)
i = 31;
else if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)
i = 32;
else i = 30;
Show(i, n);
}
else
{
for (i = 0; i < m; i++)
{
t = t + fate1[i];
}
n = t % 7 ;
if (m == 4 || m == 6 || m == 9 || m == 11)
i = 31;
else if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)
i = 32;
else  i = 29;
Show(i, n);
}
return 0;
}
int Calendar::Show(int i, int t)
{


int  n, j, p;
n = 1;

cout << setw(10) << "Sunday"<< setw(10)<<"Monday" << setw(10) << "Tuesday" << setw(10) << "Wednesday" << setw(10) <<
"Thursday" << setw(10) << "Friday" << setw(10) << "Saturday" << endl;
if (t == 0)
{
for (p = 0; p<5; p++)
{
for (j = 0; j < 7; j++)
{
cout << setw(10) << n;
n++;
if (n == i)
break;
}
if (n == i)
break;
cout << endl;


}
cout << endl;
}
else
{
j = 0;
for (p = 0; p<7; p++)
{


if (j <t)
cout << setw(10) <<" ";
else
{
cout << setw(10) << n;
n++;
}
j++;
}
cout << endl;
for (p = 0; p<5; p++)
{
for (j = 0; j < 7; j++)
{
cout << setw(10) << n;
n++;
if (n == i)
break;
}
cout << endl;
if (n == i)
break;
}
cout << endl;
}
return 0;
}
int Calendar::Show1(int y, int m)
{
cout << "      " << y << "年       ";
cout << "      " << m << "月      " << endl;;
Date(y, m);
return 0;


}
void notepad::record()
{
ofstream fout("notepad.txt",  ios::out|ios::app);
Heavy s;
cout << "请输入时间和事件(如2015 07 02 C++程序设计答辩):" << endl;
cin >> s;
fout << s;
fout.close();
}
void notepad::recordlook()
{
cout << "请输入要查询的时间" << endl;
int y,m,d;
int sum = 0;
Heavy s;
cout<<"年:";
cin >> y;
cout<<"月:";
cin>>m;
cout<<"日:";
cin>>d;
ifstream fin("notepad.txt",ios::in);
fin >> s;
while (!fin.eof())
{
        sum=0;
while(sum<1)
{
if (s.year == y)
if(s.month==m)
if(s.day==d)
cout << s;
fin>>s;
}
}
fin.close();
cout << endl << endl;
}
void notepad::allrecord()
{
ifstream fin("notepad.txt");
char s[100];
cout << "所有的待办事项有:" << endl;
while (!fin.eof())
{
        fin.getline(s,100);
cout << s;

}
fin.close();
cout << endl << endl;
}
void notepad::Delete()
{
    Heavy s;
int y,m,d;
ifstream infile("notepad.txt");
ofstream outfile("in.txt");
  cout<<"请输入需要删除日程的时间"<<endl;
   cout<<"年:";
   cin >> y;
   cout<<"月:";
   cin>>m;
   cout<<"日:";
   cin>>d;
   while(!infile.eof())
{
         infile>>s;
if (s.year != y)
if(s.month!=m)
if(s.day!=d)
      outfile<<s;
}
        infile.close();
   outfile.close();
        ifstream infile1("in.txt");
      ofstream outfile1("notepad.txt");
        while(!infile1.eof())
{
         infile1>>s;
outfile1<<s;
}
        infile1.close();
   outfile1.close();
system("del in.dat");
}
void notepad::Modify_the()
{
    Heavy s,q;
int t,y,m,d;
char z[100];
ifstream infile("notepad.txt");
ofstream outfile("in.txt");
  cout<<"请输入需要修改日程的时间"<<endl;
   cout<<"年:";
   cin >> y;
   cout<<"月:";
   cin>>m;
   cout<<"日:";
cin>>d; 
while(!infile.eof())
{
        infile>>s;
if (s.year == y)
{
if(s.month==m)
{
if(s.day==d)
{
cout<<"请输入新内容:"<<endl;
cin>>q;
         outfile<<q;
}
                else
{
         infile.getline(z,100);
             outfile<<z;
}
}
else
{
    infile.getline(z,100);
        outfile<<z;
}
}
else
{
infile.getline(z,100);
    outfile<<z;
}
}
    infile.close();
outfile.close();
    ifstream infile1("in.txt");
ofstream outfile1("notepad.txt");
    while(!infile1.eof())
{
         infile1>>s;
outfile1<<s;
}
    infile1.close();
outfile1.close();
system("del in.txt");


}
void notepad::Mome()
{
int sel;
cout<<"\t ******************欢迎使用******************\n";
cout<<"\t ****************日历记事本******************\n";
cout<<"\t *------------------------------------------*\n";
cout<<"\t *              1--添加日程                 *\n";
cout<<"\t *              2--查询日程                 *\n";
cout<<"\t *              3--显示所有日程             *\n";
        cout<<"\t *              4--修改日程                 *\n";
cout<<"\t *              5--删除日程                 *\n";
cout<<"\t *              0--退出                     *\n";
cout<<"\t *------------------------------------------*\n";
cout<<"\t 你要输入的编号是(0--5):";
cin>>sel;
if(sel==0) return;
switch (sel)
{
case 1:
record();
system("pause"); break;
case 2:
recordlook();
system("pause"); break;
case 3:
allrecord();
system("pause"); break;
case 4:
Modify_the();break;
case 5:
Delete();break;


}


}
void System::Time()
{
int  day, week;
time_t timer;
struct tm *p;
timer = time(NULL);
p = localtime(&timer);
year = p->tm_year + 1900;
month = p->tm_mon + 1;
day = p->tm_mday;
week = p->tm_wday;
cout <<setw(25)<<" "<<"今天是"<<year<<"年"<<month<<"月"<<day<<"日"<<"星期"<<week<<endl;
cout << endl << endl;
Cal.Date(year, month);
        cout << endl ;
}
void System::Input()
{
int y, m;
cout << "请输入需要查询的年月(如2015 7):";
cin >> y >> m;
Cal.Show1(y, m);
}
void System::Interface()
{
int sel;
while (1)
{
system("cls");
cout<<"\t ******************欢迎使用******************\n";
cout<<"\t *****************日历记事本*****************\n";
Time();
cout<<"\t *------------------------------------------*\n";
cout<<"\t *              0--退出                     *\n";
cout<<"\t *              1--查询日历                 *\n";
cout<<"\t *              2--日程提醒                 *\n";
        cout<<"\t *------------------------------------------*\n";
cout<<"\t 你要输入的编号是(0--2):";
cout << "请输入需要的服务序号:";
cin >> sel;
if(sel==0)  break;
switch (sel)
{
case 1:
   query();
system("pause"); break;
case 2:
note.Mome();
system("pause"); break;
}
}
}
int main()
{
System sys;
sys.Interface();
return 0;
}
void System::query()
{
int y,m,s;
cout<<"1--上个月"<<endl;
cout<<"2--下个月"<<endl;
cout<<"3--指定日期查询"<<endl;
cout<<"请输入需要的服务序号(1-3):";
cin>>s;
  switch(s)
  {
   case 1:
 
if (month == 1)
{
y = year - 1; m = 12;
}
else
{
m = month - 1; y = year;
}
Cal.Show1(y, m);
             system("pause"); break;
   case 2:
  if (month == 12)
{
y = year + 1; m = 1;
}
else
{
m = month + 1; y = year;
}
Cal.Show1(y, m);
            system("pause"); break;
   case 3:
 Input();
      system("pause"); break;


  }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java 日历记事本是一种用Java编程语言开发的软件应用程序,旨在帮助用户记录和管理日程安排和事件。用户可以使用该应用程序来创建、编辑和删除事件,并根据日期和时间来安排和跟踪这些事件。 Java 日历记事本通常具有以下功能: 1. 日历显示:应用程序通过呈现一个日历界面,让用户可以在不同日期之间切换和查看事件。用户可以通过点击特定日期来查看该日期的事件详情。 2. 事件创建:用户可以创建新事件,包括事件的名称、日期、时间、地点以及其他相关详细信息。用户可以选择是否重复事件,例如每天、每周、每月或每年重复。 3. 事件编辑和删除:用户可以编辑已存在的事件,包括修改事件的日期、时间、地点和其他详细信息。用户也可以删除不再需要的事件。 4. 提醒功能:Java 日历记事本通常提供事件提醒功能,以确保用户不会错过重要的事件。用户可以设置提醒时间,并在提醒时间到达时接收通知。 5. 搜索和过滤:为了方便用户查找和整理事件,Java 日历记事本通常提供搜索和过滤功能。用户可以通过关键词、日期、标签等条件来搜索和过滤事件,以快速找到所需的信息。 6. 数据存储:Java 日历记事本通常使用数据库或文件来存储用户的事件数据。这样,用户可以在不同设备之间同步和访问他们的事件。 总之,Java 日历记事本是一种方便的工具,用于帮助用户管理和记录重要的日程安排和事件。它提供了简单易用的界面和多样化的功能,以满足用户的个性化需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值