标题:第八周项目1-求简单分段函数的值
问题及代码:
/*
*Copyright (c) 2014,烟台大学计算机学院
*All rights reserved.
*文件名称:test.cop
*作者:
*完成日期:2014年10月19日
*版本号:v1.0
*
*问题描述:输入年份和月份,输出本月有多少天
*输入描述:年份和月份
*输出描述:本月有多少天
#include <iostream>
using namespace std;
int main()
{
int year,month,day;
cout<<"请输入年,月"<<endl;
cin>>year>>month;
if(month=2)
{if(year%4==0)
{if(year%100==0)
{if(year%400==0)
day=29;
else day=30;
}
else day=29;
}
else day=30;
}
else
switch(month)
{
case 1:day=31;break;
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
case 4:day=30;break;
case 6:
case 9:
case 11:day=30;break;
}
cout<<"本月"<<day<<"天";
return 0;
}
运行结果:
知识点总结:
我学会了if 和switch结合运用
学习心得:
我的自信报表了,加油,没有不可能!!