| 查看: 730 | 回复: 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人回复
小论文投稿
已经有3人回复
Bioresource Technology期刊,第一次返修的时候被退回好几次了
已经有9人回复
心脉受损
已经有3人回复
到新单位后,换了新的研究方向,没有团队,持续积累2区以上论文,能申请到面上吗
已经有8人回复
申请2026年博士
已经有6人回复
请问哪里可以有青B申请的本子可以借鉴一下。
已经有5人回复
4楼2009-07-09 09:20:10
3楼2009-07-09 08:35:45
5楼2009-07-09 10:01:52
6楼2009-07-09 10:14:36













ut()
回复此楼
