C++第3次实验(基础班)作业报告

来源:互联网 发布:js判断是否为整数 编辑:程序博客网 时间:2024/05/29 14:02

一、问题及代码

#include<iostream>  
using namespace std;  
int main()  
{  
    int year,days,mouth,temp1=1,temp2=0;    
    cout<<"请输入年份:";  
    cin>>year;  
    if(year%400==0||(year%4==0&&year%100!=0))  
        temp2=1;  
    while(temp1)  
    {  
        cout<<"请输入月份:";  
        cin>>mouth;  
        if(!(mouth>0&&mouth<13))  
        {  
            cout<<"您输入的有误"<<endl;  
            continue;  
        }  
        temp1=0;  
    }  
    if(mouth==2)  
    {  
        days=28;  
        if(temp2)  
        {  
            days++;  
            cout<<"本月共有"<<days<<"天。\n";  
        }  
    }  
    else if(mouth%2==0)  
        cout<<"本月共有30天;\n";  
    else  
        cout<<"本月共有31天。\n";  
  
    return 0;  
}  

二、运行结果:


一、问题及代码

#include <iostream>    
using namespace std;    
int main()    
{    
    int t;    
    double a,b,c,d,e,f;    
    cout<<"欢迎使用利息计算器!"<<endl;    
    cout<<"======存款期限======"<<endl;    
    cout<<"1.  3个月"<<endl;    
    cout<<"2.  6个月"<<endl;    
    cout<<"3.  一年"<<endl;    
    cout<<"4.  二年"<<endl;    
    cout<<"5.  三年"<<endl;    
    cout<<"6.  五年"<<endl;    
    cout<<"请输入存款金额和存款期限的代号:";    
    cin>>a>>b;    
    t=(b<1)+(b<2)+(b<3)+(b<4)+(b<5)+(b<6);    
    switch (t)    
    {    
    case 0:    
        c=5,d=5.50;    
        break;    
    case 1:    
        c=3,d=5.00;    
        break;    
    case 2:    
        c=2,d=4.40;    
        break;    
    case 3:    
        c=1,d=3.50;    
        break;    
    case 4:    
        c=0.5,d=3.30;    
        break;    
    case 5:    
        c=0.25,d=3.10;    
    }    
    e=a*d*c/100;    
    f=e+a;    
    cout<<"到期利息为:"<<e<<"元,本息合计共"<<f<<"元。"<<endl;    
    cout<<"感谢您的使用,欢迎下次光临!"<<endl;  
}

二、运行结果:


一、问题及代码

#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 y=1/(x+1);
    cout<<"="<<y<<endl;    
    return 0;  
}  

二、运行结果:



0 0