c++作业3

来源:互联网 发布:jennifer lopez知乎 编辑:程序博客网 时间:2024/06/05 16:16

一.问题及代码

/**文件名称:EX1-1.CPP*作       者:李东辉*完成时间:2017年3月21日*版  本  号:v1.0*对任务及求解方法的描述部分:*输入描述:*问题描述:*程序输出:*问题分析:*算法设计:*/#include<iostream>using namespace std;int main()     int x;     cin>>x;     if(x<2)     cout<<"y="<<x<<endl;     if(2<=x&&x<6)     cout<<"y="<<x2<<endl;     if(6<=x&&x<10)     cout<<"y="<<"sprt(x+1)"<<endl;     if(x>=10)     cout<<"y="<<1/x+1<<endl;     return 0;}

二.运行结果


一.问题及代码
#include<iostream.h>void main(){   int xiangmu;      double JE,lixi,ze;      cout<<"欢迎使用利息计算器"<<endl;      cout<<"请输入存款金额:"<<endl;      cin>>JE;      cout<<"======存款期限======"<<endl;      cout<<"1、3个月\n";      cout<<"2、6个月\n";      cout<<"3、一年\n";      cout<<"4、两年\n";      cout<<"5、三年\n";      cout<<"6、五年\n";      cout<<"请输入存款期限代号:"<<endl;      cin>>xiangmu;      switch(xiangmu){      case 1:lixi=JE*0.031*0.25;ze=JE+lixi;break;//年利率:0.031      case 2:lixi=JE*0.033*0.5;ze=JE+lixi;break;//年利率:0.033      case 3:lixi=JE*0.035*1;ze=JE+lixi;break;//年利率:0.035      case 4:lixi=JE*0.044*2;ze=JE+lixi;break;//年利率:0.044      case 5:lixi=JE*0.05*3;ze=JE+lixi;break;//年利率:0.05      case 6:lixi=JE*0.055*5;ze=JE+lixi;break;//年利率:0.055      default:cout<<"error"<<endl; }     cout<<"到期利息为:"<<lixi<<endl;      cout<<"本息合计共:"<<ze<<endl;   cout<<"感谢您的使用,欢迎下次光临!"<<endl;}

二.运行结果

一.问题及代码
#include<iostream>using namespace std;int main(){int year,month,day;cout<<"请输入年份:\n";        cout<<"请输入月份:\n";        cin>>year>>month;if(year%4==0&&year%100!=0||year%400==0){        if(month==2)        day=29;else if(month==4||month==6||month==9||month==11)        day=30;else day=31;}        else{        if(month==2)        day=28;        else if(month==4||month==6||month==9||month==11)        day=30;else         day=31;}cout<<"本月的天数是:"<<day<<endl;return 0;}


二.运行结果




0 0
原创粉丝点击