第九周项目4-输入年月,输出本月天数
2013-10-15 20:41
274 查看
/* *程序的版权和版本声明部分: *Copyright(c)2013,烟台大学计算机学院学生 *All rights reserved. *文件名称: *作者:田成琳 *完成日期:2013年 10月15 日 *版本号:v1.0 *对任务及求解方法的描述部分: *输入描述:输入年月,显示本月多少天 *问题描述:输入年月,显示本月多少天 *程序输出:本月天数 *问题分析: *算法设计: 先判断是否闰年 */ 我的程序: #include<iostream> using namespace std; int main() { int year,month,day; cout<<"请输入年,月:"<<endl; cin>>year>>month; if(year%4==0&&year%100!=0||year%400==0) //先讨论是不是闰年 { if(month==1||month==3||month==5||month==7||month==8||month==10||month==12) day=31; else if(month==4||month==6||month==9||month==11) day=30; else day=29; //闰年2月有29天 } else { if(month==1||month==3||month==5||month==7||month==8||month==10||month==12) day=31; else if(month==4||month==6||month==9||month==11) day=30; else day=28; } cout<<"本月有"<<day<<"天"<<endl; return 0; }
上机内容:练习
运行结果:
心得体会:在解决实际问题时,往往要经过讨论,灵活运用if-else语句。关键头脑中要先有此问题的算法,解法。
相关文章推荐
- 输入年月输出该月天数
- 输入年月输出该月天数(改良版)
- 输入年月输出该月天数
- 第九周 项目1 在第八周基础上定义一个流输入输出以及-c
- 第九周项目5 从键盘输入20个整数,输出它们的和
- 第九周【项目1】在第8周项1的基础上(1)再定义一目运算符 -,-c相当于0-c(2)定义Complex类中的<<和>>运算符的重载,实现输入和输出,改造原程序中对运算结果显示方式,使程序读起来更自然
- 第九周任务四(建立一个二维数组类Douary,使该类中有以下数据成员、成员函数及友员函数,完成矩阵的输入、输出、加、减、相等判断等操作。)
- 用户从键盘输入月份,使用switch语句输出该月份的天数
- 第7周项目4 输入三个整数 输出最大值
- delphi 输入年月判断天数,判断指定年份与月份判断当月有多少天
- 第五周 项目1-当输入的三条边不能构成三角形时 ,输出:
- 第三十九讲项目3.1——输入一个正整数,输出它的反序数
- 第九周项目3-输出星号图
- 第九周 项目三 图形输出
- 第九周项目三—输出星号图
- 第九周项目三输出星号图(f)
- 第12周项目3-输出输入的数的二进制形式
- 【C语言】笔记:输入身份证号,输出出生年月
- 输入年份与月份 判断是否是闰年 与该年月的天数
- 软件项目需求说明书中输入 加工 输出 等的说明