date2.cpp
Upload User: puke2000
Upload Date: 2022-07-25
Package Size: 912k
Code Size: 1k
Category:

CSharp

Development Platform:

Visual C++

  1. //==================================
  2. // Date class
  3. //==================================
  4. #include<iostream>
  5. #include<iomanip>
  6. using namespace std;
  7. //----------------------------------
  8. class Date{
  9.   int year, month, day;
  10. public:
  11.   void set(int y,int m,int d){      // 默认内联
  12.     year=y; month=m; day=d;
  13.   }//------------------------------
  14.   bool isLeapYear();
  15.   void print();
  16. };//-------------------------------
  17. inline bool Date::isLeapYear(){    // 显式内联
  18.   return (year%4==0 && year%100!=0)||(year%400==0);
  19. }//--------------------------------
  20. void Date::print(){
  21.   cout<<setfill('0');
  22.   cout<<setw(4)<<year<<'-'<<setw(2)<<month<<'-'<<setw(2)<<day<<'n';
  23.   cout<<setfill(' ');
  24. }//--------------------------------
  25.