您的位置:首页 > 编程语言 > C语言/C++

c++作业3多分段函数求值,定期存款利息计算器,本月有几天?

2016-04-07 10:42 375 查看
一.多分段函数求值
/*
* 文件名称:  多分数段函数求值
* 作    者:  刘晓光
* 完成日期:    2016   年  4   月 7   日
* 版 本 号:v1.0
* 对任务及求解方法的描述部分:
* 输入描述:
* 问题描述:
* 程序输出:
* 问题分析:
* 算法设计:
*/
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x,y;
cout<<"输入x的值:";
cin>>x;
if(x<2)
y=x;
else if(x<6)
y=x*x+1;
else if(x<10)
y=sqrt(x+1);
else if(x>=10)
y=1/(x+1);
cout<<"y="<<y<<endl;
return 0;
}
运行结果
<img src="http://img.blog.csdn.net/20160411211903858?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
二.<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;">定期存款利息计算器</span>
<pre name="code" class="cpp">/** 文件名称:  定期存款利息计算器* 作    者:  刘晓光* 完成日期:    2016   年  4   月 7   日* 版 本 号:v1.0* 对任务及求解方法的描述部分:* 输入描述:* 问题描述:* 程序输出:* 问题分析:* 算法设计:*/#include<iostream>using namespace std;int main(){int x,r;double d,s,g,h;cout<<"欢迎使用利息计算器!"<<endl;cout<<"请输入存款金额:";cin>>x;cout<<"======存款期限======"<<endl;cout<<"1、3个月\n2、6个月\n3、一年\n4、二年\n5、三年\n6、五年\n"<<endl;cout<<"请输入存款期限的代号:";cin>>r;switch(r){case 1:d=0.25;s=0.0310;break;case 2:d=0.50;s=0.0330;break;case 3:d=1.00;s=0.0350;break;case 4:d=2.00;s=0.0440;break;case 5:d=3.00;s=0.0500;break;case 6:d=5.00;s=0.0550;break;}g=x*d*s;h=g+x;cout<<"到期利息为:"<<g<<"本息合计共"<<h<<endl;cout<<"感谢您的使用,欢迎下次光临!"<<endl;return 0;}  
运行结果
<img src="http://img.blog.csdn.net/20160411212834985?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
三.本月有几天?
<pre name="code" class="cpp">/** 文件名称:  本月有几天?* 作    者:  刘晓光* 完成日期:    2016   年  4   月 7   日* 版 本 号:v1.0* 对任务及求解方法的描述部分:* 输入描述:* 问题描述:* 程序输出:* 问题分析:* 算法设计:*/#include<iostream>using namespace std;int main(){int a,b,c;cout<<"请输入年份";cin>>a;cout<<"请输入月份";cin>>b;switch(b){case 1:case 3:case 5:case 7:case 8:case 10:case 12: c=31;break;case 4:case 6:case 9:case 11: c=30;break;case 2:if( a%400==0 || (a%4==0 && a%100!=0))c=29;else c=28;break;}cout<<"该月有"<<c<<endl;return 0;}  
运行结果
<img src="http://img.blog.csdn.net/20160411213325970?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;"></span>
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;"></span><pre name="code" class="cpp">
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;"></span>
<span style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 15px; line-height: 35px;"></span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: