欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

用c++實(shí)現(xiàn)的簡(jiǎn)單的日期類(lèi)-創(chuàng)新互聯(lián)

 自己寫(xiě)的這個(gè)日期類(lèi)實(shí)現(xiàn)了簡(jiǎn)單的一些日期可能會(huì)用到的功能,

前鋒ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書(shū)未來(lái)市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)的ssl證書(shū)銷(xiāo)售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:028-86922220(備注:SSL證書(shū)合作)期待與您的合作!

比如加減某一個(gè)日期等等,詳細(xì)的已在代碼里面標(biāo)注出來(lái)了。

#include <iostream>
using namespace std;

class Date
{
public:
 Date(int year = 1900, int month = 1, int day = 1)
  :_year(year)   //初始化列表
    ,_month(month)
    ,_day(day)
 {
  if (year < 1900
   ||month < 1 || month > 12
   || day < 1 || day > GetMonthDay(year,month))
  {
   cout << "Invalid Date" << endl;
  }
 }

 int GetMonthDay(int year, int month)
 {
  int monthArray[12] = { 31, 28, 31, 30, 31,
   30, 31, 31, 30, 31, 30, 31 };
  if (IsLeapYear(year)&&month==2)
  {
   return monthArray[month - 1] + 1;
  }
  return monthArray[month - 1];
 }

 bool IsLeapYear(int year)
 {
  return year % 400 == 0 || year % 4 == 0
   && year % 100 != 0;
 }

 Date operator+(int day)     //加一個(gè)天數(shù)
 {
  Date tmp(*this);
  tmp._day += day;
  while (tmp._day > GetMonthDay(tmp._year,tmp._month))
  {
   tmp._day -= GetMonthDay(tmp._year, tmp._month);

   if (tmp._month == 12)
   {
    tmp._year += 1;
    tmp._month = 1;
   }
   else
   {
    tmp._month += 1;
   }

  }
  return tmp;
 }

 Date& operator+=(int day)
 {
  this->_day += day;
  while (this->_day > GetMonthDay(this->_year, this->_month))
  {
   this->_day -= GetMonthDay(this->_year, this->_month);

   if (this->_month == 12)
   {
    this->_year += 1;
    this->_month = 1;
   }
   else
   {
    this->_month += 1;
   }

  }
  return *this;
 }

 Date operator-(int day)   //減一個(gè)天數(shù)
 {
  Date tmp(*this);
  tmp._day -= day;
  while (tmp._day < 0)
  {
   if (tmp._month == 1)
   {
    tmp._year -= 1;
    tmp._month = 12;
    tmp._day += GetMonthDay(tmp._year, tmp._month);
   }
   else
   {
    tmp._month -= 1;
    tmp._day += GetMonthDay(tmp._year, tmp._month);
   }

  }
  return tmp;
 }

 Date operator++() //前置自增
 {
  *this += 1;
  return *this;
 }

 bool operator==(const Date& d)  //測(cè)試日期相等
 {
  return _year == d._year&&
   _month == d._month&&
   _day == d._day;
 }

 bool operator!=(const Date& d)
 {
  return !(_year == d._year&&
   _month == d._month&&
   _day == d._day);
 }

 bool operator<(const Date& d)
 {
  return !(_year < d._year&&
   _month < d._month&&
   _day < d._day);
 }

 int operator-(const Date& d)  //一個(gè)日期減一個(gè)日期
 {
  Date tmp1 = d;
  Date tmp2 = *this;

  int count = 0;
  if (tmp2 < tmp1)
  {
   Date rev;
   rev = tmp2;
   tmp2 = tmp1;
   tmp1 = rev;
  }

  while (tmp2 != tmp1)
  {
   count++;
   ++tmp1;
  }

  return count;
 }

 void Display()
 {
  cout << _year << "-" << _month << "-" << _day << endl;
 }

private:
 int _year;
 int _month;
 int _day;
};

void Test1() //測(cè)試加減某一個(gè)天數(shù)
{
 int day;
 Date d1(2015,3,1);
 d1.Display();
 cin >> day;
 //(d1 + day).Display();
 (d1 - day).Display();
}

void Test2()
{
 Date d1(2015, 2, 28);
 //d1.Display();

 Date d2(2015, 2, 28);
 cout << (d1 != d2) << endl;
 //(d1++).Display();

}

void Test3()
{
 Date d1(2004, 2, 1);
 Date d2(2004, 3, 1);

 int ret = d1 - d2;
 cout << ret << endl;
}

int main()
{
 //Test1();
 //Test2();
 Test3();
 return 0;
}

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。

本文名稱(chēng):用c++實(shí)現(xiàn)的簡(jiǎn)單的日期類(lèi)-創(chuàng)新互聯(lián)
文章出自:http://aaarwkj.com/article48/ccjhhp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、網(wǎng)站制作網(wǎng)站維護(hù)、服務(wù)器托管、做網(wǎng)站商城網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)
五月婷婷丁香噜噜噜噜| 国产精品国产三级国产av丨| 国产精品伦理一区二区三区| 超碰97免费在线观看| 老熟妇仑乱换频一区二区| 人妻熟女一区二区视频| 国产一区二区精品久久岳√| 青青草原网址在线观看| 精品人妻一区二区av| 免费在线成人av观看| 国产看片色网站亚洲av| 国产精品99久久久久久| 热九九这里只有热九九| 91中文在线观看一区| 日本免费高清一区二区| 亚洲乱码国产乱码精品| 婷婷91麻豆精品国产人妻| 亚洲日本一区二区一本一道| 涩涩涩丁香色婷五月网| 丝袜美腿一区二区三区| 麻豆亚洲av熟女国产| 欧美三级伦理片免费观看| 国产日韩熟女中文字幕| 日韩成人中文字幕在线视频| 国产精品国产三级国产不产一地| 欧美日韩亚洲人人夜夜澡| 丰满人妻在线一区二区三区| 97在线视频观看视频在线| 麻豆精品国产粉嫩av| 亚洲国产女人精品久久久| 久久精品免成人费电影| 日本人妻伦理在线播放| 麻豆精品人妻中文在线| 羞涩插射视频网站在线观看| 视频一区二区三区不卡| 中文字幕精品一区二区三区在线| 日本一区二区三区高清在线| 亚洲熟妇精品一区二区| 中日韩中文字幕一区二区| 日韩蜜桃av一二三四区| 亚洲国产精品自拍视频|