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

c++作业3

2016-04-17 00:30 471 查看
一、定期存款利息计算器
#include <iostream>
using namespace std;
int main()
{
int a,b;
double interest,rate,term,sum;
cout<<"欢迎使用利息计算器!"<<endl;
cout<<"请输入存款金额:";
cin>>a;
cout<<"存款期限\n";
cout<<"1.3个月\n"<<"2.6个月\n"<<"3.一年\n"<<"4.二年\n"<<"5.三年\n"<<"6.五年\n";
cout<<"请输入存款期限的代号:";
cin>>b;
switch(b)
{
case 1:term=0.25;rate=0.031;break;
case 2:term=0.50;rate=0.033;break;
case 3:term=1.00;rate=0.035;break;
case 4:term=2.00;rate=0.044;break;
case 5:term=3.00;rate=0.050;break;
case 6:term=5.00;rate=0.055;break;
}
interest=a*term*rate;
sum=a+interest;
cout<<"到期利息为:"<<interest<<"元,"<<"本息合计共:"<<sum<<"元。\n";
cout<<"感谢您的使用,欢迎下次光临!\n";
return 0;
}
二、本月有几天?
<pre class="cpp" name="code">#include<iostream>
using namespace std;
int main()
{
int  year, month, day;
cout << "请输入年份:";
cin>>year;
cout<<"请输入月份";
cin>>month;
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:   day=31;break;
case 4:
case 6:
case 9:
case 11:   day=30;break;
case 2:
if(year%4==0 && year%100!=0 ||year%400==0) day=29;
else       day=28;
}
cout<<year<<"年"<<month<<"月"<<"有"<<day<<"天\n";
return 0;
}


三、多分数段函数求值
<pre class="cpp" name="code">#include <iostream>
#include<cmath>
using namespace std;
int main()
{
double x,y;
cout<<"请输入x的值"<<endl;
cin>>x;
if(x<2)  y=x;
else if(x<6)  y=x*x+1;
else if(x<10)  y=sqrt(x+1);
else y=1/(x+1);
cout<<"分段函数y的值为:"<<y<<endl;
return 0;
}





内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: