要求:定义一个类,定义构造函数进行初始化,设计相应的输出,完成填空,运行程序,检查效果。
#include <iostream.h>
class TDate1{
public:
TDate1(int y=0,int m=0,int d=0) { year=y; month=m;day=d; }
int IsLeapYear();
void Print() { cout<<year<<"."<<month<<"."<<day<<endl; }
private:
int year,month,day;
};
int TDate1::IsLeapYear(){
return (year%4==0&&year%100!=0)||(year%400==0);}
void main(){
TDate1 today(2014,5,20);
TDate1 tomorrow(2014,5,21);
cout<<"Today is:";
_____________; //输出今天的日期
cout<<"Tomorrow is:";
_____________; //输出明天的日期
_____________; //以下判断2015年是不是闰年,
_____________; //输出2015年是不是闰年
}
#include <iostream>
using namespace std;
class TDate1
{
public:
TDate1(int y = 0, int m = 0, int d = 0)
{
year = y;
month = m;
day = d;
}
int IsLeapYear();
void Print() { cout << year << "." << month << "." << day << endl; }
private:
int year, month, day;
};
int TDate1::IsLeapYear()
{
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
int main()
{
TDate1 today(2014, 5, 20);
TDate1 tomorrow(2014, 5, 21);
cout << "Today is:";
today.Print(); //输出今天的日期
cout << "Tomorrow is:";
tomorrow.Print(); //输出明天的日期
TDate1 y2015(2015, 1, 1);
int a = y2015.IsLeapYear(); //以下判断2015年是不是闰年,
cout << a << endl; //输出2015年是不是闰年
}
是不是一个空行只能填一句代码?
int main()
{
TDate1 today(2014, 5, 20);
TDate1 tomorrow(2014, 5, 21);
cout << "Today is:";
today.Print(); //输出今天的日期
cout << "Tomorrow is:";
tomorrow.Print(); //输出明天的日期
TDate1 y2015(2015); //以下判断2015年是不是闰年,
cout << y2015.IsLeapYear() << endl; //输出2015年是不是闰年
}