代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C
】
万年历实现类
作者:
纳兰清风
/ 发布于
2013/2/17
/
525
#ifndef CALENDAR_H_INCLUDED #define CALENDAR_H_INCLUDED #include <string> #include <iostream> #include <iomanip> using std::string; class Calendar{ protected: int year; int month; int day; int week; public: static int mon[13]; static string EngMon[13]; protected: void getWeekDay(); public: Calendar(); Calendar(int y,int m=1,int d=1); bool isLeapYear(int y) const; void printYear(); void printMonth(); void printWeek(); void setYear(int y); int getYear() const; void setMonth(int m); int getMonth() const; void setDay(int d); int getDay() const; void setWeek(int w); string getWeek() const; }; int Calendar::mon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; string Calendar::EngMon[13]={" ","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; Calendar::Calendar(){ week=0; } Calendar::Calendar(int y,int m,int d){ setYear(y); setMonth(m); setDay(d); week=0; } bool Calendar::isLeapYear(int y) const{ return (y%4==0&&y%100!=0)||(y%400==0); } void Calendar::printYear(){ Calendar c(this->getYear()); for(int i=1;i<13;i++){ c.setMonth(i); c.printMonth(); } } void Calendar::printMonth(){ getWeekDay(); int w=(week-(day-1)%7+7)%7; std::cout<<" "<<year<<" "<<EngMon[month]<<" "<<std::endl; std::cout<<"Sun Mon Tue Wed Thu Fri Sat"<<std::endl; for(int i=0;i<w;i++){ std::cout<<" "; } if(isLeapYear(year)){ mon[2]=29; }else{ mon[2]=28; } for(int d=1;d<mon[month]+1;d++){ std::cout<<std::setw(3)<<d<<" "; if(w==6) std::cout<<std::endl; w=(w+1)%7; } std::cout<<std::endl; } void Calendar::printWeek(){ getWeekDay(); std::cout<<getWeek()<<std::endl; } void Calendar::getWeekDay(){ int sumDay=0; for(int i=1900;i<year;i++){ if(isLeapYear(i)){ sumDay+=366; } else { sumDay+=365; } } if(isLeapYear(year)){ mon[2]=29; } for(int j=1;j<month;j++){ sumDay+=mon[j]; } sumDay+=day; week=sumDay%7; } void Calendar::setYear(int y){ if(y<1900) y=1900; year=y; } int Calendar::getYear() const{ return year; } void Calendar::setMonth(int m){ if(m<1) m=1; if(m>12) m=12; month=m; } int Calendar::getMonth() const{ return month; } void Calendar::setDay(int d){ if(d<1) d=1; day=d; } int Calendar::getDay() const{ return day; } void Calendar::setWeek(int w){ week=w; } string Calendar::getWeek() const{ string w[7]={"Sun","Mon","Tue","Wen","Thu","Fri","Sat"}; return w[week]; } #endif // CALENDAR_H_INCLUDED //测试函数 void test(){ int year,month,day; Calendar cal; while(1){ std::cout<<"1.print the year calendar"<<std::endl; std::cout<<"2.print the year month calendar"<<std::endl; std::cout<<"3.print the weekday of year month day"<<std::endl; std::cout<<"4.exit"<<std::endl; char temp[2]={'\0'}; std::cin>>temp; switch(temp[0]){ case '1': { std::cout<<"please input the year usage yyyy(>1900):"<<std::endl; std::cin>>year; cal.setYear(year); cal.printYear(); break; } case '2': { std::cout<<"please input the year usage yyyy(>1900) mm(1~12):"<<std::endl; std::cin>>year>>month; cal.setYear(year); cal.setMonth(month); cal.printMonth(); break; } case '3': { std::cout<<"please input the year usage yyyy(>=1900) mm(1~12) dd:"<<std::endl; std::cin>>year>>month>>day; cal.setYear(year); cal.setMonth(month); cal.setDay(day); cal.printWeek(); break; } case '4': { exit(0); break; } default: break; } } }
试试其它关键字
万年历
同语言下
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
纳兰清风
贡献的其它代码
(
2
)
.
监听发往本机和从本机发出的数据包
.
万年历实现类
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3