c++第3次作业

项目二  本月有几天

#include <iostream>

using namespace std;

int main()
{
    int year,month,leap,t;
    cout<<"请输入年份和月份:"<<endl;
    cin>>year>>month;
    if((year%4==0&&year%100!=0)||(year%400==0))
        leap=true;
    else
        leap=false;
    if(leap==true)
        cout<<year<<"是闰年"<<endl;
    else
        cout<<year<<"不是闰年"<<endl;
        if(month==2&&leap==true)
            cout<<"本月有29天";
        if(month==2&&leap==false)
            cout<<"本月有28天";
        if(month==1)
            cout<<"本月有31天";
        if(month==3)
            cout<<"本月有31天";
        if(month==4)
            cout<<"本月有30天";
        if(month==5)
            cout<<"本月有31天";
        if(month==6)
            cout<<"本月有30天";
        if(month==7)
            cout<<"本月有31天";
        if(month==8)
            cout<<"本月有31天";
        if(month==9)
            cout<<"本月有30天";
        if(month==10)
            cout<<"本月有31天";
        if(month==11)
            cout<<"本月有30天";
        if(month==12)
            cout<<"本月有31天";
    return 0;
}

项目三  定期存款利息计算器

#include <iostream>

using namespace std;

int main()
{
    cout<<"欢迎使用利息计算器!";
    int a,b;
    double c,d;
    cout<<"请输入存款金额(元):"<<endl;
    cin>>a;
    cout<<"存款期限:\n,1.3个月\n2.6个月\n3.一年\n4.两年\n5.三年\n6.五年"<<endl;
    cout<<"请输入存款期限的代号:";
    cin>>b;
    switch(b)
    {
    case 1:c=a*0.0310*0.25;break;
    case 2:c=a*0.033*0.5;break;
    case 3:c=a*0.035*1;break;
    case 4:c=a*0.044*2;break;
    case 5:c=a*0.05*3;break;
    case 6:c=a*0.055*5;break;
    default:cout<<"error!";break;
    }
    d=a+c;
    cout<<"到期利息为:"<<c<<endl;
    cout<<"本息和共计:"<<d<<endl;
    cout<<"感谢您的使用,欢迎下次光临!";
    return 0;
}

项目四 多分数段函数求值

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    double x,y;
    cout<<"请输入x的值:";
    cin>>x;
    if(x<2)
            cout<<"y="<<x;
    else if(2<=x&&x<6)
            cout<<"y="<<(x*x+1);
    else if(6<=x&&x<10)
            cout<<"y="<<sqrt(x+1);
    else
            cout<<"y="<<1/(x+1);
    return 0;
}



你可能感兴趣的:(c++第3次作业)