C++作业3

来源:互联网 发布:正装衬衫 知乎 编辑:程序博客网 时间:2024/06/15 04:10

一.本月有几天

#include <iostream>  using namespace std;  int main() {     int year,month,day;      cout<<"请您分别输入年份和月份:";      cin>>year>>month;switch(month){          case 1:            case 3:            case 5:            case 7:            case 8:            case 10:            case 12:  cout<<"本月天数为31天";break;            case 4:            case 6:            case 9:            case 11:cout<<"本月天数为30天";break;            case 2:{  if((year%4==0&&year%100!=0)||(year%400==0))      cout<<"本月天数为29天";  else  cout<<"本月天数为28天";         }   break;}     return 0;}
二.定期存款利息计算器

#include <iostream>using namespace std;int main(){    int money,number;    double year,s,m,n;    cout<<"欢迎使用利息计算器\n";    cout<<"请输入存款金额:";    cin>>money;    cout<<"请输入存款期限代号:\n1.三个月\n2.六个月\n3.一年\n4.两年\n5.三年\n6.五年\n";    cin>>number;    switch(number)    {        case 1:year=0.25;s=0.031;break;        case 2:year=0.5;s=0.033;break;        case 3:year=1;s=0.035;break;        case 4:year=2;s=0.044;break;        case 5:year=3;s=0.05;break;        case 6:year=5;s=0.055;break;        default:cout<<"不好意思,您的输入有误!\n";    }    m=money*s*year;    n=money+l;    cout << "到期利息为" <<m<<"本息合计共"<<n<< endl;    return 0;}
三.多分数段函数的求值
#include<iostream>#include<cmath>using namespace std;int main(){double x,y;cout<<"请输入x的值:";cin>>x;if(x<2)y=x;else if(x<6)y=x*x+1;else if(x<10)y=sqrt(x+1);else if(x>=10)y=1/(x+1);cout<<"输出y的值为:"<<y;return 0;}



0 0
原创粉丝点击