项目二
#include<iostream>
using namespace std;
int main()
{
int year,month,day;
cout<<"输入年份和月份:";
cin>>year>>month;
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
day=31;
if(month==4||month==6||month==9||month==11)
day=30;
if(month==2)
{
if(year%4==0&&year%100!=0||year%400==0)
day=29;
else
day=28;
}
cout<<"本月有"<<day<<"天。";
return 0;
}
项目三
#include<iostream>
using namespace std;
int main()
{
int x;
double deposit,y1,y2,y3,y4,y5,y6;
cout<<"欢迎使用利息计算器!"<<endl;
cout<<"请输入存款金额:"<<endl;
cin>>deposit;
cout<<" 存款期限 "<<endl;
cout<<"1.三个月\n2.六个月\n3.一年\n4.二年\n5.三年\n6.五年\n"<<endl;
cout<<"请输入存款期限的代号:"<<endl;
cin>>x;
y1=deposit*0.031*0.25;
y2=deposit*0.033*0.5;
y3=deposit*0.035*1;
y4=deposit*0.044*2;
y5=deposit*0.050*3;
y6=deposit*0.055*5;
switch(x)
{
case 1:cout<<"到期利息为:"<<y1<<"元,"<<"本息合计共:"<<y1+deposit<<"元。";break;
case 2:cout<<"到期利息为:"<<y2<<"元,"<<"本息合计共:"<<y2+deposit<<"元。";break;
case 3:cout<<"到期利息为:"<<y3<<"元,"<<"本息合计共:"<<y3+deposit<<"元。";break;
case 4:cout<<"到期利息为:"<<y4<<"元,"<<"本息合计共:"<<y4+deposit<<"元。";break;
case 5:cout<<"到期利息为:"<<y5<<"元,"<<"本息合计共:"<<y5+deposit<<"元。";break;
case 6:cout<<"到期利息为:"<<y6<<"元,"<<"本息合计共:"<<y6+deposit<<"元。";break;
default:cout<<"输入错误。\n";break;
}
cout<<"感谢您的使用,欢迎下次光临!";
return 0;
}
项目四
#include <iostream>
#include <cmath>
using namespace std;
int main( )
{
double x,y;
cout<<"输入x:";
cin>>x;
if(x>=10)
y=1/x+1;
else if(x>=6) y=sqrt(x+1);
else if(x>=2) y=x*x+1;
else y=x;
cout<<"y="<<y<<endl;
return 0;
}