c++ Date 类

来源:百度知道 编辑:UC知道 时间:2024/06/14 03:57:31
//====================================
//满足Date 的类
//====================================
#include<iostream>
using namespace std;
//--------------------------------------
class Date{
int year,month,day;

public:
Date() {year=2009;month=1;day=1;}
void change();

void print();
void set(int y,int m,int d);

};

void Date::change()
{
if((year%4==0&&year%100!=0)||(year%400==0))
{
if(month==2)
if(day=28)
{
day=29;

}

}
else
{
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10: {
if(day==31)
{
month++;
day=1;
}
else day++;
break;

}

case 4:
case 6:
case 9:{
if(day==30)
{
month++;
day=1;
}<

void Date::print()
{
cout<<day<<"\"<<month<<"\"<<year<<endl;
}
这段代码有错,
void Date::print()
{
cout<<day<<"\\"<<month<<"\\"<<year<<endl;
}
就行了,
前者“\“会有错,因为\+符号会有特别意思的,比如\n表示回车。
应该写成"\\"就行了