//===================== //f0803.cpp //对象指针使用成员函数 //===================== #include<iostream> #include<iomanip> using namespace std; //---------------------- class Date { int year; int month; int day; public: void set(int y,int m,int day); bool isLeapYear(); void print(); }; //----------------------- void print(Date); bool isLeapYear(Date d); //----------------------- void Date::set(int y,int m,int d) { year = y; month = m; day = d; } //----------------------- void Date::print() { cout << setfill('0') << setw(4) << year << '-' << setw(2) << month << '-' << setw(2) << day << '/n'; cout<<setfill(' '); } //-------------------------- bool Date::isLeapYear() { return (year % 4 == 0 && year % 100 != 0 )||(year % 400 == 0); } //----------------------- int main() { Date * dp = new Date(); //Date * dp = new Date; //和上面的形式都正确 dp->set(2000,12,6); if(dp->isLeapYear()) //(*dp).print(); //和下面的形式都正确 dp->print(); return 0; } //===========================