c++作业3
2016-04-12 17:05
267 查看
项目2:本月有几天?
项目3:定期存款利息计算器
项目4:多分数段函数求值
#include <iostream.h> void main() { int year,month; cout<<"请输入年份和月份:"<<endl; cin>>year>>month; if(month==2) { if(year%4==0&&year%100!=0||year%400==0) cout<<month<<"月的天数为29天"<<endl; else cout<<month<<"月的天数为28天"<<endl; } else if(month==4||month==6||month==9||month==11) cout<<month<<"月的天数为30天"<<endl; else cout<<month<<"月的天数为31天"<<endl; }
项目3:定期存款利息计算器
#include<iostream.h> void main() { int a; double b, Dmoney,Dinterest,Dyear,Drate; cout<<"欢迎使用利息计算器!"<<'\n'; cout<<"请输入存款金额:"; cin>>Dmoney; cout<<"=====存款期限====="<<'\n'<<"1.3个月"<<'\n'<<"2.6个月"<<'\n'<<"3.一年"<<'\n'<<"4.二年"<<'\n'<<"5.三年"<<'\n'<<"6.六年"<<endl; cout<<"请输入存款期限的代码:"; cin>>a; switch(a) { case 1:Dyear=0.25;Drate=0.031;break; case 2:Dyear=0.5;Drate=0.033;break; case 3:Dyear=1;Drate=0.035;break; case 4:Dyear=2;Drate=0.044;break; case 5:Dyear=3;Drate=0.05;break; case 6:Dyear=6;Drate=0.055;break; default:cout<<"代码错误!"<<endl; } Dinterest=Dmoney*Dyear*Drate; b=Dinterest+Dmoney; cout<<"到期利息为:"<<Dinterest<<"元,本息合计共"<<b<<"元"<<'\n'; cout<<"感谢您的使用,欢迎下次光临"<<endl; }
项目4:多分数段函数求值
#include<iostream.h> #include<cmath> void 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; }