設計日期,求出將年月日向後推n天的日期

2021-09-26 23:20:12 字數 913 閱讀 9907

設計乙個日期類,包含以下功能:

1、只能通過傳入年月日初始化。

2、可以加上乙個數字n,返回乙個該日期後推n天之後的日期。

方法:對日期實現逐月累加

//建立date.**件

#pragma once

#include using namespace std;

typedef unsigned int uint;

class date

date operator + (uint delay) const;//保證this不被改變,對 + 運算子進行過載

friend ostream & operator << (ostream &os, date &d);//對輸出運算子 << 過載

};//建立date.cpp檔案

#include "date.h"

static uint getmonthday(uint y, uint m)

if (m == 4 || m == 6 || m == 9 || m == 11)

else if (m == 2)

else

}ostream & operator << (ostream &os, date &d)

date date::operator + (uint delay) const

tmp = getmonthday(res.m_year, res.m_month);

}//直到delay的天數不夠乙個月,跳出迴圈

res.m_day += delay;//將剩餘天數加在天數上

if (res.m_day > tmp)

return res;

}//建立main.cpp檔案

#include "date.h"

int main()

進行日期年月日的加減

data lv date b like sy datum.data date ruzi like sy datum.call function rp calc date in interval exporting date date ruzi days 0 天數加n或者減n 不加也不減 寫0 mon...

vue 顯示日期只顯示年月 vue獲取年月日

1.暴利獲取 const nowdate new date const date year nowdate.getfullyear month nowdate.getmonth 1,date nowdate.getdate const newmonth date.month 10?date.mont...

C 按日期年月日分別寫入記錄

private static string startpath c rs data private static string startpath environment.currentdirectory region 工具函式區 寫入log public static void writelog ...