date.cpp

来自「it is a usefull thing」· C++ 代码 · 共 24 行

CPP
24
字号
//=====================================
// date.cpp
//=====================================
#include"date.h"
#include<exception>
using namespace std;
//-------------------------------------
void Date::init(int y, int m, int d)throw(out_of_range){
  if(y>5000 || y<1 || m<1 || m>12 || d<1 || d>31) throw out_of_range("rangeError");
  year=y, month=m, day=d;
}//------------------------------------
Date::Date(const string& s)throw(out_of_range){
  int y = atoi(s.substr(0,4).c_str());
  int m = atoi(s.substr(5,2).c_str());
  int d = atoi(s.substr(8,2).c_str());
  init(y,m,d);
}//------------------------------------
Date::Date(int y, int m, int d)throw(out_of_range){ init(y,m,d); }
//-------------------------------------
bool Date::isLeapYear()const{
  return (year % 4==0 && year % 100 )|| year % 400==0;
}//------------------------------------

 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?