資源簡介
定義一個Date 類,數據成員有year,month, day。以“年_月_日“的格式輸出日期, 還提供把天加一的成員函數nextdate( ),要求能測試出如下的結果:
a. 能夠進入下一個月。
b. 能夠進入下一個年。
c. 能顯示日期。
代碼片段和文件信息
#include?
using?namespace?std;
int?DAY[13]?=?{0?31?28?31?30?31?30?31?31?30?31?30?31};
bool?Syear(int?year)?{
if(?!(year?%?400)?||?!(year?%?4)?&&?year?%?100)?return?true;
return?false;
}
class?Date?{
private:
int?year?month?day;
public:
Date()?{
year?=?0?month?=?0?day?=?0;
}
void?show()?{
cout?< }
void?nextdate()?{
int?IncMonth?=?0?IncYear?=?0?MaxMonth?=?12?MaxDay;
if(?Syear(year)?&
評論
共有 條評論