1。请将下列代码,在2008VC环境下编译运行。
/*
Date : 20091109
For : class const function and inline function
Book : qianNeng
Page : 276/572
*/
#include <iostream>
#include <iomanip>
//.............................
using namespace std;
//=============================
class Date
{
int year,month,day;
public:
void set(int y, int m, int d);
bool isLeapYear()const; // const function
void print()const; // conse function
};
//----------------------------------
//inline void Date::set(int y, int m, int d)
void Date::set(int y, int m, int d)
{
year = y;
month = m;
day = d;
}
//KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
//inline bool Date::isLeapYear()const // const function
bool Date::isLeapYear()const
{
return (((0 == year % 4)
&& (0 != year % 100))
|| (0 == year % 400));
}
//ppppppppppppppppppppppppppppppppppp
//inline void Date::print()const // const function
void Date::print()const
{
cout << setfill('0') << endl;
/*
cout << setw( 4 ) << year << '-'
setw( 2 ) << month << '-' //question 1
setw( 2 ) << day << "/n";
*/
cout << "The date: " << year << '-'
<< month << '-' << day << " is leap year." << endl;
cout << setfill(' ') << endl;
}
//mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
void main()
{
char cEnd;
int y1 = 2008,m1 = 8,d1 = 8;
//Date D1;
Date *ptrD1 = new Date;
cout << "Please input year."<< endl;
cin >> y1;
if(0 >= y1)
{
y1 = 2009;
}
cout << "Please input month."<< endl;
cin >> m1;
if(0 >= m1)
{
m1 = 1;
}
cout << "Please input day."<< endl;
cin >> d1;
if(0 >= d1)
{
d1 = 1;
}
//D1.set(y1,m1,d1);
ptrD1->set(y1,m1,d1); //one method
if(ptrD1->isLeapYear())
{
(*ptrD1).print(); //other method
}
delete ptrD1;
cout << "Please intput any key to end." <<endl;
cin >> cEnd;
cout << " " << endl;
2 。运行的时候,是不是有异常提示?解决方法?