一、问题及代码
/*
* 文件名称:c++作业
* 作 者: 武鹏翔
* 完成日期: 2017.3.5
* 版 本 号:v6.0
* 对任务及求解方法的描述部分:
* 输入描述:
* 问题描述:
* 程序输出:
* 问题分析:
*?算法设计:switch语句
*/
#include<iostream>
using namespace std;
int main()
{
int year,month;
cout<<"请输入年份:";
cin>>year;
cout<<"请输入月份:";
cin>>month;
if((year%4==0&&year%100!=0)||(year%400==0))
year=1;
else
year=0;
if(year==1)
switch(month)
{
case 1:cout<<"31"<<endl;break;
case 2:cout<<"29"<<endl;break;
case 3:cout<<"31"<<endl;break;
case 4:cout<<"30"<<endl;break;
case 5:cout<<"31"<<endl;break;
case 6:cout<<"30"<<endl;break;
case 7:cout<<"31"<<endl;break;
case 8:cout<<"31"<<endl;break;
case 9:cout<<"30"<<endl;break;
case 10:cout<<"31"<<endl;break;
case 11:cout<<"30"<<endl;break;
case 12:cout<<"31"<<endl;break;
}
else
switch(month)
{
case 1:cout<<"31"<<endl;break;
case 2:cout<<"28"<<endl;break;
case 3:cout<<"31"<<endl;break;
case 4:cout<<"30"<<endl;break;
case 5:cout<<"31"<<endl;break;
case 6:cout<<"30"<<endl;break;
case 7:cout<<"31"<<endl;break;
case 8:cout<<"31"<<endl;break;
case 9:cout<<"30"<<endl;break;
case 10:cout<<"31"<<endl;break;
case 11:cout<<"30"<<endl;break;
case 12:cout<<"31"<< endl;break;
}
return 0;
}
二、