C++作业3
2016-04-10 23:35
351 查看
项目2:本月有几天?
自选if语句的嵌套或/和switch语句完成程序设计
编程序,输入年份和月份,输出本月有多少天。合理选择分支语句完成设计任务。
样例输入1:2004 2
输出结果1:本月29天
样例输入2:2010 4
输出结果2:本月30天
项目3:多分数段函数求值
从键盘输入x的值(要求为实型),根据下面的公式计算并输出y的值。
项目4:定期存款利息计算器
输入存款金额并选择存款种类,计算出利息(不计利息税)和本息合计。要求使用switch语句,根据选择的存款种类,确定利率和存期后计算。
提示:利息=金额×年利率×存期(单位:年,3个月为0.25年,6个月为0.5年)。
例如:1000元存6个月,利息=1000×0.033×0.5=16.5元
年利率:3个月 3.10%,6个月 3.30%,一年 3.50%,二年 4.40%,三年 5.00%,五年 5.50%。
自选if语句的嵌套或/和switch语句完成程序设计
编程序,输入年份和月份,输出本月有多少天。合理选择分支语句完成设计任务。
样例输入1:2004 2
输出结果1:本月29天
样例输入2:2010 4
输出结果2:本月30天
#include <iostream> using namespace std; int main() { int year,month; 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) cout<<"本月有31天\n"; else if(month==2) cout<<"本月有29天\n"; else if(month==4||month==6||month==9||month==11) cout<<"本月有30天\n"; } else { if(month==1||month==3||month==5||month==7||month==8||month==10||month==12) cout<<"本月有31天\n"; else if(month==2) cout<<"本月有28天\n"; else if(month==4||month==6||month==9||month==11) cout<<"本月有30天\n"; } return 0; }
项目3:多分数段函数求值
从键盘输入x的值(要求为实型),根据下面的公式计算并输出y的值。
#include <iostream> #include<math.h> using namespace std; int main() { cout<<"从键盘输入x的值"<<endl; double y,x; cin>>x; if(x>=10) y=1/(x+1); else if (x>=6) y=sqrt(x+1); else if(x>=2) y=x*x+1; if(x<2) y=x; cout<<y; return 0; }
项目4:定期存款利息计算器
输入存款金额并选择存款种类,计算出利息(不计利息税)和本息合计。要求使用switch语句,根据选择的存款种类,确定利率和存期后计算。
提示:利息=金额×年利率×存期(单位:年,3个月为0.25年,6个月为0.5年)。
例如:1000元存6个月,利息=1000×0.033×0.5=16.5元
年利率:3个月 3.10%,6个月 3.30%,一年 3.50%,二年 4.40%,三年 5.00%,五年 5.50%。
#include <iostream> #include <math.h> using namespace std; int main() { double m,l,s; cout<<"欢迎使用利息计算器!\n请输入存款金额"<<endl; cin>>m; cout<<"=====存款期限=====\n1.3个月\n2.6个月\n3.一年\n4.两年\n5.三年\n6.五年\n请输入存款期限的代号"<<endl; int n; cin>>n; switch(n) { case 1:l=m*0.031*0.25;break; case 2:l=m*0.033*0.5;break; case 3:l=m*0.035*1;break; case 4:l=m*0.044*2;break; case 5:l=m*0.05*3;break; case 6:l=m*0.055*5;break; default:cout<<"error\n"; } s=m+l; cout<<"到期利息为:"<<l<<"元。本息合计:"<<s<<"元"; return 0; }
<img src="http://img.blog.csdn.net/20160412085750115?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
相关文章推荐
- 指针数组和数组指针的区别
- leetcode----Best Time to Buy and Sell Stock
- C++第3次上机作业
- C++ 11 vlearning
- C++第3次上机实验--个人所得税计算器
- C++类的继承的基本认识
- c++string流之istringstream
- Java与c++异同 小结
- c++实验3--个人所得税计算器
- C++ Primer 第五版(中文版) ----容器与继承练习15.28 & 15.29
- 如何自己编写Arduino支持的C++类库
- 学生管理系统c++链表实现
- c混合运算和数据类型转换
- 求两个字符串的最长公共子序列
- 结构体的内存分配
- C++继承 总结
- C++中引用和匿名对象的理解和本质剖析
- 【步兵 c++】试用default_random_engine
- c++第三次实验—作业
- [LeetCode]16. 3Sum Closest