一项目二
本月有几天?
<pre name="code" class="cpp"><pre name="code" class="cpp">#include<iostream>
using namespace std;
int main()
{
int year;
char m;
cout<<"请输入年份和月份:";
cin>>year>>m;
switch(m)
{
case'1':
case'3':
case'5':
case'7':
case'8':
case'10':
case'12':cout<<"该月共有31天";break;
case'4':
case'6':
case'9':
case'11':cout<<"该月共有30天";break;
case'2':
{
if(year%4==0&&year%100!=0||year%400==0)
cout<<"该月共有29天";
else
cout<<"该月共有28天";
}
}
return 0;
}
二项目三
定期存款利息计算器
#include<iostream>
using namespace std;
int main()
{
int a,b;
double c,e;
cout<<"欢迎使用利息计算器!\n请输入存款金额:"<<endl;
cin>>a;
cout<<"======存款期限======\n1.3个月\n2.6个月\n3.一年\n4.两年\n5.三年\n6.五年\n";
cout<<"请输入存款利息代号"<<endl;
cin>>b;
switch(b)
{
case 1:c=a*0.0350*0.25;break;
case 2:c=a*0.0330*0.5;break;
case 3:c=a*0.0350*1;break;
case 4:c=a*0.0440*2;break;
case 5:c=a*0.0500*3;break;
case 6:c=a*0.0550*5;break;
default:cout<<" error\n";
}
e=a+c;
cout<<"到期利息为"<<c<<"元,本息合计共"<<e<<"元。"<<endl;
cout<<"感谢您的使用,欢迎下次光临!:";
return 0;
}
</pre><p>三项目四</p><p>分段函数求值</p><p></p><pre name="code" class="cpp">#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;
}