| 查看: 813 | 回复: 13 | ||
| 【奖励】 本帖被评价4次,作者烂熊邓增加金币 3 个 | ||
| 当前主题已经存档。 | ||
| 当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖 | ||
[资源]
【分享】日期的加整数运算符的重载
|
||
|
下面是日期加整数的重载 分两个文件:一个头文件,一个源文件 //1.h #include using namespace std; class Date {int year,month,day; public: Date(int a=0,int b=0,int c=0) {year=a; month=b; day=c; } void out(); Date operator +(int j); }; void Date: ut(){cout<<"the Date is :"< Date Date: perator +(int j){int m,i,n; int d[12]={31,28,31,30,31,30,31,31,30,31,30,31}; cout<<"请输入要相加的天数m:"< cout<<"要相加的天数是:"< if(n<=d[month-1]) day=day+m; else for(i=0;i<=11;i++) {i=month-1; n=n-d; if(i<11) month++; else {year++; month=1;} if(d[month-1]>n) { day=n; break;} else continue; i++; } return ; } //1.cpp #include"1.h" void main() {int y,m,d,n; while(1) {cout<<"请输入年份,月份,号数,追加天数:"; cin>>y>>m>>d>>n; Date d(y,m,d); Date D; cout<<"原始日期:"; d.out(); D=d+n; cout<<"追加天使之后的日期:"; d.out();} } 大家一起分享一下,可以的话还可以优化一下; |
» 猜你喜欢
球磨粉体时遇到了大的问题,请指教!
已经有15人回复
过年走亲戚时感受到了所开私家车的鄙视链
已经有5人回复
情人节自我反思:在爱情中有过遗憾吗?
已经有5人回复
江汉大学解明教授课题组招博士研究生/博士后
已经有3人回复
10楼2009-07-09 15:19:03
3楼2009-07-09 08:35:45
4楼2009-07-09 09:20:10
5楼2009-07-09 10:01:52













ut()
回复此楼