f0803.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:

C#编程

开发平台:

Visual C++

  1. //==================================
  2. // f0803.cpp
  3. // using object pointer calling member functions
  4. //==================================
  5. #include<iostream>
  6. #include<iomanip>
  7. using namespace std;
  8. //----------------------------------
  9. class Date{
  10.   int year, month, day;
  11. public:
  12.   void set(int y,int m,int d);
  13.   bool isLeapYear();
  14.   void print();
  15. };//-------------------------------
  16. void Date::set(int y,int m,int d){
  17.   year=y; month=m; day=d;
  18. }//--------------------------------
  19. bool Date::isLeapYear(){
  20.   return (year%4==0 && year%100!=0)||(year%400==0);
  21. }//--------------------------------
  22. void Date::print(){
  23.   cout<<setfill('0');
  24.   cout<<setw(4)<<year<<'-'<<setw(2)<<month<<'-'<<setw(2)<<day<<'n';
  25.   cout<<setfill(' ');
  26. }//--------------------------------
  27. int main(){
  28.   Date* dp;
  29.   dp->set(2000,12,6);
  30.   if(dp->isLeapYear())
  31.     (*dp).print();
  32. }//================================
  33.