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

C++作业3

2016-04-12 23:50 537 查看
1.本月有几天

#include <iostream>
using namespace std;
int main( )
{
int year,month;
cout<<"请输入年份和月份:";
cin>>year>>month;
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
cout<<"本月有31天。";
else if(month==4||month==6||month==9||month==11)
cout<<"本月有30天。";
else if(month==2)
if(year%4==0&&year%100!=0||year%400==0)
cout<<"本月有29天。";
else
cout<<"本月有28天。";
else
cout<<"请输入正确的年份和月份!";
return 0;
}


2.定期存款利息计算器

#include<iostream.h>
void main()
{
double x,a;
cout<<"欢迎使用利息计算器!"<<endl;
cout<<"请输入存款金额:";
cin>>x;
cout<<"======存款期限及利率======"<<endl;
cout<<"   1.三个月。"<<endl;
cout<<"   2.六个月。"<<endl;
cout<<"   3.一年。  "<<endl;
cout<<"   4.两年。  "<<endl;
cout<<"   5.三年。  "<<endl;
cout<<"   6.五年。  "<<endl;
cout<<"请输入存款期限的代号:";
int y;
cin>>y;
switch(y)
{
case 1:a=x*0.031*0.25;break;
case 2:a=x*0.033*0.5;break;
case 3:a=x*0.035*1;break;
case 4:a=x*0.044*2;break;
case 5:a=x*0.05*3;break;
case 6:a=x*0.055*5;break;
}
cout<<"到期利息为:"<<a<<"元,本息合计共:"<<a+x<<"元。"<<endl;
cout<<"感谢您的使用,欢迎下次光临!";
}


3.多分数段函数求值

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
cout<<"请输入x的值:"<<endl;
int x,y;
cin>>x;
if(x<2)
y=x;
cout<<"y"<<endl;
else if(2<=x<6)
y=x*x+1;
cout<<"y"<<endl;
else if(6<=x<10)
y=sqrt(x+1);
cout<<"y"<<endl;
else
y=1/(x+1);
cout<<"y"<<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: