c++作业3

代码

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	double x,y;
	cout<<"请输入一个实数:"<<endl;
	cin>>x;
	if(x<2)y=x;
	else if(2<=x && x<6)y=x*x+1;
	else if(6<=x && x<10)y=sqrt(x+1);
	else y=1/(x+1);
	cout<<y<<endl;
	return 0;
}

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

#include <iostream>
using namespace std;
int main()
{
    int b;
    double a,c,d;
    cout<<"欢迎使用利息计算器!"<<endl;
    cout<<"请输入存款金额:"<<endl;
    cin>>a;
    cout<<"======存款期限======\n1.3个月\n2.6个月\n3.一年\n4.两年\n5.三年\n6.五年"<<endl;
    cout<<"请输入存款期限的代号:"<<endl;
    cin>>b;
    switch(b)
    {
        case 1:c=a*0.031*0.25;break;
        case 2:c=a*0.033*0.50;break;
        case 3:c=a*0.035*1.00;break;
        case 4:c=a*0.044*2.00;break;
        case 5:c=a*0.050*3.00;break;
        case 6:c=a*0.055*5.00;break;
        default:cout<<"输入错误\n";break;
    }
    d=a+c;
    cout<<"到期利息为:"<<c<<"元,本息合计共"<<d<<"元。"<<endl;
    cout<<"感谢您的使用,欢迎下次光临!"<<endl;
    return 0;
}


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