您的位置:首页 > 编程语言 > C语言/C++

c++作业3

2016-04-08 23:08 393 查看
一、本月有几天?

#include<iostream.h>
void main()
{
int year,month,day,y;
cout<<"输入年份";
cin>>year;
cout<<"输入月份";
cin>>month;
{
if((year%4==0 && year%100!=0)||year%400==0)
y=1;
else
y=0;
}
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:day=31;break;
case 4:
case 6:
case 9:
case 11:day=30;break;
case 2:day=28+y;break;
}
cout<<year<<"年"<<month<<"月"<<"有"<<day<<"天\n";
}


二、多分数段函数求值

#include<iostream.h>
#include<cmath>
void main()
{
double x,y;
cout<<"输入x的值:";
cin>>x;
if(x<2)
y=x;
else if(x>=2&&x<6)
y=x*x+1;
else if(x>=6&&x<10)
y=sqrt(x+1);
else
y=1/(x+1);
cout<<"y="<<y<<"\n";
}


三、定期存款利息计算器

#include<iostream.h>
void main()
{
int y,z;
double interest,sum,rate,term;
cout<<"欢迎使用利息计算器!";
cout<<"请输入存款金额:";
cin>>y;
cout<<"======存款期限======\n";
cout<<"1.3个月\n"<<"2.6个月\n"<<"3.一年\n"<<"4.二年\n"<<"5.三年\n"<<"6.五年\n";
cout<<"请输入存款期限代号:";
cin>>z;
switch(z)
{
case 1:term=0.25;rate=0.031;break;
case 2:term=0.50;rate=0.033;break;
case 3:term=1.00;rate=0.035;break;
case 4:term=2.00;rate=0.044;break;
case 5:term=3.00;rate=0.050;break;
case 6:term=5.00;rate=0.055;break;
}
interest=y*term*rate;
sum=y+interest;
cout<<"到期利息为:"<<interest<<"元,"<<"本息合计共"<<sum<<"元。\n";
cout<<"感谢您的使用,欢迎下次光临!\n";

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: