C++作业3

本文主要探讨了C++编程作业中的关键概念和技术,适合初学者理解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本月有几天

#include<iostream>
using namespace std;
int main()
{
   int y,m,d;
   cout<<" 请输入年月:"<<endl;//输入年月之间用空格分开
   cin>>y>>m;
   if(m==2)
   {
       if((y%400==0)||(y%4==0&&y%100!=0))
       d=29;
    else
       d=28;
   }
   if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)
   d=31;
   if(m==4||m==6||m==9||m==11)
   d=30;
   cout<<"这个月的天数:"<<d<<endl;
   return 0;
}

定期存款利息计算器

#include<iostream>
using namespace std;
int main()
{
    int a;
    double m,r,i,sum;
    cout<<"欢迎使用利息计算器!";
    cout<<"请输入存款金额:";
    cin>>m;
    cout<<"======存款期限======"<<endl;  
    cout<<"1.三个月"<<endl;  
    cout<<"2.六个月"<<endl;  
    cout<<"3.一年"<<endl;  
    cout<<"4.二年"<<endl;  
    cout<<"5.三年"<<endl;  
    cout<<"6.五年"<<endl;
	cout<<"请输入存款期限代号:";
    cin>>a;
    switch (a)  
    {  
      case 1:r=0.031*0.25;break;  
      case 2:r=0.033*0.5;break;  
      case 3:r=0.035*1;break;  
      case 4:r=0.044*2;break;  
      case 5:r=0.050*3;break;  
      case 6:r=0.055*5;break;  
    }
    i=m*r;
    sum=m+i;
    cout<<"到期利息为:"<<i<<"元,"<<"本息合计共"<<sum<<"元。"<<endl;  
    cout<<"感谢您的使用,欢迎下次光临!";  
    return 0; 
}
多分数段函数求值

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    double x,y;
	cout<<"请输入x:"<<endl;
	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;
	return 0;
}



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值