日期類的完善

2021-09-27 03:36:46 字數 2818 閱讀 2072

函式的宣告

包括日期加、日期減、大於、大於等於、小於、小於等於、判斷等於、不等於、以及前置++、--,後置++、--

#include using namespace std;

typedef unsigned int uint;

class date

date operator +(const uint delay) const;

date operator -(const uint delay) const;

bool operator >(const date & d) const;

bool operator

bool operator <=(const date & d) const;

bool operator >=(const date & d) const;

bool operator ==(const date & d) const;

bool operator !=(const date & d) const;

date operator ++();

date operator ++(int);

date operator --();

date operator --(int);

friend ostream &operator << (ostream & os, date & d);

//void showdate();

};

函式的實現

#include "date.h"

static uint getmonthday(int y,uint m)

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

if (m == 2)

else }

date date:: operator +(uint delay) const

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

} res.m_day += delay;

if (res.m_day > tmp)

res.m_day -= tmp;

} return res;

} date date:: operator -(uint delay) const

else

res.m_month--;

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

while (delay >= tmp)

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

} int tmpday = res.m_day;

tmpday = res.m_day - delay;

if (tmpday <= 0)

else

}res.m_day = tmpday;

return res;

}ostream &operator << (ostream & os, date & d) //輸出流

bool date ::operator

else if (m_year == d.m_year && m_month < d.m_month)

else if (m_year == d.m_year && m_month == d.m_month && m_day < d.m_day)

return false;

}bool date ::operator <=(const date & d) const

bool date ::operator >(const date & d) const

else if (m_year == d.m_year && m_month > d.m_month)

else if (m_year == d.m_year && m_month == d.m_month && m_day > d.m_day)

return false;

}bool date ::operator >=(const date & d) const

bool date ::operator ==(const date & d) const

return false; }

bool date ::operator !=(const date & d) const

date date:: operator ++()

} return *this;

}date date:: operator ++(int)

} return tmp;

}date date::operator --()

m_day = getmonthday(m_year, m_month);

} return *this;

}date date::operator --(int)

m_day = getmonthday(m_year, m_month);

} return tmp;

}

測試函式日期加減

int main()

前置++、--,後置++、--

大整數類(已完善)

include include include include include include using namespace std define maxn 9999 define maxsize 1000 define dlen 4 class bignum 建構函式 bignum const ...

SAP日期函式整理 完善中

type pools trff data log op type trff type c 2.call function fima date compare exporting i intraday i date 20191101 i time 000000 i sincl 0 計算期間開始的排除標...

第31課 完善的複數類

1.1 運算 1.2 比較 1.3 賦值 1.4 求模 modulus 2.1 統一複數與實數的運算方式 complex operator const complex c 因為物件的this關鍵字的緣故,省去乙個引數 complex operator const complex c complex ...