一、项目2 -本月有几天
#include <iostream>
using namespace std;
void main()
{
int a,b,c;
cout<<"输入年份和月份:"<<endl;
cin>>a>>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%4==0&&a%100!=0||a%400==0) c=29;
else c=28;
}
cout<<a<<"年"<<b<<"月共有"<<c<<"天。"<<endl;
}
二、项目3-定期存款利息计算器
#include <iostream>
using namespace std;
void main()
{
int a,b,c,d;
cout<<"欢迎使用利息计算器!\n请输入存款金额:";
cin>>a;
cout<<"======存款期限======\n1. 3个月\n2.6个月\n3. 一年\n4. 二年\n5. 三年\n6. 五年\n请输入存款期限代号:";
cin>>b;
switch(b)
{
case 1:c=a*3.10*0.01*0.25; break;
case 2:c=a*3.30*0.01*0.5; break;
case 3:c=a*3.50*0.01*1; break;
case 4:c=a*4.40*0.01*2; break;
case 5:c=a*5.00*0.01*3; break;
case 6:c=a*5.50*0.01*5; break;
}
d=a+c;
cout<<"到期利息为:"<<c<<"元,本息合计共"<<d<<"元。"<<endl;
cout<<"感谢您的使用,欢迎下次光临!"<<endl;
}
三、项目4-多分数段函数求值
#include <iostream>
#include <cmath>
using namespace std;
int main( )
{
double x,y;
cout<<"从键盘上输入x:";
cin>>x;
if(x>=10) y=1/(1+x);
else if(x>=6) y=sqrt(x+1);
else if(x>=2) y=x*x+1;
else y=x;
cout<<"算得y="<<y<<endl;
}