第三次作业

* 文件名称: 年份月份天数
* 作    者: 张吉瑞  
* 完成日期:    2017  年  3   月   22 日  
* 版 本 号:v1.0  
* 对任务及求解方法的描述部分: 
* 输入描述:   
* 问题描述: 我的第5个C++程序,熟悉程序的编辑、运行过程 
* 程序输出:  天数29 
* 问题分析:  
* 算法设计:   
*/  
一、一个月有多少天
#include<iostream>
using namespace std;
int main()
{
    int month,day,year;
	cout<<"请输入年份,月份:"<<endl;
	cin>>year>>month;
if    ((year%4==0&&year%100!=0)||year%400==0)
{	if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
			day=31;
		if(month==2)
		day=29;
		else day=30;}
else
{ if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
			day=31;
	if(month==2) day=28;
	else day=30;}
cout<<"天数为:"<<day<<endl;
return 0;
}


二、存款利率

#include<iostream>
using namespace std;
void main()
{
	int m,x;
	cout<<"欢迎使用利息计算器\n";
	cout<<"请输入存款金额=";
	cin>>m;
	cout<<"==========存款期限===========\n";
    cout<<"1、3个月\n";
	cout<<"2、6个月\n";
	cout<<"3、一年\n";
	cout<<"4、两年\n";
	cout<<"5、三年\n";
	cout<<"6、五年\n";
	cout<<"请输入存款期限代号:";
	cin>>x;
	switch(x)
	{
	double a,z;
	case 1:a=m*0.031*0.25,z=m+a;
		cout<<"到期利息:"<<a<<"元,本息合计共:"<<z<<"元。"<<endl;break;
	case 2:a=m*0.033*0.5,z=m+a;
        cout<<"到期利息:"<<a<<"元,本息合计共:"<<z<<"元。"<<endl;break;
	case 3:a=m*0.035*1,z=m+a;
        cout<<"到期利息:"<<a<<"元,本息合计共:"<<z<<"元。"<<endl;break;
	case 4:a=m*0.044*2,z=m+a;
        cout<<"到期利息:"<<a<<"元,本息合计共:"<<z<<"元。"<<endl;break;
	case 5:a=m*0.05*3,z=m+a;
        cout<<"到期利息:"<<a<<"元,本息合计共:"<<z<<"元。"<<endl;break;
	case 6:a=m*0.055*5,z=m+a;
        cout<<"到期利息:"<<a<<"元,本息合计共:"<<z<<"元。"<<endl;break;
	default:cout<<"error\n";
	}
	cout<<"感谢您的使用,欢迎下次光临!\n";
}

三、多分段函数求值

#include<iostream>
#include<cmath>
using namespace std;
void main()
{
	double x,y;
	cout<<"请输入x=";
	cin>>x;
	if(x<2)
		y=x;
	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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值