项目二:本月有几天?
一、问题及代码
#include<iostream.h>
int main()
{
int year,mon;
cout<<"请输入年份和月份"<<endl;
cin>>year>>mon;
if(mon==2)
{
if((year%4==0 && year%100!=0)||year%400==0)
cout<<"本月有29天"<<endl;
else
cout<<"本月有28天"<<endl;
}
else if(mon==1||mon==3||mon==5||mon==7||mon==8||mon==10||mon==12)
{
cout<<"本月有31天"<<endl;
}
else
cout<<"本月有30天"<<endl;
return 0;
}
项目三:定期存款利息计算器
一、问题及代码
#include<iostream.h>
int main()
{
double money,interest,sum;
int a;
cout<<"欢迎使用利息计算器!"<<endl<<"请输入存款金额:";
cin>>money;
cout<<"======存款期限======"<<endl<<"1,3个月"<<endl;
cout<<"2,6个月"<<endl<<"3,一年"<<endl;
cout<<"4,两年"<<endl<<"5,三年"<<endl<<"6,五年"<<endl;
cout<<"请输入存款期限的代号";
cin>>a;
switch(a)
{
case(1):interest=money*0.031*(1.0/4);
break;
case(2):interest=money*0.033*0.5;
break;
case(3):interest=money*0.035;
break;
case(4):interest=money*0.044*2;
break;
case(5):interest=money*0.05*3;
break;
case(6):interest=money*0.055*5;
break;
default :cout<<"输入错误";
interest=0;
break;
}
sum=money+interest;
cout<<"到期利息为"<<interest<<",元 本息合计共"<<sum<<"元。"<<endl;
cout<<"感谢您的使用,欢迎下次光临!";
return 0;
}
项目四:多分数段函数求值
一、问题及代码
#include<iostream.h>
#include<math.h>
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;
return 0;
}