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

📄 date2.cpp

📁 C++程序设计源代码例
💻 CPP
字号:
#include <iostream.h>
class Date
{   public: 
      int year,month,day;
  	  Date();
	  Date(int y,int m,int d);
	  Date(const Date& D);

	  ~Date()
	  {
		  cout<<"Destructor called."<<endl;
	  }
       
	  void SetYear(int y) {year=y;}
	  void SetMonth(int m) {month=m;}
	  void SetDay(int d) {day=d;}
	  void PrintDate();
};

Date::Date()
{ 
    year=2003; month=1;  day=1;
	cout<<"Constructor called."<<endl;
}

Date::Date(int y,int m,int d)
{
    year=y; month=m;  day=d;
	cout<<"Constructor called."<<endl;
}

Date::Date(const Date& D)
{
	year=D.year;
	month=D.month;
	day=D.day;
	cout<<"Copy Constructor called."<<endl;

}

void Date::PrintDate()
{
	cout<<year<<"-"<<month<<"-"<<day<<endl;
}

void main()
{
	int year,month,day;
	cout<<"输入当前的年、月、日:"<<endl;
	cin>>year>>month>>day;

	Date today;
	today.SetYear(year);
	today.SetMonth(month);
	today.SetDay(day);

    Date tomorrow(today);
	switch (tomorrow.month)
	{
		case 4:
		case 6:
		case 9:
		case 11:
			if(tomorrow.day==30) 
			{ 
				tomorrow.day=1;
				tomorrow.month+=1;
			}
			else
				tomorrow.day+=1; break;
		case 12:
			if(tomorrow.day==31)
			{ 
				tomorrow.year+=1;
				tomorrow.month=1;
				tomorrow.day=1;
			}
			else
				tomorrow.day+=1; break;
		case 2:
			if(tomorrow.day==28) 
			{ 
				tomorrow.day=1;
				tomorrow.month+=1;
			}
			else
				tomorrow.day+=1; break;
		default:
			if(tomorrow.day==31) 
			{ 
				tomorrow.day=1;
				tomorrow.month+=1;
			}
			else
				tomorrow.day+=1;
	}
	cout<<"tomorrow的日期为:"<<endl;
	tomorrow.PrintDate();
}




⌨️ 快捷键说明

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