一个C++日历源码

includes #include <iostream> #include <iomanip> #include <cmath> #include <windows.h> #include <cstdlib> using namespace std; void clrscr(); void gotoxy(int,int); class calender { public: calender(int d=1,int m=1,int y=2001); virtual ~calender() {} void printcalender(); private: bool isleapyear(); int checkday(int); int whatdayisfirstofmonth(); int howmanydays(); int day; int month; int year; }; calender::calender(int d,int m,int y) { if (y<1582) { cout<<endl<<"The year "<<y<<" is before the gregorian calender was accepted by the church." <<"Setting to 2001."<<endl; year=2001; } else { year=y; } if ((m>=1) && (m<=12)) { month=m; } else { cout<<endl<<"The month "<<m<<" is invalid. Setting to month 1"<<endl; month=1; } day=checkday(d); } bool calender::isleapyear() { if ((year%400==0) || ((year %4==0) && (year%100 !=0))) { return true; } else { return false; } } int calender::checkday(int testday) { if ((testday>0) && (testday<= howmanydays())) { return testday; } cout<<endl<<"Invalid day entered "<<testday<<"/"<<month<<"/"<<year <<". Setting to the first of the month."<<endl; return 1; } int calender::howmanydays() { if((month==2)&& isleapyear()) { return 29; } static const int daysinmonth[12]={31,28,31,30,31,30,31,31,30,31,30,31}; return daysinmonth[month-1]; } int calender::whatdayisfirstofmonth() { int c=year/100; int d=year%100; int m=(month+10)%12; int k=1; if ((month==1)||(month==2)) { if (d==0) { d=99; c-=1; } else { d-=1; } } float g=(k + (floor(((13*m)-1)/5)) + d + (floor(d/4)) + (floor(c/4)) - (2*c)); int f=static_cast<int>(g)%7; if (f<0) { f+=7; } return f; } void calender::printcalender() { clrscr(); cout<<"Date entered was :- "<<day<<"/"<<month<<"/"<<year<<endl; cout<<endl<<setw(8)<<"SUNDAY"<<setw(8)<<"MONDAY"<<setw(9)<<"TUESDAY"<<setw(11)<<"WEDNESDAY"<<setw(10) <<"THURSDAY"<<setw(8)<<"FRIDAY"<<setw(10)<<"SATURDAY"<<endl; int startday=whatdayisfirstofmonth(); int endday=howmanydays(); for (int i=0;i<startday;i++) { if (i==0) { gotoxy(4,4); cout<<"-"; } if (i==1) { gotoxy(12,4); cout<<"-"; } if (i==2) { gotoxy(21,4); cout<<"-"; } if (i==3) { gotoxy(31,4); cout<<"-"; } if (i==4) { gotoxy(42,4); cout<<"-"; } if (i==5) { gotoxy(50,4); cout<<"-"; } } int rows=4; int count=1; for(int j=startday;j<(startday+endday);j++) { if(j%7==0) { rows+=2; gotoxy(4,rows); } if(j%7==1) gotoxy(12,rows); if(j%7==2) gotoxy(21,rows); if(j%7==3) gotoxy(31,rows); if(j%7==4) gotoxy(42,rows); if(j%7==5) gotoxy(50,rows); if(j%7==6) gotoxy(60,rows); if(count==day) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED); } else { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN); } cout<<count; count ++; } cout<<endl<<endl<<endl; } void clrscr() { COORD coordScreen = { 0, 0 }; DWORD cCharsWritten; CONSOLE_SCREEN_BUFFER_INFO csbi; DWORD dwConSize; HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfo(hConsole, &csbi); dwConSize = csbi.dwSize.X * csbi.dwSize.Y; FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten); GetConsoleScreenBufferInfo(hConsole, &csbi); FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten); SetConsoleCursorPosition(hConsole, coordScreen); } void gotoxy(int x, int y) { COORD point; point.X = x; point.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),point); } int main() { while (1) { clrscr(); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN); cout<<"Welcome to the gregorian calender calculator. v.1.00"<<endl<<endl <<"Use UK format.... day/month/full year. Use the '/' char to delimit your entry..." <<endl<<endl; cout<<"Please enter the date you would like to see the calender for :- "; char input_day[4]; char input_month[4]; char input_year[6]; cin.getline(input_day,3,'/'); cin.getline(input_month,3,'/'); cin.getline(input_year,5,'\n'); cout<<endl; int d=atoi(input_day); int m=atoi(input_month); int y=atoi(input_year); calender date(d,m,y); system("PAUSE"); date.printcalender(); cout<<"Another calender (Y/N) ? "; char input[5]; cin.getline(input,4); if ((input[0]=='N') || (input[0]=='n')) { break; } } return 0; } 蓝莓友情提醒:梅超风来喽,大家注意关好门窗哈!唉,白天的雷声响的我都不敢开电脑。。

转载于:https://www.cnblogs.com/mrjim/archive/2011/08/11/4475236.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iDesktopCalendar(我的桌面日历)<br><br>运行环境:WIN2000/XP/2003/VISTA<br>软件类别:桌面工具<br>授权形式:免费<br>软件作者:蓝剑<br>技术支持:pdc2008@hotmail.com<br><br>【软件介绍】<br>我的桌面日历(iDesktopCalendar)是一款简洁小巧的桌面日期时间提醒工具软件,<br>同时提供邮件提醒等功能。<br><br>软件特色:<br>--电子日历可以显示西历和阴历,以及二十四节气和十二生肖。<br> 可以自由定义是否显示节气,生肖,以及年月日等标签。<br>--电子时钟可以语音报时和定时提醒。<br> 可以自由定制定时提醒的提示方式。选择提示音乐时,<br> 可以设定提示音乐以及每次提示时重复的次数。<br>--启动迅速,占用资源少,轻便快速。<br>--独特的背景半透明技术。<br> 目前大多数此类软件的透明,是背景和前景的一起透明,当透明度很高时,导致整个软件都不可见。<br> 而本软件提供的技术,可以独立调节背景的透明度而完全不影响前景的显示。<br> 取消了前景的透明度调节,取而代之以不同的窗口风格来显示。<br>--多种窗口风格供您选择。<br> 总在最前,嵌入桌面,以及普通窗口三种风格。<br> 嵌入桌面风格以外可以选择自动靠边隐藏,方便用户在桌面的正常工作。<br>--快捷方便的人性化设计。<br> 快速显示功能功能。<br> 在窗口自动隐藏后可以通过双击系统托盘图标来快速显示,方便查询时间。<br> 语音报时或者音乐提示时,可以通过双击系统托盘图标或者窗口来停止声音播放。<br> 在窗口自动隐藏时,可以有系统任务栏的气泡提示。<br>--自带简单的实时皮肤编辑器,轻松实现皮肤定制。<br>--完全免费,不含任何广告等流氓插件,可以放心使用。<br><br>------------------------------------------<br>【更新日志】<br><br>iDesktopCalendar 1.1.0<br>1、追加了邮件检查功能。<br>2、提供了对Windows2000的支持。<br>3、对于保存的密码等信息进行了128位加密处理。<br>4、修正了一些Bug

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值