c++第三次作业

一、利息计算器
#include <iostream.h>
void main()
{
    int  a;
    double b, c, d, f;
    cout << "欢迎使用利息计算器!"<<"\n";
    cout << "请输入存款金额:";
    cin >> b;
    cout << "======存款期限======" << "\n";
    cout << "1. 3个月 " << "\n";
    cout << "2. 6个月" << "\n";
    cout << "3. 一年 " << "\n";
    cout << "4. 二年" << "\n";
    cout << "5. 三年" << "\n";
    cout << "6. 五年" << "\n";
    cout << "请输入存款期限的代号:";
    cin >> a;
    if (a>=1 && a <=6)
    {
        switch(a)
        {
        case 1:
            c = 0.25;
            d = 0.031;
            break;
        case 2:
            c = 0.5;
            d = 0.033;
            break;
        case 3:
            c = 1;
            d = 0.035;
            break;
        case 4:
            c = 2;
            d = 0.044;
            break;
        case 5:
            c = 3;
            d = 0.05;
            break;
        case 6:
            c = 5;
            d = 0.055;
            break;
        }
        f = b * c * d;
        cout << "到期利息为:" << f << "元,本息合计共"<< f + b <<"元。"<<"\n";
    }
    else
        cout << "选择存款类型错误!"<<"\n";
    cout << "感谢您的使用,欢迎下次光临!"<<"\n";
}


运行结果:

二、多分数段函数求值

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


 

#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;
}

运行结果


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值