项目2:本月有几天?
#include <iostream>
using namespace std;
{
int y,m,d;
cout<<"请输入年份与月份(中间用空格隔开):";
cin>>y>>m>>"\n";
if(m==1||3||5||7||8||10||12)
cout<<"该月有31天";
else
{
switch(m)
case 4 :cout<<"该月有30天\n";break;
case 6 :cout<<"该月有30天\n";break;
case 9 :cout<<"该月有30天\n";break;
case 11 :cout<<"该月有30天\n";break;
case 2:
{ if(y%400==0||y%4==0&&y%100!=0)
cout<<"该月有29天\n";
else
cout<<"该月有28天\n";
}
cout<<"该月的天数为:"<<d;}
return 0;
}
项目3:定期存款利息计算器
#include<iostream>
using namespace std;
int main()
{
int money,x;
double w,y,time,sum;
cout<<"欢迎使用利息计算器!"<<"\n";
cout<<"请输入存款金额:"<<"\n";
cin>>money>>"\n";
cout<<"=======存款期限======="<<"\n";
cout<<"1. 3个月 2. 6个月 3. 一年4. 两年5. 三年6. 五年"<<endl;
cout<<"请输入存款期限的代号:"<<"\n";
cin>>x;
switch(x)
{
case 1: time=0.25;y=0.031;break;
case 2: time=0.50;y=0.033;break;
case 3: time=1;y=0.035;break;
case 4: time=2;y=0.044;break;
case 5: time=3;y=0.050;break;
case 6: time=5;y=0.055;break;
}
w=money*time*y;
sum=money+w;
cout<<"到期利息为:"<<w<<","<<"本息合计共:"<<sum<<"元"<<"\n";
cout<<"感谢您的使用,欢迎下次光临!"<<"\n";
return 0;
}
#include <cmath>
using namespace std;
int main()
{
int x,y;
cout<<"请输入x的值";
cin>>x>>"\n";
if (x<2)
y=x;
if(x>=2&&x<6)
y=x*x+1;
if(x>=6&&x<10)
y=sqrt(x+1);
if(x>=10)
y=1/x+1;
cout<<"y的值为:"<<y;
return 0;
}