MyDate类的头文件声明如下,为该类创建一个CPP文件,并采取类内声明类外...
发布网友
发布时间:2024-05-08 00:43
我来回答
共1个回答
热心网友
时间:2024-06-21 02:38
MyData.h
string get_Cmonth(void);
MyData.cpp
MyData::MyData(int x = 2012,int y = 11,int z = 27):year(x),month(y),day(z){}
MyData::~MyData(){}
void MyData::set_data(int x,int y,int z)
{
year = x;
month = y;
day = z;
}
void MyData::set_year(int x)
{
year = x;
}
void MyData::set_month(int y)
{
month = y;
}
void MyData::set_day(int z)
{
day = z;
}
void MyData::input_data(void)
{
cout<<"请输入年月日,以空格分隔"<<endl;
cin>>year>>month>>day;
}
int MyData::get_year(void)
{
return year;
}
int MyData::get_month(void)
{
return month;
}
string MyData::get_Cmonth(void)
{
switch (month)
{
case 1:
return "一";
break;
case 2:
return "二";
case 3:
return "三";
break;
case 4:
return "四";
break;
case 5:
return "五";
break;
case 6:
return "六";
break;
case 7:
return "七";
break;
case 8:
return "八";
break;
case 9:
return "九";
break;
case 10:
return "十";
break;
case 11:
return "十一";
break;
case 12:
return "十二";
break;
default:
return 0;
}
}
int MyData::get_day(void)
{
return day;
}
void MyData::print_data(void)
{
cout<<"年:"<<year<<"月:"<<month<<"日:"<<day<<endl;
}
int MyData::isleapyear(void)
{
if ((year/4==0 && year/100!=0) || year/400==0)
return 1;
else
return 0;
}
int main()
{
MyData myData(2012,2,2);
cout<<myData.get_Cmonth()<<endl;
return 0;
}