首页 > 编程 > C++ > 正文

C++第二次实验项目3、5

2019-11-06 07:54:25
字体:
来源:转载
供稿:网友
一、问题及代码二、运行结果三、心得体会四、知识点总结上机内容:C++上机目的:掌握简单C++程序的编写和运行过程项目3代码:
/* *文件名称:Exl-1.cpp *作者:周世豪 *完成日期:2017年3月3日 *版本号:v1.0 *对任务求解方法的描述部分:略*输入描述:我的第三个C++程序,熟悉博客的写法 *程序输出:自助机的页面*问题分析:略*算法分析:运用switch语句*/#include<iostream>using namespace std;int main(){    int a;    double iInterest,n,iMoney;    cout<<"欢迎使用利息计算器!"<<endl;    cout<<"请输入存款金额:";    cin>>iMoney;    cout<<"====存款期限====/n"<<"1.3个月/n"<<"2.6个月/n"<<"3.一年/n"<<"4.二年/n"<<"5.三年/n"<<"6.五年/n"<<endl;    cout<<"请输入存款期限的代号:";    cin>>a;    switch(a)    {        case 1: iInterest=iMoney*0.0310*.25;n=iInterest+iMoney;break;        case 2: iInterest=iMoney*0.0330*.5;n=iInterest+iMoney;break;        case 3: iInterest=iMoney*0.0350*1;n=iInterest+iMoney;break;        case 4: iInterest=iMoney*0.0440*2;n=iInterest+iMoney;break;        case 5: iInterest=iMoney*0.0500*3;n=iInterest+iMoney;break;        case 6: iInterest=iMoney*0.0550*5;n=iInterest+iMoney;break;        default :cout<<"error"<<endl;    }    cout<<"到期利息为:"<<iInterest<<"元,"<<"本息合计共"<<n<<"元。"<<endl;    cout<<"感谢您的使用,欢迎下次光临!"<<endl;    return 0;}运行结果心得体会       switch语句思路清晰,但在最后输出时想用C中PRitnf("利息有%lf元",iInterest);之类来表达,发现不行。知识点总结       switch语句的用法项目5代码:
/* *文件名称:Exl-1.cpp *作者:周世豪 *完成日期:2017年3月3日 *版本号:v1.0 *对任务求解方法的描述部分:对第一和最后一行单独输出;中间的就按行输出*输入描述:我的第四个C++程序,熟悉博客的写法 *程序输出:星号图*问题分析:运用for循环输出星号图,该星号图中有由空格组成的三角形*算法分析:略 */#include<iostream>using namespace std;int main(){    int i,j,n;    cin>>n;    for(i=0;i<n;i++)    cout<<" ";    cout<<"*"<<endl;    for(i=1;i<n-1;i++)    {        for(j=0;j<n-i;j++)            cout<<" ";            cout<<"*";        for(j=0;j<2*i-1;j++)            cout<<" ";            cout<<"*";            cout<<endl;    }    cout<<" ";    for(i=0;i<2*n-1;i++)        cout<<"*";        cout<<endl;    return 0;}运行结果心得体会       有难度,想了好久。算法能力不行知识点总结       for()循环的用法。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选