日历记事本

原创 2015年07月07日 12:47:05
#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;


  }
}

相关文章推荐

自动班“C++程序设计",日历记事本

6、日历记事本 要求:带有日程提醒功能的日历。 显示信息:用户可以向前查询前一个月的日期,也可以向后查询下一个月的日期。 定时提醒:用户可以针对某一天来添加,删除和编辑这一天的日程提...

经典电子日历记事本

  • 2017年08月19日 13:39
  • 479KB
  • 下载

日历记事本

  • 2015年12月15日 17:39
  • 2.71MB
  • 下载

用java实现简单记事本的编写

以上就是简单记事本的java语言实现。

日历记事本

  • 2013年06月23日 16:25
  • 477KB
  • 下载

日历记事本.rar

  • 2006年02月23日 09:05
  • 125KB
  • 下载

android 记事本demo!!!(listview与SQLite综合)

android记事本的demo在网上一搜一大堆,但是大神写的demo往往功能太多导致新手难以着手,很难啃得动;而一些新手写的demo又往往是东拼西凑,代码很多都是copy的别人的,直接放在项目里面用,...

java日历记事本源代码

  • 2010年06月07日 12:34
  • 83KB
  • 下载

日历记事本

  • 2012年11月23日 22:19
  • 478KB
  • 下载

用java开发的一个简单的记事本程序

代码如下:package IO; import java.io.*; import java.awt.*; import javax.swing.*;import java.awt.event.*; ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:日历记事本
举报原因:
原因补充:

(最多只允许输入30个字)