⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 日期类的自增和自减运算符的重载2.txt

📁 学C++的同学是不是遇到麻烦了
💻 TXT
字号:
#include  <iostream.h>
class    Date
{
   public: 
       Date(){}
       Date(int  y,int  m,int  d){year=y;  month=m;  day=d;}	 
       void   Print() 
       {
            cout<<year<<","<<month<<","<<day<<endl;
        }
       Date   operator ++(int);
       Date   operator --(int);
   private:
         int   year ,  month,  day;
};
Date  Date::operator ++(int)
{
      Date   temp;
      temp=*this;
      day++;
      return  temp;
}
Date  Date::operator --(int)
{
      Date   temp;
      temp=*this;
      day--;
      return  temp;
}

void  main()
{
   Date  today(2003,10,13),tomorrow,yesterday,d1,d2;
   cout<<"今天是:";
   today.Print();

   cout<<"明天是:";
   today++;
   tomorrow=today;
   tomorrow.Print();

   cout<<"昨天是:";
   tomorrow--;
   today=tomorrow;
   today--;
   yesterday=today;
   yesterday.Print();
}

⌨️ 快捷键说明

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