| 查看: 742 | 回复: 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();} } 大家一起分享一下,可以的话还可以优化一下; |
» 猜你喜欢
实验室接单子
已经有6人回复
假如你的研究生提出不合理要求
已经有11人回复
全日制(定向)博士
已经有5人回复
萌生出自己或许不适合搞科研的想法,现在跑or等等看?
已经有4人回复
Materials Today Chemistry审稿周期
已经有4人回复
参与限项
已经有3人回复
对氯苯硼酸纯化
已经有3人回复
求助:我三月中下旬出站,青基依托单位怎么办?
已经有12人回复
所感
已经有4人回复
要不要辞职读博?
已经有7人回复
2楼2009-07-09 08:22:33
3楼2009-07-09 08:35:45
4楼2009-07-09 09:20:10
5楼2009-07-09 10:01:52
6楼2009-07-09 10:14:36
7楼2009-07-09 10:17:15
8楼2009-07-09 10:31:19
9楼2009-07-09 15:11:36
10楼2009-07-09 15:19:03
11楼2009-07-10 20:55:56
12楼2009-07-10 23:42:34
13楼2009-07-14 22:59:10
14楼2009-07-15 13:19:43












ut()
回复此楼
