BANK(第二部)

来源:互联网 发布:unity3d 编程语言 编辑:程序博客网 时间:2024/04/25 13:55

上机内容:C++程序的编写和运行
上机目的:掌握简单C++程序的编辑、编译、连接和运行的一般过程
我的程序:

/*Copyright (c) 2013, 烟台大学计算机学院* All rights reserved.* 作    者:赵玲玲* 完成日期:2013 年 11 月 19 日* 版 本 号:v1.0* 输入描述: 无* 问题描述: 银行系统第二部,有更多功能* 程序输出: 略* 问题分析:密码输入判断正确性,选项的选择,选项的循环* 算法设计:略*/#include <iostream>using namespace std;bool pass();void work();void see_balance();void withdrawing_money();void deposit();void transfer_accounts();void change_pass();const int Rpass=123456;             //声明密码double balance=3000;                //账户余额int main(){    cout<<"欢迎来到赵家超级银行。"<<endl;    if(pass())    {        work();    }else    {        cout<<"笨蛋!密码错了!"<<endl;    }    return 0;}bool pass()                         //判断密码是否错误,用bool语句{    int pass;    bool bpass=false;    int i=1;    do    {        cout<<"请输入密码:";        cin>>pass;        i++;        if(Rpass==pass)        {            bpass=true;        }    }while(i<=3&&!bpass);            //有三次机会    return bpass;}//开始工作void work(){     int cChoice;     bool exit=false;     do                                   //循环,用do-while语句{cout<<endl<<"*  您可以办理下面的业务:"<<endl;cout<<"*  1.查询"<<endl;cout<<"*  2.取款"<<endl;cout<<"*  3.存款"<<endl;cout<<"*  4.转账"<<endl;cout<<"*  5.修改密码"<<endl;cout<<"*  0.退出"<<endl;cout<<"*  请输入(0-5):";cin>>cChoice;switch(cChoice)                  //用switch语句进行选择{case 1:see_balance();               //查询余额函数调用break;case 2:withdrawing_money();         //提款函数调用break;case 3:deposit();                   //存款函数调用break;case 4:transfer_accounts();         //转账函数调用break;            case 5:change_pass();               //修改密码函数调用break;case 0:exit=true;break;             //退出            default :                cout<<"输入有误!"<<endl;    //防止输入其他数字}}while(!exit);                       //根据贺老师的答案,需要bool语句来保持循环}//查询void see_balance(){    cout<<"您的余额为"<<balance<<"元。"<<endl;}//取款void withdrawing_money(){    int Iwithdrawing_money;    cout<<"请输入取款金额:";    cin>>Iwithdrawing_money;    if(Iwithdrawing_money>balance)    {        cout<<"您的余额已不足!"<<endl;    }else    {        cout<<"取款成功!剩余"<<balance-Iwithdrawing_money<<"元"<<endl;    }}//存款void deposit(){    int Ideposit;    cout<<"请输入存款金额。";    cin>>Ideposit;    cout<<"存款后,您的账户共有"<<Ideposit+balance<<"元。"<<endl;}//转账void transfer_accounts(){    int money,account;    cout<<"请输入转账金额:";    cin>>money;    if(money>balance)    {        cout<<"您的余额不足!"<<endl;    }else    {        cout<<"请输入对方账户:";        cin>>account;        cout<<"已成功转给"<<account<<"\t"<<balance-money<<"元。";    }}//修改密码void change_pass(){    int old_pass,new_pass,new_pass2;  cout<<"请输入原密码:";  cin>>old_pass;  if(old_pass==Rpass)  {      cout<<"请输入新密码:";      cin>>new_pass;      cout<<"请再输入一遍:";      cin>>new_pass2;      if(new_pass==new_pass2)      {          cout<<"密码修改成功!不要忘记哦"<<endl;      }else      {          cout<<"两次密码不一致,修改失败。"<<endl;      }  }else  {      cout<<"密码错误!修改失败!"<<endl;  }}运行结果: 
          
           心得体会:根据贺老师的答案做出的,看着这个还是挺简单的,估计自己做会很纠结 知识点总结:多个函数的调用