f0803.cpp

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

CPP
34
字号
//==================================
// f0803.cpp
// using object pointer calling member functions
//==================================
#include<iostream>
#include<iomanip>
using namespace std;
//----------------------------------
class Date{
  int year, month, day;
public:
  void set(int y,int m,int d);
  bool isLeapYear();
  void print();
};//-------------------------------
void Date::set(int y,int m,int d){
  year=y; month=m; day=d;
}//--------------------------------
bool Date::isLeapYear(){
  return (year%4==0 && year%100!=0)||(year%400==0);
}//--------------------------------
void Date::print(){
  cout<<setfill('0');
  cout<<setw(4)<<year<<'-'<<setw(2)<<month<<'-'<<setw(2)<<day<<'\n';
  cout<<setfill(' ');
}//--------------------------------
int main(){
  Date* dp;
  dp->set(2000,12,6);
  if(dp->isLeapYear())
    (*dp).print();
}//================================

 

⌨️ 快捷键说明

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