项目2:本月有几天?
#include <iostream>
using namespace std;
int main( )
{
int IY,IM;
cout<<"请输入年月,系统将提示您该月的天数"<<endl;
cin>>IY;
cin>>IM;
if(IY%4==0)
{if(IY%100==0)
if(IY%400==0)
{if(IM==2)
cout<<"本月"<<29<<"天"<<endl;
else
if(IM==1||3||5||7||8||10||12)
cout<<"本月"<<31<<"天"<<endl;
else
cout<<"本月"<<30<<"天"<<endl;
}
else
if(IM==2)
cout<<"本月"<<28<<"天"<<endl;
else
{ if(IM==1||3||5||7||8||10||12)
cout<<"本月"<<31<<"天"<<endl;
else
cout<<"本月"<<30<<"天"<<endl;
}
else
if(IM==2)
cout<<"本月"<<29<<"天"<<endl;
else
{if(IM==1||3||5||7||8||10||12)
cout<<"本月"<<31<<"天"<<endl;
else
cout<<"本月"<<30<<"天"<<endl;
}
}
else
if(IM==2)
cout<<"本月"<<28<<"天"<<endl;
else
{ if(IM==1||3||5||7||8||10||12)
cout<<"本月"<<31<<"天"<<endl;
else
cout<<"本月"<<30<<"天"<<endl;
}
return 0;
}
项目3:定期存款利息计算器
#include <iostream>
using namespace std;
int main()
{
int x;
double money,accrual,num;
cout<<"欢迎使用定期存款利息计算器!""\n请输入存款金额:";
cin>>money;
cout<<"1:3个月\n2:6个月\n3:一年\n4:二年\n5:三年\n6:五年\n请选择1至6中的一项:";
cin>>x;
switch(x)
{
case 1:accrual=money*0.031*0.25;break;
case 2:accrual=money*0.033*0.5;break;
case 3:accrual=money*0.035*1;break;
case 4:accrual=money*0.044*2;break;
case 5:accrual=money*0.05*3;break;
case 6:accrual=money*0.055*5;break;
default:cout<<"错误!请选择1至6中的一项!"<<endl;break;
}
if(1<=x && x<=6)
{
num=accrual+money;
cout<<"到期应得利息:"<<accrual<<"本息和为:"<<num;
}
return 0;
}
项目4:多分数段函数求值
#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 y=1/(1+x);
}
cout<<"y"<<"="<<y<<endl;
return 0;
}