| 查看: 1061 | 回复: 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();} } 大家一起分享一下,可以的话还可以优化一下; |
» 猜你喜欢
征友后感触
已经有10人回复
考博求助
已经有4人回复
憎水剂,表面活性剂
已经有3人回复
申博
已经有7人回复
食品与机械 编辑C处理稿子时间
已经有4人回复
注意啦!用基金购买打印纸、硒鼓、优盘、移动硬盘、个人计算机属于违规了
已经有4人回复
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()
回复此楼
