设计一个程序,输入年月,输出年月和这个月有多少天
- 提问者网友:轮囘Li巡影
- 2021-04-23 17:17
- 五星知识达人网友:荒野風
- 2021-04-23 18:06
class Tdate
{
public:
void SetDate(int y,int m);
int Fday();
void printf();
private:
int year,month;
}
void Tdate:: SetDate(int y,int m)
{
year=y;
month=m;
}
int Tdate :: Fday()
{
int day;
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: day=31; break;
case 4:
case 6:
case 9:
case 11: day=30;break;
case 2: if((year%400==0)||(year%4==0&&year%100=0)
day=29;
else day=28;
}
void Tdate ::printf()
{
cout<<year<<"."<<month<<"."<<day<<endl;
}
void main()
{
cout<<"please input year, month:"<<endl;
cin>>y>>m;
Tdate date1(y,m);
date1.SetDate();
int days= date1.Fday();
date.printf();
cout<<days<<endl;
}
- 1楼网友:有你哪都是故乡
- 2021-04-23 19:28