//定义一个日期类
#include <iostream>
class Date
{
private :
int year,month,day;
public:
void set(int year, int month, int day);
bool fun();
void show();
};
//Date 类中成员函数的实现(可以使用默认值)
void Date::set(int _year, int _month, int _day)
{
year=_year;
month=_month;
day=_day;
}
bool Date::fun()
{
if ((year%4==0&&year%100!=0)||(year%400==0)) {
return true;
}
else
return false;
}
void Date::show()
{
std::cout<<year<<"-"<<month<<"-"<<day<<std::endl;
}
int main(int argc, const char * argv[])
{
Date newDate;
newDate.set(2013, 11, 18);
newDate.show();
}
C++ 定义一个日期类
最新推荐文章于 2024-07-28 15:43:54 发布