| 查看: 849 | 回复: 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();} } 大家一起分享一下,可以的话还可以优化一下; |
» 猜你喜欢
085601材料工程找调剂
已经有11人回复
总分293求调剂
已经有9人回复
334分 一志愿武理 材料求调剂
已经有5人回复
327求调剂
已经有6人回复
329求调剂
已经有10人回复
275求调剂
已经有15人回复
291求调剂
已经有6人回复
309求调剂
已经有7人回复
297求调剂
已经有11人回复
一志愿南航 335分 | 0856 | GPA 4.07 | 有科研经历
已经有6人回复
7楼2009-07-09 10:17:15
3楼2009-07-09 08:35:45
4楼2009-07-09 09:20:10
5楼2009-07-09 10:01:52














ut()
回复此楼